8000 stm32/machine_uart: Implement uart.flush() and uart.txdone(). · lowfatcode/micropython@8ea6fef · GitHub
[go: up one dir, main page]

Skip to content

Commit 8ea6fef

Browse files
robert-hhdpgeorge
authored andcommitted
stm32/machine_uart: Implement uart.flush() and uart.txdone().
Since uart.write() of the STM32 port waits until all bytes have been sent, uart.flush() and uart.txdone() are implemented as empty functions to provide API consistency. uart.flush() flush() will always return immediately. ret = uart.txdone() uart.txdone() will always return True.
1 parent 8804993 commit 8ea6fef

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ports/stm32/machine_uart.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,12 @@ STATIC mp_obj_t pyb_uart_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
523523
}
524524
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_irq_obj, 1, pyb_uart_irq);
525525

526+
// Since uart.write() waits up to the last byte, uart.txdone() always returns True.
527+
STATIC mp_obj_t machine_uart_txdone(mp_obj_t self_in) {
528+
return mp_const_true;
529+
}
530+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_txdone_obj, machine_uart_txdone);
531+
526532
STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = {
527533
// instance methods
528534

@@ -538,11 +544,13 @@ STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = {
538544
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
539545
/// \method write(buf)
540546
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
547+
{ MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&mp_stream_flush_obj) },
541548
{ MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pyb_uart_irq_obj) },
542549

543550
{ MP_ROM_QSTR(MP_QSTR_writechar), MP_ROM_PTR(&pyb_uart_writechar_obj) },
544551
{ MP_ROM_QSTR(MP_QSTR_readchar), MP_ROM_PTR(&pyb_uart_readchar_obj) },
545552
{ MP_ROM_QSTR(MP_QSTR_sendbreak), MP_ROM_PTR(&pyb_uart_sendbreak_obj) },
553+
{ MP_ROM_QSTR(MP_QSTR_txdone), MP_ROM_PTR(&machine_uart_txdone_obj) },
546554

547555
// class constants
548556
{ MP_ROM_QSTR(MP_QSTR_RTS), MP_ROM_INT(UART_HWCONTROL_RTS) },
@@ -635,6 +643,9 @@ STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t a
635643
if ((flags & MP_STREAM_POLL_WR) && uart_tx_avail(self)) {
636644
ret |= MP_STREAM_POLL_WR;
637645
}
646+
} else if (request == MP_STREAM_FLUSH) {
647+
// Since uart.write() waits up to the last byte, uart.flush() always succeds.
648+
ret = 0;
638649
} else {
639650
*errcode = MP_EINVAL;
640651
ret = MP_STREAM_ERROR;

0 commit comments

Comments
 (0)
0