添加串口读写
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* drv_usart.h
|
||||
*
|
||||
* Created on: Mar 31, 2023
|
||||
* Author: gxms0
|
||||
*/
|
||||
|
||||
#ifndef BSP_DRV_UART_H_
|
||||
#define BSP_DRV_UART_H_
|
||||
|
||||
#include "ch32v20x.h"
|
||||
#include "string.h"
|
||||
|
||||
#define RingBuffSize 128
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RINGBUFFER_NORMAL,
|
||||
RINGBUFFER_EMPTY,
|
||||
RINGBUFFER_FULL,
|
||||
RINGBUFFER_HALFFULL,
|
||||
}RingBuffer_State;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t buff[RingBuffSize];
|
||||
uint16_t Write;
|
||||
uint16_t Read;
|
||||
uint16_t Size;
|
||||
}RingBuff_Type;
|
||||
|
||||
|
||||
|
||||
|
||||
typedef enum eUART_FIFO_MODE
|
||||
{
|
||||
UART_FIFO_BLOCK = 0,
|
||||
UART_FIFO_IT,
|
||||
UART_FIFO_DMA,
|
||||
} uart_fifo_mode_t;
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct sUART
|
||||
{
|
||||
USART_TypeDef *USART;
|
||||
|
||||
GPIO_TypeDef *GPIO_Tx;
|
||||
GPIO_TypeDef *GPIO_Rx;
|
||||
uint32_t Pin_Tx;
|
||||
uint32_t Pin_Rx;
|
||||
|
||||
|
||||
uint8_t *buffer_rx;
|
||||
uint8_t *buffer_tx;
|
||||
|
||||
size_t buffer_rx_head;
|
||||
size_t buffer_rx_tail;
|
||||
size_t buffer_tx_head;
|
||||
size_t buffer_tx_tail;
|
||||
size_t buffer_rx_len;
|
||||
size_t buffer_tx_len;
|
||||
size_t buffer_tx_len_2;
|
||||
|
||||
|
||||
|
||||
struct sUART *next_ptr;
|
||||
|
||||
}UART_t;
|
||||
|
||||
typedef UART_t* UART_ptr;
|
||||
|
||||
|
||||
|
||||
void usart_init(void);
|
||||
|
||||
void usart_config(UART_ptr ptr,USART_TypeDef *UART, GPIO_TypeDef *GPIO_Tx, uint32_t Pin_Tx, GPIO_TypeDef *GPIO_Rx, uint32_t Pin_Rx,
|
||||
uint32_t BaudRate, uint16_t WordLength, uint16_t StopBits, uint16_t Parity,
|
||||
uint32_t buff_tx_len,uint32_t buff_rx_len);
|
||||
|
||||
size_t usart_read(UART_ptr ptr,unsigned char *buff,const unsigned int len);
|
||||
|
||||
size_t usart_write(UART_ptr ptr,const unsigned char *buff,const unsigned int len);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* BSP_DRV_UART_H_ */
|
||||
Reference in New Issue
Block a user