lcd_touch_sample.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-05-26 Chushicheng the first version
  9. */
  10. /*
  11. * Program Listing: This is an LCD device touch usage routine
  12. * The routine exports lcd_touch_sample commands to the control terminal
  13. * Command invocation format: lcd_touch_sample
  14. * Program functions: draw the trajectory of the touch on the screen and print the coordinates of the touch point on the terminal
  15. */
  16. #include <rtdevice.h>
  17. #include "drv_st7796.h"
  18. #include "drv_gt911.h"
  19. static void lcd_touch_sample(void)
  20. {
  21. static rt_uint16_t white[319*2];
  22. rt_uint16_t green[4*4*2];
  23. st7796_t *lcd_obj = (st7796_t *)rt_device_find("lcd");
  24. rt_device_t dev = rt_device_find("capt");
  25. capt_t *capt = (capt_t*)dev->user_data;
  26. gt911_input_t ctp_input;
  27. for (rt_uint32_t i = 0; i < 319*2; i++)
  28. {
  29. white[i] = 0xffff;
  30. }
  31. for (rt_uint32_t i = 0; i < 4*4*2; i++)
  32. {
  33. green[i] = 0x07;
  34. }
  35. for (rt_uint16_t i = 0; i < 159; i++)
  36. {
  37. lcd_load(i, i, 0, 319, white);
  38. }
  39. for (rt_uint16_t i = 159; i < 318; i++)
  40. {
  41. lcd_load(i, i, 0, 319, white);
  42. }
  43. for (rt_uint16_t i = 318; i < 479; i++)
  44. {
  45. lcd_load(i, i, 0, 319, white);
  46. }
  47. while(1)
  48. {
  49. gt911_ctp_read(&capt->gt911, &ctp_input);
  50. for (rt_uint8_t i = 0; i < ctp_input.num_pos; i++)
  51. {
  52. /* Found track ID #0 */
  53. if (ctp_input.pos[i].id == 0)
  54. {
  55. lcd_load(capt->gt911.pos_y_max - ctp_input.pos[i].pos_y, capt->gt911.pos_y_max - ctp_input.pos[i].pos_y+4, ctp_input.pos[i].pos_x, ctp_input.pos[i].pos_x+4, green);
  56. rt_kprintf("x:%d, y:%d\r\n", capt->gt911.pos_y_max - ctp_input.pos[i].pos_y , ctp_input.pos[i].pos_x);
  57. }
  58. }
  59. }
  60. }
  61. MSH_CMD_EXPORT(lcd_touch_sample, lcd sample);