25 #if !defined(BOARD_ATTINY) 26 #define USE_SPI_PREFETCH 34 Clock rate, uint8_t mode, Order order,
38 m_cs(cs, ((pulse & 0x01) == 0)),
42 | ((order & 0x1) << DORD)
44 | ((mode & 0x3) << CPHA)
45 | ((rate & 0x3) << SPR0)),
47 m_spsr(((rate & 0x04) != 0) << SPI2X)
70 #if defined(BOARD_ATTINYX4) || defined(BOARD_ATTINYX61) 73 #elif defined(BOARD_ATTINYX5) 79 Clock rate, uint8_t mode, Order order,
83 m_cs(cs, ((pulse & 0x01) == 0)),
91 m_usicr = (_BV(USIWM0) | _BV(USICS1) | _BV(USICLK) | _BV(USITC));
92 if (mode == 1 || mode == 2) m_usicr |= _BV(USICS0);
125 #if defined(USE_SPI_PREFETCH) 130 uint8_t* dp = (uint8_t*) buf;
134 uint8_t* tp = dp + 1;
146 uint8_t* dp = (uint8_t*) dst;
147 const uint8_t* sp = (
const uint8_t*) src;
148 uint8_t data = *sp++;
151 uint8_t* tp = dp + 1;
163 uint8_t* dp = (uint8_t*) buf;
173 const uint8_t* sp = (
const uint8_t*) buf;
174 uint8_t data = *sp++;
187 const uint8_t* sp = (
const uint8_t*) buf;
188 uint8_t data = pgm_read_byte(sp++);
191 data = pgm_read_byte(sp++);
203 uint8_t* bp = (uint8_t*) buf;
214 uint8_t* dp = (uint8_t*) dst;
215 const uint8_t* sp = (
const uint8_t*) src;
216 do *dp++ =
transfer(*sp++);
while (--count);
223 uint8_t* bp = (uint8_t*) buf;
224 do *bp++ =
transfer(0);
while (--count);
231 const uint8_t* bp = (
const uint8_t*) buf;
232 do transfer(*bp++);
while (--count);
239 const uint8_t* bp = (
const uint8_t*) buf;
240 do transfer(pgm_read_byte(bp++));
while (--count);
258 uint8_t key =
lock(m_busy);
292 if (dev->m_irq !=
NULL) dev->m_irq->enable();
300 m_spcr = (m_spcr & ~(0x3 << SPR0)) | ((rate & 0x3) << SPR0);
301 m_spsr = (m_spsr & ~(1 << SPI2X)) | (((rate & 0x04) != 0) << SPI2X);
311 outs <<
PSTR(
"SPI::DIV2_CLOCK(") << F_CPU / 2000000.0;
314 outs <<
PSTR(
"SPI::DIV4_CLOCK(") << F_CPU / 4000000.0;
317 outs <<
PSTR(
"SPI::DIV8_CLOCK(") << F_CPU / 8000000.0;
320 outs <<
PSTR(
"SPI::DIV16_CLOCK(") << F_CPU / 16000000.0;
323 outs <<
PSTR(
"SPI::DIV32_CLOCK(") << F_CPU / 32000000.0;
326 outs <<
PSTR(
"SPI::DIV64_CLOCK(") << F_CPU / 64000000.0;
329 outs <<
PSTR(
"SPI::DIV128_CLOCK(") << F_CPU / 128000000.0;
332 outs <<
PSTR(
" MHz)");
uint8_t m_spsr
SPI/SPSR hardware status register.
#define bit_mask_clear(p, m)
Divide system clock by 4.
void acquire(Driver *dev)
uint8_t transfer_next(uint8_t data)
Interrupt::Handler * m_irq
Interrupt handler.
void set_clock(Clock rate)
Driver * m_next
List of drivers.
Divide system clock by 128.
IOStream & operator<<(IOStream &outs, SPI::Clock rate)
Divide system clock by 8.
void transfer_start(uint8_t data)
Divide system clock by 16.
uint8_t transfer(uint8_t data)
uint8_t m_spcr
SPI/SPCR hardware control register setting.
#define bit_write(c, p, b)
Divide system clock by 64.
Divide system clock by 32.
void write_P(const void *buf, size_t count)
#define bit_mask_set(p, m)
Divide system clock by 2.
void read(void *buf, size_t count)
Driver(Board::DigitalPin cs, Pulse pulse=DEFAULT_PULSE, Clock rate=DEFAULT_CLOCK, uint8_t mode=0, Order order=MSB_ORDER, Interrupt::Handler *irq=NULL)
void write(const void *buf, size_t count)