#pragma once

#include <stdint.h>
#include "rkfifo.h"
#include "usart.h"
//#define BSP_USING_UART1
//#define BSP_USING_UART2
//#define BSP_USING_UART3
//#define BSP_USING_UART4
//#define BSP_USING_UART5

//#define BSP_UART_USING_DMA

#define BSP_UART_RX_BUFF_SIZE 64
#define BSP_UART_TX_BUFF_SIZE 64

typedef struct
{
    uint8_t _pTxBuff[BSP_UART_TX_BUFF_SIZE];
    uint8_t _pRxBuff[BSP_UART_RX_BUFF_SIZE];
    rkfifo_t _rxFifo;
    rkfifo_t _txFifo;
    UART_HandleTypeDef *huart;
#ifdef BSP_UART_USING_DMA /* dma 相关配置 */
    uint32_t _dmarx_remaining_cnt;
    DMA_HandleTypeDef *_dmarx_handle;
    DMA_HandleTypeDef *_dmatx_handle;
#endif
} Serial;

#ifdef BSP_USING_UART1
extern Serial serial1;
#endif
#ifdef BSP_USING_UART2
extern Serial serial2;
#endif
#ifdef BSP_USING_UART3
extern Serial serial3;
#endif
#ifdef BSP_USING_UART4
extern Serial serial4;
#endif
#ifdef BSP_USING_UART5
extern Serial serial5;
#endif

void bspSerialInit(void);

int bspSerialSetTxdoneCallback(Serial *serial, int (*txCompleteCallback)(void *arg));

int bspSerialReadReady(Serial *serial, uint32_t timeOut);

int bspSerialWriteDone(Serial *serial, uint32_t timeOut);

uint32_t bspSerialWrite(Serial *serial, const uint8_t *pTxData, uint32_t txLen);

uint32_t bspSerialRead(Serial *serial, uint8_t *pTxData, uint32_t txLen);
void _uartIsr( Serial *serial );
//static int _serialInit(Serial *serial, UART_HandleTypeDef *huart);
