/**
  **********************************************************************************
  * @file    uart_hal.c
  * @author  Product application department
  * @version V1.0
  * @date    2020.02.13
  * @brief   UART模块HAL层驱动.
  *
  @verbatim
  ===================================================================================
                                  ##### 更新 #####
  ===================================================================================
  [..] 更新时间:
  [..] 更新人:
  [..] 更新内容:
        1. nothing.
  @endverbatim
*/

#include "uart_hal.h"
#include "uart_drv.h"


/*** 全局变量定义 ***************************************************************/
/** @
  * @{volatile
  */
/** @ 
  * @}
  */
/** @ 
  * @{static
  */
/** @ 
  * @}
  */
/*** 常量定义 *******************************************************************/
/** @
  * @{const
  */
/** @ 
  * @}
  */

/*** 函数定义 *******************************************************************/


/**
  *@brief 将DRV层状态转化为HAL层的状态.
  *-
  *@param[in] DrvStatus驱动层状态，参见@ref DRV_IIC_StatusTypeDef
  *@retval @ref HAL_StatusTypeDef
  */
static HAL_StatusTypeDef DrvStatusToHalStatus(DRV_UART_StatusTypeDef DrvStatus)
{
    switch(DrvStatus)
    {
        case DRV_UART_OK:
        {
            return(HAL_OK);
        }

        case DRV_UART_ERROR:
        {
            return(HAL_ERROR);
        }

        case DRV_UART_BUSY:
        {
            return(HAL_BUSY);
        }

        case DRV_UART_TIMEOUT:
        {
            return(HAL_TIMEOUT);
        }
    }
}
/**
  *@brief 恢复UART模块的设置.
  *
  *@param[in] huart 指向UART_HandleTypeDef结构体指针;
  *@retval @ref HAL_StatusTypeDef
  */
HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart)
{
    DRV_UART_Deinit(huart->Instance);

    huart->pRxBuffPtr = 0;
    huart->RxXferCount = 0;
    huart->RxXferSize = 0;

    huart->pTxBuffPtr = 0;
    huart->TxXferCount = 0;
    huart->TxXferSize = 0;

    huart->State = HAL_UART_STATE_RESET;
    huart->ErrorCode = HAL_UART_ERROR_NONE;

	return(HAL_OK);
}
/**
  *@brief 根据UART_InitTypeDef指定的参数初始化UART模块,并初始化相关handle.
  *
  *@param[in] huart 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
  *@retval @ref HAL_StatusTypeDef
  */
HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart)
{
    /*
    if(huart->Instance == NULL)
        {
        return(HAL_ERROR);
    }
    */
    if(huart->State == HAL_UART_STATE_RESET)
    {
        HAL_UART_MspInit(huart);
    }

    huart->State = HAL_UART_STATE_BUSY;

    DRV_UART_Dis(huart->Instance);

    DRV_UART_Init(huart->Instance, huart->Init);

    DRV_UART_EnTx(huart->Instance);
    DRV_UART_EnRx(huart->Instance);

    huart->ErrorCode = HAL_UART_ERROR_NONE;
    huart->State = HAL_UART_STATE_READY;

    return(HAL_OK);
}
/**
  *@brief 初始化UART_HandleTypeDef结构体指定的UART模块的管脚、时钟、中断、DMAC等配置.
  *
  * @param[in] huart 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
  *@retval 无
  */
__weak void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{

}
/**
  *@brief 恢复UART_HandleTypeDef结构体指定的UART模块的管脚、时钟、中断、DMAC等为默认配置.
  *
  * @param[in] huart huart 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
  *@retval 无
  */
__weak void HAL_UART_MspDeInit(UART_HandleTypeDef *huart)
{

}
/**
  *@brief 查询方式通过指定的UART端口发送数据.
  *
  *@param[in] 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
  *@param[in] pData   待发送数据指针;
  *@param[in] Size    待发送数据长度;
  *@param[in] Timeout 超时时间;
  *@retval @ref HAL_StatusTypeDef
  */
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart,
                                    uint8_t *pData,
                                    uint16_t Size,
                                    uint32_t Timeout)
{
    uint16_t loop = 0;
	DRV_UART_StatusTypeDef DrvStatus = DRV_UART_OK;
    HAL_StatusTypeDef tmp_status = HAL_OK;

    /**/
    huart->TxXferSize = Size;
    huart->TxXferCount = 0;
    huart->pTxBuffPtr = pData;

    if(huart->State & HAL_UART_STATE_BUSY_RX)
    {
        huart->State = HAL_UART_STATE_BUSY_TX_RX;
    }
    else
    {
        huart->State = HAL_UART_STATE_BUSY_TX;
    }

    for(loop = 0; loop < huart->TxXferSize; loop++)
    {
        /*是否空了?*/
        tmp_status = DRV_UART_WaitonFlagTimeout(huart->Instance,
                                              UART_FLAG_INDEX_TDRE,
                                              SET,
                                              Timeout);

        if(tmp_status != HAL_OK)
        {
            return(HAL_TIMEOUT);
        }

        DRV_UART_SendData(huart->Instance, *(huart->pTxBuffPtr + loop), huart->Init.WordLength);
        /*发送完成*/
        DrvStatus = DRV_UART_WaitonFlagTimeout(huart->Instance,
                                              UART_FLAG_INDEX_TC,
                                              SET,
                                              Timeout);

        if(DrvStatus != DRV_UART_OK)			
        {
            return(HAL_TIMEOUT);
        }

        huart->TxXferCount++;
    }

    huart->State = HAL_UART_STATE_READY;

    return(HAL_OK);
}
/**
  *@brief 查询方式通过指定的UART端接收数据.
  *
  *@param[in] 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
  *@param[in] pData   待接收数据指针;
  *@param[in] Size    待接收数据长度;
  *@param[in] Timeout 超时时间;
  *@retval @ref HAL_StatusTypeDef
  */
HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart,
                                   uint8_t *pData,
                                   uint16_t Size,
                                   uint32_t Timeout)
{
    uint16_t loop = 0;
    uint16_t tmp_val = 0x00;
    DRV_UART_StatusTypeDef DrvStatus;
    HAL_StatusTypeDef tmp_status = HAL_OK;

    /**/
    huart->RxXferSize = Size;
    huart->RxXferCount = 0;
    huart->pRxBuffPtr = pData;

    for(loop = 0; loop < huart->RxXferSize; loop++)
    {
        /*是否空了?*/
        DrvStatus = DRV_UART_WaitonFlagTimeout(huart->Instance,
                                              UART_FLAG_INDEX_RDRF,
                                              SET,
                                              Timeout);

        if(DrvStatus != HAL_OK)
        {
            return(HAL_TIMEOUT);
        }

        DRV_UART_GetData(huart->Instance, &tmp_val, huart->Init.WordLength);
        *(huart->pRxBuffPtr + loop) = tmp_val;

        huart->RxXferCount++;
    }

    return(HAL_OK);
}
/**
 *@brief 中断方式通过指定的UART端口发送数据.
 *
 *@param[in] 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
 *@param[in] pData   待发送数据指针;
 *@param[in] Size    待发送数据长度;
 *@retval @ref HAL_StatusTypeDef
 */
HAL_StatusTypeDef HAL_UART_TransmitIT(UART_HandleTypeDef *huart,
                                      uint8_t *pData,
                                      uint16_t Size)
{
    HAL_StatusTypeDef tmp_status = HAL_OK;

    /**/
    huart->TxXferSize = Size;
    huart->TxXferCount = 0;
    huart->pTxBuffPtr = pData;

    if((huart->State & HAL_UART_STATE_BUSY_RX) == HAL_UART_STATE_BUSY_RX)
    {
        huart->State = HAL_UART_STATE_BUSY_TX_RX;
    }
    else
    {
        huart->State = HAL_UART_STATE_BUSY_TX;

    }

    /*使能TDRE--TIE中断*/
    DRV_UART_DisIt(huart->Instance, UART_IT_INDEX_TCIE);
    DRV_UART_EnIt(huart->Instance, UART_IT_INDEX_TDRE);

    return(HAL_OK);
}
/**
* @brief 中断方式接收数据
*
* @param huart huart 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
* @param pData 待接收数据指针;
* @param Size  待接收数据长度;
* @return  @ref HAL_StatusTypeDef
*/
HAL_StatusTypeDef HAL_UART_ReceiveIT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
{
    HAL_StatusTypeDef tmp_status = HAL_OK;

    /**/
    huart->RxXferSize = Size;
    huart->RxXferCount = 0;
    huart->pRxBuffPtr = pData;

    if((huart->State == HAL_UART_STATE_BUSY_TX) == HAL_UART_STATE_BUSY_TX)
    {
        huart->State = HAL_UART_STATE_BUSY_TX_RX;
    }
    else
    {
        huart->State = HAL_UART_STATE_BUSY_RX;
    }

    /*使能接收中断*/
    DRV_UART_EnIt(huart->Instance, UART_IT_INDEX_RIE);

    return(HAL_OK);
}


/**
 *@brief 中断方式通过指定的UART端口发送数据.
 *
 *@param[in] 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
 *@param[in] pData   待发送数据指针;
 *@param[in] Size    待发送数据长度;
 *@retval @ref HAL_StatusTypeDef
 */
void HAL_UART_SendByteIT(UART_TypeDef *UARTx, UINT8 SendByte)
{
		UART_SendByte(UARTx, SendByte);//发送接收到的数据
}
/**
* @brief 中断方式接收数据
*
* @param huart huart 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
* @param pData 待接收数据指针;
* @param Size  待接收数据长度;
* @return  @ref HAL_StatusTypeDef
*/
INT8 HAL_UART_RecvByteIT(UART_TypeDef *UARTx, UINT8 *dat)
{
	if (UART_RecvByte(UARTx, dat)== TRUE)//串口接收到数据
       return TRUE;
  else
			 return FALSE;
}

/**
  *@brief 发送完成回调函数.
  *
  * @param[in] huart 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
  *@retval 无
  */
__weak void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{

}
/**
  *@brief 接收完成回调函数.
  *
  * @param[in] huart 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
  *@retval 无
  */
__weak void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{

}
/**
  *@brief 中断服务函数.
  *
  * @param[in] huart 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
  *@retval 无
  */
void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
{
    uint8_t status1, status2;
    uint16_t tmp_val = 0x00;
    FlagStatusTypeDef it_src_flag = RESET;

    DRV_UART_GetStatus(huart->Instance, &status1, &status2);

    it_src_flag = DRV_UART_GetItSource(huart->Instance, UART_IT_INDEX_TCIE);

    if((status1 & (1 << UART_FLAG_INDEX_TC)) && (it_src_flag == SET))
    {
        /*发送完成中断*/
        DRV_UART_DisIt(huart->Instance, UART_IT_INDEX_TCIE);

        if((huart->State & HAL_UART_STATE_BUSY_TX_RX) == HAL_UART_STATE_BUSY_RX)
        {
            huart->State = HAL_UART_STATE_BUSY_RX;
        }
        else
        {
            huart->State = HAL_UART_STATE_READY;

        }

        /*回调函数*/
        HAL_UART_TxCpltCallback(huart);
    }

    /*发送空中断*/
    it_src_flag = DRV_UART_GetItSource(huart->Instance, UART_IT_INDEX_TDRE);

    if((status1 & (1 << UART_FLAG_INDEX_TDRE)) && (it_src_flag == SET))
    {
        /*发送剩余的数据*/
        DRV_UART_SendData(huart->Instance, *huart->pTxBuffPtr, huart->Init.WordLength);
        huart->TxXferCount++;

        if(huart->TxXferCount == huart->TxXferSize)
        {
            DRV_UART_EnIt(huart->Instance, UART_IT_INDEX_TCIE);
            DRV_UART_DisIt(huart->Instance, UART_IT_INDEX_TDRE);
        }

        else
        {
            huart->pTxBuffPtr++;
        }
    }

    /*接收中断*/
    it_src_flag =DRV_UART_GetItSource(huart->Instance, UART_IT_INDEX_RIE);

    if((status1 & (1 << UART_FLAG_INDEX_RDRF)) && (it_src_flag == SET))
    {
        if((huart->State == HAL_UART_STATE_BUSY_RX) || (huart->State == HAL_UART_STATE_BUSY_TX_RX))
        {
            DRV_UART_GetData(huart->Instance, &tmp_val, UART_WORDLENGTH_8B);
            *huart->pRxBuffPtr = tmp_val;
            huart->RxXferCount++;

            if(huart->RxXferCount == huart->RxXferSize)
            {
                DRV_UART_DisIt(huart->Instance, UART_IT_INDEX_RIE);

                huart->State = (huart->State == HAL_UART_STATE_BUSY_TX_RX) ? HAL_UART_STATE_BUSY_TX : HAL_UART_STATE_READY;

                HAL_UART_RxCpltCallback(huart);
            }

            else
            {
                huart->pRxBuffPtr++;
            }
        }
    }
}

/**
  *@brief 中断服务函数.
  *
  * @param[in] UARTx 指向UART_TypeDef结构体的指针,此结构体包含了UART模块的配置信息;
  *@retval 无
  */
void HAL_UART_ISR_IRQHandler(UART_TypeDef *UARTx)
{
	UART_ISR(UARTx);
}

/**
  *@brief 禁止串口TCIE中断.
  *
  *@param[in] huart 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
  *@retval 无
  */
void HAL_UART_DisItTcie(UART_HandleTypeDef *huart)
{
	DRV_UART_DisItTcie(huart->Instance);
}
/**
  *@brief 禁止串口TIE中断.
  *
  *@param[in] huart 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
  *@retval 无
  */
void HAL_UART_DisItTie(UART_HandleTypeDef *huart)
{
	DRV_UART_DisItTie(huart->Instance);
}
/**
  *@brief 禁止串口RE中断.
  *
  *@param[in] huart 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
  *@retval 无
  */
void HAL_UART_DisItRe(UART_HandleTypeDef *huart)
{
	DRV_UART_DisItRe(huart->Instance);
}
/**
  *@brief 获取当前状态.
  *
  *@param[in] huart 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
  *@retval 当前状态 @ref HAL_UART_StateTypeDef
  */
HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart)
{
	return(huart->State);
}
/**
  *@brief 获取当前错误码.
  *
  *@param[in] huart 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
  *@retval 错误码
  */
uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart)
{
	return(huart->ErrorCode);
}
/**
  *@brief 初始化UART_TypeDef指定的UART的管脚作为GPIO功能,GPIO_InitTypeDef为初始化信息如方向、上拉、输出模式、输入模式.
  *
  *@param[in] puart     指向UART_TypeDef结构体的指针;
  *@param[in] GPIO_Init 指向GPIO_InitTypeDef结构体的指针;
  *@attention
  *- 方向可独立设置;
  *- 上拉/下拉/三态影响
  *- 输出方式影响所有的管脚;
  *- 输入方式影响所有的管脚;
  *- 驱动能力影响所有的管脚;
  *- SLEWRATE影响所有的管脚;

  *@retval 无
  */
void  HAL_UART_GPIOInit(UART_TypeDef  *puart, GPIO_InitTypeDef *GPIO_Init)
{
    if(GPIO_Init->Pin == UART_PIN_TXD)
    {
        DRV_UART_DisTx(puart);

        if(GPIO_Init->Dir == GPIO_DIR_IN)
        {
            DRV_UART_SetTxdDirInput(puart);
        }
        else if(GPIO_Init->Dir == GPIO_DIR_OUT)
        {
            DRV_UART_SetTxdDirOutput(puart);

            /*cmos还是OPENDRAIN输出*/
            if(GPIO_Init->OutputMode == GPIO_OUTPUT_MODE_OPEN_DRAIN)
            {

            }
            else if(GPIO_Init->OutputMode == GPIO_OUTPUT_MODE_CMOS)
            {

            }
        }
        else if(GPIO_Init->Dir == GPIo_DIR_TRIGATE)
        {
            /*IO control 控制*/
        }

        /*上拉\下拉的控制在IO conttrol*/
        if(GPIO_Init->PullMode == GPIO_PULL_MODE_NOPULL)
        {
            /*既不上拉也不下拉*/
        }
        else if(GPIO_Init->PullMode == GPIO_PULL_MODE_UP)
        {
            /*上拉*/
        }
        else if(GPIO_Init->PullMode == GPIO_PULL_MODE_DOWN)
        {
            /*下拉*/
        }
    }
    else if(GPIO_Init->Pin == UART_PIN_RXD)
    {
        DRV_UART_DisRx(puart);

        if(GPIO_Init->Dir == GPIO_DIR_IN)
        {
            DRV_UART_SetRxdDirInput(puart);
        }
        else if(GPIO_Init->Dir == GPIO_DIR_OUT)
        {
            DRV_UART_SetRxdDirOutput(puart);

            /*cmos还是OPENDRAIN输出*/
            if(GPIO_Init->OutputMode == GPIO_OUTPUT_MODE_OPEN_DRAIN)
            {

            }
            else if(GPIO_Init->OutputMode == GPIO_OUTPUT_MODE_CMOS)
            {

            }
        }
        else if(GPIO_Init->Dir == GPIo_DIR_TRIGATE)
        {
            /*IO control 控制*/
        }
    }

    /*以下影响整个模块*/

    /*输入模式影响整个模块*/

    /*驱动能力*/

    /*slew_rate*/
}
/**
  *@brief 使能RX DMA.
  *
  *@param[in] puart     指向UART_TypeDef结构体的指针;
  *@retval 无
  */
void HAL_UART_EnRxDma(UART_HandleTypeDef *huart)
{
	_uart_rx_dma_en(huart->Instance);
}
/**
  *@brief 禁止RX DMA.
  *
  *@param[in] puart     指向UART_TypeDef结构体的指针;
  *@retval 无
  */
void HAL_UART_DisRxDma(UART_HandleTypeDef *huart)
{
	_uart_rx_dma_dis(huart->Instance);
}

/**
  *@brief 使能TX DMA.
  *
  *@param[in] puart     指向UART_TypeDef结构体的指针;
  *@retval 无
  */
void HAL_UART_EnTxDma(UART_HandleTypeDef *huart)
{
	_uart_tx_dma_en(huart->Instance);
}
/**
  *@brief 禁止TX DMA.
  *
  *@param[in] puart     指向UART_TypeDef结构体的指针;
  *@retval 无
  */
void HAL_UART_DisTxDma(UART_HandleTypeDef *huart)
{
	_uart_tx_dma_dis(huart->Instance);
}

/**
  *@brief 使能RX FIFO.
  *
  *@param[in] puart     指向UART_TypeDef结构体的指针;
  *@retval 无
  */
void HAL_UART_EnRxFifo(UART_HandleTypeDef *huart)
{
	_uart_fifo_rx_en(huart->Instance);
}
/**
  *@brief 禁止RX FIFO.
  *
  *@param[in] puart     指向UART_TypeDef结构体的指针;
  *@retval 无
  */
void HAL_UART_DisRxFifo(UART_HandleTypeDef *huart)
{
	_uart_fifo_rx_dis(huart->Instance);
}

/**
  *@brief 使能TX FIFO.
  *
  *@param[in] puart     指向UART_TypeDef结构体的指针;
  *@retval 无
  */
void HAL_UART_EnTxFifo(UART_HandleTypeDef *huart)
{
	_uart_fifo_tx_en(huart->Instance);
}
/**
  *@brief 禁止TX FIFO.
  *
  *@param[in] puart     指向UART_TypeDef结构体的指针;
  *@retval 无
  */
void HAL_UART_DisTxFifo(UART_HandleTypeDef *huart)
{
	_uart_fifo_tx_dis(huart->Instance);
}
/**
  *@brief 初始化UART_TypeDef指定的UART的管脚作为GPIO功能,GPIO_InitTypeDef为初始化信息如方向、上拉、输出模式、输入模式.
  *
  *@param[in] puart     指向UART_TypeDef结构体的指针;
  *@param[in] pin 具体管脚;
  UART_PIN_TXD;
  UART_PIN_RXD;
  *@retval 无
  */
void  HAL_UART_GPIODeInit(UART_TypeDef  *puart, UART_PinTypeDef Pin)
{
    /*调用模块复位模数即可
      UART模块本身
      IO control*/
}
/**
  *@brief 读取pin指定的UART的管脚当电平.
  *
  *@param[in] puart     指向UART_TypeDef结构体的指针;
  *@param[in] pin 具体管脚;
  UART_PIN_TXD;
  UART_PIN_RXD;
  *@retval @ref GPIO_PinStateTypeDef
  */
GPIO_PinStateTypeDef HAL_UART_GPIOReadPin(UART_TypeDef *puart, UART_PinTypeDef Pin)
{
    uint8_t tmp_val = 0;

    if(Pin == UART_PIN_RXD)
    {
        tmp_val = DRV_UART_GetRxdPinBit(puart);

        if(tmp_val)
        {
            return(SET);
        }
        else
        {
            return(RESET);
        }
    }
    else if(Pin == UART_PIN_RXD)
    {
        tmp_val = DRV_UART_GetTxdPinBit(puart);

        if(tmp_val)
        {
            return(SET);
        }
        else
        {
            return(RESET);
        }
    }
}

/**
  *@brief pin指定的UART的管脚输出PinState指定电平.
  *
  *@param[in] puart     指向UART_TypeDef结构体的指针;
  *@param[in] pin 具体管脚;
  UART_PIN_TXD;
  UART_PIN_RXD;
  *@param[in] PinState
  *- SET
  *- RESET
  *@retval 无
  */
void HAL_UART_GPIOWritePin(UART_TypeDef *puart, UART_PinTypeDef Pin, GPIO_PinStateTypeDef PinState)
{
  
        switch(Pin)
        {
            case UART_PIN_RXD:
            {
                if(PinState == SET)
                {
                    DRV_UART_SetRxdPinBit(puart);
                }
                else
                {
                    DRV_UART_ResetRxdPinBit(puart);
                }

                break;
            }

            case UART_PIN_TXD:
            {
                if(PinState == SET)
                {
                    DRV_UART_SetTxdPinBit(puart);
                }
                else
                {
                    DRV_UART_ResetTxdPinBit(puart);
                }

                break;
            }

            default:
                break;
        }
    
}
/**
  *@brief 翻转pin指定的UART的管脚电平.
  *
  *@param[in] puart     指向UART_TypeDef结构体的指针;
  *@param[in] pin 具体管脚;
  UART_PIN_TXD;
  UART_PIN_RXD;
  *@retval 无
  */
void HAL_UART_GPIOTogglePin(UART_TypeDef *puart, UART_PinTypeDef Pin)
{
    if(Pin == UART_PIN_RXD)
    {
        DRV_UART_RxdPinToggle(puart);
    }
    else
    {
        DRV_UART_TxdPinToggle(puart);
    }
}
//xukai20200408,bt_demo调用的函数 begin *****************************************************************//
/**
  *@brief 使能串口接收中断.
  *
  *@param[in] huart 指向UART_HandleTypeDef结构体的指针,此结构体包含了UART模块的配置信息;
  *@retval @ref HAL_StatusTypeDef
  */
HAL_StatusTypeDef HAL_UART_EnIt(UART_HandleTypeDef *huart)
{
    DRV_UART_EnIt(huart->Instance, UART_IT_INDEX_RIE);

    return(HAL_OK);
}
uint8_t HAL_UART_GetData(UART_HandleTypeDef *huart)
{
    return _uart_get_data(huart->Instance);
}

uint8_t HAL_UART_GetRxItFlag(UART_HandleTypeDef *huart)
{
    return _uart_get_rx_it_flag(huart->Instance);
}
void HAL_UART_SendData(UART_HandleTypeDef *huart, uint8_t *send, uint16_t len)
{
    uint16_t i = 0;
	
    _uart_en_txd(huart->Instance);
    for ( ; i < len; i++)
    {
        while((_uart_get_tdre_it_flag(huart->Instance))==0);
        DRV_UART_SendData(huart->Instance, send[i], huart->Init.WordLength);
        while((_uart_get_tc_flag(huart->Instance))==0);
    }
    _uart_dis_txd(huart->Instance);
}
