/*** * @Author: shenghao.xu * @Date: 2023-04-11 16:06:04 * @LastEditors: shenghao.xu * @LastEditTime: 2023-04-11 16:27:54 * @Description: * @email:545403892@qq.com * @Copyright (c) 2023 by shenghao.xu, All Rights Reserved. */ #ifndef _USART_H #define _USART_H #include "sys.h" #include "usart.h" #include "lib.h" typedef void (*rx_interupt_cb_t)(UART_HandleTypeDef *huart); typedef enum { UART_1, // 串口1 UART_2, // 串口2 UART_3, // 串口3 UART_4, // 串口4 UART_5, // 串口5 UART_MAX, } uart_id_e; typedef struct { uart_id_e id; UART_HandleTypeDef *huart; uint16_t lastindex; uint16_t newindex; uint16_t rxIndex; // 接收数据索引 bool dma_rx_en; uint8_t *rx_buffer; uint16_t rx_sta; uint16_t rx_size; uint16_t txIndex; bool dma_tx_en; uint8_t *tx_buffer; uint16_t tx_size; // 接收中断回调 rx_interupt_cb_t rx_interupt_cb; } uart_t; extern void UartInit(uart_id_e id, UART_HandleTypeDef *huart, bool dma_rx_en, uint16_t rxsize, rx_interupt_cb_t rx_cb, bool dma_tx_en, uint16_t txsize); extern uart_t *UartGetHandle(uart_id_e id); extern void UartSend(uart_id_e id, uint8_t *data, uint16_t len); extern void UARTReceiveIT(uart_id_e id); #endif