void KeyInputExtiInit(GPIO_Module* GPIOx, uint16_t Pin)
{
GPIO_InitType GPIO_InitStructure;
EXTI_InitType EXTI_InitStructure;
NVIC_InitType NVIC_InitStructure;
/* Check the parameters */
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
/* Enable the GPIO Clock */
if (GPIOx == GPIOA)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_AFIO, ENABLE);
}
else if (GPIOx == GPIOB)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE);
}
else if (GPIOx == GPIOC)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOC | RCC_APB2_PERIPH_AFIO, ENABLE);
}
else if (GPIOx == GPIOF)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOF | RCC_APB2_PERIPH_AFIO, ENABLE);
}
else
{
return;
}
/*Configure the GPIO pin as input floating*/
if (Pin <= GPIO_PIN_ALL)
{
GPIO_InitStruct(&GPIO_InitStructure);
GPIO_InitStructure.Pin = Pin;
GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP;
GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure);
}
/*Configure key EXTI Line to key input Pin*/
GPIO_ConfigEXTILine(KEY_INPUT_PORT_SOURCE, KEY_INPUT_PIN_SOURCE);
/*Configure key EXTI line*/
EXTI_InitStructure.EXTI_Line = KEY_INPUT_EXTI_LINE;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; // EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_InitPeripheral(&EXTI_InitStructure);
/*Set key input interrupt priority*/
NVIC_InitStructure.NVIC_IRQChannel = KEY_INPUT_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**
* @brief Inserts a delay time.
* @param count specifies the delay time length.
*/
void Delay(uint32_t count)
{
for (; count > 0; count--)
;
}
/**
* @brief Configures LED GPIO.
* @param GPIOx x can be A to G to select the GPIO port.
* @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15.
*/
void LedInit(GPIO_Module* GPIOx, uint16_t Pin)
{
GPIO_InitType GPIO_InitStructure;
/* Check the parameters */
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
/* Enable the GPIO Clock */
if (GPIOx == GPIOA)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
}
else if (GPIOx == GPIOB)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
}
else if (GPIOx == GPIOC)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOC, ENABLE);
}
else if (GPIOx == GPIOF)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOF, ENABLE);
}
else
{
return;
}
/* Configure the GPIO pin */
if (Pin <= GPIO_PIN_ALL)
{
GPIO_InitStruct(&GPIO_InitStructure);
GPIO_InitStructure.Pin = Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure);
}
}
/**
* @brief Turns selected Led on.
* @param GPIOx x can be A to G to select the GPIO port.
* @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15.
*/
void LedOn(GPIO_Module *GPIOx, uint16_t Pin)
{
GPIO_SetBits(GPIOx, Pin);
}
/**
* @brief Turns selected Led Off.
* @param GPIOx x can be A to G to select the GPIO port.
* @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15.
*/
void LedOff(GPIO_Module* GPIOx, uint16_t Pin)
{
GPIO_ResetBits(GPIOx, Pin);
}
/**
* @brief Toggles the selected Led.
* @param GPIOx x can be A to G to select the GPIO port.
* @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15.
*/
void LedBlink(GPIO_Module* GPIOx, uint16_t Pin)
{
GPIO_TogglePin(GPIOx, Pin);
}
void LedBreath(GPIO_Module* GPIOx, uint16_t Pin)
{
unsigned char i = 0;
unsigned int t = 1;
unsigned char flag = 1;
while(1)
{
if(flag == 1) //LED??
{
for(i=0;i<10;i++)
{
GPIO_ResetBits(PORT_GROUP, LED1_PIN | LED2_PIN | LED3_PIN);
Delay(t);
GPIO_SetBits(PORT_GROUP,LED1_PIN | LED2_PIN | LED3_PIN); //LED??
Delay(1001-t);
}
t++;
if(t == 1000)
{
flag = 0;
}
}
if(flag == 0) //LED????
{
for(i=0;i<10;i++)
{
GPIO_ResetBits(PORT_GROUP, LED1_PIN | LED2_PIN | LED3_PIN); //LED??
Delay(t);
GPIO_SetBits(PORT_GROUP,LED1_PIN | LED2_PIN | LED3_PIN); //LED??
Delay(1001-t);
}
t--;
if(t == 1)
{
flag = 1;
}
}
}
}
/**
* @brief 用户断言失败的功能。
* @param文件 失败的调用的名称。
* @param行 失败的呼叫的源线路号。
*/
#ifdef USE_FULL_ASSERT
void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line){
while (1)
{
}
}