Skip to content

Commit 7d7d810

Browse files
matthijskooijmanianfixes
authored andcommitted
Make SPI.h work on non-AVR unittests
The SPI library contains some code to read the SPCR register to determine the byte order of 16-bit transfers, presumably because there is no official Arduino API to set it, so sketches had to rely on setting this register directly. By reading it, the SPI unittest implementation can detect how to emulate multibyte transfers. However, this register is only defined by avr/io.h when the unittest emulates an AVR platform, so this code would fail to compile on other platforms. This adds a preprocessor guard around this code, defaulting to the lsb-first, which is also the hardware and Arduino default. This fixes Arduino-CI#140.
1 parent 42bc4fe commit 7d7d810

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: cpp/arduino/SPI.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,14 @@ class SPIClass: public ObservableDataStream {
9494
uint16_t transfer16(uint16_t data) {
9595
union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } in, out;
9696
in.val = data;
97+
#if defined(SPCR) && defined(DORD)
9798
if (!(SPCR & (1 << DORD))) {
9899
out.msb = transfer(in.msb);
99100
out.lsb = transfer(in.lsb);
100-
} else {
101+
}
102+
else
103+
#endif
104+
{
101105
out.lsb = transfer(in.lsb);
102106
out.msb = transfer(in.msb);
103107
}

0 commit comments

Comments
 (0)