File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -222,6 +222,26 @@ int uart0_rx(void) {
222222}
223223*/
224224
225+ // Waits at most timeout microseconds for at least 1 char to become ready for reading.
226+ // Returns true if something available, false if not.
227+ bool uart_rx_wait (uint32_t timeout_us ) {
228+ uint32_t start = system_get_time ();
229+ for (;;) {
230+ if (input_buf .iget != input_buf .iput ) {
231+ return true; // have at least 1 char ready for reading
232+ }
233+ if (system_get_time () - start >= timeout_us ) {
234+ return false; // timeout
235+ }
236+ ets_event_poll ();
237+ }
238+ }
239+
240+ // Returns char from the input buffer, else -1 if buffer is empty.
241+ int uart_rx_char (void ) {
242+ return ringbuf_get (& input_buf );
243+ }
244+
225245int uart_rx_one_char (uint8 uart_no ) {
226246 if (READ_PERI_REG (UART_STATUS (uart_no )) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S )) {
227247 return READ_PERI_REG (UART_FIFO (uart_no )) & 0xff ;
Original file line number Diff line number Diff line change @@ -91,6 +91,8 @@ typedef struct {
9191
9292void uart_init (UartBautRate uart0_br , UartBautRate uart1_br );
9393int uart0_rx (void );
94+ bool uart_rx_wait (uint32_t timeout_us );
95+ int uart_rx_char (void );
9496void uart_tx_one_char (uint8 uart , uint8 TxChar );
9597void uart_flush (uint8 uart );
9698void uart_os_config (int uart );
You can’t perform that action at this time.
0 commit comments