Skip to content

Commit 25ae225

Browse files
James Fosterianfixes
James Foster
authored andcommitted
Additional __ARDUINO_CI_SFR_MOCK commits (squashed)
1 parent cbccf6a commit 25ae225

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

Diff for: SampleProjects/TestSomething/test/defines.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ unittest(SFR_IO8)
1919
// this tests that directly
2020
auto foo = &DDRE; // avoid compiler warning by using the result of an expression
2121
}
22+
23+
unittest(read_write)
24+
{
25+
_SFR_IO8(1) = 0x11;
26+
_SFR_IO8(2) = 0x22;
27+
assertEqual((int) 0x11, (int) _SFR_IO8(1));
28+
assertEqual((int) 0x22, (int) _SFR_IO8(2));
29+
assertEqual((int) 0x2211, (int) _SFR_IO16(1));
30+
}
2231
#endif
2332

2433
unittest_main()

Diff for: SampleProjects/TestSomething/test/godmode.cpp

+20-2
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,35 @@ unittest(spi) {
176176
// 8-bit
177177
state->reset();
178178
state->spi.dataIn = "LMNO";
179+
SPI.beginTransaction(SPISettings(14000000, LSBFIRST, SPI_MODE0));
179180
uint8_t out8 = SPI.transfer('a');
181+
SPI.endTransaction();
180182
assertEqual("a", state->spi.dataOut);
181183
assertEqual('L', out8);
182184
assertEqual("MNO", state->spi.dataIn);
183185

184-
// 16-bit
186+
// 16-bit MSBFIRST
185187
union { uint16_t val; struct { char lsb; char msb; }; } in16, out16;
186188
state->reset();
187189
state->spi.dataIn = "LMNO";
188190
in16.lsb = 'a';
189191
in16.msb = 'b';
192+
SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0));
190193
out16.val = SPI.transfer16(in16.val);
194+
SPI.endTransaction();
195+
assertEqual("NO", state->spi.dataIn);
196+
assertEqual('M', out16.lsb);
197+
assertEqual('L', out16.msb);
198+
assertEqual("ba", state->spi.dataOut);
199+
200+
// 16-bit LSBFIRST
201+
state->reset();
202+
state->spi.dataIn = "LMNO";
203+
in16.lsb = 'a';
204+
in16.msb = 'b';
205+
SPI.beginTransaction(SPISettings(14000000, LSBFIRST, SPI_MODE0));
206+
out16.val = SPI.transfer16(in16.val);
207+
SPI.endTransaction();
191208
assertEqual("NO", state->spi.dataIn);
192209
assertEqual('L', out16.lsb);
193210
assertEqual('M', out16.msb);
@@ -197,14 +214,15 @@ unittest(spi) {
197214
state->reset();
198215
state->spi.dataIn = "LMNOP";
199216
char inBuf[6] = "abcde";
217+
SPI.beginTransaction(SPISettings(14000000, LSBFIRST, SPI_MODE0));
200218
SPI.transfer(inBuf, 4);
219+
SPI.endTransaction();
201220

202221
assertEqual("abcd", state->spi.dataOut);
203222
assertEqual("LMNOe", String(inBuf));
204223
}
205224

206225

207-
208226
#ifdef HAVE_HWSERIAL0
209227

210228
void smartLightswitchSerialHandler(int pin) {

Diff for: cpp/arduino/Godmode.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,4 @@ TwoWire Wire = TwoWire();
119119
EEPROMClass EEPROM;
120120
#endif
121121

122-
volatile long long __ARDUINO_CI_SFR_MOCK[1024];
122+
volatile uint8_t __ARDUINO_CI_SFR_MOCK[1024];

Diff for: cpp/arduino/avr/io.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@
9696
#ifndef _AVR_IO_H_
9797
#define _AVR_IO_H_
9898

99-
// hardware mocks
99+
#include <stdint.h>
100100

101+
// hardware mocks
101102
// this set of macros is all we need from the sfr file
102103
extern volatile long long __ARDUINO_CI_SFR_MOCK[1024];
103104
#define _SFR_IO8(io_addr) (*(volatile uint8_t *)(__ARDUINO_CI_SFR_MOCK + io_addr))

0 commit comments

Comments
 (0)