1
0

application.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. * 2013-07-12 aozima update for auto initial.
  10. */
  11. /**
  12. * @addtogroup STM32
  13. */
  14. /*@{*/
  15. #include <board.h>
  16. #include <rtthread.h>
  17. #ifdef RT_USING_DFS
  18. /* dfs filesystem:ELM filesystem init */
  19. #include <dfs_elm.h>
  20. /* dfs Filesystem APIs */
  21. #include <dfs_fs.h>
  22. #endif
  23. #ifdef RT_USING_RTGUI
  24. #include <rtgui/rtgui.h>
  25. #include <rtgui/rtgui_server.h>
  26. #include <rtgui/rtgui_system.h>
  27. #include <rtgui/driver.h>
  28. #include <rtgui/calibration.h>
  29. #endif
  30. #include "led.h"
  31. ALIGN(RT_ALIGN_SIZE)
  32. static rt_uint8_t led_stack[ 512 ];
  33. static struct rt_thread led_thread;
  34. static void led_thread_entry(void* parameter)
  35. {
  36. unsigned int count=0;
  37. rt_hw_led_init();
  38. while (1)
  39. {
  40. /* led1 on */
  41. #ifndef RT_USING_FINSH
  42. rt_kprintf("led on, count : %d\r\n",count);
  43. #endif
  44. count++;
  45. rt_hw_led_on(0);
  46. rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
  47. /* led1 off */
  48. #ifndef RT_USING_FINSH
  49. rt_kprintf("led off\r\n");
  50. #endif
  51. rt_hw_led_off(0);
  52. rt_thread_delay( RT_TICK_PER_SECOND/2 );
  53. }
  54. }
  55. #ifdef RT_USING_RTGUI
  56. rt_bool_t cali_setup(void)
  57. {
  58. rt_kprintf("cali setup entered\n");
  59. return RT_FALSE;
  60. }
  61. void cali_store(struct calibration_data *data)
  62. {
  63. rt_kprintf("cali finished (%d, %d), (%d, %d)\n",
  64. data->min_x,
  65. data->max_x,
  66. data->min_y,
  67. data->max_y);
  68. }
  69. #endif /* RT_USING_RTGUI */
  70. void rt_init_thread_entry(void* parameter)
  71. {
  72. #ifdef RT_USING_COMPONENTS_INIT
  73. /* initialization RT-Thread Components */
  74. rt_components_init();
  75. #endif
  76. /* Filesystem Initialization */
  77. #if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT)
  78. /* mount sd card fat partition 1 as root directory */
  79. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  80. {
  81. rt_kprintf("File System initialized!\n");
  82. }
  83. else
  84. rt_kprintf("File System initialzation failed!\n");
  85. #endif /* RT_USING_DFS */
  86. #ifdef RT_USING_RTGUI
  87. {
  88. extern void rt_hw_lcd_init();
  89. extern void rtgui_touch_hw_init(void);
  90. rt_device_t lcd;
  91. /* init lcd */
  92. rt_hw_lcd_init();
  93. /* init touch panel */
  94. rtgui_touch_hw_init();
  95. /* find lcd device */
  96. lcd = rt_device_find("lcd");
  97. /* set lcd device as rtgui graphic driver */
  98. rtgui_graphic_set_device(lcd);
  99. #ifndef RT_USING_COMPONENTS_INIT
  100. /* init rtgui system server */
  101. rtgui_system_server_init();
  102. #endif
  103. calibration_set_restore(cali_setup);
  104. calibration_set_after(cali_store);
  105. calibration_init();
  106. }
  107. #endif /* #ifdef RT_USING_RTGUI */
  108. }
  109. int rt_application_init(void)
  110. {
  111. rt_thread_t init_thread;
  112. rt_err_t result;
  113. /* init led thread */
  114. result = rt_thread_init(&led_thread,
  115. "led",
  116. led_thread_entry,
  117. RT_NULL,
  118. (rt_uint8_t*)&led_stack[0],
  119. sizeof(led_stack),
  120. 20,
  121. 5);
  122. if (result == RT_EOK)
  123. {
  124. rt_thread_startup(&led_thread);
  125. }
  126. #if (RT_THREAD_PRIORITY_MAX == 32)
  127. init_thread = rt_thread_create("init",
  128. rt_init_thread_entry, RT_NULL,
  129. 2048, 8, 20);
  130. #else
  131. init_thread = rt_thread_create("init",
  132. rt_init_thread_entry, RT_NULL,
  133. 2048, 80, 20);
  134. #endif
  135. if (init_thread != RT_NULL)
  136. rt_thread_startup(init_thread);
  137. return 0;
  138. }
  139. /*@}*/