application.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. */
  14. /**
  15. * @addtogroup STM32
  16. */
  17. /*@{*/
  18. #include <rtthread.h>
  19. #include <finsh.h>
  20. #include <stm32f10x.h>
  21. #include "board.h"
  22. #include "netbuffer.h"
  23. #include "lcd.h"
  24. #ifdef RT_USING_DFS
  25. /* dfs init */
  26. #include <dfs_init.h>
  27. /* dfs filesystem:FAT filesystem init */
  28. #include <dfs_fat.h>
  29. /* dfs filesystem:EFS filesystem init */
  30. #include <dfs_efs.h>
  31. /* dfs Filesystem APIs */
  32. #include <dfs_fs.h>
  33. #endif
  34. #ifdef RT_USING_LWIP
  35. #include <lwip/sys.h>
  36. #include <lwip/api.h>
  37. #endif
  38. #ifdef RT_USING_RTGUI
  39. #include <rtgui/rtgui.h>
  40. #include <rtgui/rtgui_system.h>
  41. #endif
  42. /*
  43. key_enter PA0
  44. key_down PA1
  45. key_up PA2
  46. key_right PC2
  47. key_left PC3
  48. */
  49. #define key_enter_GETVALUE() GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)
  50. #define key_down_GETVALUE() GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_1)
  51. #define key_up_GETVALUE() GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_2)
  52. #define key_right_GETVALUE() GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_2)
  53. #define key_left_GETVALUE() GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_3)
  54. void rt_key_entry(void *parameter)
  55. {
  56. GPIO_InitTypeDef GPIO_InitStructure;
  57. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC,ENABLE);
  58. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  59. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  60. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
  61. GPIO_Init(GPIOA,&GPIO_InitStructure);
  62. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
  63. GPIO_Init(GPIOC,&GPIO_InitStructure);
  64. while (1)
  65. {
  66. if ( key_enter_GETVALUE() == 0 )rt_kprintf("key_enter\r\n");
  67. if ( key_down_GETVALUE() == 0 )rt_kprintf("key_down\r\n");
  68. if ( key_up_GETVALUE() == 0 )rt_kprintf("key_up\r\n");
  69. if ( key_right_GETVALUE() == 0 )rt_kprintf("key_right\r\n");
  70. if ( key_left_GETVALUE() == 0 )rt_kprintf("key_left\r\n");
  71. rt_thread_delay(20);
  72. }
  73. }
  74. /* thread phase init */
  75. void rt_init_thread_entry(void *parameter)
  76. {
  77. /* Filesystem Initialization */
  78. #ifdef RT_USING_DFS
  79. {
  80. /* init the device filesystem */
  81. dfs_init();
  82. #ifdef RT_USING_DFS_EFSL
  83. /* init the efsl filesystam*/
  84. efsl_init();
  85. /* mount sd card fat partition 1 as root directory */
  86. if (dfs_mount("sd0", "/", "efs", 0, 0) == 0)
  87. rt_kprintf("File System initialized!\n");
  88. else
  89. rt_kprintf("File System init failed!\n");
  90. #elif defined(RT_USING_DFS_ELMFAT)
  91. /* init the elm FAT filesystam*/
  92. elm_init();
  93. /* mount sd card fat partition 1 as root directory */
  94. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  95. rt_kprintf("File System initialized!\n");
  96. else
  97. rt_kprintf("File System init failed!\n");
  98. #endif
  99. }
  100. #endif
  101. /* LwIP Initialization */
  102. #ifdef RT_USING_LWIP
  103. {
  104. extern void lwip_sys_init(void);
  105. /* init lwip system */
  106. lwip_sys_init();
  107. rt_kprintf("TCP/IP initialized!\n");
  108. }
  109. #endif
  110. #if STM32_EXT_SRAM
  111. /* init netbuf worker */
  112. net_buf_init(320 * 1024);
  113. #endif
  114. /* RTGUI Initialization */
  115. #ifdef RT_USING_RTGUI
  116. {
  117. rtgui_rect_t rect;
  118. rtgui_system_server_init();
  119. /* register dock panel */
  120. rect.x1 = 0;
  121. rect.y1 = 0;
  122. rect.x2 = 240;
  123. rect.y2 = 25;
  124. rtgui_panel_register("info", &rect);
  125. /* register main panel */
  126. rect.x1 = 0;
  127. rect.y1 = 25;
  128. rect.x2 = 240;
  129. rect.y2 = 320;
  130. rtgui_panel_register("main", &rect);
  131. rt_hw_lcd_init();
  132. }
  133. #endif
  134. }
  135. int rt_application_init()
  136. {
  137. rt_thread_t init_thread;
  138. rt_hw_lcd_init();
  139. #if (RT_THREAD_PRIORITY_MAX == 32)
  140. init_thread = rt_thread_create("init",
  141. rt_init_thread_entry, RT_NULL,
  142. 2048, 8, 20);
  143. #else
  144. init_thread = rt_thread_create("init",
  145. rt_init_thread_entry, RT_NULL,
  146. 2048, 80, 20);
  147. #endif
  148. if (init_thread != RT_NULL) rt_thread_startup(init_thread);
  149. /* create keypad thread */
  150. {
  151. rt_thread_t key_tid;
  152. key_tid = rt_thread_create("key",
  153. rt_key_entry, RT_NULL,
  154. 512, 30, 5);
  155. if (key_tid != RT_NULL) rt_thread_startup(key_tid);
  156. }
  157. return 0;
  158. }
  159. /*@}*/