#ifndef USER_DRIVERS_UART_C_
#define USER_DRIVERS_UART_C_

#include "CH57x_common.h"

#define Recv_2400_TimeOut           3       //ms
#define Recv_9600_TimeOut           3       //ms
#define Recv_115200_TimeOut         3       //ms

#define USART_BUFFER_NUM            3
#define USART_BUFFER_SIZE           80

#define UART_SEND_BUFFER_NUM        5
#define UART_SEND_BUFFER_SIZE       20


#define MCU485_EN_High              //GPIOA_SetBits(GPIO_Pin_12)
#define MCU485_EN_Low               //GPIOA_ResetBits(GPIO_Pin_12)

typedef uint8_t (*Uart_prt)(uint8_t *,uint16_t);

typedef enum
{
    UART_0,

    UART_MAX,
}UART_IDX;

typedef struct{

    uint8_t     RecvBuffer[USART_BUFFER_SIZE];
    uint8_t     Receiving;
    uint16_t    RecvLen;

    uint32_t    RecvTimeout;
    uint32_t    RecvIdleTiming;

    Uart_prt    processing_cf;      //´¦Àíº¯ÊýÖ¸Õë
}__attribute__((packed)) UART_t;

extern UART_t g_uart[UART_MAX];

void UARTx_Init(UART_IDX uart_id, uint32_t buad, Uart_prt prt_cf) ;
void Set_Uart_recvTimeout(UART_t *set_uart,uint32_t baud);
void UART_RECEIVE(void);

#endif /* USER_DRIVEN_UART_C_ */
