20
20
#include " greentea-client/test_env.h"
21
21
#include " mbed.h"
22
22
23
- // #if !TARGET_FF_ARDUINO_UNO
23
+ /*
24
+ Requirements specified in docs/design-documents/hal/0005-pin-names-Arduino-Uno-standard.md
25
+ */
26
+
24
27
#if !(defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO))
25
28
#error [NOT_SUPPORTED] Test needs Arduino Uno form factor
26
29
#else
@@ -34,26 +37,26 @@ using namespace utest::v1;
34
37
template <PinName TestedPin>
35
38
void GPIO_test ()
36
39
{
37
- printf ( " Pin 0x%x\n " , TestedPin);
40
+ utest_printf ( " GPIO Pin 0x%x\n " , TestedPin);
38
41
39
- TEST_SKIP_UNLESS_MESSAGE (TestedPin != (PinName)NC, " NC pin" );
40
- TEST_SKIP_UNLESS_MESSAGE (TestedPin != USBTX, " USBTX pin" );
41
- TEST_SKIP_UNLESS_MESSAGE (TestedPin != USBRX, " USBRX pin" );
42
+ TEST_SKIP_UNLESS_MESSAGE (TestedPin != USBTX, " ARDUINO_UNO pin shared with USBTX" );
43
+ TEST_SKIP_UNLESS_MESSAGE (TestedPin != USBRX, " ARDUINO_UNO pin shared with USBRX" );
42
44
43
45
const PinMap *maps = gpio_pinmap (); // hal/source/mbed_gpio.c
44
- while (maps->pin != (PinName)NC) {
45
- // printf("map pin 0x%x\n", maps->pin);
46
+ while (maps->pin != (PinName)NC) { // check each pin from PinMap table till NC pin
46
47
if (maps->pin == TestedPin) {
47
48
{
48
49
DigitalOut TEST1 (maps->pin );
49
50
TEST1 = !TEST1;
50
51
}
51
52
{
52
53
DigitalIn TEST1 (maps->pin );
54
+ // Basic API call
53
55
TEST1.read ();
54
56
}
55
57
{
56
58
DigitalInOut TEST1 (maps->pin );
59
+ // Basic API call
57
60
TEST1.input ();
58
61
TEST1.output ();
59
62
}
@@ -63,43 +66,47 @@ void GPIO_test()
63
66
}
64
67
maps++;
65
68
}
69
+
70
+ // Pin is not part of gpio PinMap
66
71
TEST_ASSERT (false );
67
72
}
68
73
69
74
70
75
template <PinName TestedPin>
71
76
void AnalogIn_test ()
72
77
{
73
- printf ( " Pin 0x%x\n " , TestedPin);
78
+ utest_printf ( " ADC Pin 0x%x\n " , TestedPin);
74
79
75
80
const PinMap *maps = analogin_pinmap ();
76
- while (maps->pin != (PinName)NC) {
77
- // printf("map pin 0x%x\n", maps->pin);
81
+ while (maps->pin != (PinName)NC) { // check each pin from PinMap table till NC pin
78
82
if (maps->pin == TestedPin) {
79
83
80
84
AnalogIn TEST (TestedPin);
85
+ // Basic API call
81
86
TEST.read_u16 ();
82
87
83
88
TEST_ASSERT (true );
84
89
return ;
85
90
}
86
91
maps++;
87
92
}
93
+
94
+ // Pin is not part of analogin PinMap
88
95
TEST_ASSERT (false );
89
96
}
90
97
91
98
92
99
template <PinName TestedPin>
93
100
void PWM_test ()
94
101
{
95
- printf ( " Pin 0x%x\n " , TestedPin);
102
+ utest_printf ( " PWM Pin 0x%x\n " , TestedPin);
96
103
97
104
const PinMap *maps = pwmout_pinmap ();
98
- while (maps->pin != (PinName)NC) {
99
- // printf("map pin 0x%x\n", maps->pin);
105
+ while (maps->pin != (PinName)NC) { // check each pin from PinMap table till NC pin
100
106
if (maps->pin == TestedPin) {
101
107
102
108
PwmOut pwm (TestedPin);
109
+ // Basic API call
103
110
pwm.period (1 .0f );
104
111
pwm.write (0 .5f );
105
112
@@ -109,132 +116,138 @@ void PWM_test()
109
116
maps++;
110
117
}
111
118
112
- // PWM support is not mandatory
113
- TEST_SKIP_UNLESS_MESSAGE (false , " ARDUINO_UNO WARNING: NO PWM " );
119
+ // From docs/design-documents/hal/0005-pin-names-Arduino-Uno-standard.md
120
+ // Although this is recomended as per the Arduino Uno standard,
121
+ // it's not a mandatory as requirement to be compliant with the Arduino Uno standard for Mbed boards.
122
+ TEST_SKIP_UNLESS_MESSAGE (false , " ARDUINO_UNO: this pin doesn’t support PWM" );
114
123
}
115
124
116
125
117
126
template <PinName TX_pin, PinName RX_pin>
118
127
void UART_test ()
119
128
{
120
- printf ( " TX Pin 0x%x RX Pin 0x%x\n " , TX_pin, RX_pin);
129
+ utest_printf ( " UART TX Pin 0x%x RX Pin 0x%x\n " , TX_pin, RX_pin);
121
130
122
- TEST_SKIP_UNLESS_MESSAGE (TX_pin != USBTX, " USBTX pin" );
123
- TEST_SKIP_UNLESS_MESSAGE (RX_pin != USBRX, " USBRX pin" );
131
+ TEST_SKIP_UNLESS_MESSAGE (TX_pin != USBTX, " ARDUINO_UNO_UART pin shared with USBTX " );
132
+ TEST_SKIP_UNLESS_MESSAGE (RX_pin != USBRX, " ARDUINO_UNO_UART pin shared with USBRX " );
124
133
125
134
{
126
135
const PinMap *maps = serial_tx_pinmap ();
127
- while (maps->pin != (PinName)NC) {
128
- // printf("map pin 0x%x\n", maps->pin);
136
+ while (maps->pin != (PinName)NC) { // check each pin from PinMap table till NC pin
129
137
if (maps->pin == TX_pin) {
130
138
break ;
131
139
}
132
140
maps++;
133
141
}
142
+ // Pin is not part of serial_tx PinMap
134
143
TEST_ASSERT_NOT_EQUAL (NC, maps->pin );
135
144
}
145
+
136
146
{
137
147
const PinMap *maps = serial_rx_pinmap ();
138
- while (maps->pin != (PinName)NC) {
139
- // printf("map pin 0x%x\n", maps->pin);
148
+ while (maps->pin != (PinName)NC) { // check each pin from PinMap table till NC pin
140
149
if (maps->pin == RX_pin) {
141
150
break ;
142
151
}
143
152
maps++;
144
153
}
154
+ // Pin is not part of serial_rx PinMap
145
155
TEST_ASSERT_NOT_EQUAL (NC, maps->pin );
146
156
}
147
157
148
158
BufferedSerial TEST (TX_pin, RX_pin);
159
+ // Basic API call
149
160
TEST.set_baud (115200 );
150
161
}
151
162
152
163
153
164
template <PinName SDA_pin, PinName SCL_pin>
154
165
void I2C_test ()
155
166
{
156
- printf ( " SDA Pin 0x%x SCL Pin 0x%x\n " , SDA_pin, SCL_pin);
167
+ utest_printf ( " I2C SDA Pin 0x%x SCL Pin 0x%x\n " , SDA_pin, SCL_pin);
157
168
158
169
{
159
170
const PinMap *maps = i2c_master_sda_pinmap ();
160
- while (maps->pin != (PinName)NC) {
161
- // printf("map pin 0x%x\n", maps->pin);
171
+ while (maps->pin != (PinName)NC) { // check each pin from PinMap table till NC pin
162
172
if (maps->pin == SDA_pin) {
163
173
break ;
164
174
}
165
175
maps++;
166
176
}
177
+ // Pin is not part of i2c_master_sda PinMap
167
178
TEST_ASSERT_NOT_EQUAL (NC, maps->pin );
168
179
}
169
180
{
170
181
const PinMap *maps = i2c_master_scl_pinmap ();
171
- while (maps->pin != (PinName)NC) {
172
- // printf("map pin 0x%x\n", maps->pin);
182
+ while (maps->pin != (PinName)NC) { // check each pin from PinMap table till NC pin
173
183
if (maps->pin == SCL_pin) {
174
184
break ;
175
185
}
176
186
maps++;
177
187
}
188
+ // Pin is not part of i2c_master_scl PinMap
178
189
TEST_ASSERT_NOT_EQUAL (NC, maps->pin );
179
190
}
180
191
181
192
I2C i2c (SDA_pin, SCL_pin);
193
+ // Basic API call
182
194
i2c.read (0 );
183
195
}
184
196
185
197
186
198
template <PinName MOSI_pin, PinName MISO_pin, PinName CLK_pin, PinName CS_pin>
187
199
void SPI_test ()
188
200
{
189
- printf ( " MOSI Pin 0x%x MISO Pin 0x%x CLOCK Pin 0x%x CS Pin0x%x\n " , MOSI_pin, MISO_pin, CLK_pin, CS_pin);
201
+ utest_printf ( " SPI MOSI Pin 0x%x MISO Pin 0x%x CLOCK Pin 0x%x CS Pin0x%x\n " , MOSI_pin, MISO_pin, CLK_pin, CS_pin);
190
202
191
203
{
192
204
const PinMap *maps = spi_master_mosi_pinmap ();
193
- while (maps->pin != (PinName)NC) {
194
- // printf("map pin 0x%x\n", maps->pin);
205
+ while (maps->pin != (PinName)NC) { // check each pin from PinMap table till NC pin
195
206
if (maps->pin == MOSI_pin) {
196
207
break ;
197
208
}
198
209
maps++;
199
210
}
211
+ // Pin is not part of spi_master_mosi PinMap
200
212
TEST_ASSERT_NOT_EQUAL (NC, maps->pin );
201
213
}
202
214
{
203
215
const PinMap *maps = spi_master_miso_pinmap ();
204
- while (maps->pin != (PinName)NC) {
205
- // printf("map pin 0x%x\n", maps->pin);
216
+ while (maps->pin != (PinName)NC) { // check each pin from PinMap table till NC pin
206
217
if (maps->pin == MISO_pin) {
207
218
break ;
208
219
}
209
220
maps++;
210
221
}
222
+ // Pin is not part of spi_master_miso PinMap
211
223
TEST_ASSERT_NOT_EQUAL (NC, maps->pin );
212
224
}
213
225
{
214
226
const PinMap *maps = spi_master_clk_pinmap ();
215
- while (maps->pin != (PinName)NC) {
216
- // printf("map pin 0x%x\n", maps->pin);
227
+ while (maps->pin != (PinName)NC) { // check each pin from PinMap table till NC pin
217
228
if (maps->pin == CLK_pin) {
218
229
break ;
219
230
}
220
231
maps++;
221
232
}
233
+ // Pin is not part of spi_master_clk PinMap
222
234
TEST_ASSERT_NOT_EQUAL (NC, maps->pin );
223
235
}
224
236
{
225
237
const PinMap *maps = gpio_pinmap (); // CS pin could be a simple GPIO
226
- while (maps->pin != (PinName)NC) {
227
- // printf("map pin 0x%x\n", maps->pin);
238
+ while (maps->pin != (PinName)NC) { // check each pin from PinMap table till NC pin
228
239
if (maps->pin == CS_pin) {
229
240
break ;
230
241
}
231
242
maps++;
232
243
}
244
+ // Pin is not part of gpio PinMap
233
245
TEST_ASSERT_NOT_EQUAL (NC, maps->pin );
234
246
}
235
247
236
248
SPI device (MOSI_pin, MISO_pin, CLK_pin);
237
249
DigitalOut cs (CS_pin);
250
+ // Basic API call
238
251
device.frequency (10000000 );
239
252
}
240
253
0 commit comments