application.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /***************************************************************************//**
  2. * @file application.c
  3. * @brief application tasks
  4. * COPYRIGHT (C) 2011, RT-Thread Development Team
  5. * @author Bernard, onelife
  6. * @version 0.4 beta
  7. *******************************************************************************
  8. * @section License
  9. * The license and distribution terms for this file may be found in the file
  10. * LICENSE in this distribution or at http://www.rt-thread.org/license/LICENSE
  11. *******************************************************************************
  12. * @section Change Logs
  13. * Date Author Notes
  14. * 2009-01-05 Bernard first version
  15. * 2010-12-29 onelife Modify for EFM32
  16. * 2011-05-06 onelife Add SPI Flash DEMO
  17. * 2011-07-15 onelife Add accelerometer DEMO
  18. * 2011-07-27 onelife Modify Ethernet DEMO
  19. * 2011-08-23 onelife Modify Ethernet DEMO according to the changes of
  20. * lwIP API in reversion 1668
  21. * 2011-12-20 onelife Add LCD DEMO
  22. ******************************************************************************/
  23. /***************************************************************************//**
  24. * @addtogroup efm32
  25. * @{
  26. ******************************************************************************/
  27. /* Includes ------------------------------------------------------------------*/
  28. #include <board.h>
  29. #if defined(RT_USING_DFS)
  30. /* dfs init */
  31. #include <dfs_init.h>
  32. /* dfs filesystem:ELM filesystem init */
  33. #include <dfs_elm.h>
  34. /* dfs Filesystem APIs */
  35. #include <dfs_fs.h>
  36. #endif
  37. #include "dev_led.h"
  38. #if defined(EFM32_USING_ACCEL)
  39. #include "dev_accel.h"
  40. #endif
  41. #if defined(EFM32_USING_SFLASH)
  42. #include "dev_sflash.h"
  43. #endif
  44. #if defined(EFM32_USING_SPISD)
  45. #include "drv_sdcard.h"
  46. #endif
  47. #if defined(EFM32_USING_ETHERNET)
  48. #include "drv_ethernet.h"
  49. #endif
  50. #if defined(EFM32_USING_LCD)
  51. #include "dev_lcd.h"
  52. #include <rtgui/rtgui_server.h>
  53. #include <rtgui/rtgui_system.h>
  54. #include <rtgui/widgets/workbench.h>
  55. #include <rtgui/widgets/widget.h>
  56. #include <rtgui/widgets/view.h>
  57. #include <rtgui/widgets/label.h>
  58. #include <rtgui/widgets/window.h>
  59. #include <rtgui/widgets/box.h>
  60. #endif
  61. /* Private typedef -----------------------------------------------------------*/
  62. /* Private define ------------------------------------------------------------*/
  63. /* Private macro -------------------------------------------------------------*/
  64. /* Private variables ---------------------------------------------------------*/
  65. volatile rt_uint32_t rt_system_status = 0;
  66. /* Private function prototypes -----------------------------------------------*/
  67. /* Private functions ---------------------------------------------------------*/
  68. static rt_uint8_t index = 0 ;
  69. static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
  70. {
  71. if (event->type == RTGUI_EVENT_PAINT)
  72. {
  73. struct rtgui_dc* dc;
  74. struct rtgui_rect rect;
  75. dc = rtgui_dc_begin_drawing(widget);
  76. if (dc == RT_NULL)
  77. return RT_FALSE;
  78. rtgui_widget_get_rect(widget, &rect);
  79. rtgui_dc_fill_rect(dc, &rect);
  80. rect.x2 -= 1; rect.y2 -= 1;
  81. rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1);
  82. rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2);
  83. rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2);
  84. rtgui_dc_draw_vline(dc, rect.x2, rect.y1, rect.y2 + 1);
  85. /* shrink border */
  86. rtgui_rect_inflate(&rect, -1);
  87. /* draw text */
  88. rtgui_widget_get_rect(widget, &rect);
  89. rect.y1 += 25;
  90. rtgui_dc_draw_text(dc, " EFM3 EFM32GG_DK3750 Kit", &rect);
  91. rect.y1 += 10;
  92. rtgui_dc_draw_text(dc, " RT-Thread & RTGUI", &rect);
  93. rect.y1 += 10;
  94. rtgui_dc_draw_text(dc, " ÖÐÎÄÒ²ÐÐ!", &rect);
  95. rtgui_dc_end_drawing(dc);
  96. return RT_FALSE;
  97. }
  98. else if (event->type == RTGUI_EVENT_KBD)
  99. {
  100. struct rtgui_dc* dc;
  101. struct rtgui_rect rect;
  102. struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
  103. if (ekbd->type == RTGUI_KEYDOWN)
  104. {
  105. char key_str[16];
  106. switch (ekbd->key)
  107. {
  108. case RTGUIK_LEFT:
  109. rt_sprintf(key_str, "%s", "L");
  110. break;
  111. case RTGUIK_RIGHT:
  112. rt_sprintf(key_str, "%s", "R");
  113. break;
  114. case RTGUIK_DOWN:
  115. rt_sprintf(key_str, "%s", "D");
  116. break;
  117. case RTGUIK_UP:
  118. rt_sprintf(key_str, "%s", "U");
  119. break;
  120. default:
  121. rt_sprintf(key_str, "%s", "S");
  122. break;
  123. }
  124. dc = rtgui_dc_begin_drawing(widget);
  125. if (dc == RT_NULL)
  126. return RT_FALSE;
  127. rect.x1 = 118;
  128. rect.y1 = 1;
  129. rect.x2 = 127;
  130. rect.y2 = 10;
  131. rtgui_dc_fill_rect(dc, &rect);
  132. rtgui_dc_draw_text(dc, key_str, &rect);
  133. rtgui_dc_end_drawing(dc);
  134. }
  135. else if (ekbd->type == RTGUI_KEYUP)
  136. {
  137. dc = rtgui_dc_begin_drawing(widget);
  138. if (dc == RT_NULL)
  139. return RT_FALSE;
  140. rect.x1 = 118;
  141. rect.y1 = 1;
  142. rect.x2 = 127;
  143. rect.y2 = 10;
  144. rtgui_dc_fill_rect(dc, &rect);
  145. //rtgui_dc_draw_text(dc, key_str, &rect);
  146. rtgui_dc_end_drawing(dc);
  147. }
  148. }
  149. else if (event->type == RTGUI_EVENT_COMMAND)
  150. {
  151. char str[16];
  152. struct rtgui_dc* dc;
  153. struct rtgui_rect rect;
  154. struct rtgui_event_command* ecmd;
  155. rt_uint8_t major,minor;
  156. dc = rtgui_dc_begin_drawing(widget);
  157. if (dc == RT_NULL)
  158. return RT_FALSE;
  159. ecmd = (struct rtgui_event_command*)event;
  160. switch (ecmd->command_id)
  161. {
  162. default:
  163. rect.x1 = 1;
  164. rect.y1 = 1;
  165. rect.x2 = 117;
  166. rect.y2 = 10;
  167. rtgui_dc_fill_rect(dc, &rect);
  168. rt_sprintf(str, "ADC = %d mv", 123);
  169. rtgui_dc_draw_text(dc, str, &rect);
  170. break;
  171. /* case ADC_UPDATE:
  172. rect.x1 = 1;
  173. rect.y1 = 1;
  174. rect.x2 = 117;
  175. rect.y2 = 10;
  176. rtgui_dc_fill_rect(dc, &rect);
  177. rt_sprintf(str, "ADC = %d mv", adc_value);
  178. rtgui_dc_draw_text(dc, str, &rect);
  179. break;
  180. case CPU_UPDATE:
  181. cpu_usage_get(&major, &minor);
  182. rect.x1 = 1;
  183. rect.y1 = 12;
  184. rect.x2 = 127;
  185. rect.y2 = 22;
  186. rtgui_dc_fill_rect(dc, &rect);
  187. rt_sprintf(str, "CPU : %d.%d%", major, minor);
  188. rtgui_dc_draw_text(dc, str, &rect);
  189. rect.y1 = 23;
  190. rect.y2 = 63;
  191. index++;
  192. if (index == 127)
  193. {
  194. index = 1;
  195. rtgui_dc_fill_rect(dc, &rect);
  196. }
  197. if (major>40)
  198. rtgui_dc_draw_vline(dc, index, rect.y1, rect.y2);
  199. else
  200. rtgui_dc_draw_vline(dc, index, rect.y2-major, rect.y2);
  201. break;
  202. */ }
  203. rtgui_dc_end_drawing(dc);
  204. }
  205. return rtgui_view_event_handler(widget, event);
  206. }
  207. static void wb_info(void* parameter)
  208. {
  209. rt_mq_t mq;
  210. rtgui_view_t *view;
  211. rtgui_workbench_t *workbench;
  212. /* Create message queue for self */
  213. mq = rt_mq_create("mq_wb1", 256, 4, RT_IPC_FLAG_FIFO);
  214. if(mq == RT_NULL)
  215. {
  216. rt_kprintf("Create mq failed!\n");
  217. return;
  218. }
  219. rtgui_thread_register(rt_thread_self(), mq);
  220. /* Create workbench */
  221. workbench = rtgui_workbench_create("info", "wb_1");
  222. if(workbench == RT_NULL)
  223. {
  224. rt_kprintf("Create wb failed!\n");
  225. return;
  226. }
  227. /* Create a view */
  228. view = rtgui_view_create("view_1");
  229. if(view == RT_NULL)
  230. {
  231. rt_kprintf("Create view failed!\n");
  232. return;
  233. }
  234. RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = red;
  235. RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(view)) = white;
  236. // rtgui_widget_set_event_handler(RTGUI_WIDGET(view), view_event_handler);
  237. /* Create a lable */
  238. rtgui_label_t *label = rtgui_label_create("R-Thread & RTGUI");
  239. if(label == RT_NULL)
  240. {
  241. rt_kprintf("Create lable failed!\n");
  242. return;
  243. }
  244. RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(label)) = red;
  245. RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = white;
  246. /* Set lable position */
  247. rtgui_rect_t rect;
  248. rect.x1 = 10; rect.y1 = 2;
  249. rect.x2 = 230; rect.y2 = 22;
  250. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  251. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  252. /* Add view to workbench */
  253. rtgui_workbench_add_view(workbench, view);
  254. /* this view can be focused */
  255. // RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
  256. /* set widget focus */
  257. // rtgui_widget_focus(RTGUI_WIDGET(view));
  258. /* Show view */
  259. rtgui_view_show(view, RT_FALSE);
  260. /* Workbench loop */
  261. rtgui_workbench_event_loop(workbench);
  262. /* Prepare for exit */
  263. rtgui_thread_deregister(rt_thread_self());
  264. rt_mq_delete(mq);
  265. }
  266. static void wb_main(void* parameter)
  267. {
  268. rt_mq_t mq;
  269. rtgui_view_t *view;
  270. rtgui_workbench_t *workbench;
  271. /* Create message queue for self */
  272. mq = rt_mq_create("mq_wb2", 256, 4, RT_IPC_FLAG_FIFO);
  273. if(mq == RT_NULL)
  274. {
  275. rt_kprintf("Create mq failed!\n");
  276. return;
  277. }
  278. rtgui_thread_register(rt_thread_self(), mq);
  279. /* Create workbench */
  280. workbench = rtgui_workbench_create("main", "wb_2");
  281. if(workbench == RT_NULL)
  282. {
  283. rt_kprintf("Create wb failed!\n");
  284. return;
  285. }
  286. /* Create a view */
  287. view = rtgui_view_create("view_2");
  288. if(view == RT_NULL)
  289. {
  290. rt_kprintf("Create view failed!\n");
  291. return;
  292. }
  293. RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
  294. RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(view)) = red;
  295. // rtgui_widget_set_event_handler(RTGUI_WIDGET(view), view_event_handler);
  296. /* Create a lable */
  297. rtgui_label_t* label = rtgui_label_create("EFM32GG_DK3750 Kit");
  298. if(label == RT_NULL)
  299. {
  300. rt_kprintf("Create lable failed!\n");
  301. return;
  302. }
  303. RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(label)) = white;
  304. RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = red;
  305. /* Set lable position */
  306. rtgui_rect_t rect;
  307. rect.x1 = 10; rect.y1 = 50;
  308. rect.x2 = 230; rect.y2 = 70;
  309. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  310. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  311. /* Add view to workbench */
  312. rtgui_workbench_add_view(workbench, view);
  313. /* this view can be focused */
  314. // RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
  315. /* set widget focus */
  316. // rtgui_widget_focus(RTGUI_WIDGET(view));
  317. /* Show view */
  318. rtgui_view_show(view, RT_FALSE);
  319. /* Workbench loop */
  320. rtgui_workbench_event_loop(workbench);
  321. /* Prepare for exit */
  322. rtgui_thread_deregister(rt_thread_self());
  323. rt_mq_delete(mq);
  324. }
  325. static void win_hello(void* parameter)
  326. {
  327. rt_mq_t mq;
  328. struct rtgui_view* view;
  329. rtgui_win_t *win;
  330. /* Create message queue for self */
  331. mq = rt_mq_create("mq_win", 256, 4, RT_IPC_FLAG_FIFO);
  332. if(mq == RT_NULL)
  333. {
  334. rt_kprintf("Create mq failed!\n");
  335. return;
  336. }
  337. rtgui_thread_register(rt_thread_self(), mq);
  338. /* Window position */
  339. rtgui_rect_t rect;
  340. rect.x1 = 50; rect.y1 = 50;
  341. rect.x2 = 180; rect.y2 = 180;
  342. /* Create window */
  343. win = rtgui_win_create(RT_NULL, "Hello", &rect, RTGUI_WIN_STYLE_DEFAULT);
  344. if(win == RT_NULL)
  345. {
  346. rt_kprintf("Create win failed!\n");
  347. return;
  348. }
  349. /* Create a box */
  350. rtgui_box_t *box = rtgui_box_create(RTGUI_VERTICAL, RT_NULL);
  351. if(box == RT_NULL)
  352. {
  353. rt_kprintf("Create box failed!\n");
  354. return;
  355. }
  356. rtgui_win_set_box(win, box);
  357. rtgui_label_t *label = rtgui_label_create("¹þÂÞ,íïÅÖ!");
  358. if(label == RT_NULL)
  359. {
  360. rt_kprintf("Create lable failed!\n");
  361. return;
  362. }
  363. RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(label)) = white;
  364. RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = black;
  365. RTGUI_WIDGET(label)->align = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
  366. rtgui_widget_set_miniwidth(RTGUI_WIDGET(label),130);
  367. rtgui_box_append(box, RTGUI_WIDGET(label));
  368. /* Auto layout */
  369. rtgui_box_layout(box);
  370. /* Show window */
  371. rtgui_win_show(win, RT_FALSE);
  372. /* Window loop */
  373. rtgui_win_event_loop(win);
  374. /* Prepare for exit */
  375. rtgui_thread_deregister(rt_thread_self());
  376. rt_mq_delete(mq);
  377. }
  378. void rt_demo_thread_entry(void* parameter)
  379. {
  380. #if 0 //defined(EFM32_USING_ACCEL)
  381. {
  382. struct efm32_accel_result_t result;
  383. rt_kprintf(">>> waiting\n");
  384. rt_thread_sleep(6000);
  385. rt_kprintf(">>> start\n");
  386. while(1)
  387. {
  388. efm_accel_get_data(&result);
  389. rt_kprintf("Accel x: %x\n", result.x);
  390. rt_kprintf("Accel y: %x\n", result.y);
  391. rt_kprintf("Accel z: %x\n\n", result.z);
  392. rt_thread_sleep(200);
  393. }
  394. }
  395. #endif
  396. #if defined(RT_USING_DFS)
  397. {
  398. rt_kprintf("File system DEMO start...\n");
  399. /* Filesystem Initialization */
  400. dfs_init();
  401. #if defined(RT_USING_DFS_ELMFAT)
  402. /* init the elm chan FatFs filesystam*/
  403. elm_init();
  404. #if defined(EFM32_USING_SPISD)
  405. /* mount sd card fat partition 1 as root directory */
  406. if (dfs_mount(SPISD_DEVICE_NAME, "/", "elm", 0, 0) == 0)
  407. {
  408. rt_kprintf("FatFs init OK\n");
  409. }
  410. else
  411. {
  412. rt_kprintf("FatFs init failed!\n");
  413. }
  414. #endif
  415. #endif
  416. rt_kprintf("File system DEMO end.\n");
  417. }
  418. #endif
  419. #ifdef EFM32_USING_SFLASH
  420. {
  421. rt_kprintf("SPI Flash DEMO start...\n");
  422. rt_uint8_t i;
  423. rt_uint8_t test[] = "123456789ABCDEF";
  424. rt_uint8_t buf[30], buf2[30];
  425. efm_spiFlash_cmd(sflash_inst_rdid_l, EFM32_NO_DATA, buf, sizeof(buf));
  426. rt_kprintf("Manuf ID: %x\n", buf[0]);
  427. rt_kprintf("Memory type: %x\n", buf[1]);
  428. rt_kprintf("Memory capacity: %x\n", buf[2]);
  429. rt_kprintf("CFD length: %x\n", buf[3]);
  430. rt_kprintf("CFD: %x%x%x...%x%x\n", buf[4], buf[5], buf[6], buf[18], buf[19]);
  431. efm_spiFlash_cmd(sflash_inst_wren, EFM32_NO_DATA, EFM32_NO_POINTER, EFM32_NO_DATA);
  432. do
  433. {
  434. efm_spiFlash_cmd(sflash_inst_rdsr, EFM32_NO_DATA, buf2, sizeof(buf2));
  435. rt_kprintf("Status: %x\n", buf2[0]);
  436. } while (buf2[0] == 0xFF);
  437. rt_kprintf("Status: %x\n", buf2[0]);
  438. //efm_spiFash_cmd(sflash_inst_pp, 0x000003F8, test, sizeof(test) - 1);
  439. efm_spiFlash_cmd(sflash_inst_rdsr, EFM32_NO_DATA, buf2, sizeof(buf2));
  440. rt_kprintf("Status: %x\n", buf2[0]);
  441. efm_spiFlash_cmd(sflash_inst_read, 0x00000300, buf, sizeof(buf));
  442. rt_kprintf("READ: \n");
  443. for (i = 0; i < sizeof(buf); i++)
  444. {
  445. rt_kprintf("%c\n", buf[i]);
  446. }
  447. //efm_spiFlash_deinit();
  448. rt_kprintf("SPI Flash DEMO end.\n");
  449. }
  450. #endif
  451. #if defined(EFM32_USING_ETHERNET)
  452. {
  453. rt_kprintf("Ethernet DEMO start...\n");
  454. extern void lwip_sys_init(void);
  455. /* init lwip system */
  456. lwip_sys_init();
  457. rt_kprintf("TCP/IP stack init OK!\n");
  458. #if defined(EFM32_USING_ETH_HTTPD)
  459. extern void httpd_init(void);
  460. /* init http server */
  461. httpd_init();
  462. rt_kprintf("Http service init OK!\n");
  463. #endif /* defined(EFM32_USING_ETH_HTTPD) */
  464. rt_kprintf("Ethernet DEMO end.\n");
  465. }
  466. #endif /* defined(EFM32_USING_ETHERNET) */
  467. #if defined(EFM32_USING_LCD)
  468. {
  469. rt_kprintf("LCD DEMO start...\n");
  470. /* find lcd device */
  471. rt_device_t lcd = rt_device_find(LCD_DEVICE_NAME);
  472. if (lcd == RT_NULL)
  473. {
  474. rt_kprintf("Can't find LCD\n");
  475. }
  476. /* read LCD info */
  477. struct rt_device_graphic_info lcd_info;
  478. lcd->control(lcd, RTGRAPHIC_CTRL_GET_INFO, (void *)&lcd_info);
  479. rt_kprintf("LCD size: %dX%d\n", lcd_info.width, lcd_info.height);
  480. /* register panels */
  481. rtgui_rect_t rect;
  482. rect.x1 = 0;
  483. rect.y1 = 0;
  484. rect.x2 = lcd_info.width;
  485. rect.y2 = 25;
  486. rtgui_panel_register("info", &rect);
  487. rect.x1 = 0;
  488. rect.y1 = 25;
  489. rect.x2 = lcd_info.width;
  490. rect.y2 = lcd_info.height;
  491. rtgui_panel_register("main", &rect);
  492. rtgui_panel_set_default_focused("main");
  493. /* Create workbenc threads */
  494. rt_thread_t wb_tid;
  495. wb_tid = rt_thread_create(
  496. "wb_main",
  497. wb_main,
  498. RT_NULL,
  499. 2048,
  500. 25,
  501. 10);
  502. if (wb_tid != RT_NULL)
  503. {
  504. rt_thread_startup(wb_tid);
  505. }
  506. else
  507. {
  508. rt_kprintf("Create workbench \"main\" failed!\n");
  509. }
  510. wb_tid = rt_thread_create(
  511. "wb_info",
  512. wb_info,
  513. RT_NULL,
  514. 2048,
  515. 25,
  516. 10);
  517. if (wb_tid != RT_NULL)
  518. {
  519. rt_thread_startup(wb_tid);
  520. }
  521. else
  522. {
  523. rt_kprintf("Create workbench \"info\" failed!\n");
  524. }
  525. wb_tid = rt_thread_create(
  526. "win",
  527. win_hello,
  528. RT_NULL,
  529. 2048,
  530. 25,
  531. 10);
  532. if (wb_tid != RT_NULL)
  533. {
  534. rt_thread_startup(wb_tid);
  535. }
  536. else
  537. {
  538. rt_kprintf("Create window \"win\" failed!\n");
  539. }
  540. rt_kprintf("LCD DEMO end.\n");
  541. }
  542. #endif
  543. rt_kprintf("All Demo end.\n");
  544. while(1)
  545. {
  546. rt_thread_sleep(10);
  547. }
  548. }
  549. void rt_led_thread_entry(void* parameter)
  550. {
  551. rt_uint8_t n = 0;
  552. rt_hw_led_on(0);
  553. rt_hw_led_on(1);
  554. rt_hw_led_on(2);
  555. rt_hw_led_on(3);
  556. while(1)
  557. {
  558. /* Toggle a led per second */
  559. rt_hw_led_toggle(n++);
  560. if (n == LEDS_MAX_NUMBER)
  561. {
  562. n =0;
  563. }
  564. rt_thread_delay(100);
  565. }
  566. }
  567. int rt_application_init()
  568. {
  569. rt_thread_t demo_thread, led_thread;
  570. #if defined(EFM32_USING_ACCEL)
  571. if (efm_accel_init() != RT_EOK)
  572. {
  573. rt_kprintf("*** Init accelerometer driver failed!");
  574. while(1); //Or do something?
  575. }
  576. #endif
  577. #if defined(EFM32_USING_SFLASH)
  578. if (efm_spiFlash_init() != RT_EOK)
  579. {
  580. rt_kprintf("*** Init SPI Flash driver failed!");
  581. while(1); //Or do something?
  582. }
  583. #endif
  584. #if defined(EFM32_USING_SPISD)
  585. if (efm_spiSd_init() != RT_EOK)
  586. {
  587. rt_kprintf("*** Init SD card driver failed!");
  588. while(1); //Or do something?
  589. }
  590. #endif
  591. /* Initialize all device drivers (dev_?.c) */
  592. if (rt_hw_led_init() != RT_EOK)
  593. {
  594. rt_kprintf("*** Init LED driver failed!");
  595. while(1); //Or do something?
  596. }
  597. #if defined(RT_USING_MISC)
  598. if (rt_hw_misc_init() != RT_EOK)
  599. {
  600. rt_kprintf("*** Init miscellaneous driver failed!");
  601. while(1); //Or do something?
  602. }
  603. #endif
  604. #if defined(RT_USING_LWIP)
  605. {
  606. /* Create Ethernet Threads */
  607. if (eth_system_device_init() != RT_EOK)
  608. {
  609. rt_kprintf("*** Create Ethernet threads failed!");
  610. while(1); //Or do something?
  611. }
  612. #if defined(EFM32_USING_ETHERNET)
  613. if (efm_hw_eth_init() != RT_EOK)
  614. {
  615. rt_kprintf("*** Init Ethernet driver failed!");
  616. while(1); //Or do something?
  617. }
  618. #endif
  619. }
  620. #endif
  621. #if (RT_THREAD_PRIORITY_MAX == 32)
  622. demo_thread = rt_thread_create(
  623. "demo",
  624. rt_demo_thread_entry,
  625. RT_NULL,
  626. 1024,
  627. 5,
  628. 20);
  629. led_thread = rt_thread_create(
  630. "led",
  631. rt_led_thread_entry,
  632. RT_NULL,
  633. 256,
  634. 5,
  635. 20);
  636. #else
  637. #endif
  638. if(demo_thread != RT_NULL)
  639. {
  640. rt_kprintf("demo sp:%x\n", demo_thread->sp);
  641. rt_thread_startup(demo_thread);
  642. }
  643. if(led_thread != RT_NULL)
  644. {
  645. rt_thread_startup(led_thread);
  646. }
  647. return 0;
  648. }
  649. /***************************************************************************//**
  650. * @}
  651. ******************************************************************************/