| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #include "Key.h"
- #include "gd32e23x_rcu.h"
- static unsigned char s_arrKeyDownLevel[KEY_NAME_MAX] = {0};
- static void ConfigKeyGPIO(void);
- static void ConfigKeyGPIO(void)
- {
- rcu_periph_clock_enable(KEY_A_RCU);
- rcu_periph_clock_enable(KEY_B_RCU);
-
-
- gpio_mode_set(KEY_B_IO, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, KEY1);
- gpio_mode_set(KEY_B_IO, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, KEY2);
- gpio_mode_set(KEY_B_IO, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, KEY3);
- gpio_mode_set(KEY_B_IO, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, KEY4);
- gpio_mode_set(KEY_A_IO, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, KEY5);
-
- }
- void InitKey(void)
- {
- ConfigKeyGPIO();
- }
- unsigned char ScanKey(unsigned int gpio_periph,unsigned int pin)
- {
- if(gpio_input_bit_get(gpio_periph,pin)==0)
- return KEY_ON;
- else
- return KEY_OFF;
- }
- unsigned char ReadKeyValue(void)
- {
- static unsigned char SlaveAddress;
- s_arrKeyDownLevel[0] = ScanKey(KEY_B_IO,KEY1);
- s_arrKeyDownLevel[1] = ScanKey(KEY_B_IO,KEY2);
- s_arrKeyDownLevel[2] = ScanKey(KEY_B_IO,KEY3);
- s_arrKeyDownLevel[3] = ScanKey(KEY_B_IO,KEY4);
- s_arrKeyDownLevel[4] = ScanKey(KEY_A_IO,KEY5);
- SlaveAddress=(~((s_arrKeyDownLevel[0]<<0)|(s_arrKeyDownLevel[1]<<1)|(s_arrKeyDownLevel[2]<<2)|(s_arrKeyDownLevel[3]<<3)|(s_arrKeyDownLevel[4]<<4)))& 0x1f;
-
- return SlaveAddress;
- }
|