keypad_demo.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. @file
  3. keypad_demo.c
  4. @brief
  5. quectel keypad_demo.
  6. */
  7. /*================================================================
  8. Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  9. Quectel Wireless Solution Proprietary and Confidential.
  10. =================================================================*/
  11. /*=================================================================
  12. EDIT HISTORY FOR MODULE
  13. This section contains comments describing changes made to the module.
  14. Notice that changes are listed in reverse chronological order.
  15. WHEN WHO WHAT, WHERE, WHY
  16. ------------ ------- -------------------------------------------------------------------------------
  17. 16/11/2020 Neo Init version
  18. =================================================================*/
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <stdlib.h>
  22. #include "ql_keypad.h"
  23. #include "ql_api_osi.h"
  24. #include "ql_log.h"
  25. #include "keypad_demo.h"
  26. /*===========================================================================
  27. * Macro Definition
  28. ===========================================================================*/
  29. #define QL_KEYPADDEMO_LOG_LEVEL QL_LOG_LEVEL_INFO
  30. #define QL_KEYPADDEMO_LOG(msg, ...) QL_LOG(QL_KEYPADDEMO_LOG_LEVEL, "ql_KEYPADDEMO", msg, ##__VA_ARGS__)
  31. #define QL_KEYPADDEMO_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_KEYPADDEMO", msg, ##__VA_ARGS__)
  32. /**
  33. * keypad position,support 6*6 keypad,Compatible with the old 6*5 keypad
  34. keyin0 keyin1 keyin2 keyin3 keyin4 keyin5
  35. keyout0 QL_KEY_MAP_0 QL_KEY_MAP_1 QL_KEY_MAP_2 QL_KEY_MAP_3 QL_KEY_MAP_4 QL_KEY_MAP_5
  36. keyout1 QL_KEY_MAP_31 QL_KEY_MAP_6 QL_KEY_MAP_7 QL_KEY_MAP_8 QL_KEY_MAP_9 QL_KEY_MAP_10
  37. keyout2 QL_KEY_MAP_32 QL_KEY_MAP_11 QL_KEY_MAP_12 QL_KEY_MAP_13 QL_KEY_MAP_14 QL_KEY_MAP_15
  38. keyout3 QL_KEY_MAP_33 QL_KEY_MAP_16 QL_KEY_MAP_17 QL_KEY_MAP_18 QL_KEY_MAP_19 QL_KEY_MAP_20
  39. keyout4 QL_KEY_MAP_34 QL_KEY_MAP_21 QL_KEY_MAP_22 QL_KEY_MAP_23 QL_KEY_MAP_24 QL_KEY_MAP_25
  40. keyout5 QL_KEY_MAP_35 QL_KEY_MAP_26 QL_KEY_MAP_27 QL_KEY_MAP_28 QL_KEY_MAP_29 QL_KEY_MAP_30
  41. */
  42. /*========================================================================
  43. * function Definition
  44. *========================================================================*/
  45. void ql_keypad_callback(ql_keymatrix_t keymatrix)
  46. {
  47. QL_KEYPADDEMO_LOG("keymap:%d keyout:%d keyin:%d pressd:%d", keymatrix.keymap, keymatrix.keyout, keymatrix.keyin, keymatrix.keystate);
  48. }
  49. void ql_keypad_demo_thread(void *param)
  50. {
  51. QlOSStatus err = 0;
  52. uint32_t pressed;
  53. uint32_t press_last[QL_KEY_MAP_MAX_COUNT] = {0};
  54. int i=0;
  55. ql_keypad_out_e row[QL_KEYPAD_ROW_LENGTH] = {QL_KP_OUT0, QL_KP_OUT1, QL_KP_OUT2, QL_KP_OUT3, QL_KP_OUT4, QL_KP_OUT5};
  56. ql_keypad_in_e col[QL_KEYPAD_COL_LENGTH] = {QL_KP_IN0, QL_KP_IN1,QL_KP_IN2, QL_KP_IN3, QL_KP_IN_NO_VALID, QL_KP_IN_NO_VALID};
  57. err = ql_keypad_init(ql_keypad_callback, row, col);
  58. if(err == QL_KEYPAD_SUCCESS)
  59. {
  60. while(1)
  61. {
  62. for (i=QL_KEY_MAP_0; i<QL_KEY_MAP_MAX_COUNT; i++)
  63. {
  64. err = ql_keypad_state(&pressed, (ql_keymap_e)i);
  65. if(err == QL_KEYPAD_SUCCESS)
  66. {
  67. if (press_last[i] != pressed)
  68. {
  69. press_last[i] = pressed;
  70. QL_KEYPADDEMO_LOG("keypad%d pressed: %d", i, pressed);
  71. }
  72. }
  73. else
  74. {
  75. QL_KEYPADDEMO_LOG("keymap id read error!");
  76. continue;
  77. }
  78. }
  79. ql_rtos_task_sleep_ms(100);
  80. }
  81. }
  82. err = ql_rtos_task_delete(NULL);
  83. if(err != QL_OSI_SUCCESS)
  84. {
  85. QL_KEYPADDEMO_LOG("task deleted failed");
  86. }
  87. }
  88. void ql_keypad_app_init()
  89. {
  90. QlOSStatus err = QL_OSI_SUCCESS;
  91. ql_task_t keypad_task = NULL;
  92. err = ql_rtos_task_create(&keypad_task, 1024, APP_PRIORITY_NORMAL, "ql_keypaddemo", ql_keypad_demo_thread, NULL, 1);
  93. if( err != QL_OSI_SUCCESS )
  94. {
  95. QL_KEYPADDEMO_LOG("keypad demo task created failed");
  96. }
  97. }