14 #ifndef _SPI_H_INCLUDED 15 #define _SPI_H_INCLUDED 21 #define SPI_HAS_TRANSACTION 1 24 #define SPI_HAS_NOTUSINGINTERRUPT 1 31 #define SPI_ATOMIC_VERSION 1 46 #define SPI_CLOCK_DIV4 0x00 47 #define SPI_CLOCK_DIV16 0x01 48 #define SPI_CLOCK_DIV64 0x02 49 #define SPI_CLOCK_DIV128 0x03 50 #define SPI_CLOCK_DIV2 0x04 51 #define SPI_CLOCK_DIV8 0x05 52 #define SPI_CLOCK_DIV32 0x06 54 #define SPI_MODE0 0x00 55 #define SPI_MODE1 0x04 56 #define SPI_MODE2 0x08 57 #define SPI_MODE3 0x0C 59 #define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR 60 #define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR 61 #define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR 65 #define SPI_AVR_EIMSK EIMSK 67 #define SPI_AVR_EIMSK GICR 69 #define SPI_AVR_EIMSK GIMSK 75 if (__builtin_constant_p(clock)) {
113 if (__builtin_constant_p(clock)) {
114 if (clock >= F_CPU / 2) {
116 }
else if (clock >= F_CPU / 4) {
118 }
else if (clock >= F_CPU / 8) {
120 }
else if (clock >= F_CPU / 16) {
122 }
else if (clock >= F_CPU / 32) {
124 }
else if (clock >= F_CPU / 64) {
132 while (clockDiv < 6 && clock < clockSetting) {
146 spcr = _BV(SPE) | _BV(MSTR) | ((bitOrder ==
LSBFIRST) ? _BV(DORD) : 0) |
166 static void usingInterrupt(uint8_t interruptNumber);
168 static void notUsingInterrupt(uint8_t interruptNumber);
179 if (interruptMode > 0) {
184 if (interruptMode == 1) {
185 interruptSave = SPI_AVR_EIMSK;
186 SPI_AVR_EIMSK &= ~interruptMask;
191 interruptSave = sreg;
195 #ifdef SPI_TRANSACTION_MISMATCH_LED 196 if (inTransactionFlag) {
200 inTransactionFlag = 1;
203 SPCR = settings.
spcr;
204 SPSR = settings.
spsr;
217 while (!(SPSR & _BV(SPIF))) ;
221 union { uint16_t
val;
struct { uint8_t lsb; uint8_t msb; }; }
in, out;
223 if (!(SPCR & _BV(DORD))) {
226 while (!(SPSR & _BV(SPIF))) ;
230 while (!(SPSR & _BV(SPIF))) ;
235 while (!(SPSR & _BV(SPIF))) ;
239 while (!(SPSR & _BV(SPIF))) ;
245 if (count == 0)
return;
246 uint8_t *
p = (uint8_t *)buf;
248 while (--count > 0) {
249 uint8_t out = *(p + 1);
250 while (!(SPSR & _BV(SPIF))) ;
255 while (!(SPSR & _BV(SPIF))) ;
261 #ifdef SPI_TRANSACTION_MISMATCH_LED 262 if (!inTransactionFlag) {
266 inTransactionFlag = 0;
269 if (interruptMode > 0) {
275 if (interruptMode == 1) {
276 SPI_AVR_EIMSK = interruptSave;
281 SREG = interruptSave;
292 if (bitOrder ==
LSBFIRST) SPCR |= _BV(DORD);
293 else SPCR &= ~(_BV(DORD));
317 #ifdef SPI_TRANSACTION_MISMATCH_LED 318 static uint8_t inTransactionFlag;
static uint16_t transfer16(uint16_t data)
void init_AlwaysInline(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) __attribute__((__always_inline__))
void pinMode(uint8_t, uint8_t)
static uint8_t interruptMode
static void detachInterrupt()
SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode)
static uint8_t interruptSave
EIGEN_STRONG_INLINE iterator begin()
static void setBitOrder(uint8_t bitOrder)
void init_MightInline(uint32_t clock, uint8_t bitOrder, uint8_t dataMode)
static uint8_t transfer(uint8_t data)
static void transfer(void *buf, size_t count)
static void setDataMode(uint8_t dataMode)
static void endTransaction(void)
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
rp::arch::net::raw_serial __attribute__
static uint8_t initialized
void digitalWrite(uint8_t, uint8_t)
GLuint GLuint GLsizei count
static void beginTransaction(SPISettings settings)
static void attachInterrupt()
static uint8_t interruptMask
static void setClockDivider(uint8_t clockDiv)