/*********************************************************
*Copyright (C), 2017, Shanghai Eastsoft Microelectronics Co., Ltd.
 * @文件名:  uart.c
 * @作  者:  AE Team
 * @版  本:  V1.00
 * @日  期:  2022/07/25
 * @描  述:  
 * @note
 *          Change Logs:
 *          Date            Author          Notes
 *          25 July 2022    AE Team         change license to Apache-2.0
 *
 * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the License); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 **********************************************************************************
 */


#include "uart.h"
#include "string.h"

/*********************************************************
函数名: void UART_Pins_Init(void)
描  述: 初始化UART通讯IO
输入值: 无
输出值: 无
返回值: 无
**********************************************************/
void BUZ_Init(void)
{
    GPIO_InitSettingType x;
	memset(&x, 0, sizeof(x));
	
    x.Signal = GPIO_Pin_Signal_Digital;
    x.Dir = GPIO_Direction_Output;
    x.Func = GPIO_Reuse_Func1;
    x.PUE = GPIO_PUE_Input_Disable;
    x.PDE = GPIO_PDE_Input_Disable;
    x.ODE = GPIO_ODE_Output_Disable;
    x.DS = GPIO_DS_Output_Strong;

    GPIO_Init(BUZZZER_PIN, &x);

    /* Fbuz = 480kHz */
    BUZC_Frequence(480000, Enable);
}

/*********************************************************
函数名: void UART_Pins_Init(void)
描  述: 初始化UART通讯IO
输入值: 无
输出值: 无
返回值: 无
**********************************************************/
void UART_Pins_Init(void)
{
    GPIO_InitSettingType x;
	memset(&x, 0, sizeof(x));

    x.Signal = GPIO_Pin_Signal_Digital;
    x.Dir = GPIO_Direction_Output;
    x.Func = GPIO_Reuse_Func1;
    x.ODE = GPIO_ODE_Output_Disable;
    x.DS = GPIO_DS_Output_Normal;
    x.PUE = GPIO_PUE_Input_Disable;
    x.PDE = GPIO_PDE_Input_Disable;
    GPIO_Init(GPIO_Pin_A23, &x);        /* TXD - PA23 */

    x.Signal = GPIO_Pin_Signal_Digital;
    x.Func = GPIO_Reuse_Func1;
    x.Dir = GPIO_Direction_Input;
    x.PUE = GPIO_PUE_Input_Disable;
    x.PDE = GPIO_PDE_Input_Disable;
    GPIO_Init(GPIO_Pin_A22, &x);        /* RXD - PA22 */
}


/*********************************************************
函数名: void UARTInit(void)
描  述: UART初始化子程序
输入值: 无
输出值: 无
返回值: 无
**********************************************************/
void UARTInit(void)
{
    UART_InitStruType y;
	memset(&y, 0, sizeof(y));
	
    y.UART_ClockSet = UART_Clock_1;         /* 时钟选择：Pclk */
    y.UART_BaudRate = 115200;               /* 波特率:115200 */
    y.UART_StopBits = UART_StopBits_1;      /* 停止位：1 */
    y.UART_TxMode = UART_DataMode_8;        /* 发送数据格式：8位数据，无校验 */
    y.UART_TxPolar = UART_Polar_Normal;     /* 发送端口极性：正常 */
    y.UART_RxMode = UART_DataMode_8;        /* 接收数据格式：8位数据，无校验 */
    y.UART_RxPolar = UART_Polar_Normal;     /* 接收端口极性：正常 */
    UART_Init(UART0, &y);

    UART_Pins_Init();
    BUZ_Init();

    GPIO_TX0Config(UART_TXPLV_Low, UART_TX0PS_BUZ, UART_TYPE_TXD0, Enable);

    UART0_TxEnable();
}

/*********************************************************
函数名: void UARTInit(void)
描  述: UART初始化子程序
输入值: 无
输出值: 无
返回值: 无
**********************************************************/
void UARTSend(UART_TypeDef *UARTx, uint8_t u8data)
{
    while (UART_GetFlagStatus(UARTx, UART_FLAG_TB) == RESET);

    UART_SendByte(UARTx, u8data);
}


/*************************END OF FILE**********************/
