Skip to content

Commit a4350f7

Browse files
jeromecoutantgpsimenos
authored andcommitted
[STD-PIN] BUTTON and LED define
hal/tests/TESTS/mbed_hal/gpio/main.cpp is replaced by hal/tests/TESTS/pin_names/generic/main.cpp now
1 parent 23e3bb3 commit a4350f7

File tree

5 files changed

+37
-88
lines changed

5 files changed

+37
-88
lines changed

docs/design-documents/hal/0004-pin-names-general-guidelines.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,28 @@ To achieve meaningful portability of application code across various Mbed Enable
4242
Only add LEDs that are available on the board. This is an example on how to define LEDs in PinNames.h:
4343

4444
// Px_xx relates to the processor pin connected to the LED
45-
#define LED1 = Px_xx // LED1
46-
#define LED2 = Px_xx // LED2
47-
#define LED3 = Px_xx // LED3
48-
#define LED4 = Px_xx // LED4
45+
#define LED1 Px_xx // LED1
46+
#define LED2 Px_xx // LED2
47+
#define LED3 Px_xx // LED3
48+
#define LED4 Px_xx // LED4
4949
.
5050
.
51-
#define LEDN = Px_xx // LEDN
51+
#define LEDN Px_xx // LEDN
5252

5353
Note this document is proposing changing LEDs from `enums` to `define`, which causes a minor change in the compile preprocessor. From application point of view, there are no implications.
5454

5555
**Using LEDs at application**
5656

5757
The detection of available LEDs at application level can be done as follow:
5858

59-
#ifdef(LED1)
59+
#ifdef LED1
6060
DigitalOut myLED(LED1);
6161
myLED = 1;
6262
#endif
6363

6464
Alternatively, if the usage of an LED is required, then the application can detect its availability and generate an error accordingly:
6565

66-
#ifndef(LED1)
66+
#ifndef LED1
6767
#error This application requires the availability of an LED
6868
#endif
6969

@@ -81,28 +81,28 @@ However, these names do not apply to all boards and hence should not be used in
8181
Only add buttons that are available on the board. This is an example on how to define buttons in PinNames.h:
8282

8383
// Px_xx relates to the processor pin connected to the button
84-
#define BUTTON1 = Px_xx // BUTTON1
85-
#define BUTTON2 = Px_xx // BUTTON2
86-
#define BUTTON3 = Px_xx // BUTTON3
87-
#define BUTTON4 = Px_xx // BUTTON4
84+
#define BUTTON1 Px_xx // BUTTON1
85+
#define BUTTON2 Px_xx // BUTTON2
86+
#define BUTTON3 Px_xx // BUTTON3
87+
#define BUTTON4 Px_xx // BUTTON4
8888
.
8989
.
90-
#define BUTTONN = Px_xx // BUTTONN
90+
#define BUTTONN Px_xx // BUTTONN
9191

9292
Note this document is proposing changing buttons from `enums` to `define`, which causes a minor change in the compile preprocessor. From application point of view, there are no implications.
9393

9494
**Using Buttons at application**
9595

9696
The detection of available buttons at application level can be done as follow:
9797

98-
#ifdef(BUTTON1)
98+
#ifdef BUTTON1
9999
DigitalIn myBUTTON(BUTTON1);
100100
int input = myBUTTON.read();
101101
#endif
102102

103103
Alternatively, if the usage of a button is required, then the application can detect its availability and generate an error accordingly:
104104

105-
#ifndef(BUTTON1)
105+
#ifndef BUTTON1
106106
#error This application requires the availability of a button
107107
#endif
108108

@@ -135,15 +135,15 @@ Note this document is proposing unifying the pin names used for UART communicati
135135
If either LEDs or buttons are not available, they should not be defined.
136136
This allows for unavailable LEDs or BUTTONs to be caught in Mbed OS allowing the corresponding errors to be generated.
137137

138-
LED1 = PB_0, // LED1 is valid
139-
LED2 = LED1, // Not valid as it's duplicate and LED2 does not exist on the board
140-
LED3 = PB_0, // Not valid as it's duplicate and LED3 does not exist on the board
141-
LED4 = NC // Not valid definition as LED4 does not exist
142-
143-
BUTTON1 = PB_1, // BUTTON1 is valid
144-
BUTTON2 = BUTTON1, // Not valid as it's duplicate and BUTTON2 does not exist on the board
145-
BUTTON3 = PB_1, // Not valid as it's duplicate and BUTTON3 does not exist on the board
146-
BUTTON4 = NC, // Not valid as BUTTON4 does not exist
138+
#define LED1 PB_0 // LED1 is valid
139+
#define LED2 LED1 // Not valid as it's duplicate and LED2 does not exist on the board
140+
#define LED3 PB_0 // Not valid as it's duplicate and LED3 does not exist on the board
141+
#define LED4 NC // Not valid definition as LED4 does not exist
142+
143+
#define BUTTON1 PB_1 // BUTTON1 is valid
144+
#define BUTTON2 BUTTON1 // Not valid as it's duplicate and BUTTON2 does not exist on the board
145+
#define BUTTON3 PB_1 // Not valid as it's duplicate and BUTTON3 does not exist on the board
146+
#define BUTTON4 NC // Not valid as BUTTON4 does not exist
147147

148148

149149
### Testing compliance

hal/tests/TESTS/mbed_hal/gpio/main.cpp

Lines changed: 0 additions & 57 deletions
This file was deleted.

platform/source/mbed_board.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ WEAK MBED_NORETURN void mbed_die(void)
2929
core_util_critical_section_enter();
3030
#endif
3131
gpio_t led_err;
32+
#ifdef LED1
3233
gpio_init_out(&led_err, LED1);
34+
#endif
3335

3436
while (1) {
37+
#ifdef LED1
3538
for (int i = 0; i < 4; ++i) {
3639
gpio_write(&led_err, 1);
3740
wait_us(150000);
@@ -45,6 +48,7 @@ WEAK MBED_NORETURN void mbed_die(void)
4548
gpio_write(&led_err, 0);
4649
wait_us(400000);
4750
}
51+
#endif
4852
}
4953
}
5054

platform/tests/TESTS/mbed_platform/stats_cpu/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929
using namespace utest::v1;
3030

31+
#ifdef LED1
3132
DigitalOut led1(LED1);
33+
#endif
3234

3335
// Targets with these cores have their RAM enough size to create threads with bigger stacks
3436
#if defined(__CORTEX_A9) || defined(__CORTEX_M23) || defined(__CORTEX_M33) || defined(__CORTEX_M7)
@@ -47,7 +49,9 @@ static void busy_thread()
4749
volatile uint64_t i = ~0;
4850

4951
while (i--) {
52+
#ifdef LED1
5053
led1 = !led1;
54+
#endif
5155
wait_us(wait_time);
5256
}
5357
}

targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L4S5xI/TARGET_B_L4S5I_IOT01A/PinNames.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,6 @@ typedef enum {
203203
SPI_MISO = D12,
204204
SPI_SCK = D13,
205205

206-
// Standardized LED and button names
207-
LED1 = PA_5, // ARD_D13 [SPI1_SCK/LED1]
208-
LED2 = PB_14, // LED2 [LED_GREEN]
209-
LED3 = PC_9, // LED3_WIFI_ LED4_BLE
210-
BUTTON1 = PC_13, // BUTTON_EXTI13 [B2]
211-
212-
// Backward legacy names
213-
USER_BUTTON = BUTTON1,
214206
PWM_OUT = D3,
215207

216208
/**** USB FS pins ****/
@@ -264,6 +256,12 @@ typedef enum {
264256
NC = (int)0xFFFFFFFF
265257
} PinName;
266258

259+
// Standardized LED and button names
260+
#define LED1 PA_5 // Green LED (LD1) // D13
261+
#define LED2 PB_14 // Green LED (LD2)
262+
#define LED3 PC_9 // Yellow LED (LD3 WIFI) / Blue LED (LD4 BLE)
263+
#define BUTTON1 PC_13 // BUTTON_EXTI13 [B2]
264+
267265
#ifdef __cplusplus
268266
}
269267
#endif

0 commit comments

Comments
 (0)