55 */
66
77#include < unity.h>
8- #include " SPI.h"
8+
9+ #if SOC_I2S_SUPPORTED
10+ #include " ESP_I2S.h"
11+ #endif
12+
13+ #if SOC_I2C_SUPPORTED
914#include " Wire.h"
15+ #endif
16+
17+ #if SOC_GPSPI_SUPPORTED
18+ #include " SPI.h"
19+ #endif
20+
21+ #if SOC_SDMMC_HOST_SUPPORTED
22+ #include " SD_MMC.h"
23+ #endif
24+
25+ #if SOC_USB_OTG_SUPPORTED && (ARDUINO_USB_MODE == 0)
26+ #include " USB.h"
27+ #endif
28+
29+ #include " ETH.h"
30+
31+ /* Definitions */
32+
33+ #define UART1_RX_DEFAULT 4
34+ #define UART1_TX_DEFAULT 5
1035
1136/* Global variables */
1237
1338String last_test = " " ;
39+ int8_t uart1_rx_pin;
40+ int8_t uart1_tx_pin;
1441
1542/* Unity functions */
1643
1744// This function is automatically called by unity before each test is run
18- void setUp (void ) {}
45+ void setUp (void ) {
46+ Serial1.setPins (uart1_rx_pin, uart1_tx_pin);
47+ uart_internal_loopback (1 , SOC_RX0);
48+ delay (100 );
49+ }
1950
2051// This function is automatically called by unity after each test is run
2152void tearDown (void ) {
22- Serial .print (last_test);
23- Serial .println (" test: This should not be printed" );
24- Serial .flush ();
53+ Serial1 .print (last_test);
54+ Serial1 .println (" test: This should not be printed" );
55+ Serial1 .flush ();
2556
26- Serial.setPins (SOC_RX0, SOC_TX0);
57+ Serial1.setPins (uart1_rx_pin, uart1_tx_pin);
58+ uart_internal_loopback (1 , SOC_RX0);
2759 delay (100 );
28- Serial .print (last_test);
29- Serial .println (" test: This should be printed" );
30- Serial .flush ();
60+ Serial1 .print (last_test);
61+ Serial1 .println (" test: This should be printed" );
62+ Serial1 .flush ();
3163}
3264
3365/* Test functions */
3466/* These functions must only init the peripheral on the same pins and update "last_test" */
3567
3668void gpio_test (void ) {
37- pinMode (SOC_RX0 , INPUT);
38- pinMode (SOC_TX0, INPUT );
69+ pinMode (uart1_rx_pin , INPUT);
70+ pinMode (uart1_tx_pin, OUTPUT );
3971 last_test = " GPIO" ;
4072}
4173
4274#if SOC_SDM_SUPPORTED
4375void sigmadelta_test (void ) {
44- if (!sigmaDeltaAttach (SOC_RX0, 312500 )) {
45- TEST_FAIL_MESSAGE (" SigmaDelta init failed" );
46- }
47- if (!sigmaDeltaAttach (SOC_TX0, 312500 )) {
76+ if (!sigmaDeltaAttach (uart1_tx_pin, 312500 )) {
4877 TEST_FAIL_MESSAGE (" SigmaDelta init failed" );
4978 }
5079 last_test = " SigmaDelta" ;
5180}
5281#endif
5382
83+ #if SOC_ADC_SUPPORTED
84+ void adc_test (void ) {
85+ analogReadResolution (12 );
86+ analogRead (A4);
87+ last_test = " ADC" ;
88+ }
89+ #endif
90+
91+ #if SOC_DAC_SUPPORTED
92+ void dac_test (void ) {
93+ dacWrite (DAC1, 255 );
94+ last_test = " DAC" ;
95+ }
96+ #endif
97+
5498#if SOC_LEDC_SUPPORTED
5599void ledc_test (void ) {
56- if (!ledcAttach (SOC_RX0, 5000 , 12 )) {
57- TEST_FAIL_MESSAGE (" LEDC init failed" );
58- }
59- if (!ledcAttach (SOC_TX0, 5000 , 12 )) {
100+ if (!ledcAttach (uart1_rx_pin, 5000 , 12 )) {
60101 TEST_FAIL_MESSAGE (" LEDC init failed" );
61102 }
62103 last_test = " LEDC" ;
@@ -65,19 +106,32 @@ void ledc_test(void) {
65106
66107#if SOC_RMT_SUPPORTED
67108void rmt_test (void ) {
68- if (!rmtInit (SOC_RX0 , RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000 )) {
109+ if (!rmtInit (uart1_rx_pin , RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000 )) {
69110 TEST_FAIL_MESSAGE (" RMT init failed" );
70111 }
71- if (!rmtInit (SOC_TX0, RMT_TX_MODE , RMT_MEM_NUM_BLOCKS_1, 10000000 )) {
112+ if (!rmtInit (uart1_tx_pin, RMT_RX_MODE , RMT_MEM_NUM_BLOCKS_1, 10000000 )) {
72113 TEST_FAIL_MESSAGE (" RMT init failed" );
73114 }
74115 last_test = " RMT" ;
75116}
76117#endif
77118
119+ #if SOC_I2S_SUPPORTED
120+ void i2s_test (void ) {
121+ I2SClass i2s;
122+
123+ i2s.setPins (uart1_rx_pin, uart1_tx_pin, -1 );
124+ i2s.setTimeout (1000 );
125+ if (!i2s.begin (I2S_MODE_STD, 16000 , I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO)) {
126+ TEST_FAIL_MESSAGE (" I2S init failed" );
127+ }
128+ last_test = " I2S" ;
129+ }
130+ #endif
131+
78132#if SOC_I2C_SUPPORTED
79133void i2c_test (void ) {
80- if (!Wire.begin (SOC_RX0, SOC_TX0 )) {
134+ if (!Wire.begin (uart1_rx_pin, uart1_tx_pin )) {
81135 TEST_FAIL_MESSAGE (" I2C init failed" );
82136 }
83137 last_test = " I2C" ;
@@ -86,19 +140,65 @@ void i2c_test(void) {
86140
87141#if SOC_GPSPI_SUPPORTED
88142void spi_test (void ) {
89- SPI.begin (SOC_RX0, SOC_TX0 , -1 , -1 );
143+ SPI.begin (uart1_rx_pin, uart1_tx_pin , -1 , -1 );
90144 last_test = " SPI" ;
91145}
92146#endif
93147
148+ #if SOC_SDMMC_HOST_SUPPORTED
149+ void sdmmc_test (void ) {
150+ // begin() will always fail without a card. How to test?
151+ if (!SD_MMC.begin (" /sdcard" , true )) {
152+ TEST_FAIL_MESSAGE (" SDMMC init failed" );
153+ }
154+ last_test = " SDMMC" ;
155+ }
156+ #endif
157+
158+ #if SOC_TOUCH_SENSOR_SUPPORTED
159+ void touch_test (void ) {
160+ touchRead (T1);
161+ last_test = " Touch" ;
162+ }
163+ #endif
164+
165+ #if SOC_USB_SERIAL_JTAG_SUPPORTED && (ARDUINO_USB_MODE == 1)
166+ void jtag_test (void ) {
167+ HWCDCSerial.begin ();
168+ last_test = " JTAG" ;
169+ }
170+ #endif
171+
172+ #if SOC_USB_OTG_SUPPORTED && (ARDUINO_USB_MODE == 0)
173+ void usb_test (void ) {
174+ USB.begin ();
175+ last_test = " USB" ;
176+ }
177+ #endif
178+
179+ #if SOC_GPSPI_SUPPORTED || CONFIG_ETH_USE_ESP32_EMAC
180+ void eth_test (void ) {
181+ ETH.begin ();
182+ last_test = " ETH" ;
183+ }
184+ #endif
185+
94186/* Main functions */
95187
96188void setup () {
97189 Serial.begin (115200 );
98190 while (!Serial) { delay (10 ); }
99191
192+ Serial1.setPins (UART1_RX_DEFAULT, UART1_TX_DEFAULT);
193+ Serial1.begin (115200 );
194+ while (!Serial1) { delay (10 ); }
195+ uart_internal_loopback (1 , SOC_RX0);
196+
100197 UNITY_BEGIN ();
101198
199+ uart1_rx_pin = UART1_RX_DEFAULT;
200+ uart1_tx_pin = UART1_TX_DEFAULT;
201+
102202 RUN_TEST (gpio_test);
103203
104204 #if SOC_SDM_SUPPORTED
@@ -113,6 +213,10 @@ void setup() {
113213 RUN_TEST (rmt_test);
114214 #endif
115215
216+ #if SOC_I2S_SUPPORTED
217+ RUN_TEST (i2s_test);
218+ #endif
219+
116220 #if SOC_I2C_SUPPORTED
117221 RUN_TEST (i2c_test);
118222 #endif
@@ -121,6 +225,42 @@ void setup() {
121225 RUN_TEST (spi_test);
122226 #endif
123227
228+ uart1_tx_pin = A4;
229+
230+ #if SOC_ADC_SUPPORTED
231+ RUN_TEST (adc_test);
232+ #endif
233+
234+ uart1_tx_pin = DAC1;
235+
236+ #if SOC_DAC_SUPPORTED
237+ RUN_TEST (dac_test);
238+ #endif
239+
240+ #if 0
241+ #if SOC_SDMMC_HOST_SUPPORTED
242+ RUN_TEST(sdmmc_test);
243+ #endif
244+ #endif
245+
246+ uart1_tx_pin = T1;
247+
248+ #if SOC_TOUCH_SENSOR_SUPPORTED
249+ RUN_TEST (touch_test);
250+ #endif
251+
252+ uart1_tx_pin = UART1_TX_DEFAULT;
253+
254+ #if SOC_USB_SERIAL_JTAG_SUPPORTED && (ARDUINO_USB_MODE == 1)
255+ RUN_TEST (jtag_test);
256+ #endif
257+
258+ #if SOC_USB_OTG_SUPPORTED && (ARDUINO_USB_MODE == 0)
259+ RUN_TEST (usb_test);
260+ #endif
261+
262+ RUN_TEST (eth_test);
263+
124264 UNITY_END ();
125265}
126266
0 commit comments