summaryrefslogtreecommitdiff
path: root/esp8266/uart.c
diff options
context:
space:
mode:
authormarc hoffman <marc.m.hoffman@gmail.com>2017-01-29 21:48:55 -0500
committerDamien George <damien.p.george@gmail.com>2017-02-03 17:15:43 +1100
commit91eb0153d30420618b06efd18631490ac7fbfaae (patch)
tree83098e3bada4c2c151be6df799843830e03538a2 /esp8266/uart.c
parent90ab191b65a83d20fbae98014642e08afdc8d1ae (diff)
esp8266/uart: Add support for polling uart device.
Diffstat (limited to 'esp8266/uart.c')
-rw-r--r--esp8266/uart.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/esp8266/uart.c b/esp8266/uart.c
index 001a9c673..6c1f9e095 100644
--- a/esp8266/uart.c
+++ b/esp8266/uart.c
@@ -200,6 +200,21 @@ bool uart_rx_wait(uint32_t timeout_us) {
}
}
+int uart_rx_any(uint8 uart) {
+ if (input_buf.iget != input_buf.iput) {
+ return true; // have at least 1 char ready for reading
+ }
+ return false;
+}
+
+int uart_tx_any_room(uint8 uart) {
+ uint32_t fifo_cnt = READ_PERI_REG(UART_STATUS(uart)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S);
+ if ((fifo_cnt >> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) >= 126) {
+ return false;
+ }
+ return true;
+}
+
// Returns char from the input buffer, else -1 if buffer is empty.
int uart_rx_char(void) {
return ringbuf_get(&input_buf);