application.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. /* init the efsl filesystam*/
  83. efsl_init();
  84. /* mount sd card fat partition 1 as root directory */
  85. if (dfs_mount("sd0", "/", "efs", 0, 0) == 0)
  86. rt_kprintf("File System initialized!\n");
  87. else
  88. rt_kprintf("File System init failed!\n");
  89. }
  90. #endif
  91. /* LwIP Initialization */
  92. #ifdef RT_USING_LWIP
  93. {
  94. extern void lwip_sys_init(void);
  95. /* init lwip system */
  96. lwip_sys_init();
  97. rt_kprintf("TCP/IP initialized!\n");
  98. }
  99. #endif
  100. #if STM32_EXT_SRAM
  101. /* init netbuf worker */
  102. net_buf_init(320 * 1024);
  103. #endif
  104. /* RTGUI Initialization */
  105. #ifdef RT_USING_RTGUI
  106. {
  107. rtgui_rect_t rect;
  108. rtgui_system_server_init();
  109. /* register dock panel */
  110. rect.x1 = 0;
  111. rect.y1 = 0;
  112. rect.x2 = 240;
  113. rect.y2 = 25;
  114. rtgui_panel_register("info", &rect);
  115. /* register main panel */
  116. rect.x1 = 0;
  117. rect.y1 = 25;
  118. rect.x2 = 240;
  119. rect.y2 = 320;
  120. rtgui_panel_register("main", &rect);
  121. rt_hw_lcd_init();
  122. }
  123. #endif
  124. }
  125. int rt_application_init()
  126. {
  127. rt_thread_t init_thread;
  128. rt_hw_lcd_init();
  129. #if (RT_THREAD_PRIORITY_MAX == 32)
  130. init_thread = rt_thread_create("init",
  131. rt_init_thread_entry, RT_NULL,
  132. 2048, 8, 20);
  133. #else
  134. init_thread = rt_thread_create("init",
  135. rt_init_thread_entry, RT_NULL,
  136. 2048, 80, 20);
  137. #endif
  138. if (init_thread != RT_NULL) rt_thread_startup(init_thread);
  139. /* create keypad thread */
  140. {
  141. rt_thread_t key_tid;
  142. key_tid = rt_thread_create("key",
  143. rt_key_entry, RT_NULL,
  144. 512, 30, 5);
  145. if (key_tid != RT_NULL) rt_thread_startup(key_tid);
  146. }
  147. return 0;
  148. }
  149. /*@}*/