Files
ballu-remote/src/uart_driver.h

74 lines
1.8 KiB
C

#ifndef UART_DRIVER_H
#define UART_DRIVER_H
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
/**
* @brief UART configuration structure
*/
typedef struct {
int tx_pin;
int rx_pin;
int baud_rate;
int data_bits;
int parity; // 0 = none, 1 = odd, 2 = even
int stop_bits;
} uart_config_t;
/**
* @brief UART driver handle
*/
typedef struct {
int uart_num;
bool initialized;
} uart_driver_t;
/**
* @brief Initialize UART driver
*
* @param driver Pointer to UART driver structure
* @param config UART configuration
* @return true if successful, false otherwise
*/
bool uart_driver_init(uart_driver_t *driver, const uart_config_t *config);
/**
* @brief Deinitialize UART driver
*
* @param driver Pointer to UART driver structure
*/
void uart_driver_deinit(uart_driver_t *driver);
/**
* @brief Send data via UART
*
* @param driver Pointer to UART driver structure
* @param data Pointer to data to send
* @param length Length of data to send
* @param timeout_ms Timeout in milliseconds
* @return true if successful, false otherwise
*/
bool uart_driver_send(uart_driver_t *driver, const uint8_t *data, size_t length, uint32_t timeout_ms);
/**
* @brief Receive data via UART
*
* @param driver Pointer to UART driver structure
* @param data Buffer to store received data
* @param max_length Maximum length of data to receive
* @param timeout_ms Timeout in milliseconds
* @return Number of bytes received, or -1 on error
*/
int uart_driver_receive(uart_driver_t *driver, uint8_t *data, size_t max_length, uint32_t timeout_ms);
/**
* @brief Check if UART driver is initialized
*
* @param driver Pointer to UART driver structure
* @return true if initialized, false otherwise
*/
bool uart_driver_is_initialized(const uart_driver_t *driver);
#endif // UART_DRIVER_H