100 lines
3.2 KiB
C
Raw Normal View History

2021-10-24 10:19:26 +08:00
/***********************************************
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ذ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD> <EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD>Ϣ
--20210409 Magnin <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>
************************************************/
/**************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>***************
KEY1 -------------------------- PC7
KEY2 -------------------------- PC8
KEY3 -------------------------- PC9
KEY4 -------------------------- PA0
***********************************************/
#include "key_exti.h"
#include "share.h"
#include "cm32m101a_conf.h"
#define KEY_SCAN_DELAY 100 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱʱ<CAB1><CAB1>
typedef struct{
sp_key_value_t value;
GPIO_Module* GPIOx;
uint16_t Pin;
uint8_t PortSource;
uint8_t PinSource;
uint32_t EXTI_Line;
uint8_t NVIC_IRQChannel;
}sp_key_t;
static sp_key_t spKey[] = {
{SP_KEY_PRESS_KEY1, GPIOC, GPIO_PIN_7, GPIOC_PORT_SOURCE, GPIO_PIN_SOURCE7, EXTI_LINE7, EXTI9_5_IRQn},
{SP_KEY_PRESS_KEY2, GPIOC, GPIO_PIN_8, GPIOC_PORT_SOURCE, GPIO_PIN_SOURCE8, EXTI_LINE8, EXTI9_5_IRQn},
{SP_KEY_PRESS_KEY3, GPIOC, GPIO_PIN_9, GPIOC_PORT_SOURCE, GPIO_PIN_SOURCE9, EXTI_LINE9, EXTI9_5_IRQn},
{SP_KEY_PRESS_KEY4, GPIOA, GPIO_PIN_0, GPIOA_PORT_SOURCE, GPIO_PIN_SOURCE0, EXTI_LINE0, EXTI0_IRQn},
};
static sp_key_value_t keyValue =SP_KEY_PRESS_NONE;
//<2F><><EFBFBD><EFBFBD><EFBFBD>жϳ<D0B6>ʼ<EFBFBD><CABC>
void Key_ExtiInit(void)
{
GPIO_InitType GPIO_InitStructure;
EXTI_InitType EXTI_InitStructure;
NVIC_InitType NVIC_InitStructure;
//<2F><><EFBFBD><EFBFBD>GPIO<49>˿<EFBFBD>ʱ<EFBFBD>Ӻ͸<D3BA><CDB8><EFBFBD>ʱ<EFBFBD><CAB1>
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA| RCC_APB2_PERIPH_AFIO, ENABLE);
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOC| RCC_APB2_PERIPH_AFIO, ENABLE);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Pull = GPIO_Pull_Up; //<2F><><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Input; //<2F><><EFBFBD><EFBFBD>
for(uint8_t i = 0;i < ARRAY_SIZE(spKey);i++)
{
GPIO_InitStructure.Pin = spKey[i].Pin;
GPIO_InitPeripheral(spKey[i].GPIOx, &GPIO_InitStructure);
GPIO_ConfigEXTILine(spKey[i].PortSource, spKey[i].PinSource);
/*key EXTI line*/
EXTI_InitStructure.EXTI_Line = spKey[i].EXTI_Line;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; // <20>½<EFBFBD><C2BD>ش<EFBFBD><D8B4><EFBFBD>
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_InitPeripheral(&EXTI_InitStructure);
/*interrupt priority*/
NVIC_InitStructure.NVIC_IRQChannel = spKey[i].NVIC_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x05;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ
sp_key_value_t Key_GetValue(void)
{
sp_key_value_t value = keyValue;
keyValue =SP_KEY_PRESS_NONE;
return value;
}
//<2F>ⲿ<EFBFBD>ж<EFBFBD><D0B6><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void EXTI0_IRQHandler(void)
{
if(RESET != EXTI_GetITStatus(spKey[3].EXTI_Line)) //<2F><>ȡ<EFBFBD>ⲿ<EFBFBD>ж<EFBFBD><D0B6><EFBFBD>״̬
{
if(GPIO_ReadInputDataBit(spKey[3].GPIOx,spKey[3].Pin) == Bit_RESET) keyValue = spKey[3].value;
EXTI_ClrITPendBit(spKey[3].EXTI_Line); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
}
}
//<2F>ⲿ<EFBFBD>ж<EFBFBD><D0B6><EFBFBD>5<EFBFBD><35>9<EFBFBD><39><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void EXTI9_5_IRQHandler(void)
{
for(uint8_t i = 0;i < 3; i++)
{
if(RESET != EXTI_GetITStatus(spKey[i].EXTI_Line))
{
if(GPIO_ReadInputDataBit(spKey[i].GPIOx,spKey[i].Pin) == Bit_RESET) keyValue = spKey[i].value;
EXTI_ClrITPendBit(spKey[i].EXTI_Line);
}
}
}