summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2018-09-12 16:23:28 -0700
committerGitHub <noreply@github.com>2018-09-12 16:23:28 -0700
commit2dd9407f2125e724b4b9a1cdd4d0d0cc01284b31 (patch)
treead086ff3b420f9d6cca0d67bc77f61bef61cfe77 /shared-bindings
parentbeb9446f306642467b8fbc476179bc78994213c2 (diff)
parent6a72084198b10df61b1cf85fb8340f864bc54031 (diff)
Merge pull request #1186 from dhalbert/uart-enhancements3.0.2
UART enhancements
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/busio/UART.c35
-rw-r--r--shared-bindings/busio/UART.h1
2 files changed, 35 insertions, 1 deletions
diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c
index 9bad2468e..864fb974a 100644
--- a/shared-bindings/busio/UART.c
+++ b/shared-bindings/busio/UART.c
@@ -252,6 +252,36 @@ const mp_obj_property_t busio_uart_baudrate_obj = {
(mp_obj_t)&mp_const_none_obj},
};
+//| .. attribute:: in_waiting
+//|
+//| The number of bytes in the input buffer, available to be read
+//|
+STATIC mp_obj_t busio_uart_obj_get_in_waiting(mp_obj_t self_in) {
+ busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ raise_error_if_deinited(common_hal_busio_uart_deinited(self));
+ return MP_OBJ_NEW_SMALL_INT(common_hal_busio_uart_rx_characters_available(self));
+}
+MP_DEFINE_CONST_FUN_OBJ_1(busio_uart_get_in_waiting_obj, busio_uart_obj_get_in_waiting);
+
+const mp_obj_property_t busio_uart_in_waiting_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&busio_uart_get_in_waiting_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+//| .. method:: reset_input_buffer()
+//|
+//| Discard any unread characters in the input buffer.
+//|
+STATIC mp_obj_t busio_uart_obj_reset_input_buffer(mp_obj_t self_in) {
+ busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ raise_error_if_deinited(common_hal_busio_uart_deinited(self));
+ common_hal_busio_uart_clear_rx_buffer(self);
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(busio_uart_reset_input_buffer_obj, busio_uart_obj_reset_input_buffer);
+
//| .. class:: busio.UART.Parity
//|
//| Enum-like class to define the parity used to verify correct data transfer.
@@ -306,9 +336,12 @@ STATIC const mp_rom_map_elem_t busio_uart_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_reset_input_buffer), MP_ROM_PTR(&busio_uart_reset_input_buffer_obj) },
+
// Properties
{ MP_ROM_QSTR(MP_QSTR_baudrate), MP_ROM_PTR(&busio_uart_baudrate_obj) },
-
+ { MP_ROM_QSTR(MP_QSTR_in_waiting), MP_ROM_PTR(&busio_uart_in_waiting_obj) },
+
// Nested Enum-like Classes.
{ MP_ROM_QSTR(MP_QSTR_Parity), MP_ROM_PTR(&busio_uart_parity_type) },
};
diff --git a/shared-bindings/busio/UART.h b/shared-bindings/busio/UART.h
index fa39d8ad5..513ff50c8 100644
--- a/shared-bindings/busio/UART.h
+++ b/shared-bindings/busio/UART.h
@@ -60,6 +60,7 @@ extern void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t
extern uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self);
+extern void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self);
extern bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_UART_H