Skip to content

Commit cc0249c

Browse files
robert-hhdpgeorge
authored andcommitted
nrf/modules/machine/uart: Implement uart.flush() and uart.txdone().
Since uart.write() of the nrf port waits until all bytes but the last one have been sent, uart.flush() and uart.txdone() are implemented as empty functions to provide API consistency. uart.flush() flush() will always return immediately, even if the last byte may still be sent. ret = uart.txdone() uart.txdone() will always return True, even if the last byte may still be sent.
1 parent 8ea6fef commit cc0249c

File tree

1 file changed

+13
-0
lines changed
  • ports/nrf/modules/machine

1 file changed

+13
-0
lines changed

ports/nrf/modules/machine/uart.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@ STATIC mp_obj_t machine_hard_uart_sendbreak(mp_obj_t self_in) {
292292
}
293293
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_hard_uart_sendbreak_obj, machine_hard_uart_sendbreak);
294294

295+
// Since uart.write() waits up to the last byte, uart.txdone() always returns True.
296+
STATIC mp_obj_t machine_uart_txdone(mp_obj_t self_in) {
297+
return mp_const_true;
298+
}
299+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_txdone_obj, machine_uart_txdone);
300+
295301
STATIC const mp_rom_map_elem_t machine_hard_uart_locals_dict_table[] = {
296302
// instance methods
297303
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
@@ -302,6 +308,8 @@ STATIC const mp_rom_map_elem_t machine_hard_uart_locals_dict_table[] = {
302308
{ MP_ROM_QSTR(MP_QSTR_writechar), MP_ROM_PTR(&machine_hard_uart_writechar_obj) },
303309
{ MP_ROM_QSTR(MP_QSTR_readchar), MP_ROM_PTR(&machine_hard_uart_readchar_obj) },
304310
{ MP_ROM_QSTR(MP_QSTR_sendbreak), MP_ROM_PTR(&machine_hard_uart_sendbreak_obj) },
311+
{ MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&mp_stream_flush_obj) },
312+
{ MP_ROM_QSTR(MP_QSTR_txdone), MP_ROM_PTR(&machine_uart_txdone_obj) },
305313

306314
// class constants
307315
/*
@@ -347,6 +355,11 @@ STATIC mp_uint_t machine_hard_uart_write(mp_obj_t self_in, const void *buf_in, m
347355
STATIC mp_uint_t machine_hard_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
348356
machine_hard_uart_obj_t *self = self_in;
349357
(void)self;
358+
359+
if (request == MP_STREAM_FLUSH) {
360+
// Since uart.write() waits up to the last byte, uart.flush() always succeds.
361+
return 0;
362+
}
350363
return MP_STREAM_ERROR;
351364
}
352365

0 commit comments

Comments
 (0)