application.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2009-01-05 Bernard the first version
  9. * 2014-04-27 Bernard make code cleanup.
  10. */
  11. #include <board.h>
  12. #include <rtthread.h>
  13. #ifdef RT_USING_FINSH
  14. #include <shell.h>
  15. #include <finsh.h>
  16. #endif
  17. #ifdef RT_USING_LWIP
  18. #include <lwip/sys.h>
  19. #include <lwip/api.h>
  20. #include <netif/ethernetif.h>
  21. #include "stm32f4xx_eth.h"
  22. #endif
  23. #ifdef RT_USING_GDB
  24. #include <gdb_stub.h>
  25. #endif
  26. #include "drv_touch.h"
  27. #ifdef PKG_USING_LITTLEVGL2RTT
  28. #include "littlevgl2rtt.h"
  29. #endif
  30. static void rt_touch_thread_entry(void *parameter)
  31. {
  32. #ifdef PKG_USING_LITTLEVGL2RTT
  33. int16_t x;
  34. int16_t y;
  35. #endif
  36. struct touch_state ts;
  37. while(1)
  38. {
  39. touch_get_state(&ts);
  40. #ifdef PKG_USING_LITTLEVGL2RTT
  41. if(ts.pressed)
  42. {
  43. x = (3706 - ts.x) / 14;
  44. y = (-461 + ts.y) / 10.5;
  45. littlevgl2rtt_send_input_event(x, y, LITTLEVGL2RTT_INPUT_DOWN);
  46. }
  47. else
  48. littlevgl2rtt_send_input_event(-1, -1, LITTLEVGL2RTT_INPUT_UP);
  49. #endif
  50. rt_thread_mdelay(100);
  51. }
  52. }
  53. void rt_init_thread_entry(void* parameter)
  54. {
  55. rt_thread_t tid;
  56. /* GDB STUB */
  57. #ifdef RT_USING_GDB
  58. gdb_set_device("uart6");
  59. gdb_start();
  60. #endif
  61. /* LwIP Initialization */
  62. #ifdef RT_USING_LWIP
  63. {
  64. extern void lwip_sys_init(void);
  65. /* register ethernetif device */
  66. eth_system_device_init();
  67. rt_hw_stm32_eth_init();
  68. /* init lwip system */
  69. lwip_sys_init();
  70. rt_kprintf("TCP/IP initialized!\n");
  71. }
  72. #endif
  73. rt_components_init();
  74. rt_device_t tscreen = rt_device_find("touch");
  75. rt_device_open(tscreen, RT_DEVICE_FLAG_RDWR);
  76. tid = rt_thread_create("touch",
  77. rt_touch_thread_entry, RT_NULL,
  78. 1024, 4, 20);
  79. if (tid != RT_NULL)
  80. rt_thread_startup(tid);
  81. }
  82. int rt_application_init()
  83. {
  84. rt_thread_t tid;
  85. tid = rt_thread_create("init",
  86. rt_init_thread_entry, RT_NULL,
  87. 2048, RT_THREAD_PRIORITY_MAX/3, 20);
  88. if (tid != RT_NULL)
  89. rt_thread_startup(tid);
  90. return 0;
  91. }
  92. /*@}*/