本帖最后由 creep 于 2018-1-13 19:14 编辑
4 m/ h- ?/ ~7 b) k6 d% @$ ^2 r, o& ?6 E" X% b4 U
推荐阅读最新的Littlevgl移植(更新时间:2018-1-13):
1 I7 O& c5 O+ q" X2 A 3 \4 F7 I4 T6 F& `
开源GUI LittlevGL V5.0版本移植
$ s4 d* H1 @0 M2 B7 T+ |* o- O9 L
: O) c& M* o7 @: Q4 P; R. I. @' j& Y* l" ]1 q4 p
LittlevGL 是一个开源免费的GUI,支持触摸屏操作,移植简单方便,开发者一直在不断完善更新。LittlevGL 自带了丰富的控件:窗口、按键、标签、list、图表等,还可以自定义控件;支持很多特效:透明、阴影、自动显示隐藏滚动条、界面切换动画、图标打开关闭动画、平滑的拖拽控件、分层显示、反锯齿等等。
6 B% x8 ?; A) @. }' s7 J+ P
, _4 n7 D; L4 e. {. o
, r3 [9 A6 V! k下面是我在STM32F769-DISCO上移植的演示模式的效果图片.
: n3 l+ T; D0 Y. m- f; K- m7 \5 k" c5 t: K9 F7 ?( n$ r; T! E! [9 A9 v
" e9 \ r7 D$ T. A/ ~# x6 @% A% s% t! X% s' P
1 @; T9 v; R) ~8 h' k
* L' x* g% F7 t7 X: E
主要控件可以通过下面的图片有个基本的了解:. m/ x C8 d. Q! V9 G
6 y; b1 L7 I+ x( G. w' V9 j$ `
8 y8 T/ }3 C/ |. R$ v; S! p
3 c; x% u4 n* Z2 q+ S
1、移植2 [( q4 B; w1 Z0 b0 z8 A2 N
! x6 j- e; _" A5 i
LittlevGL 的移植非常简单,用户只需要提供systick、触摸屏、LCD显示接口即可。源码里面有3个文件用于分别添加这3个接口,具体如下:9 h: v8 L r8 P1 Z
: |2 U( j2 V2 g% ?; R6 V
; a y8 I K+ }2 q* W. I也就是下面几个函数:
% C0 q! t. E( `- I2 s" n% E& N- t- l0 o( l# ?/ N
* H4 l7 V2 p. O& M- hal/disp disp_fill(x1, y1, x2, y2, color) to fill area with a color
- hal/disp disp_map(x1, y1, x2, y2, &color_array) copy a color map to an area
- hal/disp disp_color_cpy(dest, src, length, opa) copy pixel, optional for GPU
- hal/indev indev_get(id, &x, &y) get the x and y coordinates from an input device (e.g. touch pad)
- hal/systick systick_get() get a system tick with 1 ms resolution
- hal/systick systick_elapse(prev_time) get the elapsed milliseconds sience prev_time
- 5 w; I8 `( G0 [( {
a)systick的移植直接使用的是HAL库里面提供的
- K1 p: |3 n5 D2 C3 C/ y8 I* W! w( O) `& a- Z: \" i6 i" m" b
- /**
- T. _7 G% P6 R0 ]8 W - * Get the elapsed milliseconds since start up; U1 m5 B/ q- r
- * @return the elapsed milliseconds
% W$ t& p% S6 x- w& j# U5 s) w - */
4 Z) A* |6 L Q! W9 @9 v - uint32_t systick_get(void). o. c0 X8 r2 j) s1 e# y
- {! `9 B5 |: q; F2 i: d
- return HAL_GetTick();
& g: @8 n6 [$ K V; I- e' ?- J - }& g& t4 _: b6 c/ e# C( N+ C
- /**
; e3 i8 T/ ^# H0 T, o# m - * Get the elapsed milliseconds science a previous time stamp. U4 ^' q0 x9 J, o* w1 M
- * @param prev_tick a previous time stamp from 'systick_get' m8 h: z; [5 _8 E- Q! ~! `2 _) \" z* S
- * @return the elapsed milliseconds since 'prev_tick'
( x: v0 N0 x+ `8 s+ w0 s1 }" w - */. x8 o7 i$ s4 o3 L' \' h
- uint32_t systick_elaps(uint32_t prev_tick)/ |. p, T" t% i
- {
$ s. q$ l" u& n6 i! j T - volatile uint32_t act_time = systick_get();& Q$ d2 k+ P* ]0 K% S
' N% x0 P; G. D7 l- /*If there is no overflow in sys_time ?" b: t& y. d' j5 f
- simple subtract*/
3 S) G; H8 Y/ Q6 n2 R- d$ ] - if(act_time >= prev_tick) {
8 ]7 t, O& e' a/ x7 Q- p7 c j5 q - prev_tick = act_time - prev_tick;# G: G0 C# a, m% u
- } else {. m5 j6 }% S1 j* ?+ {% x
- prev_tick = UINT32_MAX - prev_tick + 1;% F: B+ x" L: L7 J9 {: |
- prev_tick += act_time;1 n; b5 N2 b% Q6 Q0 l6 \- B
- }& W0 K3 v1 Q- G
- return prev_tick;1 [4 ]; G* G/ x/ n
- }
复制代码 b)提供触摸屏的函数,用于初始化触摸屏和返回触摸屏扫描结果3 t4 A9 h( J5 U3 N
- /**
8 w. ]' I* u# G' c, z - * Initialize your input devices here: X2 }; L/ b8 ^' E: k* t
- */+ |7 T( z O" { j# s& ~3 h) C
- void indev_init(void)
% ]" x2 Y& ?' |0 Q9 w" H8 b' [ - {# `% ^ k3 q+ q5 G. z: D8 _* O6 h
- BSP_TS_Init(DISP_HOR_RES, DISP_VER_RES);# }; n3 m' H4 v+ K+ w) d
- }9 p4 t; w, ~, u: B' `
; f( E, l& P; b: E1 j/ m: N- /**
- N A4 e7 ~5 a6 i7 D$ Z - * Read an input device6 H8 x1 U" I# }) k. h4 N; m o
- * @param indev_id id of the input device to read! a% N; i" c5 M7 o
- * @param x put the x coordinate here
* Y* g0 C6 d5 T9 ~3 _* k - * @param y put the y coordinate here
, h) c$ H8 N2 c; I" P! {% I! @, h - * @return true: the device is pressed, false: released. y' l$ r$ R. q
- */* q! C/ f9 Q; O* r6 V, ?8 R6 k
- bool indev_get(uint8_t indev_id, int16_t * x, int16_t * y)' V j0 _+ ^" T: s
- {/ D0 o/ L2 C" ~4 W3 l4 {
- if(indev_id != 0) {4 Y" Y1 A5 ]& r% l' d
- *x = 0;
' q# F/ S- W# ]7 l/ ~. R' u - *y = 0;
# _) B L/ `: V* w% ]5 ? - return false;
" a3 i7 R( p2 b# D9 I! v2 @1 F - }
6 L$ a( e4 k5 ~ W" X1 d - static int16_t last_x = 0;
# A# T* x) S' F - static int16_t last_y = 0;
# M- ]/ Q8 m) r5 ^' d - bool press;& @6 y: s7 p& N' s0 t! ^$ { U
- BSP_TS_GetState(&TS_State);3 ^ t* ~; Q7 N: O- l: A8 ~
- if(TS_State.touchDetected != 0) {* j( g2 p% w( z! i) T" g' d
- *x = TS_State.touchX[0];7 o c( D8 y8 j/ d; v' A; U" N- U+ L4 L
- *y = TS_State.touchY[0];
( ]: v- E2 y7 i3 R - press = true;
0 K! {# ]# t s# u" o - } else {8 {, i0 b: O z: M7 A5 z
- *x = last_x;- n. L" e8 e6 S4 k3 d# U: d
- *y = last_y;
4 ]* x. e5 s1 B* k6 j - press = false;( g$ n9 v0 q0 A: l8 x
- }; o, B8 i" I3 O, W) Q: T
# }8 v2 R( ]. L% @/ n; o" S, l- return press;4 ?+ Q! Y$ s# W
- }
复制代码 c)LCD的移植分为几个函数,9 s% j- c; `, t
: q+ f, o" `2 h) q" r
1)一个是用单一色填充矩形区域,这个实际调用的次数较小9 C2 F& l9 s$ v$ r" w) q Z3 I
) R4 S! A4 e2 j! C6 W
- /**0 p+ e* C6 [7 Z, A/ _$ B
- * Fill a rectangular area with a color. l- b" F; @$ U' t' g( q0 m
- * @param x1 left coordinate of the rectangle4 `, s2 \, r8 m# c/ _' D& g
- * @param x2 right coordinate of the rectangle
. g7 ]/ W( c5 r' r9 e+ A - * @param y1 top coordinate of the rectangle
/ Q# G) W1 F' H$ ]. @! k4 A - * @param y2 bottom coordinate of the rectangle
. L/ \- h9 O. i - * @param color fill color
/ x3 a' O! \% Y5 l7 r - */: E$ T2 Q c% S/ K/ l' ]! y: n
- void disp_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, color_t color)6 I- W2 x* ]/ D' J
- {
( g; d7 C) k6 ?8 b - /*Return if the area is out the screen*/
- H) y, f( g6 `$ H - if(x2 < 0) return;
7 c9 b4 k; r: V' S. X6 F* I
- D& s! \. Q. O+ I& q- if(y2 < 0) return;+ d+ `; ]0 h$ M9 G, q
- ) p4 h y5 Y% n
- if(x1 > DISP_HOR_RES - 1) return;
! r+ c& j/ F" W5 n - E1 B3 V2 H3 W4 ^. L- [& T. }" ]: Y* ]
- if(y1 > DISP_VER_RES - 1) return;
7 Z" e+ v' ?& ]5 f G" z - 3 Y9 b& h0 _6 J0 W
- /*Truncate the area to the screen*/
: p; L0 @' H; } ~, k- V, c - int32_t act_x1 = x1 < 0 ? 0 : x1;) K8 b! a5 _0 x2 K
- int32_t act_y1 = y1 < 0 ? 0 : y1;- K7 @+ @$ e: x* O. q
- int32_t act_x2 = x2 > DISP_HOR_RES - 1 ? DISP_HOR_RES - 1 : x2;& S4 b6 b+ G* v1 a4 q
- int32_t act_y2 = y2 > DISP_VER_RES - 1 ? DISP_VER_RES - 1 : y2;
0 [1 }% @* p' `2 d. w - ?) o' e& I$ h/ Z; r3 L) o/ D+ Y
- LCD_FillRectPart(act_x1, act_y1, act_x2 - act_x1 + 1, act_y2 - act_y1 + 1, ((color.full)));( q8 P5 U& g3 d! x
- }
复制代码 2)这个是用一个颜色map填充一个矩形区域,这个主要用显示时局部刷新使用,是LCD显示调用的底层接口,使用非常频繁,如果需要优先显示速度,可以从这个函数入手,使用块内存复制或者DMA2D来实现。) h1 p+ n9 ^! J+ O, w0 W
- /**
! p* M Q+ F, M' m' x% P - * Put a color map to a rectangular area' Z8 [+ V3 n3 a6 j7 ?/ N
- * @param x1 left coordinate of the rectangle7 i) b& ^" U" f1 ~# v9 o2 _. g
- * @param x2 right coordinate of the rectangle
7 L% U* O9 ?; C! V) W' U9 S' T - * @param y1 top coordinate of the rectangle
' T% a0 c, }: p - * @param y2 bottom coordinate of the rectangle, k) S, P6 O8 z/ V
- * @param color_p pointer to an array of colors
% [/ {5 }4 y6 t$ N _ - */
5 b, r! q5 ?( B$ V - void disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const color_t * color_p)
, b' C" D& r3 j4 T- V1 {5 l) a) x - {
4 {2 y9 e2 X9 j2 y F+ k, R' h& ? V - /*Return if the area is out the screen*/: _3 c1 C7 e4 T' U2 B6 s& E
- if(x2 < 0) return;
F) B. `5 O! }+ s% |: X
- w& D, E- E' y- if(y2 < 0) return;" K" p' q: Q& t0 p; ?& C' ~" Y
1 v9 ^: N" J) l0 i- if(x1 > DISP_HOR_RES - 1) return;3 a) T5 A4 W* `+ w+ Q1 B; R
- 9 T: T3 t* b+ l6 m, D9 ~, M
- if(y1 > DISP_VER_RES - 1) return;
, L; ]6 r+ w' s( L3 p% ?6 b
+ X% L- c2 C- N& R) T3 _6 Y4 N- /*Truncate the area to the screen*/) f6 n% c6 q% z0 @
- int32_t act_x1 = x1 < 0 ? 0 : x1;1 {+ s5 M, D9 r' n: s% c
- int32_t act_y1 = y1 < 0 ? 0 : y1;
4 [; j6 t# u3 M! m! T' U7 D2 @ - int32_t act_x2 = x2 > DISP_HOR_RES - 1 ? DISP_HOR_RES - 1 : x2;3 V4 l. C- \% _2 N" I
- int32_t act_y2 = y2 > DISP_VER_RES - 1 ? DISP_VER_RES - 1 : y2;# R! ?6 r5 _; u
- S. i- F# `( _& u4 |/ o
- 6 o# s8 _ j* o: R' _
- uint32_t y;
! @9 S7 l6 ~+ t, B( `7 l9 Z; J' x
0 t+ F) ^5 C6 ^+ G# q, q6 R* w0 w- for(y = act_y1; y <= act_y2; y++)/ w, p4 \, ~% ]# n! p
- {+ P1 q, t e1 v
- memcpy(&my_fb[y * DISP_HOR_RES + act_x1],
m$ @7 ?! i9 E& f8 `: L - color_p,
% I. q1 G+ d+ ~% _: ?7 ~ - (act_x2 - act_x1 + 1) * sizeof(my_fb[0]));% @0 a7 X) E& D8 V$ f* J
- color_p += x2 - x1 + 1; /*Skip the parts out of the screen*/# B# c' r: B- x( Q6 K5 u; I( l
- } h* _- Q& h9 a! |4 W4 e
- . h2 M2 z4 s! x& o# `5 [$ [5 B1 Q
- }
复制代码 3)硬件加速可选项打开后可以使用下面的函数复制加速填充复制内存/ c* \" S& C1 _, m2 r+ |& P3 k
- /**
) K$ I( o$ _, I) \9 C - * Copy pixels to destination memory using opacity
. P% S! V/ `$ X; c* @ - * @param dest a memory address. Copy 'src' here.5 s5 F3 E, ~5 d. ^- a( d
- * @param src pointer to pixel map. Copy it to 'dest'.6 K4 A1 B; O: y! t: a, h
- * @param length number of pixels in 'src'
2 k* W$ a5 u' H+ ~ - * @param opa opacity (0, OPA_TRANSP: transparent ... 255, OPA_COVER, fully cover)% D* }" g. o& h3 O. _% i1 Y: ]
- */, H' F4 U5 }* s1 S8 @5 r6 u v! m, S
- void disp_color_cpy(color_t * dest, const color_t * src, uint32_t length, opa_t opa)
9 K: Y0 i6 B: k8 V* t2 j - {
. `- u2 U0 c+ w' E) v3 [ - /*Wait for the previous operation*/ u! f2 _7 Q2 @! c/ e/ C
- HAL_DMA2D_PollForTransfer(&Dma2dHandle, 100);1 h# T+ {9 g, x3 ~
- % X6 c( `. Q# N9 ^* h0 V
- Dma2dHandle.LayerCfg[1].InputAlpha = opa;
o% L) N6 Z: C. M# l - HAL_DMA2D_ConfigLayer(&Dma2dHandle, 1);
. |5 @0 L* L( A% ^" f - HAL_DMA2D_BlendingStart(&Dma2dHandle, (uint32_t) src, (uint32_t) dest, (uint32_t)dest, length, 1);
7 E& o( D$ Y4 C) _ - }
复制代码 移植了上面接口之后基本问题就不大了,littlevgl 目前的代码结构有点乱,分为core、hal、misc 几个部分,我是分别建立一个文件夹然后把相应的文件全部添加到里面了,官网也没有详细的移植说明文档。所有的源码如下:. v U7 F( R: F) H) P
5 _: V) k" Y7 J( I" U5 }$ ~, Y
添加到工程中后如下整体如下:
/ c+ J9 \5 A' w
5 |' f2 @# j2 ?0 I
& o* Y2 S$ Z9 ^ S$ G$ P( K4 b6 L) Z1 e. }8 i
' ~% Z4 n. z! E/ U- [) G6 d u% H/ Y
, N7 R2 N9 e( O4 ~1 @6 K5 B" Y将所有的文件添加到工程中后用keil编译可能会有一些错误和警告出现,但都很好解决。
) m4 x; R8 w7 Q7 \* Z2 X) U4 q% V% g/ S0 H" R
' N4 d- y h7 t' L6 R* F
2、运行效果9 w2 H0 N9 H& e- Q4 X2 }
# i i: F5 v# o" z3 [! r- v% k
LittlevGL内置一个类似桌面系统的演示例子,通过打开相应的宏定义即可9 S x& i" T: m& e* [+ D" O
; a0 q+ x2 ?4 X+ a& @6 y/ X1 ?; O% ~ L6 r$ x; H2 D9 e2 ^9 h
2 E7 }% S6 o% i N
8 D2 L. t1 T1 q5 KLittlevGL有个桌面上模拟的工程,下面是论坛网友 @QianFan 在linux下运行官方例子的运行效果:+ n0 ^+ Q2 ]& @6 T' F% l4 a( I
# f1 v; I) n+ `
6 }- v3 M' C$ V" g/ X
. `' O+ J1 J, f$ M8 ^# u1 g
! j! }( F4 t' D; z* a: E" r除此之外官网还有一个在STM32F429-DISOC上移植的例子,在youtube上可以观看,因为转换为了gif可能看起来不是很流畅,实际演示效果很不错。' H- u0 p, `$ b
! K& T& `0 M, i$ \! k5 H
- z. e# X: L9 D) } t) g( t2 W
( l! U4 c3 }1 y5 I5 J7 l I9 D- A8 x1 n) {4 [( @ P
下面是我在STM32F769-DISOC上面的移植,和linux下模拟运行的差不多。因为769-disco的分辨率很高,移植后我没有使用优化,所以可以看到画面切换有些闪烁。) V% i6 U% }6 ]6 F. v% L
: V& X% h" U) M
# X/ z& s% E3 v; b/ F3 P3 B
3、关于LittlevGL# ]7 n5 p; s0 H# Q; n9 t Z1 [
/ k( b7 ]) O+ c2 J; t/ d+ V6 p/ ^
LittlevGL里面有个简单的时间片调度系统,刷新显示和触摸处理等任务会周期的被调用处理。LCD刷新采用了局部缓存刷新,这样能避免闪烁出现。LittlevGL目前只有一个开发者在业余时间维护更新,但是开发者热情很高,可以在github上看到更新很频繁,我测试的使用的V4.2版本,开发者正在开发4.3版本并加入了不少新的功能,有建议可以在github和作者讨论互动。
5 d; w0 J: K+ Z, ^2 T/ h* B目前代码结构看上去有点乱,有人在也提到了这个问题,计划好像是在5.0版本引入新的代码组织结构,感兴趣的可以去github提意见,开发者很乐意沟通讨论。官网也有不少控件的使用介绍和例子参考。
3 s- R) ^3 _2 a! O3 T
) U9 ?+ J+ T j: }: g
. c7 U& \" H; L2 W- {- U# @( z& H- J1 x1 O2 B- g
% e8 n+ G4 t! W
& V5 k& {: B5 M7 q. R, K' W& N
) n# o% @0 [2 H5 U" H6 w+ G官网和github地址如下: S7 m. Z* B2 G2 [, C2 [( o$ `
7 a. Q, x3 X4 V+ J# X8 k/ \1 uLittlevGL官网:http://www.gl.littlev.hu/
# c/ @8 W! B1 J4 oLittlevGLgithub :http://github.com/littlevgl 和 http://github.com/littlevgl/lvgl
7 t$ B8 y# b& f+ m7 O8 ]$ u) Q+ B7 x# B- v3 m
下面2个视频是在PC Simulator (Linux)和F4-DICO上的移植演示可能需要科学的方式才能打开。! i: h" i' {: U7 W. g4 `0 i1 T
How to Run Littlev Graphics Library in PC Simulator (Linux):http://youtu.be/ZzLdct2ymvg6 d, J* l J# G8 f! S x
Embedded GUI on STM32 Discovery with Littlev Free Graphics Library:http://youtu.be/DcJdK137WKM& T# }& k* U& O3 i& }6 O
9 `; I0 g& i8 j4 v. G 和众多开源的RTOS不一样,目前GUI开源的不是很多,虽然很多商用的GUI也很炫酷,但是我们没法知道具体效果的实现细节,也没法学习到这种能力,LittlevGL目前实现的一些特性和控件我认为是开源的GUI里面水平非常高的了。但是目前LittlevGL资料不是很多,只能通过阅读源码去学习和研究。, `. h4 I) u2 Q7 L ?! C
" E) g) S* c. `2 r( B% t
) ?# c- F/ X. @. Y$ r3 F& N测试代码:
' f* W* l2 S/ N
LittlevGL-STM32F769-DISCO.rar
(4.72 MB, 下载次数: 867)
|
看到一个别人分享的开源中文教程。
http://github.com/littlevgl/proj_pc
是的,没有限制,移植吧。
谢谢楼主分享
如何模拟? 如何在linux中运行?$ s' c) u. W! ]) T- g
: `& w- ]+ [; b
3 i7 ]0 n0 L n0 {/ n8 k
文档很少/ B8 v* |5 |* E6 A
1 |/ E5 i* p( J+ n( {
文档是很少,只能通过看代码学习了,如果感兴趣的话可以一起讨论。