mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
68 lines
1.8 KiB
C
68 lines
1.8 KiB
C
/***********************************************
|
||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ذ<EFBFBD><D8B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||
* <20><><EFBFBD><EFBFBD> <09><EFBFBD><DEB8><EFBFBD> <09><EFBFBD><DEB8><EFBFBD>Ϣ
|
||
--20210409 Magnin <09><><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_poll.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;
|
||
}sp_key_t;
|
||
|
||
static sp_key_t spKey[] = {
|
||
{SP_KEY_PRESS_KEY1,GPIOC,GPIO_PIN_7},
|
||
{SP_KEY_PRESS_KEY2,GPIOC,GPIO_PIN_8},
|
||
{SP_KEY_PRESS_KEY3,GPIOC,GPIO_PIN_9},
|
||
{SP_KEY_PRESS_KEY4,GPIOA,GPIO_PIN_0},
|
||
};
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF>ʼ<EFBFBD><CABC>
|
||
void Key_PollInit(void)
|
||
{
|
||
GPIO_InitType GPIO_InitStructure;
|
||
//<2F><><EFBFBD><EFBFBD>GPIO<49>˿<EFBFBD>ʱ<EFBFBD><CAB1>
|
||
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
|
||
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOC, 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);
|
||
}
|
||
}
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ
|
||
sp_key_value_t Key_Poll(void)
|
||
{
|
||
for(uint8_t i = 0;i < ARRAY_SIZE(spKey);i++)
|
||
{
|
||
if(GPIO_ReadInputDataBit(spKey[i].GPIOx,spKey[i].Pin) == Bit_RESET)
|
||
{
|
||
//<2F><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||
Delay_Ms(KEY_SCAN_DELAY);
|
||
if(GPIO_ReadInputDataBit(spKey[i].GPIOx,spKey[i].Pin) == Bit_RESET)
|
||
{
|
||
#ifdef SP_KEY_POLL_LOOSE_CHECK
|
||
while(GPIO_ReadInputDataBit(spKey[i].GPIOx,spKey[i].Pin) == Bit_RESET) ;
|
||
#endif
|
||
return spKey[i].value;
|
||
}
|
||
}
|
||
}
|
||
return SP_KEY_PRESS_NONE;
|
||
}
|
||
|