summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266/machine_uart.c
diff options
context:
space:
mode:
Diffstat (limited to 'esp8266/machine_uart.c')
-rw-r--r--esp8266/machine_uart.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/esp8266/machine_uart.c b/esp8266/machine_uart.c
index 9bc6422cc7..efdfafd1ae 100644
--- a/esp8266/machine_uart.c
+++ b/esp8266/machine_uart.c
@@ -255,8 +255,22 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t
}
STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
- *errcode = MP_EINVAL;
- return MP_STREAM_ERROR;
+ pyb_uart_obj_t *self = self_in;
+ mp_uint_t ret;
+ if (request == MP_STREAM_POLL) {
+ mp_uint_t flags = arg;
+ ret = 0;
+ if ((flags & MP_STREAM_POLL_RD) && uart_rx_any(self->uart_id)) {
+ ret |= MP_STREAM_POLL_RD;
+ }
+ if ((flags & MP_STREAM_POLL_WR) && uart_tx_any_room(self->uart_id)) {
+ ret |= MP_STREAM_POLL_WR;
+ }
+ } else {
+ *errcode = MP_EINVAL;
+ ret = MP_STREAM_ERROR;
+ }
+ return ret;
}
STATIC const mp_stream_p_t uart_stream_p = {