本帖最后由 creep 于 2018-1-13 19:17 编辑
, M7 @- g7 m, _; W( j; @! P i# o* \6 w0 B9 G
最近看到越来越多的小伙伴在讨论littlevgl,这说明这个开源GUI正在被更多的人了解和使用,最近littlevgl正式推出了V5.0版本,完善了整个代码架构和一些API及函数的命名,重新设计了移植的接口方式,添加了众多的控件及可更换主题等功能。我之前在STM32F769-DISCO 上移植了V4.2版本,下面的移植使用最新的V5.0版本的源码。
! D: a( W8 b" a% Z0 p. i
+ c4 \7 r* b9 i
- N! \& d! T b' w& n0 W. U
5 Z$ S' u0 ]! Q3 K( D, R
9 Q$ [. b5 j: X6 |6 d1 u. H- V% |& j u2 @$ R
1、V5.0新特性
. X, b' d! P) W/ c4 A) H. z7 \, f
. j0 Q$ i+ ?! r# i8 M" b5 u% k
2 Q, n0 B9 w5 V
源码提供了各种内置主题可以选择比如下面的黑色主题6 Q4 K: T" J* i: k8 J: t) \, ]
2 q& ^# U" g7 S [+ [3 S+ m1 P
Elegant dark theme which shows confidence and high quality.
; w- Z: B2 c# w* B
6 i: z! M; `6 V3 u
6 E/ h7 X$ v& p1 g; x; G下面的是Android's material design风格主题
" t$ r! o( }% ?. J# B2 I2 a8 j! I3 U5 x0 a7 N2 c) A
) }, `" q. [# p4 E/ @ A1 H& `: E$ G4 [. p
3 j. z! u3 G' s5 M+ `$ e& ~
更多主题可以到官网查看:http://littlevgl.com/themes
, _1 L) C4 S# U5 r1 qUnicode support、Symbol fonts 支持
; n+ I% |6 a5 H+ F( F+ ]& C' Q$ A$ k, A0 e0 W9 u( d" S
" |# X+ {) @" `7 b
% _$ n! g: e. _" G
. `! j/ Q3 z; @$ J4 m6 S9 G; D# H# C2 K- U( L
5.0版本也增加了一些新的的控件:http://littlevgl.com/object-types$ G" a- M9 T5 S0 l. K1 R3 ]5 U$ j
5 N1 [5 @% W3 E8 m$ A
0 f; u; g$ B6 j. `3 M) I更详细的请移步官网:http://littlevgl.com/basics! t( F+ _% a, A: A, z5 |% }/ X
6 x# R; X6 Y9 I. D1 A( u% ~( q+ X2、移植
- J$ T( @ V' M4 D4 |) q2 u官网给出的移植要求如下,littlevgl 的移植性很高,基本不需要单片机外部资源。
* X; n8 ~( o0 e% t# D3 ]" B0 B8 J5 B
5 e. Z/ E0 z4 k8 ?7 n; W* L新的5.0版本的移植接口采用了函数注册的方式,Display interface、Input device interface、Tick interface ,只要实现这3个简单的接口就可以# x9 T( V! [# P( L l7 h: D
简单的跑起来littlevgl,接口的移植的详细的说明可以参考:http://littlevgl.com/porting, n( B* z' U b) S+ c l
' W7 q$ H, a V* e8 d! y
其中需要注意的Display interface,为了优化显示,可以使用2个Virtual Display buffers (VDB)并行的rendering and flushing。作者的移植例子使用的是DMA中断在进行background flushing。我移植的时候为了简单就直接使用的单缓冲,然后手动调用lv_flush_ready();。7 G* d$ O! m) r6 B0 p+ B6 `
! S q; a& ] H$ ]2 N
) i2 P2 y3 s) ?1 X, U- R9 J
- /**
! g! P1 m0 H& t: y. x. X2 | - * Flush a color buffer2 I# t+ f N7 U$ z* _) A6 D
- * @param x1 left coordinate of the rectangle
) L: ]0 S6 Y# H3 L% D - * @param x2 right coordinate of the rectangle
$ Z3 F7 [/ D! _0 C - * @param y1 top coordinate of the rectangle4 T4 J5 B: Y/ H0 B% y3 v
- * @param y2 bottom coordinate of the rectangle, s7 @' B( `; a/ y, N
- * @param color_p pointer to an array of colors* r& s% Z8 r& O1 H) m# ]
- */0 N1 o! C$ S, S' X3 w
- static void tft_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p); L% ^. n. V0 e- z
- {
* }! W M7 m% O) g' f5 v! b/ Z - /*Return if the area is out the screen*/) Q% r/ D9 h; V) u% H
- if(x2 < 0) return;" H l8 f( D2 P0 M6 m
- 8 J$ ^* B! s* B2 S, F f
- if(y2 < 0) return;
3 K% I* |. e% s+ N) |/ h6 f! p F
; e. V6 n0 N9 U; s) P: r' B- if(x1 > TFT_HOR_RES - 1) return;
; j/ j% }& n$ C - 2 |8 y6 h3 }: Y: _
- if(y1 > TFT_VER_RES - 1) return;8 _/ P3 v2 U ] p% H8 @$ ^' E
- 9 u, }/ Q* Y# ^, ?! k: c* u! {
- /*Truncate the area to the screen*/
/ c0 s/ u% M; W2 g% R+ E4 y - int32_t act_x1 = x1 < 0 ? 0 : x1;
; ^1 r0 M5 O: v" F9 | - int32_t act_y1 = y1 < 0 ? 0 : y1; ^/ I3 V! N8 ~2 ~, O: |
- int32_t act_x2 = x2 > TFT_HOR_RES - 1 ? TFT_HOR_RES - 1 : x2;
6 \! d4 f2 c, b1 O$ ~, v% R; l8 k - int32_t act_y2 = y2 > TFT_VER_RES - 1 ? TFT_VER_RES - 1 : y2;
8 T9 V# e0 F8 u+ K1 F5 I - - d) x3 l- r- y( S& m! t
- uint32_t x;
, F+ r( k, ~0 m - uint32_t y;
! @5 L: i' v& U' _8 G i - 4 `3 {0 }/ H# E
- /*Put the map to the remaining area*/
# c. q, }% t8 d' R9 [% k$ V - for(y = act_y1; y <= act_y2; y++)% j' u+ T V9 f
- {, C3 L$ X8 m: @ Z& v/ D
- for(x = act_x1; x <= act_x2; x++)
p7 O6 O5 I2 l0 u4 [( x" C- @ - {/ j5 s& c& f" k. C! t! I
- /*Your specific function comes here!*/
" G! Z$ o! }3 n) d - /*my_put_pixel(x, y, color_p->full);*/
# }$ J# } w; ]1 N4 f - BSP_LCD_DrawPixel(x, y, ((color_p->full) | 0xFF000000));
) m2 B' G0 ` b- S - color_p++;
. B1 O c3 A7 k7 x& i: r/ ~ - }
$ e& K2 |( u' H3 u5 \/ w
: ]) o+ K& I* [% i2 Y9 f- color_p += x2 - act_x2; /*Skip the parts out of the screen*/* {( k2 f9 C& a9 j' e& T$ Z
- } C) t( I1 c- b4 o
- lv_flush_ready();
/ y S/ Q$ O! U0 d - }
复制代码
, U# @4 a+ D" ~$ |, T) `% s0 t( k* W& Z5 U
首先测试下一个demo/ ]# R" S) C" G j
0 O6 h; X9 P2 L% P, L
! }+ x/ H0 K5 h" ~; @
8 c6 G; C" W6 @, D, S6 @
0 M: `9 [( r# c x$ E3 q3 Q- {2 N5 \! r
然后测试下内置的主题换肤
* l, Z/ L( ?4 v( X+ T/ I+ W: k; ?- N% s4 W: ^+ b
/ K9 l6 r6 |& X3 \' ~$ M" r9 a8 T6 ]5 f$ a3 X
% a: K3 d& b: |" O
4 p9 v5 X5 @/ D1 K5 E5 a- Z
# \. Z' @3 c( u6 K* t7 a6 D" S% J
看下main函数2 X' p- a1 V" l5 T, G
- int main(void)
5 j* t+ O2 q# f" Q" v' }8 u - {. P: p j* Y; g
9 |- G" M( a! I# i: ?5 m- CPU_CACHE_Enable();
2 g! J' l/ V' b: Q; `5 u* p+ h* ^ - HAL_Init();8 k, K% h8 ^* `2 o0 d& [- n
- SystemClock_Config();
1 o% K, ^* E+ } @; t: S5 { - USART1_Init();
& |$ \( w9 m: y9 X9 _ [& x0 y - BSP_LCD_Init();
) l( z( V& S) E; S; j - BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);. O, }; G/ g* Q: [! l' R: y
- BSP_LCD_SetTextColor(LCD_COLOR_RED);
8 L( V# O. r4 [& s1 }8 _, q7 _ - BSP_LCD_Clear(LCD_COLOR_WHITE);2 p8 c1 k0 V$ d" C7 C, j, C
- BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
7 n2 |2 N* v/ o( V! O; w/ s - 7 m- E9 j7 C6 Y7 ]9 \4 t- T5 u
- lv_init();4 u- r; u1 m; Z# m- y' [% M- d
- tft_init();
/ _+ `! i* G7 X0 d/ ?6 q - touchpad_init();
; {* \5 _) S1 \ - //可以使用下面的注释
4 H3 I) g% _/ l - //测试button
) g! f% K$ j. g2 w4 ^6 I/ o; N" Q2 s - //button_test();
* O- |8 I8 T" b1 b+ b -
1 ^8 g" k" o) J* i% F) z - //测试demo7 e1 Q( {5 L5 ^( f0 D
- //demo_create();
: B0 U6 F" I r -
4 T! r' y; J) {& R+ y - //测试theme
" d0 @, c' D+ c( Q% r# H - lv_theme_t *th = lv_theme_alien_init(21, NULL);
* q+ D* J7 E; A3 }$ H - lv_test_theme_1(th);
' a# `0 y, k: d. s9 L$ T) N -
8 P1 w3 N$ x" H- V) ~5 o( J/ P! u& R- w - while(1)
/ m& z3 O3 A3 ^ - {- ^7 D9 ]" l5 f+ a7 L! U
- HAL_Delay(10);) K% I" B1 p) k0 H* f/ i
- lv_task_handler();
4 I3 j/ U% p" N4 k q
$ K0 K& F- V" Y2 {" q5 P/ q- }
/ o: E' Y0 s! g. } - }
复制代码
6 v% @: p& h/ {4 B! y8 U9 X' H& L7 v+ c
$ c) ~2 }0 z0 u/ [ E8 s
) E% w' ]: I: E" G' {" w8 @$ @2 Y3、参考资料, p4 H. S$ U; ~
, j% t" e4 h _ U: s' Y
& L" V5 @$ E& B7 d( V 参考资料要推荐的官网的详细的说明和各种控件的使用说明及代码实例,还有就是作者在github上提供了PC模拟器以及各种控件和入门的代码可以参考,最后要感谢作者无私的开源精神!
+ T, C- B- S6 Z$ ^9 P3 M/ ~2 Q3 {. {* k1 `. r
9 g. c$ T4 }* B( j2 s$ `- S6 C官网:http://littlevgl.com// q( h* o9 W. V q, ~; u
pc_simulator:http://github.com/littlevgl/pc_simulator) \+ U9 z2 m, t5 E
lv_examples:http://github.com/littlevgl/lv_examples% U/ `+ m, r: T" j5 a* O& n) A
6 Z1 C/ }3 ^: j
% z# j z( Y$ ^- u; h1 D测试代码:9 P0 [' L& R1 n. w
LittlevGL-V5-STM32F69-DISCO.rar
(6.01 MB, 下载次数: 2319)
|
9 y) T/ k* O3 h! N
MIT许可证之名源自麻省理工学院(Massachusetts Institute of Technology, MIT),又称「X条款」(X License)或「X11条款」(X11 License)
MIT内容与三条款BSD许可证(3-clause BSD license)内容颇为近似,但是赋予软体被授权人更大的权利与更少的限制。, f4 x0 ]0 Y: _6 i9 K( A
被授权人有权利使用、复制、修改、合并、出版发行、散布、再授权及贩售软体及软体的副本。
+ c( @. `: O! z* K, x) |8 U
被授权人可根据程式的需要修改授权条款为适当的内容。
+ @6 x" D& y- Q5 ` ~! h: x) o
在软件和软件的所有副本中都必须包含版权声明和许可声明。% F% }: x3 }5 ^; J. r" K
此授权条款并非属copyleft的自由软体授权条款,允许在自由/开放源码软体或非自由软体(proprietary software)所使用。
此亦为MIT与BSD(The BSD license, 3-clause BSD license)本质上不同处。
MIT条款可与其他授权条款并存。另外,MIT条款也是自由软体基金会(FSF)所认可的自由软体授权条款,与GPL相容。
" [6 O: {, X3 Y" ~
风格漂亮。
好呀,一起耍!