gpio_int_demo.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*================================================================
  2. Copyright (c) 2021, Quectel Wireless Solutions Co., Ltd. All rights reserved.
  3. Quectel Wireless Solutions Proprietary and Confidential.
  4. =================================================================*/
  5. /*=================================================================
  6. EDIT HISTORY FOR MODULE
  7. This section contains comments describing changes made to the module.
  8. Notice that changes are listed in reverse chronological order.
  9. WHEN WHO WHAT, WHERE, WHY
  10. ------------ ------- -------------------------------------------------------------------------------
  11. =================================================================*/
  12. /*===========================================================================
  13. * include files
  14. ===========================================================================*/
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include "ql_api_osi.h"
  19. #include "ql_log.h"
  20. #include "ql_pin_cfg.h"
  21. #include "gpio_int_demo.h"
  22. /*===========================================================================
  23. * Macro Definition
  24. ===========================================================================*/
  25. #define QL_GPIOINTDEMO_LOG_LEVEL QL_LOG_LEVEL_INFO
  26. #define QL_GPIOINTDEMO_LOG(msg, ...) QL_LOG(QL_GPIOINTDEMO_LOG_LEVEL, "ql_GPIOINTDEMO", msg, ##__VA_ARGS__)
  27. #define QL_GPIOINTDEMO_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_GPIOINTDEMO", msg, ##__VA_ARGS__)
  28. /*===========================================================================
  29. * Variate
  30. ===========================================================================*/
  31. ql_IntSel ql_intsel_flg = INT_CB01;
  32. /*===========================================================================
  33. * Functions
  34. ===========================================================================*/
  35. static void _gpioint_callback01(void *ctx)
  36. {
  37. ql_LvlMode gpio_lvl;
  38. ql_gpio_get_level(GPIO_0, &gpio_lvl);
  39. QL_GPIOINTDEMO_LOG("gpio[%d] int lvl:[%d]", GPIO_0, gpio_lvl);
  40. QL_GPIOINTDEMO_LOG("Welcome to Quectel!");
  41. }
  42. static void _gpioint_callback02(void *ctx)
  43. {
  44. ql_LvlMode gpio_lvl;
  45. ql_gpio_get_level(GPIO_1, &gpio_lvl);
  46. QL_GPIOINTDEMO_LOG("gpio[%d] int lvl:[%d]", GPIO_1, gpio_lvl);
  47. QL_GPIOINTDEMO_LOG("Quectel is No.1!");
  48. }
  49. static void ql_gpioint_demo_thread(void *param)
  50. {
  51. QL_GPIOINTDEMO_LOG("gpio int demo thread enter, param 0x%x", param);
  52. ql_event_t event;
  53. ql_pin_set_func(QL_TEST1_PIN_GPIO0, QL_TEST1_PIN_GPIO0_FUNC_GPIO); // set GPIO0
  54. ql_pin_set_func(QL_TEST1_PIN_GPIO1, QL_TEST1_PIN_GPIO1_FUNC_GPIO); // set GPIO1
  55. //ql_gpio_deinit(GPIO_0);
  56. //ql_gpio_deinit(GPIO_1);
  57. ql_int_register(GPIO_0, EDGE_TRIGGER, DEBOUNCE_EN, EDGE_RISING, PULL_DOWN, _gpioint_callback01, NULL);
  58. ql_int_register(GPIO_1, EDGE_TRIGGER, DEBOUNCE_EN, EDGE_FALLING, PULL_UP, _gpioint_callback02, NULL);
  59. ql_int_enable(GPIO_0);
  60. ql_int_enable(GPIO_1);
  61. ql_rtos_task_sleep_s(20);
  62. while(1)
  63. {
  64. ql_event_wait(&event, 1);
  65. if( ql_intsel_flg == INT_CB01 )
  66. {
  67. if( ql_int_disable(GPIO_0) == 0 )
  68. {
  69. QL_GPIOINTDEMO_LOG("gpio[%d] int disable, enable gpio[%d] int", GPIO_0, GPIO_1);
  70. ql_int_enable(GPIO_1);
  71. //ql_int_register(GPIO_30, EDGE_TRIGGER, DEBOUNCE_EN, EDGE_FALLING, PULL_UP, _gpioint_callback02, NULL);
  72. ql_intsel_flg = INT_CB02;
  73. }
  74. }
  75. else/* ql_intsel_flg == INT_CB02 */
  76. {
  77. if( ql_int_disable(GPIO_1) == 0 )
  78. {
  79. QL_GPIOINTDEMO_LOG("gpio[%d] int disable, enable gpio[%d] int", GPIO_1, GPIO_0);
  80. ql_int_enable(GPIO_0);
  81. //ql_int_register(GPIO_29, EDGE_TRIGGER, DEBOUNCE_EN, EDGE_RISING, PULL_DOWN, _gpioint_callback01, NULL);
  82. ql_intsel_flg = INT_CB01;
  83. }
  84. }
  85. ql_rtos_task_sleep_s(20);
  86. }
  87. ql_rtos_task_delete(NULL);
  88. }
  89. void ql_gpioint_app_init(void)
  90. {
  91. QlOSStatus err = QL_OSI_SUCCESS;
  92. ql_task_t gpioint_task = NULL;
  93. err = ql_rtos_task_create(&gpioint_task, 1024, APP_PRIORITY_NORMAL, "ql_gpiointdemo", ql_gpioint_demo_thread, NULL, 1);
  94. if( err != QL_OSI_SUCCESS )
  95. {
  96. QL_GPIOINTDEMO_LOG("gpio int demo task created failed");
  97. }
  98. }