107 lines
2.6 KiB
C
107 lines
2.6 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 instance identifier definitions
|
|
*/
|
|
typedef enum {
|
|
HAL_UART_INSTANCE_1 = 0U,
|
|
HAL_UART_INSTANCE_2,
|
|
HAL_UART_INSTANCE_3,
|
|
HAL_UART_INSTANCE_4,
|
|
HAL_UART_INSTANCE_5,
|
|
HAL_UART_INSTANCE_6,
|
|
HAL_UART_INSTANCE_MAX
|
|
} hal_uart_instance_t;
|
|
|
|
/**
|
|
* @brief UART configuration structure
|
|
*/
|
|
typedef struct {
|
|
hal_uart_instance_t instance;
|
|
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 for specific instance
|
|
* @param config: UART configuration structure
|
|
*/
|
|
void hal_uart_config(const hal_uart_config_t *config);
|
|
|
|
/**
|
|
* @brief Send data over specific UART instance
|
|
* @param instance: UART instance identifier
|
|
* @param data: Pointer to data buffer
|
|
* @param length: Data length in bytes
|
|
*/
|
|
void hal_uart_send(hal_uart_instance_t instance, const uint8_t *data, size_t length);
|
|
|
|
/**
|
|
* @brief Receive data from specific UART instance
|
|
* @param instance: UART instance identifier
|
|
* @param data: Pointer to data buffer
|
|
* @param length: Data length to receive in bytes
|
|
* @retval Number of bytes received
|
|
*/
|
|
size_t hal_uart_receive(hal_uart_instance_t instance, uint8_t *data, size_t length);
|
|
|
|
/**
|
|
* @brief Check if specific UART instance is ready to send
|
|
* @param instance: UART instance identifier
|
|
* @retval 1 if ready, 0 otherwise
|
|
*/
|
|
uint8_t hal_uart_is_tx_ready(hal_uart_instance_t instance);
|
|
|
|
/**
|
|
* @brief Check if specific UART instance has data to receive
|
|
* @param instance: UART instance identifier
|
|
* @retval 1 if data available, 0 otherwise
|
|
*/
|
|
uint8_t hal_uart_is_rx_ready(hal_uart_instance_t instance);
|
|
|
|
#endif /* HAL_UART_H */ |