Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 9c3def9

Browse files
committed
PYFW-323: UART.sendbreak does not default to 13 bits as suggested by Documentation
1 parent 5e6eaf3 commit 9c3def9

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

esp32/mods/machuart.c

+14-4
Original file line numberDiff line numberDiff line change
@@ -523,16 +523,26 @@ STATIC mp_obj_t mach_uart_wait_tx_done(mp_obj_t self_in, mp_obj_t timeout_ms) {
523523
}
524524
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mach_uart_wait_tx_done_obj, mach_uart_wait_tx_done);
525525

526-
STATIC mp_obj_t mach_uart_sendbreak(mp_obj_t self_in, mp_obj_t bits) {
527-
mach_uart_obj_t *self = self_in;
526+
STATIC mp_obj_t mach_uart_sendbreak(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
527+
528+
STATIC const mp_arg_t mach_uart_sendbreak_args[] = {
529+
{ MP_QSTR_bits, MP_ARG_INT, {.u_int = 13} }
530+
};
531+
532+
mp_arg_val_t args[MP_ARRAY_SIZE(mach_uart_sendbreak_args)];
533+
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &mach_uart_sendbreak_args[0], args);
534+
535+
mach_uart_obj_t *self = pos_args[0];
536+
mp_int_t bits = args[0].u_int;
537+
528538
MACH_UART_CHECK_INIT(self)
529539
pin_obj_t * pin = (pin_obj_t *)((mp_obj_t *)self->pins)[0];
530540

531541
uint32_t isrmask = MICROPY_BEGIN_ATOMIC_SECTION();
532542

533543
// only if the bus is initialized
534544
if (self->config.baud_rate > 0) {
535-
uint32_t delay = (((mp_obj_get_int(bits) + 1) * 1000000) / self->config.baud_rate) & 0x7FFF;
545+
uint32_t delay = (((bits + 1) * 1000000) / self->config.baud_rate) & 0x7FFF;
536546

537547
if (self->n_pins == 1) {
538548
// make it UART Tx
@@ -559,7 +569,7 @@ STATIC mp_obj_t mach_uart_sendbreak(mp_obj_t self_in, mp_obj_t bits) {
559569

560570
return mp_const_none;
561571
}
562-
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mach_uart_sendbreak_obj, mach_uart_sendbreak);
572+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mach_uart_sendbreak_obj, 1, mach_uart_sendbreak);
563573

564574
STATIC const mp_map_elem_t mach_uart_locals_dict_table[] = {
565575
// instance methods

0 commit comments

Comments
 (0)