Skip to content

Commit 4a11a23

Browse files
committed
Add 'tx' and 'rx' keyword args to UART.init() method.
These are intended to be used instead of the 'pins' argument, to set the tx/rx pins for the UART. Using tx/rx is much clearer than using a pins tuple. This also changes the UART default pins to the internal USB-serial TX/RX pins, so that uart.init(115200) can restore the REPL.
1 parent 9f3aac8 commit 4a11a23

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

inc/genhdr/qstrdefs.generated.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,8 @@ QDEF(MP_QSTR_baudrate, (const byte*)"\xf5\x08" "baudrate")
623623
QDEF(MP_QSTR_bits, (const byte*)"\x49\x04" "bits")
624624
QDEF(MP_QSTR_parity, (const byte*)"\x42\x06" "parity")
625625
QDEF(MP_QSTR_pins, (const byte*)"\x41\x04" "pins")
626+
QDEF(MP_QSTR_tx, (const byte*)"\x89\x02" "tx")
627+
QDEF(MP_QSTR_rx, (const byte*)"\xcf\x02" "rx")
626628
QDEF(MP_QSTR_readall, (const byte*)"\x76\x07" "readall")
627629
QDEF(MP_QSTR_readline, (const byte*)"\xf9\x08" "readline")
628630
QDEF(MP_QSTR_readinto, (const byte*)"\x4b\x08" "readinto")

inc/microbit/qstrdefsport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ Q(bits)
351351
Q(parity)
352352
Q(stop)
353353
Q(pins)
354+
Q(tx)
355+
Q(rx)
354356
Q(any)
355357
Q(read)
356358
Q(readall)

source/microbit/microbituart.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ STATIC mp_obj_t microbit_uart_init(mp_uint_t n_args, const mp_obj_t *pos_args, m
5151
{ MP_QSTR_parity, MP_ARG_OBJ, {.u_obj = mp_const_none} },
5252
{ MP_QSTR_stop, MP_ARG_INT, {.u_int = 1} },
5353
{ MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none } },
54+
{ MP_QSTR_tx, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none } },
55+
{ MP_QSTR_rx, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none } },
5456
};
5557

5658
// parse args
@@ -65,8 +67,19 @@ STATIC mp_obj_t microbit_uart_init(mp_uint_t n_args, const mp_obj_t *pos_args, m
6567
parity = (SerialParity)mp_obj_get_int(args[2].u_obj);
6668
}
6769

68-
PinName p_tx = MICROBIT_PIN_P0;
69-
PinName p_rx = MICROBIT_PIN_P1;
70+
// default pins are the internal USB-UART pins
71+
PinName p_tx = TGT_TX;
72+
PinName p_rx = TGT_RX;
73+
74+
// set tx/rx pins if they are given
75+
if (args[5].u_obj != mp_const_none) {
76+
p_tx = microbit_obj_get_pin_name(args[5].u_obj);
77+
}
78+
if (args[6].u_obj != mp_const_none) {
79+
p_rx = microbit_obj_get_pin_name(args[6].u_obj);
80+
}
81+
82+
// support for legacy "pins" argument
7083
if (args[4].u_obj != mp_const_none) {
7184
mp_obj_t *pins;
7285
mp_obj_get_array_fixed_n(args[4].u_obj, 2, &pins);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy