80 lines
1.7 KiB
C
80 lines
1.7 KiB
C
/* 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 {
|
|
hal_uart_instance_t instance;
|
|
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 */ |