qe_sample_rtthread.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "qe_touch_config.h"
  2. #include <rtthread.h>
  3. #include <rtdevice.h>
  4. #define TOUCH_SCAN_INTERVAL_EXAMPLE (20) /* milliseconds */
  5. uint64_t button_status;
  6. #if (TOUCH_CFG_NUM_SLIDERS != 0)
  7. uint16_t slider_position[TOUCH_CFG_NUM_SLIDERS];
  8. #endif
  9. #if (TOUCH_CFG_NUM_WHEELS != 0)
  10. uint16_t wheel_position[TOUCH_CFG_NUM_WHEELS];
  11. #endif
  12. void qe_touch_main(void *parameter)
  13. {
  14. fsp_err_t err;
  15. rt_uint32_t led_blu = rt_pin_get("P501");
  16. /* Open Touch middleware */
  17. rt_kprintf("TOUCH Open\n");
  18. err = RM_TOUCH_Open(g_qe_touch_instance_config01.p_ctrl, g_qe_touch_instance_config01.p_cfg);
  19. if (FSP_SUCCESS != err)
  20. {
  21. rt_kprintf("RM_TOUCH_Open fail\n");
  22. return;
  23. }
  24. rt_kprintf("TOUCH ScanStart\n");
  25. /* Main loop */
  26. while (true)
  27. {
  28. /* for [CONFIG01] configuration */
  29. err = RM_TOUCH_ScanStart(g_qe_touch_instance_config01.p_ctrl);
  30. if (FSP_SUCCESS != err)
  31. {
  32. rt_kprintf("RM_TOUCH_Open fail\n");
  33. return;
  34. }
  35. while (0 == g_qe_touch_flag) {}
  36. g_qe_touch_flag = 0;
  37. err = RM_TOUCH_DataGet(g_qe_touch_instance_config01.p_ctrl, &button_status, NULL, NULL);
  38. if (FSP_SUCCESS == err)
  39. {
  40. if (button_status)
  41. {
  42. rt_pin_write(led_blu, PIN_HIGH);
  43. }
  44. else
  45. {
  46. rt_pin_write(led_blu, PIN_LOW);
  47. }
  48. }
  49. /* FIXME: Since this is a temporary process, so re-create a waiting process yourself. */
  50. rt_thread_mdelay(TOUCH_SCAN_INTERVAL_EXAMPLE);
  51. }
  52. }
  53. int touch_init(void)
  54. {
  55. rt_thread_t tid = rt_thread_create("touch", qe_touch_main, RT_NULL, 512, 10, 50);
  56. if (tid)
  57. {
  58. rt_thread_startup(tid);
  59. }
  60. return 0;
  61. }
  62. INIT_APP_EXPORT(touch_init);
  63. //MSH_CMD_EXPORT(touch_init, touch_init);