File tree 3 files changed +44
-0
lines changed
SampleProjects/TestSomething/test
3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
8
8
## [ Unreleased]
9
9
### Added
10
10
- Add ` __AVR__ ` to defines when compiling
11
+ - Add support for ` diditalPinToPort() ` , ` digitalPinToBitMask() ` , and ` portOutputRegister() `
11
12
12
13
### Changed
13
14
- Move repository from https://github.com/ianfixes/arduino_ci to https://github.com/Arduino-CI/arduino_ci
Original file line number Diff line number Diff line change
1
+ #include < ArduinoUnitTests.h>
2
+ #include < Arduino.h>
3
+
4
+ // https://github.com/arduino-libraries/Ethernet/blob/master/src/utility/w5100.h#L337
5
+
6
+ unittest (test)
7
+ {
8
+ uint8_t ss_pin = 12 ;
9
+ uint8_t ss_port = digitalPinToPort (ss_pin);
10
+ assertEqual (12 , ss_port);
11
+ uint8_t *ss_pin_reg = portOutputRegister (ss_port);
12
+ assertEqual (GODMODE ()->pMmapPort (ss_port), ss_pin_reg);
13
+ uint8_t ss_pin_mask = digitalPinToBitMask (ss_pin);
14
+ assertEqual (1 , ss_pin_mask);
15
+
16
+ assertEqual ((int ) 1 , (int ) *ss_pin_reg); // verify initial value
17
+ *(ss_pin_reg) &= ~ss_pin_mask; // set SS
18
+ assertEqual ((int ) 0 , (int ) *ss_pin_reg); // verify value
19
+ *(ss_pin_reg) |= ss_pin_mask; // clear SS
20
+ assertEqual ((int ) 1 , (int ) *ss_pin_reg); // verify value
21
+ }
22
+
23
+ unittest_main ()
Original file line number Diff line number Diff line change @@ -30,6 +30,14 @@ unsigned long micros();
30
30
#define NUM_SERIAL_PORTS 0
31
31
#endif
32
32
33
+ // These definitions allow the following to compile (see issue #193):
34
+ // https://github.com/arduino-libraries/Ethernet/blob/master/src/utility/w5100.h:341
35
+ // add padding because some boards (__MK20DX128__) offset from the given address
36
+ #define MMAP_PORTS_SIZE (MOCK_PINS_COUNT + 256 )
37
+ #define digitalPinToBitMask (pin ) (1 )
38
+ #define digitalPinToPort (pin ) (pin)
39
+ #define portOutputRegister (port ) (GODMODE()->pMmapPort (port))
40
+
33
41
class GodmodeState {
34
42
private:
35
43
struct PortDef {
@@ -43,6 +51,8 @@ class GodmodeState {
43
51
uint8_t mode;
44
52
};
45
53
54
+ uint8_t mmapPorts[MMAP_PORTS_SIZE];
55
+
46
56
static GodmodeState* instance;
47
57
48
58
public:
@@ -87,12 +97,19 @@ class GodmodeState {
87
97
spi.readDelayMicros = 0 ;
88
98
}
89
99
100
+ void resetMmapPorts () {
101
+ for (int i = 0 ; i < MMAP_PORTS_SIZE; ++i) {
102
+ mmapPorts[i] = 1 ;
103
+ }
104
+ }
105
+
90
106
void reset () {
91
107
resetClock ();
92
108
resetPins ();
93
109
resetInterrupts ();
94
110
resetPorts ();
95
111
resetSPI ();
112
+ resetMmapPorts ();
96
113
seed = 1 ;
97
114
}
98
115
@@ -112,6 +129,9 @@ class GodmodeState {
112
129
return instance->micros ;
113
130
}
114
131
132
+ uint8_t * pMmapPort (uint8_t port) { return &mmapPorts[port]; }
133
+ uint8_t mmapPortValue (uint8_t port) { return mmapPorts[port]; }
134
+
115
135
// C++ 11, declare as public for better compiler error messages
116
136
GodmodeState (GodmodeState const &) = delete ;
117
137
void operator =(GodmodeState const &) = delete ;
You can’t perform that action at this time.
0 commit comments