application.c 4.5 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. */
  14. /**
  15. * @addtogroup STM32
  16. */
  17. /*@{*/
  18. #include <rtthread.h>
  19. #include <finsh.h>
  20. #include <stm32f10x.h>
  21. #ifdef RT_USING_DFS
  22. /* dfs init */
  23. #include <dfs_init.h>
  24. /* dfs filesystem:FAT filesystem init */
  25. #include <dfs_fat.h>
  26. /* dfs filesystem:EFS filesystem init */
  27. #include <dfs_efs.h>
  28. /* dfs Filesystem APIs */
  29. #include <dfs_fs.h>
  30. #endif
  31. #ifdef RT_USING_LWIP
  32. #include <lwip/sys.h>
  33. #include <lwip/api.h>
  34. #endif
  35. /*
  36. key_enter PA0
  37. key_down PA1
  38. key_up PA2
  39. key_right PC2
  40. key_left PC3
  41. */
  42. #define key_enter_GETVALUE() GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)
  43. #define key_down_GETVALUE() GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_1)
  44. #define key_up_GETVALUE() GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_2)
  45. #define key_right_GETVALUE() GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_2)
  46. #define key_left_GETVALUE() GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_3)
  47. void rt_key_entry(void *parameter)
  48. {
  49. GPIO_InitTypeDef GPIO_InitStructure;
  50. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC,ENABLE);
  51. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  52. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  53. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
  54. GPIO_Init(GPIOA,&GPIO_InitStructure);
  55. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
  56. GPIO_Init(GPIOC,&GPIO_InitStructure);
  57. while (1)
  58. {
  59. if ( key_enter_GETVALUE() == 0 )rt_kprintf("key_enter\r\n");
  60. if ( key_down_GETVALUE() == 0 )rt_kprintf("key_down\r\n");
  61. if ( key_up_GETVALUE() == 0 )rt_kprintf("key_up\r\n");
  62. if ( key_right_GETVALUE() == 0 )rt_kprintf("key_right\r\n");
  63. if ( key_left_GETVALUE() == 0 )rt_kprintf("key_left\r\n");
  64. rt_thread_delay(20);
  65. }
  66. }
  67. extern rt_err_t lcd_hw_init(void);
  68. void rt_lcd_entry(void *parameter)
  69. {
  70. rt_device_t device;
  71. unsigned int i,k;
  72. unsigned short color[]={0xf800,0x07e0,0x001f,0xffe0,0x0000,0xffff,0x07ff,0xf81f};
  73. lcd_hw_init();
  74. device = rt_device_find("lcd");
  75. rt_kprintf("Now test the LCD......\r\n");
  76. while (1)
  77. {
  78. for (k=0;k<8;k++)
  79. {
  80. for (i=0;i<320*240;i++)
  81. {
  82. device->write(device,i*2,&color[k],2);
  83. }
  84. rt_thread_delay(RT_TICK_PER_SECOND);
  85. }
  86. }
  87. }
  88. void lcd_test()
  89. {
  90. rt_thread_t lcd_tid;
  91. lcd_tid = rt_thread_create("lcd",
  92. rt_lcd_entry, RT_NULL,
  93. 1024, 30, 5);
  94. if (lcd_tid != RT_NULL) rt_thread_startup(lcd_tid);
  95. }
  96. FINSH_FUNCTION_EXPORT(lcd_test, test lcd)
  97. /* thread phase init */
  98. void rt_init_thread_entry(void *parameter)
  99. {
  100. /* Filesystem Initialization */
  101. #ifdef RT_USING_DFS
  102. {
  103. /* init the device filesystem */
  104. dfs_init();
  105. /* init the efsl filesystam*/
  106. efsl_init();
  107. /* mount sd card fat partition 1 as root directory */
  108. if (dfs_mount("sd0", "/", "efs", 0, 0) == 0)
  109. rt_kprintf("File System initialized!\n");
  110. else
  111. rt_kprintf("File System init failed!\n");
  112. }
  113. #endif
  114. /* LwIP Initialization */
  115. #ifdef RT_USING_LWIP
  116. {
  117. extern void lwip_sys_init(void);
  118. /* init lwip system */
  119. lwip_sys_init();
  120. rt_kprintf("TCP/IP initialized!\n");
  121. }
  122. #endif
  123. }
  124. int rt_application_init()
  125. {
  126. rt_thread_t init_thread;
  127. #if (RT_THREAD_PRIORITY_MAX == 32)
  128. init_thread = rt_thread_create("init",
  129. rt_init_thread_entry, RT_NULL,
  130. 2048, 8, 20);
  131. #else
  132. init_thread = rt_thread_create("init",
  133. rt_init_thread_entry, RT_NULL,
  134. 2048, 80, 20);
  135. #endif
  136. if (init_thread != RT_NULL) rt_thread_startup(init_thread);
  137. /* create keypad thread */
  138. {
  139. rt_thread_t key_tid;
  140. key_tid = rt_thread_create("key",
  141. rt_key_entry, RT_NULL,
  142. 512, 30, 5);
  143. if (key_tid != RT_NULL) rt_thread_startup(key_tid);
  144. }
  145. return 0;
  146. }
  147. /*@}*/