玲珑gui简介
玲珑GUI(LLGUI)是一款易于使用且成本低廉的单片机GUI解决方案。它可以替代串口屏和组态,降低产品成本,同时确保产品的软硬件自主可控。配套的界面开发软件支持图形化编辑界面,并生成C代码。
如其名,玲珑GUI小巧精致,代码量适中,采用纯c语言编写,适用于各类资源有限的单片机mcu,并且开源免费,采用apache License, Version 2.0协议,支持二次开发和非二次开发的多许可协议方式。
相关资料和教程可在语雀上找到,地址为:玲珑GUI教程。
gitee上的项目地址为:LingLongGUI,该项目旨在提供高效的界面开发解决方案,替代串口屏和组态,降低产品成本,并确保产品的软硬件自主可控。
我亲自体验了一番,感觉非常不错,在此推荐给大家。
特别值得一提的是,它提供了类似qt的可视化GUI界面编辑器GUIBulider,支持可视化编辑UI。此外,还提供了类似QT的信号和槽机制,非常实用。虽然基础控件种类有限,例如常见的label控件没有找到(作者建议使用Text替代,但我认为单独的label组件会更方便),但对于嵌入式应用来说已经足够。就像官方介绍的那样,玲珑GUI可以作为一种低成本的单片机GUI解决方案,替代串口屏。
期待未来有更多实用的组件推出,希望玲珑GUI作为国产开源项目不断发展壮大。截至目前,搭配易用的GUIBulider,玲珑GUI已经可以与LittlevGL一较高下。虽然组件丰富度不如LittlevGL,但在易用性上,玲珑GUI显得更加小巧便捷,具有独特的QT风格但更加轻量化。
希望作者能开源一些自定义组件的方法和文档或教程,以促进生态系统的扩建,增加更多实用的组件,如仪表、曲线、表格、图表等。
关于中文字库的支持,希望在文档和示例方面能进一步完善。虽然目前主要针对嵌入式MCU,但在嵌入式linux上也可以完善一些常用字库。
GUIBulider的界面风格类似于QT设计师:
可以直接拖动编辑界面UI,右侧可以更改属性,下方可以编辑发送者、信号和接收者。
点击工具栏上的绿色三角图标,可以自动生成对应的UI代码和逻辑层处理代码文件。
在嵌入式Linux上的移植(基于framebuffer的fb0):
新建一个名为test的文件夹,在其中创建llgui、ui和port文件夹。
其中,llgui文件夹存放从gitee上下载的最新llgui源码。port文件夹存放与移植相关的内容。ui文件夹存放UI和UI的响应逻辑实现文件。
移植过程非常简单,只需实现LL_Config.c中的几个函数即可,主要是三个函数:画点和读点,填充矩形函数。确实可以做到十分钟内完成移植。
在头文件LL_Config.h中进行一些配置:
// 颜色位数 #define CONFIG_COLOR_DEPTH 16 // 1 8 16 24 32 // 屏幕宽度像素 #define LL_MONITOR_WIDTH 480 // 屏幕高度像素 #define LL_MONITOR_HEIGHT 272
LL_Config.c文件内容如下:
#include "LL_Config.h" #include "string.h" #include "freeRtosHeap4.h" #include "io_fb.h" <p>uint8_t cfgColorDepth = CONFIG_COLOR_DEPTH; uint16_t cfgMonitorWidth = 0; uint16_t cfgMonitorHeight = 0;</p><h1>if USE_DOUBLE_BUFFERING == 1</h1><p>uint32_t <em>lcdFrontBuf=LL_LCD_BUF1_POINTER; uint32_t </em>lcdBackBuf=LL_LCD_BUF2_POINTER;</p><h1>endif</h1><p>void llCfgSetLcdBufAddr(uint32_t *addr) {</p><h1>if USE_DOUBLE_BUFFERING == 1</h1><pre class="brush:php;toolbar:false">lcdSetBufferAddr(addr);
endif
}
void llCfgSetLcdSrcaddr(uint32_t *addr) {
if USE_DOUBLE_BUFFERING == 1
lcdSetSrcAddr(addr);
endif
}
void llCfgLcdCopyFront2Back(void) {
if USE_DOUBLE_BUFFERING == 1
// memcpy(lcdBackBuf,lcdFrontBuf,SDRAM_LCD_SIZE); uint64_t i; for(i=0;iyy=”” yyyy=”0x07E5″>
io_fb.c文件内容如下:
#include <stdio.h></p><h1>include <stdlib.h></h1><h1>include <string.h></h1><h1>include <memory.h></h1><h1>include <fcntl.h></h1><h1>include <sys></h1><h1>include <unistd.h></h1><h1>include <sys></h1><h1>include <sys></h1><h1>include <sys></h1><h1>include <errno.h></h1><h1>include <sys></h1><h1>include <linux></h1><h1>define printV(v)printf(#v"=%dn", v);</h1><p>static unsigned char<em> npu8_fbmem; static int ns32_fb; static unsigned int nu32_screensize; static unsigned char displaybuffer[480</em>272<em>4]; static unsigned char</em> pframebuffer; static unsigned char pfbStat = 0;//0-framebuffer, 1-cache buffer</p><p>unsigned char getGUIcache(void); int setGUIcache(unsigned char stat); void GUIcache2fb(void);</p><p>static void<em> _fb_mmap(int fd, unsigned int screensize) { caddr_t fbmem; if ((fbmem = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHAred, fd, 0)) == MAP_FaiLED) { perror(<strong>func</strong>); return (void </em>) (-1); } return fbmem; }</p><p>static int _fb_munmap(void *start, size_t Length) { return (munmap(start, length)); }</p><p>static int _fb_stat(int fd, unsigned int <em>width, unsigned int </em>height, unsigned int <em>depth) { //struct fb_fix_screeninfo fb_finfo; struct fb_var_screeninfo fb_vinfo; //if (ioctl(fd, FBIOGET_FSCREENINFO, &fb_finfo)) { // perror(<strong>func</strong>); // return -1; //} if (ioctl(fd, FBIOGET_VSCREENINFO, &fb_vinfo)) { perror(<strong>func</strong>); return -1; } </em>width = fb_vinfo.xres; <em>height = fb_vinfo.yres; </em>depth = fb_vinfo.bits_per_pixel; return 0; }</p><p>int fb_init(void) { unsigned int fbw, fbh, fbd;</p><pre class="brush:php;toolbar:false">ns32_fb = open("/dev/fb0", O_RDWR);
if(ns32_fb width) || (y > height)) return -1; //unsigned short dst = ((unsigned short )npu8_fbmem + y width + x); unsigned short dst = ((unsigned short )pframebuffer + y width + x); *dst = color; return 0; }
unsigned short fb_readpixel(int width, int height, int x, int y) { if ((x > width) || (y > height)) return -1; //unsigned short dst = ((unsigned short )npu8_fbmem + y width + x); unsigned short dst = ((unsigned short )pframebuffer + y width + x); return *dst; }
unsigned char getGUIcache(void) { //printf(“%sn”, function); return pfbStat; }
int setGUIcache(unsigned char stat) { //printf(“%sn”, FUNCTION); if( stat ) { pframebuffer = displaybuffer; pfbStat = 1; } else { pframebuffer = npu8_fbmem; pfbStat = 0; } return 0; }
void GUIcache2fb(void) { printf(“%sn”, FUNCTION); memcpy( npu8_fbmem, displaybuffer, nu32_screensize); }
最后是Makefile文件,修改交叉编译工具链后,直接执行make即可。
附:Makefile文件内容:
##########################################</p><h1>makefile template by yangyongzhen</h1><p>#########################################</p><hr /><h1>Cross complie path</h1><hr /><h1>CHAIN_ROOT=/home/yang/imax283/ctools/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/bin</h1><h1>CROSS_COMPILE=$(CHAIN_ROOT)/arm-none-linux-gnueabi-</h1><p>CHAIN_ROOT= /opt/gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux/bin CROSS_COMPILE=$(CHAIN_ROOT)/arm-linux-gnueabihf-</p><h1>CROSS_COMPILE =</h1><p>CC := $(CROSS_COMPILE)gcc CXX := $(CROSS_COMPILE)g++ AS := $(CROSS_COMPILE)as AR := $(CROSS_COMPILE)ar LD := $(CROSS_COMPILE)ld RANLIB := $(CROSS_COMPILE)ranlib OBJDUMP:= $(CROSS_COMPILE)objdump OBJCOPY:= $(CROSS_COMPILE)objcopy STRIP := $(CROSS_COMPILE)strip</p><hr /><h1>Source files</h1><hr /><p>SRC_C=$(shell find . -name "*.c") OBJ_C=$(patsubst %.c, %.o, $(SRC_C)) SRCS := $(SRC_C) $(SRC_C) OBJS := $(OBJ_C)</p><hr /><h1>Flags</h1><hr /><p>LIBS := -L LIBSINCS := -I./llgui/Gui -I./llgui/Misc -I./Fonts -I./port -I./ui -I./ CFLAGS= -std=gnu99 -fno-common -fsanitize=address -fno-stack-protector -fno-omit-frame-pointer -fno-var-tracking -g1 LDSCRIPT= LDFLAGS= -lasan</p><hr /><h1>Targets of the build</h1><hr /><p>TARGET := testllgui TARGETLIB := libllgui</p><p>.PHONY: clean all: prebuild $(TARGET)</p><p>lib: prebuild $(TARGETLIB).so</p><hr /><h1>TARGET</h1><hr /><p>prebuild: @echo Building...</p><p>$(TARGET): $(OBJS) @echo Generating exe... $(CC) -o $(TARGET) $(OBJS) $(LIBS) $(LDFLAGS) @echo OK!</p><p>$(TARGETLIB).so : $(OBJS) @echo Generating shared lib... $(CC) -shared -fPIC -o $(TARGETLIB).so $(OBJS) @echo OK!</p><p>%.o : %.c $(CC) -c -fPIC $(CFLAGS) $(INCS) $
最后,将编译生成的可执行文件放置在板子上,修改执行权限后,直接运行即可。