实现串口驱动,移植方便
This commit is contained in:
79
Modules/uart/inc/uart.h
Normal file
79
Modules/uart/inc/uart.h
Normal file
@ -0,0 +1,79 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : uart.h
|
||||
* @brief : UART driver module header file
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef UART_H
|
||||
#define UART_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "hal_uart.h"
|
||||
|
||||
/**
|
||||
* @brief UART configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t baudrate;
|
||||
hal_uart_parity_t parity;
|
||||
hal_uart_stopbits_t stopbits;
|
||||
hal_uart_databits_t databits;
|
||||
} uart_config_t;
|
||||
|
||||
/**
|
||||
* @brief UART instance structure
|
||||
*/
|
||||
typedef struct {
|
||||
uart_config_t config;
|
||||
uint8_t initialized;
|
||||
} uart_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize UART module
|
||||
*/
|
||||
void uart_init(void);
|
||||
|
||||
/**
|
||||
* @brief Configure UART parameters
|
||||
* @param config: UART configuration structure
|
||||
*/
|
||||
void uart_config(const uart_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Send data over UART
|
||||
* @param data: Pointer to data buffer
|
||||
* @param length: Data length in bytes
|
||||
*/
|
||||
void uart_send(const uint8_t *data, size_t length);
|
||||
|
||||
/**
|
||||
* @brief Send string over UART
|
||||
* @param str: Pointer to string
|
||||
*/
|
||||
void uart_send_string(const char *str);
|
||||
|
||||
/**
|
||||
* @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 uart_receive(uint8_t *data, size_t length);
|
||||
|
||||
/**
|
||||
* @brief Check if UART is ready to send
|
||||
* @retval 1 if ready, 0 otherwise
|
||||
*/
|
||||
uint8_t uart_is_tx_ready(void);
|
||||
|
||||
/**
|
||||
* @brief Check if UART has data to receive
|
||||
* @retval 1 if data available, 0 otherwise
|
||||
*/
|
||||
uint8_t uart_is_rx_ready(void);
|
||||
|
||||
#endif /* UART_H */
|
||||
Reference in New Issue
Block a user