From 64e63cd1bbd5866e41f1dc548ea52714d2e16a93 Mon Sep 17 00:00:00 2001 From: Gabriel Mariano Marcelino Date: Tue, 11 Jul 2023 21:57:00 -0300 Subject: [PATCH] firmware: drivers: uart: Minor improvements and adding doxygen documentation #43 --- firmware/drivers/uart/uart.c | 13 +++++----- firmware/drivers/uart/uart.h | 50 ++++++++++++++++++------------------ 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/firmware/drivers/uart/uart.c b/firmware/drivers/uart/uart.c index 56e9a95..bfb12fd 100644 --- a/firmware/drivers/uart/uart.c +++ b/firmware/drivers/uart/uart.c @@ -166,12 +166,11 @@ int uart_init(uart_config_t config) int uart_write(uart_config_t config, uint16_t *data, uint16_t len) { int err = ERRNO_SUCCESS; - uint32_t usart; uint16_t i = 0U; for(i = 0U; i < len; i++) { - err = uart_send_byte(config, *(data + i)); + err = uart_send_byte(config, data[i]); } return err; @@ -179,7 +178,7 @@ int uart_write(uart_config_t config, uint16_t *data, uint16_t len) int uart_read(uart_config_t config, uint16_t *data, uint16_t len) { - int err; + int err = ERRNO_SUCCESS; uint16_t num_bytes = len; uint16_t i = 0U; queue_t *uart_rx_buffer; @@ -216,8 +215,8 @@ int uart_rx_enable(uart_config_t config) int uart_rx_disable(uart_config_t config) { - int err; - uint32_t usart; + int err = -1; + uint32_t usart = UINT32_MAX; err = uart_select_port_address(config, &usart); usart_disable_rx_interrupt(usart); @@ -240,7 +239,7 @@ uint16_t uart_read_available(uart_config_t config) int uart_flush(uart_config_t config) { - int err; + int err = ERRNO_SUCCESS; queue_t *uart_rx_buffer; @@ -258,7 +257,7 @@ int uart_flush(uart_config_t config) static inline int uart_send_byte(uart_config_t config, uint16_t c) { - int err = 0; + int err = ERRNO_SUCCESS; uint32_t usart; diff --git a/firmware/drivers/uart/uart.h b/firmware/drivers/uart/uart.h index c925840..c679f83 100644 --- a/firmware/drivers/uart/uart.h +++ b/firmware/drivers/uart/uart.h @@ -77,10 +77,10 @@ typedef enum */ typedef enum { - UART_SB_0_5=0, /**< . */ - UART_SB_1, /**< . */ - UART_SB_1_5, /**< . */ - UART_SB_2 /**< . */ + UART_SB_0_5=0, /**< 0.5 stop bit. */ + UART_SB_1, /**< 1 stop bit. */ + UART_SB_1_5, /**< 1.5 stop bit. */ + UART_SB_2 /**< 2 stop bits. */ } uart_sb_t; /** @@ -124,71 +124,71 @@ typedef struct } uart_config_t; /** - * \brief . + * \brief Initializes a given UART port. * - * \param[in] config . + * \param[in] config are the configuration parameters of the given UART port. * - * \return . + * \return The status/error code. */ int uart_init(uart_config_t config); /** - * \brief . + * \brief Writes data to a given UART port. * - * \param[in] config . + * \param[in] config are the configuration parameters of the given UART port. * - * \param[in] data . + * \param[in] data is the array of bytes to be written. * - * \param[in] len . + * \param[in] len is the number of bytes to be written. * - * \return . + * \return The status/error code. */ int uart_write(uart_config_t config, uint16_t *data, uint16_t len); /** - * \brief . + * \brief Reads data from a given UART port. * - * \param[in] config . + * \param[in] config are the configuration parameters of the given UART port. * - * \param[in,out] data . + * \param[in,out] data is a pointer to store the read data. * - * \param[in] len . + * \param[in] len is the number of bytes to read. * - * \return . + * \return The status/error code. */ int uart_read(uart_config_t config, uint16_t *data, uint16_t len); /** - * \brief . + * \brief Enables the RX of a given UART port. * - * \param[in] config . + * \param[in] config are the configuration parameters of the given UART port. * * \return The status/error code. */ int uart_rx_enable(uart_config_t config); /** - * \brief . + * \brief Disables the RX of a given UART port. * - * \param[in] config . + * \param[in] config are the configuration parameters of the given UART port. * * \return The status/error code. */ int uart_rx_disable(uart_config_t config); /** - * \brief . + * \brief Checks if there is available data to read from a given UART port. * - * \param[in] config . + * \param[in] config are the configuration parameters of the given UART port. * * \return The status/error code. */ uint16_t uart_read_available(uart_config_t config); /** - * \brief . + * \brief Flushes the RX buffer of a given UART port. * - * \param[in] config . + * \param[in] config are the configuration parameters of the given UART port. * * \return The status/error code. */