example_ft6236.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-10-19 liuduanfei the first version
  9. */
  10. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. #include "ft6236.h"
  13. #include "touch.h"
  14. #include "drv_common.h"
  15. #define DBG_TAG "ft6236_example"
  16. #define DBG_LVL DBG_LOG
  17. #include <rtdbg.h>
  18. rt_thread_t ft6236_thread;
  19. rt_device_t touch;
  20. void ft6236_thread_entry(void *parameter)
  21. {
  22. struct rt_touch_data *read_data;
  23. read_data = (struct rt_touch_data *)rt_calloc(1, sizeof(struct rt_touch_data));
  24. while(1)
  25. {
  26. rt_device_read(touch, 0, read_data, 1);
  27. if (read_data->event == RT_TOUCH_EVENT_DOWN)
  28. {
  29. rt_kprintf("down x: %03d y: %03d", read_data->x_coordinate, read_data->y_coordinate);
  30. rt_kprintf(" t: %d\n", read_data->timestamp);
  31. }
  32. if (read_data->event == RT_TOUCH_EVENT_MOVE)
  33. {
  34. rt_kprintf("move x: %03d y: %03d", read_data->x_coordinate, read_data->y_coordinate);
  35. rt_kprintf(" t: %d\n", read_data->timestamp);
  36. }
  37. if (read_data->event == RT_TOUCH_EVENT_UP)
  38. {
  39. rt_kprintf("up x: %03d y: %03d", read_data->x_coordinate, read_data->y_coordinate);
  40. rt_kprintf(" t: %d\n\n", read_data->timestamp);
  41. }
  42. rt_thread_delay(10);
  43. }
  44. }
  45. #define REST_PIN GET_PIN(D, 3)
  46. int ft6236_example(void)
  47. {
  48. struct rt_touch_config cfg;
  49. cfg.dev_name = "i2c1";
  50. rt_hw_ft6236_init("touch", &cfg, REST_PIN);
  51. touch = rt_device_find("touch");
  52. rt_device_open(touch, RT_DEVICE_FLAG_RDONLY);
  53. struct rt_touch_info info;
  54. rt_device_control(touch, RT_TOUCH_CTRL_GET_INFO, &info);
  55. LOG_I("type :%d", info.type);
  56. LOG_I("vendor :%d", info.vendor);
  57. LOG_I("point_num :%d", info.point_num);
  58. LOG_I("range_x :%d", info.range_x);
  59. LOG_I("range_y :%d", info.range_y);
  60. ft6236_thread = rt_thread_create("touch", ft6236_thread_entry, RT_NULL, 800, 10, 20);
  61. if (ft6236_thread == RT_NULL)
  62. {
  63. LOG_D("create ft6236 thread err");
  64. return -RT_ENOMEM;
  65. }
  66. rt_thread_startup(ft6236_thread);
  67. return RT_EOK;
  68. }
  69. INIT_APP_EXPORT(ft6236_example);