diff options
author | marc hoffman <marc.m.hoffman@gmail.com> | 2017-01-29 21:48:55 -0500 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-02-03 17:15:43 +1100 |
commit | 91eb0153d30420618b06efd18631490ac7fbfaae (patch) | |
tree | 83098e3bada4c2c151be6df799843830e03538a2 /esp8266/machine_uart.c | |
parent | 90ab191b65a83d20fbae98014642e08afdc8d1ae (diff) | |
download | micropython-91eb0153d30420618b06efd18631490ac7fbfaae.tar.gz micropython-91eb0153d30420618b06efd18631490ac7fbfaae.zip |
esp8266/uart: Add support for polling uart device.
Diffstat (limited to 'esp8266/machine_uart.c')
-rw-r--r-- | esp8266/machine_uart.c | 18 |
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 = { |