本帖最后由 creep 于 2018-1-13 19:17 编辑
w2 k7 W9 z1 P9 K, h" [
9 J5 \0 d2 o. {" {# b) y8 P 最近看到越来越多的小伙伴在讨论littlevgl,这说明这个开源GUI正在被更多的人了解和使用,最近littlevgl正式推出了V5.0版本,完善了整个代码架构和一些API及函数的命名,重新设计了移植的接口方式,添加了众多的控件及可更换主题等功能。我之前在STM32F769-DISCO 上移植了V4.2版本,下面的移植使用最新的V5.0版本的源码。9 x. z- E) ^" X& m2 S9 a2 l
+ Q$ o; E* P9 z" [& I# A# K/ C) d( T/ u
* L1 [. d) H; x* g8 Z9 J+ @
( N, p- {% Z* z& C( Y
1 h0 c1 D9 t" s1、V5.0新特性2 k! j% a6 H- j4 d3 J' f, A$ x: T
- ^" }- e7 G! t
7 X3 L7 g% B0 W+ e- w1 [2 l
源码提供了各种内置主题可以选择比如下面的黑色主题$ k! d, b$ V- A; i
; f* H- Y' U9 l% R) D' E
Elegant dark theme which shows confidence and high quality.
3 b2 m5 t9 n1 l
% _! e/ Y8 q+ l- F( Q( ~8 C
* |1 b. z; |: ?: S' _: B$ ~8 I下面的是Android's material design风格主题0 W+ z# w0 I! y' z$ c
! |6 H# h* v( O. c, i* f# J
: k# x* N& }# o
. i4 k2 n' T0 w u f
% m9 a- p+ s3 r# U0 R8 v1 y6 q
更多主题可以到官网查看:http://littlevgl.com/themes. Z/ V( j! B# [
Unicode support、Symbol fonts 支持
5 e: T( y4 S( h1 H% D
6 `2 K+ v* @3 p M! @# g
1 O8 T, ~+ }3 F+ V
' t" v# \$ j: C
L4 x2 B6 I8 L; r7 x$ ^5 n) C) ?
5.0版本也增加了一些新的的控件:http://littlevgl.com/object-types. a X- B0 a9 D) z# d/ g
8 y( S2 S# f& M
4 o. x; X$ R$ X+ Y更详细的请移步官网:http://littlevgl.com/basics- ?* A: ~4 `9 C4 y; B# c
9 A; M0 M8 t. W: Y) g K2、移植$ I$ S- w& |- i+ K
官网给出的移植要求如下,littlevgl 的移植性很高,基本不需要单片机外部资源。3 \: \& S4 C* F1 e0 E- Q
, O/ `3 K4 j) a) \9 Y- J
- F% y1 y; L4 e" Q* B
新的5.0版本的移植接口采用了函数注册的方式,Display interface、Input device interface、Tick interface ,只要实现这3个简单的接口就可以. \5 i( O8 |8 `9 Q1 o; c
简单的跑起来littlevgl,接口的移植的详细的说明可以参考:http://littlevgl.com/porting
! m, B4 A B/ D4 d+ E( g! z, _' e9 `8 i" B+ g
其中需要注意的Display interface,为了优化显示,可以使用2个Virtual Display buffers (VDB)并行的rendering and flushing。作者的移植例子使用的是DMA中断在进行background flushing。我移植的时候为了简单就直接使用的单缓冲,然后手动调用lv_flush_ready();。
2 ?# G1 t" s6 {9 U& [
' }$ @8 o: j* V C" Q/ y2 N" Y7 }: I2 a8 j5 M% H# K n$ ?
- /**
( ]2 f( U/ V/ L9 R - * Flush a color buffer
. b4 x8 M" J9 I- N4 a! V - * @param x1 left coordinate of the rectangle
* G1 c" _! n: O6 L- ` - * @param x2 right coordinate of the rectangle& i4 v P+ Y6 K3 z7 d' D3 T% J
- * @param y1 top coordinate of the rectangle
- P, \3 X$ c z - * @param y2 bottom coordinate of the rectangle
1 F/ \; |1 j) C! t3 l - * @param color_p pointer to an array of colors4 _" q0 W5 F, `+ n
- */
. r8 F+ B* C' b' W. ?# u - static void tft_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)- t) L- W( i( U5 c& z' u
- {
' F4 L3 W( B7 r$ P5 @ - /*Return if the area is out the screen*/0 Z4 x, o! g7 J$ i9 o
- if(x2 < 0) return;
/ F. O: V. s( V* Z - ) E- s3 V5 X/ J5 e- Q( U; K
- if(y2 < 0) return;
8 T" u" S& [, e0 G0 P+ I3 B - # j# N7 w+ V3 G$ I+ m# J# m
- if(x1 > TFT_HOR_RES - 1) return;
) [; V/ b3 f8 Z
( [$ x# U3 ^+ F, f f, u- if(y1 > TFT_VER_RES - 1) return;! U2 D6 c; _+ d3 F! O( ]
- ; T* t' Y( q+ }: N! f+ S- K* m
- /*Truncate the area to the screen*/
) K) n' s# @+ z - int32_t act_x1 = x1 < 0 ? 0 : x1;
7 ^( A+ b1 A- x7 `4 x% P h, [6 ? - int32_t act_y1 = y1 < 0 ? 0 : y1;
) E: W: U- a! ?9 a* N4 o5 w: l - int32_t act_x2 = x2 > TFT_HOR_RES - 1 ? TFT_HOR_RES - 1 : x2;. }( R) J0 v; ]5 _9 F% n6 D, t
- int32_t act_y2 = y2 > TFT_VER_RES - 1 ? TFT_VER_RES - 1 : y2; u% w# g! ]5 D# I. ^4 a
: T$ v# q/ m+ c# i' s- uint32_t x;
$ w, J$ l) v" {. Y/ Z% E - uint32_t y;
5 R |" x" i8 h - ' K' H! a& }4 f( `6 y& m1 E8 C q0 q' s& B
- /*Put the map to the remaining area*/
0 Q6 N$ E. M1 c& K8 @: w - for(y = act_y1; y <= act_y2; y++)
6 X! U" \/ X6 G. C- O5 R5 M - {2 D8 W* w' ~ G& v2 V
- for(x = act_x1; x <= act_x2; x++). N; I& X9 ?, M+ ?, B$ A% B* k
- {5 s1 C) j- N" e1 Q& z' y) @
- /*Your specific function comes here!*/
* S- o% u) x- K; p - /*my_put_pixel(x, y, color_p->full);*/
5 y7 G1 P6 J( P! F8 F - BSP_LCD_DrawPixel(x, y, ((color_p->full) | 0xFF000000));
' C5 ~! P# \4 w& P& t - color_p++;
% E8 S$ J9 d M" E( F) }% @ - }& D1 N5 c( x- m4 G. e. a* I
& m# D3 d! i! `' Y* l- color_p += x2 - act_x2; /*Skip the parts out of the screen*/
0 t. I# X C( ~% \5 h$ Q U1 [ - }; ~8 }3 F0 S1 j; k3 f }, ~
- lv_flush_ready();
3 ?6 G7 [$ D) u0 c# e - }
复制代码
9 A% ~8 N- n5 i* m- `. T
}3 f0 j5 y2 |% m$ O首先测试下一个demo
: R0 I1 K4 e1 b" M( ^" x4 q+ L& N4 _/ z& V& G: f
+ ~% I% M# r' ^0 ^/ ]! D4 i4 z) W
% k1 t) ~& ]+ C9 T! i
- z( T" a; x2 C' u" E
* N5 z- q4 o% M6 i# Q6 i1 K
然后测试下内置的主题换肤
6 C/ \4 N! Z. m& W: g3 i1 _
) B+ x! n6 }0 @9 m Q# O
8 D& P: X7 p# \" {0 I# t
* j( O) B8 g+ C- u/ T+ m2 D: C9 d4 b" P; m/ y) E
$ V# [% p* D$ Y" O7 B4 P$ h- t4 B; y
4 I3 w& @1 I$ W! S F看下main函数9 v' V- S9 U! V3 y/ m v1 j* e
- int main(void)2 R" a. R4 ^; {+ m# W
- {) K0 ~4 X# J8 i- A* [% a7 c
- 6 F, `9 R! i$ P7 H7 m2 E
- CPU_CACHE_Enable();
5 k1 n9 P: x" Q) e8 \( p - HAL_Init();( P: S* I; V3 u7 \* d
- SystemClock_Config();5 t# O9 @& N* c; e! ]6 Z3 E
- USART1_Init(); M7 @4 D: M; i% i$ X \, l
- BSP_LCD_Init();7 w1 K- Q& \1 X
- BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);
7 M. z0 G/ m* P/ |, ~6 V# _& U - BSP_LCD_SetTextColor(LCD_COLOR_RED);/ i6 A/ ^( [+ n# m0 R
- BSP_LCD_Clear(LCD_COLOR_WHITE);& O8 i, k8 ~2 P% W$ P F
- BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
$ V, ~3 u$ v5 ]' W& I3 l
+ _" O8 y7 B; Y+ |6 L- lv_init();9 D. H4 ^3 F$ U& Z: ]
- tft_init();
/ M3 @1 e, ~# \; ]: }% k3 ^ K. l - touchpad_init();
/ M# R4 r" [ o - //可以使用下面的注释
" }# j Q ^" X - //测试button
6 H N9 ?4 L0 Q! e5 ^% L! Q: D3 X - //button_test();0 y$ E% v" ^9 m9 Z$ A( U' e- N
- 7 f, r a" H" x. w. ~0 G
- //测试demo' `, K) Z1 Y9 P+ T4 h
- //demo_create();! {! U6 H) S0 I4 q
-
! F1 b4 C& K; Q+ q( y - //测试theme
, t5 i) S5 \6 X: P9 e2 |/ F2 y5 [ - lv_theme_t *th = lv_theme_alien_init(21, NULL);8 D( P7 u0 P- c$ I G
- lv_test_theme_1(th);
5 z/ d* X) m9 r+ l7 g7 b -
, h% y/ {0 v+ I7 ~" K6 [$ w. Z - while(1)
% o) b/ @; \/ l1 v3 e1 U8 ~# L. h2 E - {1 L. y$ n$ e3 E$ T3 K4 Q( u( T' j
- HAL_Delay(10);( R/ ~7 F$ r& O. r9 M3 Y
- lv_task_handler();
1 Y; g. F7 T" J& x/ l3 L9 }# [ - 7 O$ B3 V1 M/ N; s& p
- }0 F {- `/ d% }, ~( V
- }
复制代码 ) m% E- s3 ~3 S& j
& X/ O$ W K) s. M' \+ Y0 }
1 r, J2 H x% K3 P3 o6 O& m1 h
9 |1 ^4 T( _' A, i3、参考资料9 T! ~+ I* _5 i
* p1 |8 @+ g' @8 J7 F
7 V1 l8 ^' I- D; h9 }% T 参考资料要推荐的官网的详细的说明和各种控件的使用说明及代码实例,还有就是作者在github上提供了PC模拟器以及各种控件和入门的代码可以参考,最后要感谢作者无私的开源精神!3 Q8 P6 b6 U. w8 c
6 g: H: z" z* m; s t" V+ q
" [2 z$ T' f. C2 T* a: U
官网:http://littlevgl.com/4 @6 y, {/ I* |
pc_simulator:http://github.com/littlevgl/pc_simulator
5 `4 F" u. s( j) g; j$ Ylv_examples:http://github.com/littlevgl/lv_examples
' p& ]3 \3 O5 W
- c0 y" L0 m1 E1 g- Z$ m5 H m6 F+ h2 ^, U0 _
测试代码:
+ w3 J) i- o; i% | d
LittlevGL-V5-STM32F69-DISCO.rar
(6.01 MB, 下载次数: 2319)
|
$ y5 a: F# c4 p x0 d
MIT许可证之名源自麻省理工学院(Massachusetts Institute of Technology, MIT),又称「X条款」(X License)或「X11条款」(X11 License)8 K0 U Q7 o, k/ U7 U- C! L
/ E/ d9 d2 o6 k0 ?- S) U! J
MIT内容与三条款BSD许可证(3-clause BSD license)内容颇为近似,但是赋予软体被授权人更大的权利与更少的限制。
, M1 O8 n: a$ a$ s' @
被授权人有权利使用、复制、修改、合并、出版发行、散布、再授权及贩售软体及软体的副本。3 k0 s8 a' M C2 b# N3 Q
6 Y, A Z N1 }& p _! ]+ P
被授权人可根据程式的需要修改授权条款为适当的内容。: s! v6 T8 L: C- c) D3 o I# [0 w
在软件和软件的所有副本中都必须包含版权声明和许可声明。8 p& Y6 M, E, o) b
此授权条款并非属copyleft的自由软体授权条款,允许在自由/开放源码软体或非自由软体(proprietary software)所使用。
" [3 C8 h7 j8 K% a' a$ B( P9 h
此亦为MIT与BSD(The BSD license, 3-clause BSD license)本质上不同处。
MIT条款可与其他授权条款并存。另外,MIT条款也是自由软体基金会(FSF)所认可的自由软体授权条款,与GPL相容。
! ^) m/ Z2 U* M' v. M
风格漂亮。
好呀,一起耍!