Skip to content

Commit e8992eb

Browse files
DvdGiessendpgeorge
authored andcommitted
esp32/machine_uart: Allow passing -1 to specify pin will be unused.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
1 parent b6bc2d4 commit e8992eb

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

ports/esp32/machine_uart.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -372,21 +372,12 @@ static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
372372
}
373373
check_esp_err(uart_get_baudrate(self->uart_num, &baudrate));
374374

375-
if (args[ARG_tx].u_obj != MP_OBJ_NULL) {
376-
self->tx = machine_pin_get_id(args[ARG_tx].u_obj);
377-
}
378-
379-
if (args[ARG_rx].u_obj != MP_OBJ_NULL) {
380-
self->rx = machine_pin_get_id(args[ARG_rx].u_obj);
381-
}
382-
383-
if (args[ARG_rts].u_obj != MP_OBJ_NULL) {
384-
self->rts = machine_pin_get_id(args[ARG_rts].u_obj);
385-
}
386-
387-
if (args[ARG_cts].u_obj != MP_OBJ_NULL) {
388-
self->cts = machine_pin_get_id(args[ARG_cts].u_obj);
389-
}
375+
// set pins
376+
#define SET_PIN(prop, arg) if (arg != MP_OBJ_NULL) prop = mp_obj_is_int(arg) && mp_obj_get_int(arg) == -1 ? UART_PIN_NO_CHANGE : machine_pin_get_id(arg);
377+
SET_PIN(self->tx, args[ARG_tx].u_obj);
378+
SET_PIN(self->rx, args[ARG_rx].u_obj);
379+
SET_PIN(self->rts, args[ARG_rts].u_obj);
380+
SET_PIN(self->cts, args[ARG_cts].u_obj);
390381
check_esp_err(uart_set_pin(self->uart_num, self->tx, self->rx, self->rts, self->cts));
391382

392383
// set data bits

0 commit comments

Comments
 (0)