#include "Bsp.h"

/**
 * @brief 启用GPIO口时钟
 * @note  void
 * @param GpioX:GPIO引脚
 * @retval void
 */
void GpioClockEnable(const GPIO_MAP_T *GpioX)
{
    if(GpioX->Periph == GPIOA)
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

    if(GpioX->Periph == GPIOB)
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

    if(GpioX->Periph == GPIOC)
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

    if(GpioX->Periph == GPIOD)
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);

    if(GpioX->Periph == GPIOE)
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);

    if(GpioX->Periph == GPIOF)
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);

    if(GpioX->Periph == GPIOG)
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, ENABLE);
}
/**
 * @brief 配置GPIO口
 * @note void
 * @param GpioX:引脚 GpioMode:GPIO模式 GpioSpeed:GPIO速度
 * @retval void
 */
void GpioConfig(const GPIO_MAP_T *GpioX, GPIOMode_TypeDef GpioMode, GPIOSpeed_TypeDef GpioSpeed)
{
    GPIO_InitTypeDef GpioInitSt;

    GpioInitSt.GPIO_Pin = GpioX->GpioPin;
    GpioInitSt.GPIO_Mode = GpioMode;
    GpioInitSt.GPIO_Speed = GpioSpeed;

    GPIO_Init(GpioX->Periph, &GpioInitSt);
}
/**
 * @brief 改变GPIO口状态
 * @note
 * @param GpioX:GPIO引脚 Value:设置值
 * @retval void
 */
void GpioSet(const GPIO_MAP_T *GpioX, uint8_t Value)
{
    if (Value == (uint8_t)RESET)
    {
        GPIO_ResetBits(GpioX->Periph, GpioX->GpioPin);
    }
    else if (Value == (uint8_t)SET)
    {
        GPIO_SetBits(GpioX->Periph, GpioX->GpioPin);
    }
}
/**
 * @brief  读取GPIO口状态
 * @note
 * @param GpioX:GPIO引脚
 * @retval 0:低电平，1高电平
 */
unsigned char GpioGet(const GPIO_MAP_T *GpioX)
{
    return (unsigned char)GPIO_ReadInputDataBit(GpioX->Periph, GpioX->GpioPin);
}

