dyc1229 发表于 2022-7-24 14:25

[N32L43X评测]6.移植超小体积的Gui uGui

<p>现在Lvgl非常火,但是放到类32这一部分单片机上不论是Flash还是Ram都有点捉襟见肘的感觉,但是完全自己设计gui又有点复杂,就找了一个非常小巧的uGUI框架。这个框架虽然很老了,而且作者7年前就停更了,不过用起来确实很简单,也比较容易理解。</p>

<p>这是uGui的Github地址:https://github.com/achimdoebler/UGUI</p>

<p>以及官网地址:http://embeddedlightning.com/ugui/</p>

<p>移植只需要以下3个函数</p>

<p>static UG_RESULT HW_FillFrame ( UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, UG_COLOR c){</p>

<p>LCD_Fill(x1,y1,x2,y2,c);</p>

<p>&nbsp;&nbsp;&nbsp; return UG_RESULT_OK;</p>

<p>}</p>

<p>&nbsp;</p>

<p>static UG_RESULT HW_DrawLine ( UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, UG_COLOR c){</p>

<p>LCD_DrawLine(x1,y1,x2,y2,c);</p>

<p>&nbsp;&nbsp;&nbsp; return UG_RESULT_OK;</p>

<p>}</p>

<p>&nbsp;</p>

<p>static void pset(UG_S16 x,UG_S16 y,UG_COLOR c){</p>

<p>&nbsp;&nbsp;&nbsp; LCD_DrawPoint(x,y,c);</p>

<p>}</p>

<p>&nbsp;</p>

<p>在初始化中配置好驱动</p>

<p>void gui_ugui_init(){&nbsp;&nbsp;&nbsp;</p>

<p>UG_Init(&amp;gui, pset, 240 , 240 ) ;</p>

<p>UG_DriverRegister( DRIVER_DRAW_LINE,&nbsp; HW_DrawLine ) ;</p>

<p>UG_DriverRegister( DRIVER_FILL_FRAME,&nbsp; HW_FillFrame ) ;</p>

<p>&nbsp;</p>

<p>UG_DriverEnable ( DRIVER_DRAW_LINE ) ;</p>

<p>UG_DriverEnable ( DRIVER_FILL_FRAME ) ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>

<p>}</p>

<p>&nbsp;</p>

<p>在循环函数中调用UG_Update(),这里一定别忘了</p>

<p>&nbsp;</p>

<p>这样移植的工作就完成了,简单吧</p>

<p>根据例程中的例子使用了一个window,咱们来看看效果</p>

<pre>
<code>/* Window 1 */
UG_WINDOW window_1;
UG_OBJECT obj_buff_wnd_1;
UG_BUTTON button1_1;
UG_BUTTON button1_2;
UG_BUTTON button1_3;
UG_BUTTON button1_4;
UG_BUTTON button1_5;
UG_BUTTON button1_6;

void CreateWindow(void){
        UG_FillScreen(0x0);
        /* Create Window 1 */
        UG_WindowCreate( &amp;window_1, obj_buff_wnd_1, MAX_OBJECTS, window_1_callback );
        UG_WindowSetTitleText( &amp;window_1, "uGUI @ N32" );
        UG_WindowSetTitleTextFont( &amp;window_1, &amp;FONT_12X20 );
        UG_WindowSetTitleText( &amp;window_1, "uGUI @ N32" );
        UG_WindowSetTitleTextFont( &amp;window_1, &amp;FONT_12X20 );
        UG_WindowSetBackColor(&amp;window_1,C_WHITE);
        UG_WindowShow( &amp;window_1 );
       
        /* Create some Buttons */
        UG_ButtonCreate( &amp;window_1, &amp;button1_1, BTN_ID_0, 10, 10, 110, 60 );
        UG_ButtonCreate( &amp;window_1, &amp;button1_2, BTN_ID_1, 10, 80, 110, 130 );
        UG_ButtonCreate( &amp;window_1, &amp;button1_3, BTN_ID_2, 10, 150, 110,200 );
        UG_ButtonCreate( &amp;window_1, &amp;button1_4, BTN_ID_3, 120, 10, UG_WindowGetInnerWidth( &amp;window_1 ) - 10 , 60 );
        UG_ButtonCreate( &amp;window_1, &amp;button1_5, BTN_ID_4, 120, 80, UG_WindowGetInnerWidth( &amp;window_1 ) - 10, 130 );
        UG_ButtonCreate( &amp;window_1, &amp;button1_6, BTN_ID_5, 120, 150, UG_WindowGetInnerWidth( &amp;window_1 ) - 10, 200 );

        /* Configure Button 1 */
        UG_ButtonSetFont( &amp;window_1, BTN_ID_0, &amp;FONT_12X20 );
        UG_ButtonSetBackColor( &amp;window_1, BTN_ID_0, C_LIME );
        UG_ButtonSetText( &amp;window_1, BTN_ID_0, "Green\nLED" );
        /* Configure Button 2 */
        UG_ButtonSetFont( &amp;window_1, BTN_ID_1, &amp;FONT_12X20 );
        UG_ButtonSetBackColor( &amp;window_1, BTN_ID_1, C_RED );
        UG_ButtonSetText( &amp;window_1, BTN_ID_1, "Red\nLED" );
        /* Configure Button 3 */
        UG_ButtonSetFont( &amp;window_1, BTN_ID_2, &amp;FONT_12X20 );
        UG_ButtonSetText( &amp;window_1, BTN_ID_2, "About\n?GUI" );
        UG_WindowShow( &amp;window_1 );
        /* Configure Button 4 */
        UG_ButtonSetFont( &amp;window_1, BTN_ID_3, &amp;FONT_12X20 );
        UG_ButtonSetForeColor( &amp;window_1, BTN_ID_3, C_RED );
         UG_ButtonSetBackColor( &amp;window_1, BTN_ID_3, C_BLUE );
        UG_ButtonSetText( &amp;window_1, BTN_ID_3, "HW_ACC\nOFF" );
        /* Configure Button 5 */
        UG_ButtonSetFont( &amp;window_1, BTN_ID_4, &amp;FONT_8X14 );
        UG_ButtonSetText( &amp;window_1, BTN_ID_4, "Start\nBenchmark" );
        /* Configure Button 6 */
        UG_ButtonSetFont( &amp;window_1, BTN_ID_5, &amp;FONT_10X16 );
        UG_ButtonSetText( &amp;window_1, BTN_ID_5, "Resize\nWindow" );
       
        UG_WindowShow( &amp;window_1 );
}
</code></pre>

<p> &nbsp;</p>

<p>这个uGUI也支持触摸操作,不过我这用不上就不研究了,说实话如果用触摸的话资源应该就不紧张了,直接用Lvgl比较合适</p>

<p>&nbsp;</p>

<p>这是O0级别编译的体积</p>

<p> &nbsp;</p>

<p>以及Oz级别</p>

<p> &nbsp;</p>

<p>这样使用64KFlash的单片机基本就能满足UI部分的需要了</p>

lugl4313820 发表于 2022-7-25 07:19

谢谢分享,这个支持汉字的显示吗?如果加上汉字字库资源会不会又有些紧张了。

bigbat 发表于 2022-7-25 08:54

<p>这种都是点阵字库,多数GUI都是使用简化的汉字库,有需要的是需要自己弄的</p>

EEWORLD社区 发表于 2022-7-25 11:25

<p>看显示界面,好像没有lvgl设计的好看</p>

wangerxian 发表于 2022-7-25 13:20

<p>对,我也觉得单片机搞GUI其实压力很大的,基本都得外扩RAM或者FLASH</p>

freebsder 发表于 2022-7-28 16:02

<p>stm32可以试试<a href="https://github.com/azure-rtos/guix">guix</a></p>

freebsder 发表于 2022-7-29 10:17

<p>stm32可以试试guix</p>
页: [1]
查看完整版本: [N32L43X评测]6.移植超小体积的Gui uGui