diff options
Diffstat (limited to 'libmaple')
-rw-r--r-- | libmaple/usart.c | 16 | ||||
-rw-r--r-- | libmaple/usart.h | 1 |
2 files changed, 17 insertions, 0 deletions
diff --git a/libmaple/usart.c b/libmaple/usart.c index 998da17..0bdc37a 100644 --- a/libmaple/usart.c +++ b/libmaple/usart.c @@ -192,6 +192,22 @@ uint32 usart_tx(usart_dev *dev, const uint8 *buf, uint32 len) { } /** + * @brief Nonblocking USART receive. + * @param dev Serial port to receive bytes from + * @param buf Buffer to store received bytes into + * @param len Maximum number of bytes to store + * @return Number of bytes received + */ +uint32 usart_rx(usart_dev *dev, uint8 *buf, uint32 len) { + uint32 rxed = 0; + while (usart_data_available(dev) && rxed < len) { + *buf++ = usart_getc(dev); + rxed++; + } + return rxed; +} + +/** * @brief Transmit an unsigned integer to the specified serial port in * decimal format. * diff --git a/libmaple/usart.h b/libmaple/usart.h index e747e65..ed00e16 100644 --- a/libmaple/usart.h +++ b/libmaple/usart.h @@ -259,6 +259,7 @@ void usart_enable(usart_dev *dev); void usart_disable(usart_dev *dev); void usart_foreach(void (*fn)(usart_dev *dev)); uint32 usart_tx(usart_dev *dev, const uint8 *buf, uint32 len); +uint32 usart_rx(usart_dev *dev, uint8 *buf, uint32 len); void usart_putudec(usart_dev *dev, uint32 val); /** |