key.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "key.h"
  2. uint8_t Get_key_value(uint8_t key_num)
  3. {
  4. uint8_t key_value = 0;
  5. switch (key_num)
  6. {
  7. case KEY_1:
  8. key_value = Dt_KEY_1;
  9. break;
  10. case KEY_2:
  11. key_value = Dt_KEY_2;
  12. break;
  13. case KEY_3:
  14. key_value = Dt_KEY_3;
  15. break;
  16. case KEY_4:
  17. key_value = Dt_KEY_4;
  18. break;
  19. case KEY_5:
  20. key_value = Dt_KEY_5;
  21. break;
  22. case KEY_6:
  23. key_value = Dt_KEY_6;
  24. break;
  25. case KEY_7:
  26. key_value = Dt_KEY_7;
  27. break;
  28. case KEY_8:
  29. key_value = Dt_KEY_8;
  30. break;
  31. default:
  32. break;
  33. }
  34. return key_value;
  35. }
  36. void KEY_Init(void)
  37. {
  38. /* enable the relay GPIO clock */
  39. rcu_periph_clock_enable(RCU_GPIOA);
  40. /* enable the LED GPIO clock */
  41. rcu_periph_clock_enable(RCU_GPIOC);
  42. /* enable the User key clock */
  43. rcu_periph_clock_enable(RCU_GPIOB);
  44. gpio_init(GPIOA, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_5 | GPIO_PIN_15);
  45. gpio_init(GPIOB, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_10 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15);
  46. gpio_init(GPIOC, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
  47. /* configure relay GPIO port */ // add by zzw 20230308 relay
  48. /*GPIO_InitTypeDef GPIO_InitStructure;
  49. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  50. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  51. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
  52. GPIO_StructInit(&GPIO_InitStructure);
  53. GPIO_InitStructure.GPIO_PIN = GPIO_PIN_5 | GPIO_PIN_15;
  54. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU,;
  55. GPIO_Init(GPIOA, &GPIO_InitStructure);
  56. GPIO_StructInit(&GPIO_InitStructure);
  57. GPIO_InitStructure.GPIO_PIN = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
  58. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  59. GPIO_Init(GPIOB, &GPIO_InitStructure);
  60. GPIO_StructInit(&GPIO_InitStructure);
  61. GPIO_InitStructure.GPIO_PIN = GPIO_PIN_4 | GPIO_PIN_10;
  62. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  63. GPIO_Init(GPIOC, &GPIO_InitStructure);*/
  64. }