Skip to content

Commit 500ddf5

Browse files
jeromecoutantgpsimenos
authored andcommitted
[STD-PIN] Updates after review
1 parent d514b78 commit 500ddf5

File tree

3 files changed

+59
-40
lines changed

3 files changed

+59
-40
lines changed

hal/include/hal/ArduinoUnoAliases.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151

5252
#ifdef TARGET_FF_ARDUINO
5353

54+
#warning ARDUINO form factor should not be used any more => use ARDUINO_UNO
55+
5456
#define ARDUINO_UNO_A0 A0
5557
#define ARDUINO_UNO_A1 A1
5658
#define ARDUINO_UNO_A2 A2

hal/tests/TESTS/pin_names/arduino_uno/main.cpp

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
#include "greentea-client/test_env.h"
2121
#include "mbed.h"
2222

23-
// #if !TARGET_FF_ARDUINO_UNO
23+
/*
24+
Requirements specified in docs/design-documents/hal/0005-pin-names-Arduino-Uno-standard.md
25+
*/
26+
2427
#if !(defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO))
2528
#error [NOT_SUPPORTED] Test needs Arduino Uno form factor
2629
#else
@@ -34,26 +37,26 @@ using namespace utest::v1;
3437
template <PinName TestedPin>
3538
void GPIO_test()
3639
{
37-
printf("Pin 0x%x\n", TestedPin);
40+
utest_printf("GPIO Pin 0x%x\n", TestedPin);
3841

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");
4244

4345
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
4647
if (maps->pin == TestedPin) {
4748
{
4849
DigitalOut TEST1(maps->pin);
4950
TEST1 = !TEST1;
5051
}
5152
{
5253
DigitalIn TEST1(maps->pin);
54+
// Basic API call
5355
TEST1.read();
5456
}
5557
{
5658
DigitalInOut TEST1(maps->pin);
59+
// Basic API call
5760
TEST1.input();
5861
TEST1.output();
5962
}
@@ -63,43 +66,47 @@ void GPIO_test()
6366
}
6467
maps++;
6568
}
69+
70+
// Pin is not part of gpio PinMap
6671
TEST_ASSERT(false);
6772
}
6873

6974

7075
template <PinName TestedPin>
7176
void AnalogIn_test()
7277
{
73-
printf("Pin 0x%x\n", TestedPin);
78+
utest_printf("ADC Pin 0x%x\n", TestedPin);
7479

7580
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
7882
if (maps->pin == TestedPin) {
7983

8084
AnalogIn TEST(TestedPin);
85+
// Basic API call
8186
TEST.read_u16();
8287

8388
TEST_ASSERT(true);
8489
return;
8590
}
8691
maps++;
8792
}
93+
94+
// Pin is not part of analogin PinMap
8895
TEST_ASSERT(false);
8996
}
9097

9198

9299
template <PinName TestedPin>
93100
void PWM_test()
94101
{
95-
printf("Pin 0x%x\n", TestedPin);
102+
utest_printf("PWM Pin 0x%x\n", TestedPin);
96103

97104
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
100106
if (maps->pin == TestedPin) {
101107

102108
PwmOut pwm(TestedPin);
109+
// Basic API call
103110
pwm.period(1.0f);
104111
pwm.write(0.5f);
105112

@@ -109,132 +116,138 @@ void PWM_test()
109116
maps++;
110117
}
111118

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");
114123
}
115124

116125

117126
template <PinName TX_pin, PinName RX_pin>
118127
void UART_test()
119128
{
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);
121130

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");
124133

125134
{
126135
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
129137
if (maps->pin == TX_pin) {
130138
break;
131139
}
132140
maps++;
133141
}
142+
// Pin is not part of serial_tx PinMap
134143
TEST_ASSERT_NOT_EQUAL(NC, maps->pin);
135144
}
145+
136146
{
137147
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
140149
if (maps->pin == RX_pin) {
141150
break;
142151
}
143152
maps++;
144153
}
154+
// Pin is not part of serial_rx PinMap
145155
TEST_ASSERT_NOT_EQUAL(NC, maps->pin);
146156
}
147157

148158
BufferedSerial TEST(TX_pin, RX_pin);
159+
// Basic API call
149160
TEST.set_baud(115200);
150161
}
151162

152163

153164
template <PinName SDA_pin, PinName SCL_pin>
154165
void I2C_test()
155166
{
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);
157168

158169
{
159170
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
162172
if (maps->pin == SDA_pin) {
163173
break;
164174
}
165175
maps++;
166176
}
177+
// Pin is not part of i2c_master_sda PinMap
167178
TEST_ASSERT_NOT_EQUAL(NC, maps->pin);
168179
}
169180
{
170181
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
173183
if (maps->pin == SCL_pin) {
174184
break;
175185
}
176186
maps++;
177187
}
188+
// Pin is not part of i2c_master_scl PinMap
178189
TEST_ASSERT_NOT_EQUAL(NC, maps->pin);
179190
}
180191

181192
I2C i2c(SDA_pin, SCL_pin);
193+
// Basic API call
182194
i2c.read(0);
183195
}
184196

185197

186198
template <PinName MOSI_pin, PinName MISO_pin, PinName CLK_pin, PinName CS_pin>
187199
void SPI_test()
188200
{
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);
190202

191203
{
192204
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
195206
if (maps->pin == MOSI_pin) {
196207
break;
197208
}
198209
maps++;
199210
}
211+
// Pin is not part of spi_master_mosi PinMap
200212
TEST_ASSERT_NOT_EQUAL(NC, maps->pin);
201213
}
202214
{
203215
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
206217
if (maps->pin == MISO_pin) {
207218
break;
208219
}
209220
maps++;
210221
}
222+
// Pin is not part of spi_master_miso PinMap
211223
TEST_ASSERT_NOT_EQUAL(NC, maps->pin);
212224
}
213225
{
214226
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
217228
if (maps->pin == CLK_pin) {
218229
break;
219230
}
220231
maps++;
221232
}
233+
// Pin is not part of spi_master_clk PinMap
222234
TEST_ASSERT_NOT_EQUAL(NC, maps->pin);
223235
}
224236
{
225237
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
228239
if (maps->pin == CS_pin) {
229240
break;
230241
}
231242
maps++;
232243
}
244+
// Pin is not part of gpio PinMap
233245
TEST_ASSERT_NOT_EQUAL(NC, maps->pin);
234246
}
235247

236248
SPI device(MOSI_pin, MISO_pin, CLK_pin);
237249
DigitalOut cs(CS_pin);
250+
// Basic API call
238251
device.frequency(10000000);
239252
}
240253

hal/tests/TESTS/pin_names/generic/main.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@
2020
#include "greentea-client/test_env.h"
2121
#include "mbed.h"
2222

23+
/*
24+
Requirements specified in docs/design-documents/hal/0004-pin-names-general-guidelines.md
25+
*/
26+
2327
#ifndef LED1
24-
// Set test as not supported, could be changed as error later
25-
#error [NOT_SUPPORTED] check docs/design-documents/hal/0004-pin-names-general-guidelines.md
28+
#error [NOT_SUPPORTED] Target is not following mbed-os pin names standard // Test is set as Skipped
29+
// #error [NOT_SUPPORTED] Target is not following mbed-os pin names standard // Test is set as Error
2630
#else
2731

2832
using namespace utest::v1;
2933

3034
template <int LedId, PinName LedPin>
3135
void LED_test()
3236
{
33-
printf("LED %u Pin 0x%x\n", LedId, LedPin);
37+
utest_printf("LED %u Pin 0x%x\n", LedId, LedPin);
3438
DigitalOut TEST(LedPin);
3539
TEST = 1;
3640
ThisThread::sleep_for(1s);
@@ -41,7 +45,7 @@ void LED_test()
4145
template <int ButtonId, PinName ButtonPin>
4246
void BUTTON_test()
4347
{
44-
printf("BUTTON %u Pin 0x%x\n", ButtonId, ButtonPin);
48+
utest_printf("BUTTON %u Pin 0x%x\n", ButtonId, ButtonPin);
4549
DigitalIn TEST(ButtonPin);
4650
}
4751

0 commit comments

Comments
 (0)