application.c 2.4 KB

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