#include "Bsp.h"

/**
 * @brief  使能GPIO的时钟
 * @param  [in]  GPIOx  GPIO组
 * @retval void
 * @note   void
 * @example void
 */
void GpioClockEnable(uint32_t GpioX, FunctionalState State)
{
    switch (GpioX) {
    case GPIOA_BASE:
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, State);
	break;
    case GPIOB_BASE:
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, State);
	break;
    case GPIOC_BASE:
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, State);
	break;
    case GPIOD_BASE:
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, State);
	break;
    case GPIOE_BASE:
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, State);
	break;
    case GPIOF_BASE:
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, State);
	break;
    case GPIOG_BASE:
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, State);
	break;
    default:
	break;
    }
}

/**
 * @brief  初始化GPIO口外设的时钟
 * @param  void
 * @retval void
 * @note   void
 * @example void
 */
void BspInitGpioClock(void)
{
    #ifdef USE_GPIOA
    GpioClockEnable(GPIOA_BASE,ENABLE);
    #endif

    #ifdef USE_GPIOB
    GpioClockEnable(GPIOB_BASE,ENABLE);
    #endif

    #ifdef USE_GPIOC
    GpioClockEnable(GPIOC_BASE,ENABLE);
    #endif

    #ifdef USE_GPIOD
    GpioClockEnable(GPIOD_BASE,ENABLE);
    #endif

    #ifdef USE_GPIOE
    GpioClockEnable(GPIOE_BASE,ENABLE);
    #endif

    #ifdef USE_GPIOF
    GpioClockEnable(GPIOF_BASE,ENABLE);
    #endif

    #ifdef USE_GPIOG
    GpioClockEnable(GPIOG_BASE,ENABLE);
    #endif
}
/**
 * @brief 配置GPIO口
 * @param
 * @retval void
 * @note   void
 * @example void
 */
void GpioConfig(GPIO_TypeDef *GpioX, uint16_t GpioPinX,
		GPIOMode_TypeDef GpioMode, GPIOSpeed_TypeDef GpioSpeed)
{
    GPIO_InitTypeDef GpioInitSt;

    GpioInitSt.GPIO_Pin = GpioPinX;
    GpioInitSt.GPIO_Mode = GpioMode;
    GpioInitSt.GPIO_Speed = GpioSpeed;

    GPIO_Init(GpioX, &GpioInitSt);
}

/**
 * @brief 改变GPIO口状态
 * @param
 * @retval void
 * @note   void
 * @example void
 */
void SetGpioSts(GPIO_TypeDef *GpioX, uint16_t GpioPinX, bool_t state)
{
    if (state == RESET) {
	GPIO_ResetBits(GpioX, GpioPinX);
    } else if (state == SET){
	GPIO_SetBits(GpioX, GpioPinX);
    }
}

/**
 * @brief 读取GPIO口状态
 * @param
 * @retval void
 * @note   void
 * @example void
 */
bool_t GetGpioSts(GPIO_TypeDef *GpioX, uint16_t GpioPinX)
{
    return (bool_t)GPIO_ReadInputDataBit(GpioX, GpioPinX);
}

