31
31
32
32
/* Global variables */
33
33
34
+ bool test_executed = false ;
34
35
String last_test = " " ;
35
- int8_t uart1_rx_pin;
36
- int8_t uart1_tx_pin;
36
+ int8_t uart1_rx_pin = UART1_RX_DEFAULT ;
37
+ int8_t uart1_tx_pin = UART1_TX_DEFAULT ;
37
38
38
39
/* Callback functions */
39
40
@@ -59,13 +60,17 @@ void setUp(void) {
59
60
// This function is automatically called by unity after each test is run
60
61
void tearDown (void ) {
61
62
log_v (" Tearing down last test" );
62
- Serial1.print (last_test);
63
- Serial1.println (" test: This should not be printed" );
64
- Serial1.flush ();
63
+ if (test_executed) {
64
+ Serial1.print (last_test);
65
+ Serial1.println (" test: This should not be printed" );
66
+ Serial1.flush ();
67
+
68
+ Serial1.setPins (uart1_rx_pin, uart1_tx_pin);
69
+ uart_internal_loopback (1 , RX1);
70
+ delay (100 );
71
+ test_executed = false ;
72
+ }
65
73
66
- Serial1.setPins (uart1_rx_pin, uart1_tx_pin);
67
- uart_internal_loopback (1 , RX1);
68
- delay (100 );
69
74
Serial1.print (last_test);
70
75
Serial1.println (" test: This should be printed" );
71
76
Serial1.flush ();
@@ -75,35 +80,48 @@ void tearDown(void) {
75
80
/* These functions must only init the peripheral on the same pins and update "last_test" */
76
81
77
82
void gpio_test (void ) {
83
+ last_test = " GPIO" ;
84
+ test_executed = true ;
78
85
pinMode (uart1_rx_pin, INPUT);
79
86
pinMode (uart1_tx_pin, OUTPUT);
80
- last_test = " GPIO" ;
81
87
}
82
88
83
- #if SOC_SDM_SUPPORTED
84
89
void sigmadelta_test (void ) {
90
+ last_test = " SigmaDelta" ;
91
+ #if SOC_SDM_SUPPORTED
92
+ test_executed = true ;
85
93
if (!sigmaDeltaAttach (uart1_tx_pin, 312500 )) {
86
94
TEST_FAIL_MESSAGE (" SigmaDelta init failed" );
87
95
}
88
- last_test = " SigmaDelta" ;
89
- }
96
+ if (!sigmaDeltaAttach (uart1_rx_pin, 312500 )) {
97
+ TEST_FAIL_MESSAGE (" SigmaDelta init failed" );
98
+ }
90
99
#endif
100
+ }
91
101
92
- #if SOC_ADC_SUPPORTED
93
102
void adc_oneshot_test (void ) {
103
+ last_test = " ADC Oneshot" ;
104
+ #if SOC_ADC_SUPPORTED
105
+ test_executed = true ;
94
106
analogReadResolution (12 );
107
+ analogRead (A3);
95
108
analogRead (A4);
96
- last_test = " ADC Oneshot " ;
109
+ # endif
97
110
}
98
111
112
+ #if SOC_ADC_SUPPORTED
99
113
volatile bool adc_coversion_done = false ;
100
114
void ARDUINO_ISR_ATTR adcComplete () {
101
115
adc_coversion_done = true ;
102
116
}
117
+ #endif
103
118
104
119
void adc_continuous_test (void ) {
105
- uint8_t adc_pins[] = {A4};
106
- uint8_t adc_pins_count = 1 ;
120
+ last_test = " ADC Continuous" ;
121
+ #if SOC_ADC_SUPPORTED
122
+ test_executed = true ;
123
+ uint8_t adc_pins[] = {A3, A4};
124
+ uint8_t adc_pins_count = 2 ;
107
125
adc_continuos_data_t * result = NULL ;
108
126
109
127
analogContinuousSetWidth (12 );
@@ -121,78 +139,89 @@ void adc_continuous_test(void) {
121
139
}
122
140
123
141
analogContinuousStop ();
124
-
125
- last_test = " ADC Continuous" ;
126
- }
127
142
#endif
143
+ }
128
144
129
- #if SOC_DAC_SUPPORTED
130
145
void dac_test (void ) {
131
- dacWrite (DAC1, 255 );
132
146
last_test = " DAC" ;
133
- }
147
+ #if SOC_DAC_SUPPORTED
148
+ test_executed = true ;
149
+ dacWrite (DAC1, 255 );
150
+ dacWrite (DAC2, 255 );
134
151
#endif
152
+ }
135
153
136
- #if SOC_LEDC_SUPPORTED
137
154
void ledc_test (void ) {
155
+ last_test = " LEDC" ;
156
+ #if SOC_LEDC_SUPPORTED
157
+ test_executed = true ;
158
+ if (!ledcAttach (uart1_tx_pin, 5000 , 12 )) {
159
+ TEST_FAIL_MESSAGE (" LEDC init failed" );
160
+ }
138
161
if (!ledcAttach (uart1_rx_pin, 5000 , 12 )) {
139
162
TEST_FAIL_MESSAGE (" LEDC init failed" );
140
163
}
141
- last_test = " LEDC" ;
142
- }
143
164
#endif
165
+ }
144
166
145
- #if SOC_RMT_SUPPORTED
146
167
void rmt_test (void ) {
168
+ last_test = " RMT" ;
169
+ #if SOC_RMT_SUPPORTED
170
+ test_executed = true ;
147
171
if (!rmtInit (uart1_rx_pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000 )) {
148
172
TEST_FAIL_MESSAGE (" RMT init failed" );
149
173
}
150
174
if (!rmtInit (uart1_tx_pin, RMT_RX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000 )) {
151
175
TEST_FAIL_MESSAGE (" RMT init failed" );
152
176
}
153
- last_test = " RMT" ;
154
- }
155
177
#endif
178
+ }
156
179
157
- #if SOC_I2S_SUPPORTED
158
180
void i2s_test (void ) {
181
+ last_test = " I2S" ;
182
+ #if SOC_I2S_SUPPORTED
183
+ test_executed = true ;
159
184
I2SClass i2s;
160
185
161
186
i2s.setPins (uart1_rx_pin, uart1_tx_pin, -1 );
162
187
i2s.setTimeout (1000 );
163
188
if (!i2s.begin (I2S_MODE_STD, 16000 , I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO)) {
164
189
TEST_FAIL_MESSAGE (" I2S init failed" );
165
190
}
166
- last_test = " I2S" ;
167
- }
168
191
#endif
192
+ }
169
193
170
- #if SOC_I2C_SUPPORTED
171
194
void i2c_test (void ) {
195
+ last_test = " I2C" ;
196
+ #if SOC_I2C_SUPPORTED
197
+ test_executed = true ;
172
198
if (!Wire.begin (uart1_rx_pin, uart1_tx_pin)) {
173
199
TEST_FAIL_MESSAGE (" I2C init failed" );
174
200
}
175
- last_test = " I2C" ;
176
- }
177
201
#endif
202
+ }
178
203
179
- #if SOC_GPSPI_SUPPORTED
180
204
void spi_test (void ) {
181
- SPI.begin (uart1_rx_pin, uart1_tx_pin, -1 , -1 );
182
205
last_test = " SPI" ;
183
- }
206
+ #if SOC_GPSPI_SUPPORTED
207
+ test_executed = true ;
208
+ SPI.begin (uart1_rx_pin, uart1_tx_pin, -1 , -1 );
184
209
#endif
210
+ }
185
211
186
- #if SOC_TOUCH_SENSOR_SUPPORTED
187
212
void touch_test (void ) {
188
- touchRead (T1);
189
213
last_test = " Touch" ;
190
- }
214
+ #if SOC_TOUCH_SENSOR_SUPPORTED
215
+ test_executed = true ;
216
+ touchRead (T1);
217
+ touchRead (T2);
191
218
#endif
219
+ }
192
220
193
221
void eth_test (void ) {
194
- ETH.begin ();
195
222
last_test = " ETH" ;
223
+ test_executed = true ;
224
+ ETH.begin ();
196
225
}
197
226
198
227
/* Main functions */
@@ -204,56 +233,28 @@ void setup() {
204
233
Serial1.setPins (UART1_RX_DEFAULT, UART1_TX_DEFAULT);
205
234
Serial1.begin (115200 );
206
235
while (!Serial1) { delay (10 ); }
207
- Serial1.onReceive ([]() { onReceive_cb ();} );
236
+ Serial1.onReceive (onReceive_cb);
208
237
uart_internal_loopback (1 , RX1);
209
238
210
239
UNITY_BEGIN ();
211
240
212
- uart1_rx_pin = UART1_RX_DEFAULT;
213
- uart1_tx_pin = UART1_TX_DEFAULT;
214
-
215
241
RUN_TEST (gpio_test);
216
-
217
- #if SOC_SDM_SUPPORTED
218
242
RUN_TEST (sigmadelta_test);
219
- #endif
220
-
221
- #if SOC_LEDC_SUPPORTED
222
243
RUN_TEST (ledc_test);
223
- #endif
224
-
225
- #if SOC_RMT_SUPPORTED
226
244
RUN_TEST (rmt_test);
227
- #endif
228
-
229
- #if SOC_I2S_SUPPORTED
230
245
RUN_TEST (i2s_test);
231
- #endif
232
-
233
- #if SOC_I2C_SUPPORTED
234
246
RUN_TEST (i2c_test);
235
- #endif
236
-
237
- #if SOC_GPSPI_SUPPORTED
238
247
RUN_TEST (spi_test);
239
- #endif
240
-
241
- #if SOC_ADC_SUPPORTED
242
- uart1_tx_pin = A4;
248
+ uart1_tx_pin = A3;
249
+ uart1_rx_pin = A4;
243
250
RUN_TEST (adc_oneshot_test);
244
251
RUN_TEST (adc_continuous_test);
245
- #endif
246
-
247
- #if SOC_DAC_SUPPORTED
248
252
uart1_tx_pin = DAC1;
253
+ uart1_rx_pin = DAC2;
249
254
RUN_TEST (dac_test);
250
- #endif
251
-
252
- #if SOC_TOUCH_SENSOR_SUPPORTED
253
255
uart1_tx_pin = T1;
256
+ uart1_rx_pin = T2;
254
257
RUN_TEST (touch_test);
255
- #endif
256
-
257
258
RUN_TEST (eth_test);
258
259
259
260
UNITY_END ();
0 commit comments