application.c 4.0 KB

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