/****************************************************************************
|
* Copyright: (C)2014 Î人ÁèÔÆÇ¶ÈëʽʵÑéÊÒ www.emblinux.com
|
* Author: GuoWenxue<guowenxue@gmail.com> QQ: 281143292
|
* Description: ·Ü¶·STM32v5¿ª·¢°å°´¼ü²Ù×÷º¯Êý,°´KEY1ÔòLED1ÁÁ,°´KEY2ÔòLED2ÁÁ,°´KEY3ÔòLED3ÁÁ
|
*
|
* KEY1-PC5 KEY2-PC2 KEY3-PC3
|
* LED1-PB5 LED2-PD6 LED3-PD3
|
*
|
* ChangeLog:
|
* °æ±¾ºÅ ÈÕÆÚ ×÷Õß ËµÃ÷
|
* V1.0.0 2014.08.25 GuoWenxue ·¢²¼¸Ã°æ±¾
|
****************************************************************************/
|
#include "stm32f10x.h"
|
#include "stm32f10x_exti.h"
|
#include "stm32f10x_rcc.h"
|
#include "misc.h"
|
#include "stm32v5_led.h"
|
#include "stm32v5_key.h"
|
|
#define DEFINE_PIN_EXTI(group, pin, IRQn, SubPriority) \
|
void init_P##group##pin##_as_EXTI(void) \
|
{ \
|
GPIO_InitTypeDef GPIO_InitStructure; \
|
EXTI_InitTypeDef EXTI_InitStructure; \
|
NVIC_InitTypeDef NVIC_InitStructure; \
|
\
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO##group|RCC_APB2Periph_AFIO, ENABLE); \
|
\
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_##pin; \
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; \
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; \
|
GPIO_Init(GPIO##group, &GPIO_InitStructure); \
|
\
|
GPIO_EXTILineConfig(GPIO_PortSourceGPIO##group, GPIO_PinSource##pin); \
|
EXTI_InitStructure.EXTI_Line = EXTI_Line##pin; \
|
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; \
|
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; \
|
EXTI_InitStructure.EXTI_LineCmd = ENABLE; \
|
EXTI_Init(&EXTI_InitStructure); \
|
\
|
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); \
|
NVIC_InitStructure.NVIC_IRQChannel = IRQn; \
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; \
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; \
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; \
|
NVIC_Init(&NVIC_InitStructure); \
|
}
|
|
/* Key1(PC5) configured as EXTI5, SubPriority as 1 */
|
DEFINE_PIN_EXTI(C, 5, EXTI9_5_IRQn, 1)
|
|
/* Key2(PC2) configured as EXTI2, SubPriority as 2 */
|
DEFINE_PIN_EXTI(C, 2, EXTI2_IRQn, 2)
|
|
/* Key3(PC3) configured as EXTI3, SubPriority as 3 */
|
DEFINE_PIN_EXTI(C, 3, EXTI3_IRQn, 3)
|
|
/* PC5 Key1 interrupt handler */
|
void EXTI9_5_IRQHandler(void)
|
{
|
static uint8_t led1_status = OFF;
|
|
if(EXTI_GetITStatus(EXTI_Line5) != RESET)
|
{
|
led1_status ^= 1;
|
turn_led(LED1, led1_status);
|
// EXTI_ClearITPendingBit(EXTI_Line5);
|
}
|
}
|
|
/* PC2 Key2 interrupt handler */
|
void EXTI2_IRQHandler(void)
|
{
|
static uint8_t led2_status = OFF;
|
|
if(EXTI_GetITStatus(EXTI_Line2) != RESET)
|
{
|
led2_status ^= 1;
|
turn_led(LED2, led2_status);
|
EXTI_ClearITPendingBit(EXTI_Line2);
|
}
|
}
|
|
/* PC3 Key3 interrupt handler */
|
void EXTI3_IRQHandler(void)
|
{
|
static uint8_t led3_status = OFF;
|
|
if(EXTI_GetITStatus(EXTI_Line3) != RESET)
|
{
|
led3_status ^= 1;
|
turn_led(LED3, led3_status);
|
EXTI_ClearITPendingBit(EXTI_Line3);
|
}
|
}
|
|
void init_keys_interrupt(void)
|
{
|
init_PC5_as_EXTI();
|
init_PC2_as_EXTI();
|
init_PC3_as_EXTI();
|
}
|