[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> return UG_RESULT_OK;</p>
<p>}</p>
<p> </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> return UG_RESULT_OK;</p>
<p>}</p>
<p> </p>
<p>static void pset(UG_S16 x,UG_S16 y,UG_COLOR c){</p>
<p> LCD_DrawPoint(x,y,c);</p>
<p>}</p>
<p> </p>
<p>在初始化中配置好驱动</p>
<p>void gui_ugui_init(){ </p>
<p>UG_Init(&gui, pset, 240 , 240 ) ;</p>
<p>UG_DriverRegister( DRIVER_DRAW_LINE, HW_DrawLine ) ;</p>
<p>UG_DriverRegister( DRIVER_FILL_FRAME, HW_FillFrame ) ;</p>
<p> </p>
<p>UG_DriverEnable ( DRIVER_DRAW_LINE ) ;</p>
<p>UG_DriverEnable ( DRIVER_FILL_FRAME ) ; </p>
<p>}</p>
<p> </p>
<p>在循环函数中调用UG_Update(),这里一定别忘了</p>
<p> </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( &window_1, obj_buff_wnd_1, MAX_OBJECTS, window_1_callback );
UG_WindowSetTitleText( &window_1, "uGUI @ N32" );
UG_WindowSetTitleTextFont( &window_1, &FONT_12X20 );
UG_WindowSetTitleText( &window_1, "uGUI @ N32" );
UG_WindowSetTitleTextFont( &window_1, &FONT_12X20 );
UG_WindowSetBackColor(&window_1,C_WHITE);
UG_WindowShow( &window_1 );
/* Create some Buttons */
UG_ButtonCreate( &window_1, &button1_1, BTN_ID_0, 10, 10, 110, 60 );
UG_ButtonCreate( &window_1, &button1_2, BTN_ID_1, 10, 80, 110, 130 );
UG_ButtonCreate( &window_1, &button1_3, BTN_ID_2, 10, 150, 110,200 );
UG_ButtonCreate( &window_1, &button1_4, BTN_ID_3, 120, 10, UG_WindowGetInnerWidth( &window_1 ) - 10 , 60 );
UG_ButtonCreate( &window_1, &button1_5, BTN_ID_4, 120, 80, UG_WindowGetInnerWidth( &window_1 ) - 10, 130 );
UG_ButtonCreate( &window_1, &button1_6, BTN_ID_5, 120, 150, UG_WindowGetInnerWidth( &window_1 ) - 10, 200 );
/* Configure Button 1 */
UG_ButtonSetFont( &window_1, BTN_ID_0, &FONT_12X20 );
UG_ButtonSetBackColor( &window_1, BTN_ID_0, C_LIME );
UG_ButtonSetText( &window_1, BTN_ID_0, "Green\nLED" );
/* Configure Button 2 */
UG_ButtonSetFont( &window_1, BTN_ID_1, &FONT_12X20 );
UG_ButtonSetBackColor( &window_1, BTN_ID_1, C_RED );
UG_ButtonSetText( &window_1, BTN_ID_1, "Red\nLED" );
/* Configure Button 3 */
UG_ButtonSetFont( &window_1, BTN_ID_2, &FONT_12X20 );
UG_ButtonSetText( &window_1, BTN_ID_2, "About\n?GUI" );
UG_WindowShow( &window_1 );
/* Configure Button 4 */
UG_ButtonSetFont( &window_1, BTN_ID_3, &FONT_12X20 );
UG_ButtonSetForeColor( &window_1, BTN_ID_3, C_RED );
UG_ButtonSetBackColor( &window_1, BTN_ID_3, C_BLUE );
UG_ButtonSetText( &window_1, BTN_ID_3, "HW_ACC\nOFF" );
/* Configure Button 5 */
UG_ButtonSetFont( &window_1, BTN_ID_4, &FONT_8X14 );
UG_ButtonSetText( &window_1, BTN_ID_4, "Start\nBenchmark" );
/* Configure Button 6 */
UG_ButtonSetFont( &window_1, BTN_ID_5, &FONT_10X16 );
UG_ButtonSetText( &window_1, BTN_ID_5, "Resize\nWindow" );
UG_WindowShow( &window_1 );
}
</code></pre>
<p> </p>
<p>这个uGUI也支持触摸操作,不过我这用不上就不研究了,说实话如果用触摸的话资源应该就不紧张了,直接用Lvgl比较合适</p>
<p> </p>
<p>这是O0级别编译的体积</p>
<p> </p>
<p>以及Oz级别</p>
<p> </p>
<p>这样使用64KFlash的单片机基本就能满足UI部分的需要了</p>
谢谢分享,这个支持汉字的显示吗?如果加上汉字字库资源会不会又有些紧张了。 <p>这种都是点阵字库,多数GUI都是使用简化的汉字库,有需要的是需要自己弄的</p>
<p>看显示界面,好像没有lvgl设计的好看</p>
<p>对,我也觉得单片机搞GUI其实压力很大的,基本都得外扩RAM或者FLASH</p>
<p>stm32可以试试<a href="https://github.com/azure-rtos/guix">guix</a></p>
<p>stm32可以试试guix</p>
页:
[1]