application.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2011-02-24 Bernard the first version
  9. */
  10. /**
  11. * @addtogroup FM3
  12. */
  13. /*@{*/
  14. #include <rtthread.h>
  15. #include "board.h"
  16. #include "led.h"
  17. #include "key.h"
  18. #include "adc.h"
  19. #include "lcd.h"
  20. #include "cpuusage.h"
  21. #ifdef RT_USING_RTGUI
  22. #include <rtgui/rtgui.h>
  23. #include <rtgui/driver.h>
  24. extern void rtgui_startup();
  25. #endif
  26. struct rt_messagequeue mq;
  27. static char msg_pool[2048];
  28. void rt_init_thread_entry(void *parameter)
  29. {
  30. rt_device_t lcd;
  31. rt_hw_led_init();
  32. rt_hw_key_init();
  33. rt_hw_adc_init();
  34. rt_hw_lcd_init();
  35. rt_hw_cpu_init();
  36. #ifdef RT_USING_RTGUI
  37. extern void rtgui_system_server_init(void);
  38. /* find lcd device */
  39. lcd = rt_device_find("lcd");
  40. /* set lcd device as rtgui graphic driver */
  41. rtgui_graphic_set_device(lcd);
  42. /* init rtgui system server */
  43. rtgui_system_server_init();
  44. /* startup rtgui */
  45. rtgui_startup();
  46. #else
  47. {
  48. char buf[20] = {'\0'};
  49. struct lcd_msg msg;
  50. rt_device_t device;
  51. device = rt_device_find("lcd");
  52. rt_device_control(device, RT_DEVICE_CTRL_LCD_CLEAR_SCR, RT_NULL);
  53. x = 1;
  54. y = 1;
  55. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "ADC");
  56. x = 1;
  57. y = 20;
  58. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "CPU");
  59. x = 1;
  60. y = 40;
  61. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "KEY");
  62. while(1)
  63. {
  64. if (rt_mq_recv(&mq, &msg, sizeof(msg), RT_WAITING_FOREVER) == RT_EOK)
  65. {
  66. switch(msg.type)
  67. {
  68. case ADC_MSG:
  69. x = 40;
  70. y = 1;
  71. rt_memset(buf, 0, sizeof(buf));
  72. rt_sprintf(buf, "%04d", msg.adc_value);
  73. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf);
  74. break;
  75. case CPU_MSG:
  76. x = 40;
  77. y = 20;
  78. rt_memset(buf, 0, sizeof(buf));
  79. rt_sprintf(buf, "%03d %03d", msg.major, msg.minor);
  80. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf);
  81. break;
  82. case KEY_MSG:
  83. x = 40;
  84. y = 40;
  85. rt_memset(buf, 0, sizeof(buf));
  86. switch(msg.key)
  87. {
  88. case KEY_DOWN:
  89. rt_sprintf(buf, "DOWN KEY ");
  90. break;
  91. case KEY_UP:
  92. rt_sprintf(buf, "UP KEY ");
  93. break;
  94. case KEY_RIGHT:
  95. rt_sprintf(buf, "RIGHT KEY");
  96. break;
  97. case KEY_LEFT:
  98. rt_sprintf(buf, "LEFT KEY ");
  99. break;
  100. case KEY_ENTER:
  101. rt_sprintf(buf, "ENTER KEY");
  102. break;
  103. default:
  104. rt_sprintf(buf, "NO KEY ");
  105. break;
  106. }
  107. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf);
  108. break;
  109. }
  110. }
  111. }
  112. }
  113. #endif
  114. }
  115. int rt_application_init(void)
  116. {
  117. rt_thread_t init_thread;
  118. rt_mq_init(&mq, "mqt", &msg_pool[0], 128 - sizeof(void*), sizeof(msg_pool), RT_IPC_FLAG_FIFO);
  119. init_thread = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 1024, 21, 20);
  120. if(init_thread != RT_NULL)
  121. rt_thread_startup(init_thread);
  122. return 0;
  123. }
  124. /*@}*/