stmhal: uart.any() function now returns number of bytes available.
This commit is contained in:
parent
bd33aa313e
commit
f99491cbf7
@ -282,9 +282,15 @@ bool uart_init(pyb_uart_obj_t *uart_obj, uint32_t baudrate) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool uart_rx_any(pyb_uart_obj_t *self) {
|
mp_uint_t uart_rx_any(pyb_uart_obj_t *self) {
|
||||||
return self->read_buf_tail != self->read_buf_head
|
int buffer_bytes = self->read_buf_head - self->read_buf_tail;
|
||||||
|| __HAL_UART_GET_FLAG(&self->uart, UART_FLAG_RXNE) != RESET;
|
if (buffer_bytes < 0) {
|
||||||
|
return buffer_bytes + self->read_buf_len;
|
||||||
|
} else if (buffer_bytes > 0) {
|
||||||
|
return buffer_bytes;
|
||||||
|
} else {
|
||||||
|
return __HAL_UART_GET_FLAG(&self->uart, UART_FLAG_RXNE) != RESET;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Waits at most timeout milliseconds for at least 1 char to become ready for
|
// Waits at most timeout milliseconds for at least 1 char to become ready for
|
||||||
@ -670,11 +676,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_deinit_obj, pyb_uart_deinit);
|
|||||||
/// Return `True` if any characters waiting, else `False`.
|
/// Return `True` if any characters waiting, else `False`.
|
||||||
STATIC mp_obj_t pyb_uart_any(mp_obj_t self_in) {
|
STATIC mp_obj_t pyb_uart_any(mp_obj_t self_in) {
|
||||||
pyb_uart_obj_t *self = self_in;
|
pyb_uart_obj_t *self = self_in;
|
||||||
if (uart_rx_any(self)) {
|
return MP_OBJ_NEW_SMALL_INT(uart_rx_any(self));
|
||||||
return mp_const_true;
|
|
||||||
} else {
|
|
||||||
return mp_const_false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_any_obj, pyb_uart_any);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_any_obj, pyb_uart_any);
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ void uart_init0(void);
|
|||||||
void uart_deinit(void);
|
void uart_deinit(void);
|
||||||
void uart_irq_handler(mp_uint_t uart_id);
|
void uart_irq_handler(mp_uint_t uart_id);
|
||||||
|
|
||||||
bool uart_rx_any(pyb_uart_obj_t *uart_obj);
|
mp_uint_t uart_rx_any(pyb_uart_obj_t *uart_obj);
|
||||||
int uart_rx_char(pyb_uart_obj_t *uart_obj);
|
int uart_rx_char(pyb_uart_obj_t *uart_obj);
|
||||||
void uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len);
|
void uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len);
|
||||||
void uart_tx_strn_cooked(pyb_uart_obj_t *uart_obj, const char *str, uint len);
|
void uart_tx_strn_cooked(pyb_uart_obj_t *uart_obj, const char *str, uint len);
|
||||||
|
@ -172,11 +172,11 @@ bool uart_init(pyb_uart_obj_t *uart_obj, uint32_t baudrate) {
|
|||||||
return uart_init2(uart_obj);
|
return uart_init2(uart_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool uart_rx_any(pyb_uart_obj_t *uart_obj) {
|
mp_uint_t uart_rx_any(pyb_uart_obj_t *uart_obj) {
|
||||||
#if 0
|
#if 0
|
||||||
return __HAL_UART_GET_FLAG(&uart_obj->uart, UART_FLAG_RXNE);
|
return __HAL_UART_GET_FLAG(&uart_obj->uart, UART_FLAG_RXNE);
|
||||||
#else
|
#else
|
||||||
return false;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ UART YB
|
|||||||
ValueError Z
|
ValueError Z
|
||||||
UART(1, baudrate=9600, bits=8, parity=None, stop=1, timeout=1000, timeout_char=0, read_buf_len=64)
|
UART(1, baudrate=9600, bits=8, parity=None, stop=1, timeout=1000, timeout_char=0, read_buf_len=64)
|
||||||
UART(1, baudrate=2400, bits=8, parity=None, stop=1, timeout=1000, timeout_char=0, read_buf_len=64)
|
UART(1, baudrate=2400, bits=8, parity=None, stop=1, timeout=1000, timeout_char=0, read_buf_len=64)
|
||||||
False
|
0
|
||||||
3
|
3
|
||||||
4
|
4
|
||||||
None
|
None
|
||||||
|
Loading…
Reference in New Issue
Block a user