Files
stm32f407ve_black/HAL/Inc/hal_uart.h
2026-01-23 14:35:51 +08:00

114 lines
2.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>
#include "hal.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
* @retval HAL status code
*/
hal_ret_t hal_uart_init(void);
/**
* @brief Configure UART parameters for specific instance
* @param config: UART configuration structure
* @retval HAL status code
*/
hal_ret_t 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
* @retval HAL status code
*/
hal_ret_t 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
* @param received: Pointer to store number of bytes received
* @retval HAL status code
*/
hal_ret_t hal_uart_receive(hal_uart_instance_t instance, uint8_t *data, size_t length, size_t *received);
/**
* @brief Check if specific UART instance is ready to send
* @param instance: UART instance identifier
* @param ready: Pointer to store ready status (1 if ready, 0 otherwise)
* @retval HAL status code
*/
hal_ret_t hal_uart_is_tx_ready(hal_uart_instance_t instance, uint8_t *ready);
/**
* @brief Check if specific UART instance has data to receive
* @param instance: UART instance identifier
* @param ready: Pointer to store ready status (1 if data available, 0 otherwise)
* @retval HAL status code
*/
hal_ret_t hal_uart_is_rx_ready(hal_uart_instance_t instance, uint8_t *ready);
#endif /* HAL_UART_H */