|
|
|
|
|
|
|
|
inline static uint16_t transfer16(uint16_t data) { |
|
|
inline static uint16_t transfer16(uint16_t data) { |
|
|
union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } in, out; |
|
|
union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } in, out; |
|
|
in.val = data; |
|
|
in.val = data; |
|
|
if (!(SPCR & _BV(DORD))) { |
|
|
|
|
|
SPDR = in.msb; |
|
|
|
|
|
while (!(SPSR & _BV(SPIF))) ; |
|
|
|
|
|
out.msb = SPDR; |
|
|
|
|
|
|
|
|
if ((SPCR & _BV(DORD))) { |
|
|
SPDR = in.lsb; |
|
|
SPDR = in.lsb; |
|
|
|
|
|
asm volatile("nop"); |
|
|
while (!(SPSR & _BV(SPIF))) ; |
|
|
while (!(SPSR & _BV(SPIF))) ; |
|
|
out.lsb = SPDR; |
|
|
out.lsb = SPDR; |
|
|
} else { |
|
|
|
|
|
SPDR = in.lsb; |
|
|
|
|
|
|
|
|
SPDR = in.msb; |
|
|
|
|
|
asm volatile("nop"); |
|
|
while (!(SPSR & _BV(SPIF))) ; |
|
|
while (!(SPSR & _BV(SPIF))) ; |
|
|
out.lsb = SPDR; |
|
|
|
|
|
|
|
|
out.msb = SPDR; |
|
|
|
|
|
} else { |
|
|
SPDR = in.msb; |
|
|
SPDR = in.msb; |
|
|
|
|
|
asm volatile("nop"); |
|
|
while (!(SPSR & _BV(SPIF))) ; |
|
|
while (!(SPSR & _BV(SPIF))) ; |
|
|
out.msb = SPDR; |
|
|
out.msb = SPDR; |
|
|
|
|
|
SPDR = in.lsb; |
|
|
|
|
|
asm volatile("nop"); |
|
|
|
|
|
while (!(SPSR & _BV(SPIF))) ; |
|
|
|
|
|
out.lsb = SPDR; |
|
|
} |
|
|
} |
|
|
return out.val; |
|
|
return out.val; |
|
|
} |
|
|
} |