#ifndef __BSP_UART_H
#define __BSP_UART_H
#include "at32a423.h"
#include "circular_buffer.h"

//串口1
#define USART1_TX_BUF_LEN     2				//发送缓冲区大小
#define USART1_RX_BUF_LEN    2			  //接收的缓冲区大小
#define USART1_GPIOx         GPIOA
#define BSP_USART1_TX_PIN  	 GPIO_PINS_9  		// 串口0TX的引脚
#define BSP_USART1_RX_PIN  	 GPIO_PINS_10 		// 串口0RX的引脚

//串口2
#define USART2_TX_BUF_LEN     2				//发送缓冲区大小
#define USART2_RX_BUF_LEN    2			  //接收的缓冲区大小
#define USART2_GPIOx         GPIOB
#define BSP_USART2_TX_PIN  	 GPIO_PIN_10  		// 串口2TX的引脚
#define BSP_USART2_RX_PIN  	 GPIO_PIN_5 		// 串口2RX的引脚，GPIOC--5比较特殊

//串口3
#define USART3_TX_BUF_LEN     1024				//发送缓冲区大小
#define USART3_RX_BUF_LEN    1024			  //接收的缓冲区大小
#define USART3_GPIOx         GPIOB
#define BSP_USART3_TX_PIN  	 GPIO_PINS_10  		// 串口0TX的引脚
#define BSP_USART3_RX_PIN  	 GPIO_PINS_11 		// 串口0RX的引脚

//串口4
#define USART4_TX_BUF_LEN     2				//发送缓冲区大小
#define USART4_RX_BUF_LEN    2			  //接收的缓冲区大小
#define USART4_GPIOx         GPIOC
#define BSP_UART4_TX_PIN  	 GPIO_PIN_12  		// 串口0TX的引脚
#define BSP_UART4_RX_PIN  	 GPIO_PIN_2 		// 串口0RX的引脚，GPIOD--2

//串口5
#define USART5_TX_BUF_LEN     2				//发送缓冲区大小
#define USART5_RX_BUF_LEN    2			  //接收的缓冲区大小
#define USART5_GPIOx         GPIOB
#define BSP_USART5_TX_PIN  	 GPIO_PINS_3  		// 串口0TX的引脚
#define BSP_USART5_RX_PIN  	 GPIO_PINS_4 		// 串口0RX的引脚


#define CIRCULAR_BUFFER_ENABLE   1      //开启循环串口缓冲区

#if CIRCULAR_BUFFER_ENABLE
typedef enum {
    USART_0_TR,
    USART_1_TR,
    USART_2_TR,
    USART_3_TR,
		USART_4_TR,
		USART_5_TR,
} USART_COM_ID_T;
uint8_t usart_tx_push(USART_COM_ID_T com_id, uint8_t *data, uint16_t len);
uint8_t usart_rx_recv(USART_COM_ID_T com_id, uint8_t *data, uint16_t len);
unsigned int usart_rx_read(USART_COM_ID_T com_id,uint8_t *data,uint16_t len);
unsigned char usart_rx_at(USART_COM_ID_T com_id, uint8_t offset);
void usart_rx_drop(USART_COM_ID_T com_id, uint8_t drop_lens);
int usart_rx_get_rx_data_count(USART_COM_ID_T com_id);
int usart_rx_probe(USART_COM_ID_T com_id);
#endif


#define  ARRAYNUM(arr_name)   (uint32_t)(sizeof(arr_name) / sizeof(*(arr_name)))

void uart1_init(uint32_t band_rate);
void uart3_init(uint32_t band_rate);
void uart5_init(uint32_t band_rate);



#endif
