89 lines
1.9 KiB
C
89 lines
1.9 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file : hal_uart.h
|
|
* @brief : UART hardware abstraction layer header file
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
|
|
#ifndef HAL_UART_H
|
|
#define HAL_UART_H
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
|
|
/**
|
|
* @brief UART parity definitions
|
|
*/
|
|
typedef enum {
|
|
HAL_UART_PARITY_NONE = 0U,
|
|
HAL_UART_PARITY_ODD = 1U,
|
|
HAL_UART_PARITY_EVEN = 2U
|
|
} hal_uart_parity_t;
|
|
|
|
/**
|
|
* @brief UART stop bits definitions
|
|
*/
|
|
typedef enum {
|
|
HAL_UART_STOPBITS_1 = 0U,
|
|
HAL_UART_STOPBITS_2 = 1U
|
|
} hal_uart_stopbits_t;
|
|
|
|
/**
|
|
* @brief UART data bits definitions
|
|
*/
|
|
typedef enum {
|
|
HAL_UART_DATABITS_8 = 0U,
|
|
HAL_UART_DATABITS_9 = 1U
|
|
} hal_uart_databits_t;
|
|
|
|
/**
|
|
* @brief UART configuration structure
|
|
*/
|
|
typedef struct {
|
|
uint32_t baudrate;
|
|
hal_uart_parity_t parity;
|
|
hal_uart_stopbits_t stopbits;
|
|
hal_uart_databits_t databits;
|
|
} hal_uart_config_t;
|
|
|
|
/**
|
|
* @brief Initialize UART hardware
|
|
*/
|
|
void hal_uart_init(void);
|
|
|
|
/**
|
|
* @brief Configure UART parameters
|
|
* @param config: UART configuration structure
|
|
*/
|
|
void hal_uart_config(const hal_uart_config_t *config);
|
|
|
|
/**
|
|
* @brief Send data over UART
|
|
* @param data: Pointer to data buffer
|
|
* @param length: Data length in bytes
|
|
*/
|
|
void hal_uart_send(const uint8_t *data, size_t length);
|
|
|
|
/**
|
|
* @brief Receive data over UART
|
|
* @param data: Pointer to data buffer
|
|
* @param length: Data length to receive in bytes
|
|
* @retval Number of bytes received
|
|
*/
|
|
size_t hal_uart_receive(uint8_t *data, size_t length);
|
|
|
|
/**
|
|
* @brief Check if UART is ready to send
|
|
* @retval 1 if ready, 0 otherwise
|
|
*/
|
|
uint8_t hal_uart_is_tx_ready(void);
|
|
|
|
/**
|
|
* @brief Check if UART has data to receive
|
|
* @retval 1 if data available, 0 otherwise
|
|
*/
|
|
uint8_t hal_uart_is_rx_ready(void);
|
|
|
|
#endif /* HAL_UART_H */ |