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

Commit 8f85552

Browse files
geza-pycomiwahdan88
authored andcommitted
PYFW-323: UART.sendbreak does not default to 13 bits as suggested by Documentation
1 parent 8f74728 commit 8f85552

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

esp32/mods/machuart.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,16 +527,26 @@ STATIC mp_obj_t mach_uart_wait_tx_done(mp_obj_t self_in, mp_obj_t timeout_ms) {
527527
}
528528
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mach_uart_wait_tx_done_obj, mach_uart_wait_tx_done);
529529

530-
STATIC mp_obj_t mach_uart_sendbreak(mp_obj_t self_in, mp_obj_t bits) {
531-
mach_uart_obj_t *self = self_in;
530+
STATIC mp_obj_t mach_uart_sendbreak(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
531+
532+
STATIC const mp_arg_t mach_uart_sendbreak_args[] = {
533+
{ MP_QSTR_bits, MP_ARG_INT, {.u_int = 13} }
534+
};
535+
536+
mp_arg_val_t args[MP_ARRAY_SIZE(mach_uart_sendbreak_args)];
537+
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &mach_uart_sendbreak_args[0], args);
538+
539+
mach_uart_obj_t *self = pos_args[0];
540+
mp_int_t bits = args[0].u_int;
541+
532542
MACH_UART_CHECK_INIT(self)
533543
pin_obj_t * pin = (pin_obj_t *)((mp_obj_t *)self->pins)[0];
534544

535545
uint32_t isrmask = MICROPY_BEGIN_ATOMIC_SECTION();
536546

537547
// only if the bus is initialized
538548
if (self->config.baud_rate > 0) {
539-
uint32_t delay = (((mp_obj_get_int(bits) + 1) * 1000000) / self->config.baud_rate) & 0x7FFF;
549+
uint32_t delay = (((bits + 1) * 1000000) / self->config.baud_rate) & 0x7FFF;
540550

541551
if (self->n_pins == 1) {
542552
// make it UART Tx
@@ -563,7 +573,7 @@ STATIC mp_obj_t mach_uart_sendbreak(mp_obj_t self_in, mp_obj_t bits) {
563573

564574
return mp_const_none;
565575
}
566-
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mach_uart_sendbreak_obj, mach_uart_sendbreak);
576+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mach_uart_sendbreak_obj, 1, mach_uart_sendbreak);
567577

568578
STATIC const mp_map_elem_t mach_uart_locals_dict_table[] = {
569579
// instance methods

0 commit comments

Comments
 (0)