Skip to content

Commit d239ef9

Browse files
committed
Rename USBTX/RX to CONSOLE_TX/RX
1 parent 3af9624 commit d239ef9

File tree

17 files changed

+70
-47
lines changed

17 files changed

+70
-47
lines changed

hal/include/hal/ArduinoUnoAliases.h renamed to hal/include/hal/PinNameAliases.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@
1717
* See the License for the specific language governing permissions and
1818
* limitations under the License.
1919
*/
20-
#ifndef MBED_ARDUINO_UNO_H
21-
#define MBED_ARDUINO_UNO_H
20+
#ifndef MBED_PIN_NAME_ALIASES_H
21+
#define MBED_PIN_NAME_ALIASES_H
22+
23+
/* Aliases for legacy reasons. To be removed in the next Mbed OS version */
24+
#if defined (CONSOLE_TX) && (CONSOLE_RX)
25+
#define USBTX CONSOLE_TX
26+
#define USBRX CONSOLE_RX
27+
#else
28+
#define CONSOLE_TX USBTX
29+
#define CONSOLE_RX USBRX
30+
#endif
2231

2332
#if defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
2433

@@ -94,6 +103,6 @@
94103

95104
#endif // (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
96105

97-
#endif // MBED_ARDUINO_UNO_H
106+
#endif // MBED_PIN_NAME_ALIASES_H
98107

99108
/** @}*/

hal/include/hal/static_pinmap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef STATIC_PINMAP_H
1818
#define STATIC_PINMAP_H
1919

20+
#include "hal/PinNameAliases.h"
2021
#include "PinNames.h"
2122
#include "spi_api.h"
2223
#include "pwmout_api.h"
@@ -128,7 +129,7 @@ MSTD_CONSTEXPR_FN_14 serial_pinmap_t get_uart_pinmap(const PinName tx, const Pin
128129
return {(int) NC, NC, (int) NC, NC, (int) NC, false};
129130
}
130131

131-
if (tx_map->pin == USBTX && rx_map->pin == USBRX) {
132+
if (tx_map->pin == CONSOLE_TX && rx_map->pin == CONSOLE_RX) {
132133
return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function, true};
133134
} else {
134135
return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function, false};

hal/source/mbed_gpio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
#include "hal/gpio_api.h"
1818
#include "platform/mbed_toolchain.h"
19-
#include "hal/ArduinoUnoAliases.h"
19+
#include "hal/PinNameAliases.h"
2020

2121
static inline void _gpio_init_in(gpio_t *gpio, PinName pin, PinMode mode)
2222
{

hal/source/mbed_pinmap_default.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "platform/mbed_assert.h"
2222
#include "device.h"
2323
#include "hal/serial_api.h"
24-
#include "hal/ArduinoUnoAliases.h"
24+
#include "hal/PinNameAliases.h"
2525

2626
//*** Common form factors ***
2727
#if defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
@@ -70,7 +70,7 @@ const char *pinmap_ff_arduino_uno_pin_to_string(PinName pin)
7070
MBED_WEAK const PinList *pinmap_restricted_pins()
7171
{
7272
static const PinName pins[] = {
73-
USBTX, USBRX
73+
CONSOLE_TX, CONSOLE_RX
7474
};
7575
static const PinList pin_list = {
7676
sizeof(pins) / sizeof(pins[0]),
@@ -94,7 +94,7 @@ MBED_WEAK const PinList *pinmap_gpio_restricted_pins()
9494
#if DEVICE_SERIAL
9595
MBED_WEAK const PeripheralList *pinmap_uart_restricted_peripherals()
9696
{
97-
static const int stdio_uart = pinmap_peripheral(USBTX, serial_tx_pinmap());
97+
static const int stdio_uart = pinmap_peripheral(CONSOLE_TX, serial_tx_pinmap());
9898

9999
static const int peripherals[] = {
100100
stdio_uart

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ void GPIO_test()
3535
{
3636
utest_printf("GPIO Pin 0x%x\n", TestedPin);
3737

38-
TEST_SKIP_UNLESS_MESSAGE(TestedPin != USBTX, "ARDUINO_UNO pin shared with USBTX");
39-
TEST_SKIP_UNLESS_MESSAGE(TestedPin != USBRX, "ARDUINO_UNO pin shared with USBRX");
38+
TEST_SKIP_UNLESS_MESSAGE(TestedPin != CONSOLE_TX, "ARDUINO_UNO pin shared with CONSOLE_TX");
39+
TEST_SKIP_UNLESS_MESSAGE(TestedPin != CONSOLE_RX, "ARDUINO_UNO pin shared with CONSOLE_RX");
4040

4141
const PinMap *maps = gpio_pinmap(); // hal/source/mbed_gpio.c
4242
while (maps->pin != (PinName)NC) { // check each pin from PinMap table till NC pin
@@ -124,8 +124,8 @@ void UART_test()
124124
{
125125
utest_printf("UART TX Pin 0x%x RX Pin 0x%x\n", TX_pin, RX_pin);
126126

127-
TEST_SKIP_UNLESS_MESSAGE(TX_pin != USBTX, "ARDUINO_UNO_UART pin shared with USBTX");
128-
TEST_SKIP_UNLESS_MESSAGE(RX_pin != USBRX, "ARDUINO_UNO_UART pin shared with USBRX");
127+
TEST_SKIP_UNLESS_MESSAGE(TX_pin != CONSOLE_TX, "ARDUINO_UNO_UART pin shared with CONSOLE_TX");
128+
TEST_SKIP_UNLESS_MESSAGE(RX_pin != CONSOLE_RX, "ARDUINO_UNO_UART pin shared with CONSOLE_RX");
129129

130130
{
131131
const PinMap *maps = serial_tx_pinmap();

hal/tests/pinvalidate/pinvalidate.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def identity_assignment_check(pin_name_dict):
314314
def nc_assignment_check(pin_name_dict):
315315
invalid_items = []
316316
for key, val in pin_name_dict.items():
317-
if re.match(r"^((LED|BUTTON)\d*|USBTX|USBRX)$", key):
317+
if re.match(r"^((LED|BUTTON)\d*|CONSOLE_TX|CONSOLE_RX|USBTX|USBRX)$", key):
318318
if val == "NC":
319319
message = "cannot be NC"
320320
invalid_items.append(
@@ -329,7 +329,7 @@ def duplicate_assignment_check(pin_name_dict):
329329
invalid_items = []
330330

331331
for key, val in pin_name_dict.items():
332-
if re.match(r"^((LED|BUTTON)\d*|USBTX|USBRX)$", key):
332+
if re.match(r"^((LED|BUTTON)\d*|CONSOLE_TX|CONSOLE_RX|USBTX|USBRX)$", key):
333333
if val == "NC":
334334
continue
335335
# resolve to literal
@@ -438,6 +438,13 @@ def legacy_assignment_check(pin_name_content):
438438
invalid_items.append({"key": key, "val": val, "message": message})
439439
return invalid_items
440440

441+
def legacy_uart_check(pin_name_dict):
442+
invalid_items = []
443+
if "CONSOLE_TX" not in pin_name_dict or "CONSOLE_RX" not in pin_name_dict:
444+
message = "CONSOLE_TX or CONSOLE_RX are not defined; USBTX and USBRX are deprecated"
445+
invalid_items.append({"key": "", "val": "", "message": message})
446+
return invalid_items
447+
441448

442449
def print_summary(report):
443450
targets = set([case["platform_name"] for case in report])
@@ -653,6 +660,12 @@ def has_passed_all_test_cases(report):
653660
"case_function": legacy_assignment_check,
654661
"case_input": "content",
655662
},
663+
{
664+
"suite_name": "generic",
665+
"case_name": "uart",
666+
"case_function": legacy_uart_check,
667+
"case_input": "content",
668+
},
656669
{
657670
"suite_name": "arduino_uno",
658671
"case_name": "duplicate",

hal/tests/pinvalidate/pinvalidate_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ def test_pin_name_to_dict(pin_name_dict):
139139
"ARDUINO_UNO_D13": "PA_5",
140140
"ARDUINO_UNO_D14": "PB_9",
141141
"ARDUINO_UNO_D15": "PB_8",
142-
"USBTX": "PB_6",
143-
"USBRX": "PB_7",
142+
"CONSOLE_TX": "PB_6",
143+
"CONSOLE_RX": "PB_7",
144144
"LED1": "PA_5",
145145
"BUTTON1": "PC_2",
146146
"LED2": "PB_14",

hal/tests/pinvalidate/test_files/PinNames.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ typedef enum {
8282
LED3 = P1_21,
8383
LED4 = P1_23,
8484
#endif
85-
USBTX = P0_2,
86-
USBRX = P0_3,
85+
CONSOLE_TX = P0_2,
86+
CONSOLE_RX = P0_3,
8787

8888
// Arch Pro Pin Names
8989
D0 = P4_29,

hal/tests/pinvalidate/test_files/PinNames_test.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ typedef enum {
119119
ARDUINO_UNO_D15 = PB_8, // I2C SCL / GPIO
120120

121121
// valid STDIO definitions for console print
122-
USBTX = PB_6,
123-
USBRX = PB_7,
122+
CONSOLE_TX = PB_6,
123+
CONSOLE_RX = PB_7,
124124

125125
// invalid legacy LED/BUTTON definitions
126126
// these should be a #define, not in an enum

hal/tests/pinvalidate/test_files/duplicate_file/PinNames.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ typedef enum {
8282
LED3 = P1_21,
8383
LED4 = P1_23,
8484
#endif
85-
USBTX = P0_2,
86-
USBRX = P0_3,
85+
CONSOLE_TX = P0_2,
86+
CONSOLE_RX = P0_3,
8787

8888
// Arch Pro Pin Names
8989
D0 = P4_29,

0 commit comments

Comments
 (0)