application.c 3.9 KB

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