MainTask.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. *********************************************************************************************************
  3. *
  4. * 模块名称 : GUI界面主函数
  5. * 文件名称 : MainTask.c
  6. * 版 本 : V1.0
  7. * 说 明 : OLCD界面
  8. *
  9. * 修改记录 :
  10. * 版本号 日期 作者 说明
  11. * V1.0 2020-11-15 Eric2013 安富莱电子 www.armfly.com
  12. * V1.1 2020-11-20 HelloByeAll 移植到rt-thrad
  13. * V1.2 2020-11-26 HelloByeAll 添加虚拟mono设备
  14. *
  15. *
  16. *********************************************************************************************************
  17. */
  18. #include "MainTask.h"
  19. /*
  20. *********************************************************************************************************
  21. * 宏定义
  22. *********************************************************************************************************
  23. */
  24. /*
  25. *********************************************************************************************************
  26. * 变量
  27. *********************************************************************************************************
  28. */
  29. GX_WINDOW *pScreen;
  30. GX_WINDOW_ROOT *root;
  31. extern ULONG display_1_canvas_memory[512];
  32. uint8_t oled_canvas_memory[2048];
  33. extern void lcd_address(uint8_t page, uint8_t column);
  34. extern void transfer_data(uint8_t *data, uint8_t len);
  35. /**
  36. *@brief 向缓冲区画点
  37. *@param x,y 坐标(x = 0-127 | y = 0-127)
  38. *@param color 颜色 <目前只有黑:CBLACK 白:CWHITLE>
  39. *@retval None
  40. */
  41. void GuiDrawPoint(uint8_t x, uint8_t y, uint8_t color)
  42. {
  43. uint16_t i = y % 8;
  44. uint16_t page = y / 8;
  45. /* 添加用户代码 */
  46. if (color == 1)
  47. oled_canvas_memory[page * 128 + x] &= ~(color << i);
  48. else
  49. {
  50. color = 1;
  51. oled_canvas_memory[page * 128 + x] |= color << i;
  52. }
  53. }
  54. /*
  55. *********************************************************************************************************
  56. * 函 数 名: stm32_monochrome_buffer_toggle
  57. * 功能说明: 单色屏绘制,直接做整个屏的重绘
  58. * 形 参:
  59. * 返 回 值: 无
  60. *********************************************************************************************************
  61. */
  62. static void stm32_monochrome_buffer_toggle(GX_CANVAS *canvas, GX_RECTANGLE *dirty)
  63. {
  64. uint8_t *p;
  65. /* 防止警告 */
  66. (void)canvas;
  67. (void)dirty;
  68. /* 获得OLED画布的地址 */
  69. p = (uint8_t *)display_1_canvas_memory;
  70. #ifdef GUIX_VIRTUAL_DISPLAY_MONO
  71. extern void show_virtual_display(rt_uint8_t * p);
  72. show_virtual_display(p);
  73. #endif // GUIX_VIRTUAL_DISPLAY_MONO
  74. /* 将画布的内容绘制到OLED显存 */
  75. for (int y = 0; y < 128; y++)
  76. {
  77. for (int x = 0; x < 128; x += 8)
  78. {
  79. GuiDrawPoint(x, y, (p[16 * y + x / 8] & (0x80)) >> 7);
  80. GuiDrawPoint(x + 1, y, (p[16 * y + x / 8] & (0x40)) >> 6);
  81. GuiDrawPoint(x + 2, y, (p[16 * y + x / 8] & (0x20)) >> 5);
  82. GuiDrawPoint(x + 3, y, (p[16 * y + x / 8] & (0x10)) >> 4);
  83. GuiDrawPoint(x + 4, y, (p[16 * y + x / 8] & (0x08)) >> 3);
  84. GuiDrawPoint(x + 5, y, (p[16 * y + x / 8] & (0x04)) >> 2);
  85. GuiDrawPoint(x + 6, y, (p[16 * y + x / 8] & (0x02)) >> 1);
  86. GuiDrawPoint(x + 7, y, (p[16 * y + x / 8] & (0x01)) >> 0);
  87. }
  88. }
  89. /* 将OLED显存的内容实际绘制到OLED */
  90. for (int i = 0; i < 16; i++)
  91. {
  92. lcd_address(i + 1, 1);
  93. transfer_data(&oled_canvas_memory[i * 128], 128);
  94. }
  95. }
  96. /*
  97. *********************************************************************************************************
  98. * 函 数 名: stm32_graphics_driver_setup_monochrome
  99. * 功能说明: 单色屏驱动接口
  100. * 形 参: 无
  101. * 返 回 值: 无
  102. *********************************************************************************************************
  103. */
  104. UINT stm32_graphics_driver_setup_monochrome(GX_DISPLAY *display)
  105. {
  106. _gx_display_driver_monochrome_setup(display, (VOID *)display_1_canvas_memory, stm32_monochrome_buffer_toggle);
  107. return (GX_SUCCESS);
  108. }
  109. /*
  110. *********************************************************************************************************
  111. * 函 数 名: MainTask
  112. * 功能说明: GUI主函数
  113. * 形 参: 无
  114. * 返 回 值: 无
  115. *********************************************************************************************************
  116. */
  117. void MainTask(void)
  118. {
  119. extern void lcd_init(void);
  120. lcd_init();
  121. /*初始化配置 */
  122. gx_system_initialize();
  123. /* 配置显示屏 */
  124. gx_studio_display_configure(DISPLAY_1, stm32_graphics_driver_setup_monochrome,
  125. LANGUAGE_ENGLISH, DISPLAY_1_THEME_2, &root);
  126. /* 创建窗口 */
  127. gx_studio_named_widget_create("window", (GX_WIDGET *)GX_NULL, (GX_WIDGET **)&pScreen);
  128. gx_studio_named_widget_create("window_1", (GX_WIDGET *)root, (GX_WIDGET **)&pScreen);
  129. /* 显示根窗口 */
  130. gx_widget_show(root);
  131. /* 启动GUIX */
  132. gx_system_start();
  133. }
  134. /* 调用此函数可更换主题 */
  135. void gui_theme_switching(void)
  136. {
  137. static USHORT theme_id = DISPLAY_1_THEME_2;
  138. if (++theme_id >= DISPLAY_1_THEME_TABLE_SIZE)
  139. theme_id = 0;
  140. gx_studio_display_configure(DISPLAY_1, stm32_graphics_driver_setup_monochrome,
  141. LANGUAGE_ENGLISH, theme_id, &root);
  142. }
  143. MSH_CMD_EXPORT(gui_theme_switching, gui_theme_switching);
  144. /*************************************** (END OF FILE) ****************************************/