luat_tp.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "luat_base.h"
  2. #include "luat_tp.h"
  3. #include "luat_mem.h"
  4. #include "luat_gpio.h"
  5. #define LUAT_LOG_TAG "tp"
  6. #include "luat_log.h"
  7. luat_rtos_task_handle tp_task_handle = NULL;
  8. void luat_tp_task_entry(void* param){
  9. uint32_t message_id = 0;
  10. luat_tp_config_t *luat_tp_config = NULL;
  11. while (1){
  12. luat_rtos_message_recv(tp_task_handle, &message_id, &luat_tp_config, LUAT_WAIT_FOREVER);
  13. luat_tp_data_t* tp_data = luat_tp_config->tp_data;
  14. uint8_t touch_num = luat_tp_config->opts->read(luat_tp_config,tp_data);
  15. if (touch_num){
  16. for (uint8_t i=0; i<LUAT_TP_TOUCH_MAX; i++){
  17. if ((TP_EVENT_TYPE_DOWN == tp_data[i].event) || (TP_EVENT_TYPE_UP == tp_data[i].event) || (TP_EVENT_TYPE_MOVE == tp_data[i].event)){
  18. // LLOGD("event=%d, track_id=%d, x=%d, y=%d, s=%d, timestamp=%u.\r\n",
  19. // tp_data[i].event,
  20. // tp_data[i].track_id,
  21. // tp_data[i].x_coordinate,
  22. // tp_data[i].y_coordinate,
  23. // tp_data[i].width,
  24. // tp_data[i].timestamp);
  25. if (luat_tp_config->callback){
  26. luat_tp_config->callback(luat_tp_config,&tp_data[i]);
  27. }
  28. }
  29. }
  30. }
  31. luat_gpio_irq_enable(luat_tp_config->pin_int, 1);
  32. }
  33. }
  34. int luat_tp_init(luat_tp_config_t* luat_tp_config){
  35. if (tp_task_handle == 0){
  36. luat_rtos_task_create(&tp_task_handle, 4096, 50, "tp", luat_tp_task_entry, NULL, 10);
  37. }
  38. tp_config_gt911.init(luat_tp_config);
  39. return 0;
  40. }