Skip to content

Commit 3c39d35

Browse files
authored
Merge pull request #5350 from Guozhanxin/qemu-a9-lvgl
[qemu-a9] add lvgl support.
2 parents 289cf15 + 45dd302 commit 3c39d35

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+10487
-5
lines changed

bsp/qemu-vexpress-a9/drivers/Kconfig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@ config RT_USING_UART1
66
bool "Enable UART1"
77
default y
88

9+
config BSP_USING_LVGL
10+
bool "Enable LVGL"
11+
default n
12+
913
config BSP_DRV_CLCD
1014
bool "CLCD driver"
11-
depends on PKG_USING_GUIENGINE
15+
depends on PKG_USING_GUIENGINE || BSP_USING_LVGL
16+
default y
17+
18+
config BSP_DRV_MOUSE
19+
bool "MOUSE driver"
20+
depends on PKG_USING_GUIENGINE || BSP_USING_LVGL
1221
default y
1322

1423
if BSP_DRV_CLCD

bsp/qemu-vexpress-a9/drivers/drv_mouse.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#define DBG_LVL DBG_INFO
2121
#include "rtdbg.h"
2222

23+
#ifdef BSP_DRV_MOUSE
24+
2325
#define MOUSE_ADDRESS (0x10007000)
2426
#define MOUSE_IRQ_NUM (IRQ_VEXPRESS_A9_MOUSE)
2527
#define MOUSE_XMAX (BSP_LCD_WIDTH)
@@ -34,9 +36,15 @@
3436
#define MOUSE_BUTTON_WHELL (0x80)
3537

3638
#ifdef PKG_USING_GUIENGINE
37-
3839
#include <rtgui/event.h>
3940
#include <rtgui/rtgui_server.h>
41+
#elif defined(PKG_USING_LITTLEVGL2RTT)
42+
#include <littlevgl2rtt.h>
43+
#elif defined(PKG_USING_LVGL)
44+
#include <lvgl.h>
45+
#include <lv_port_indev.h>
46+
static rt_bool_t touch_down = RT_FALSE;
47+
#endif
4048

4149
typedef rt_uint32_t virtual_addr_t;
4250

@@ -110,6 +118,7 @@ static rt_uint32_t emouse_id;
110118

111119
void push_event_touch_move(int x, int y)
112120
{
121+
#ifdef PKG_USING_GUIENGINE
113122
struct rtgui_event_mouse emouse;
114123

115124
emouse.parent.sender = RT_NULL;
@@ -124,10 +133,16 @@ void push_event_touch_move(int x, int y)
124133

125134
LOG_D("[line]:%d motion event id:%d x:%d y:%d", __LINE__, emouse.id, x, y);
126135
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
136+
#elif defined(PKG_USING_LITTLEVGL2RTT)
137+
littlevgl2rtt_send_input_event(x, y, LITTLEVGL2RTT_INPUT_MOVE);
138+
#elif defined(PKG_USING_LVGL)
139+
lv_port_indev_input(x, y, (touch_down == RT_TRUE) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL);
140+
#endif
127141
}
128142

129143
void push_event_touch_begin(int x, int y)
130144
{
145+
#ifdef PKG_USING_GUIENGINE
131146
struct rtgui_event_mouse emouse;
132147

133148
emouse_id = rt_tick_get();
@@ -143,10 +158,17 @@ void push_event_touch_begin(int x, int y)
143158
emouse.id = emouse_id;
144159
LOG_D("[line]:%d down event id:%d x:%d y:%d", __LINE__, emouse.id, x, y);
145160
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
161+
#elif defined(PKG_USING_LITTLEVGL2RTT)
162+
littlevgl2rtt_send_input_event(x, y, LITTLEVGL2RTT_INPUT_DOWN);
163+
#elif defined(PKG_USING_LVGL)
164+
touch_down = RT_TRUE;
165+
lv_port_indev_input(x, y, (touch_down == RT_TRUE) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL);
166+
#endif
146167
}
147168

148169
void push_event_touch_end(int x, int y)
149170
{
171+
#ifdef PKG_USING_GUIENGINE
150172
struct rtgui_event_mouse emouse;
151173

152174
emouse.parent.sender = RT_NULL;
@@ -158,9 +180,15 @@ void push_event_touch_end(int x, int y)
158180
emouse.y = y;
159181
emouse.ts = rt_tick_get();
160182
emouse.id = emouse_id;
161-
183+
162184
LOG_D("[line]:%d up event id:%d x:%d y:%d", __LINE__, emouse.id, x, y);
163185
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
186+
#elif defined(PKG_USING_LITTLEVGL2RTT)
187+
littlevgl2rtt_send_input_event(x, y, LITTLEVGL2RTT_INPUT_MOVE);
188+
#elif defined(PKG_USING_LVGL)
189+
touch_down = RT_FALSE;
190+
lv_port_indev_input(x, y, (touch_down == RT_TRUE) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL);
191+
#endif
164192
}
165193

166194
static void mouse_pl050_interrupt(int irq, void * data)
@@ -243,7 +271,7 @@ int rt_hw_mouse_init(void)
243271
((read32(virt + 0xfe8) & 0xff) << 16) |
244272
((read32(virt + 0xfe4) & 0xff) << 8) |
245273
((read32(virt + 0xfe0) & 0xff) << 0));
246-
274+
247275
if(((id >> 12) & 0xff) != 0x41 || (id & 0xfff) != 0x050)
248276
{
249277
LOG_E("read id fail id:0x%08x", id);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# files format check exclude path, please follow the instructions below to modify;
2+
# If you need to exclude an entire folder, add the folder path in dir_path;
3+
# If you need to exclude a file, add the path to the file in file_path.
4+
5+
dir_path:
6+
- demo
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from building import *
2+
import os
3+
4+
cwd = GetCurrentDir()
5+
group = []
6+
src = Glob('*.c')
7+
CPPPATH = [cwd]
8+
CPPDEFINES = ['STM32F4']
9+
10+
list = os.listdir(cwd)
11+
for d in list:
12+
path = os.path.join(cwd, d)
13+
if os.path.isfile(os.path.join(path, 'SConscript')):
14+
group = group + SConscript(os.path.join(d, 'SConscript'))
15+
16+
group += DefineGroup('LVGL-port', src, depend = ['BSP_USING_LVGL'], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
17+
18+
Return('group')
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import rtconfig
2+
3+
from building import *
4+
5+
cwd = GetCurrentDir()
6+
src = Glob('*.c') + Glob('*.cpp')
7+
8+
path = [cwd]
9+
path += [cwd + '/src']
10+
11+
src += Glob('src/lv_demo_music/*.c')
12+
src += Glob('src/lv_demo_music/assets/*.c')
13+
14+
path += [cwd + '/src/lv_demo_music']
15+
path += [cwd + '/src/lv_demo_music/assets']
16+
17+
group = DefineGroup('LVGL-demo', src, depend = ['BSP_USING_LVGL'], CPPPATH = path)
18+
19+
Return('group')
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* @file lv_examples.h
3+
*
4+
*/
5+
6+
#ifndef LV_DEMO_H
7+
#define LV_DEMO_H
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
/*********************
14+
* INCLUDES
15+
*********************/
16+
17+
/*If "lv_conf.h" is available from here try to use it later.*/
18+
#ifdef __has_include
19+
# if __has_include("lvgl.h")
20+
# ifndef LV_LVGL_H_INCLUDE_SIMPLE
21+
# define LV_LVGL_H_INCLUDE_SIMPLE
22+
# endif
23+
# endif
24+
#endif
25+
26+
#ifdef __has_include
27+
# if __has_include("lv_demo_conf.h")
28+
# ifndef LV_DEMO_CONF_INCLUDE_SIMPLE
29+
# define LV_DEMO_CONF_INCLUDE_SIMPLE
30+
# endif
31+
# endif
32+
#endif
33+
34+
#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
35+
#include <lvgl.h>
36+
#else
37+
#include <lvgl.h>
38+
#endif
39+
40+
#if defined(LV_DEMO_CONF_PATH)
41+
#define __LV_TO_STR_AUX(x) #x
42+
#define __LV_TO_STR(x) __LV_TO_STR_AUX(x)
43+
#include __LV_TO_STR(LV_DEMO_CONF_PATH)
44+
#undef __LV_TO_STR_AUX
45+
#undef __LV_TO_STR
46+
#elif defined(LV_DEMO_CONF_INCLUDE_SIMPLE)
47+
#include "lv_demo_conf.h"
48+
#else
49+
#include <lv_conf.h>
50+
#endif
51+
52+
#include "src/lv_demo_music/lv_demo_music.h"
53+
54+
55+
/*********************
56+
* DEFINES
57+
*********************/
58+
/*Test lvgl version*/
59+
#if LV_VERSION_CHECK(8, 0, 0) == 0
60+
#error "lv_demo: Wrong lvgl version"
61+
#endif
62+
63+
/**********************
64+
* TYPEDEFS
65+
**********************/
66+
67+
/**********************
68+
* GLOBAL PROTOTYPES
69+
**********************/
70+
71+
72+
/**********************
73+
* MACROS
74+
**********************/
75+
76+
77+
#ifdef __cplusplus
78+
} /* extern "C" */
79+
#endif
80+
81+
#endif /*LV_DEMO_H*/
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @file lv_examples.h
3+
* This file exists only to be compatible with Arduino's library structure
4+
*/
5+
6+
#ifndef LV_DEMO_SRC_H
7+
#define LV_DEMO_SRC_H
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
/*********************
14+
* INCLUDES
15+
*********************/
16+
17+
#include "../lv_demo.h"
18+
19+
/*********************
20+
* DEFINES
21+
*********************/
22+
23+
/**********************
24+
* TYPEDEFS
25+
**********************/
26+
27+
/**********************
28+
* GLOBAL PROTOTYPES
29+
**********************/
30+
31+
/**********************
32+
* MACROS
33+
**********************/
34+
35+
36+
#ifdef __cplusplus
37+
} /* extern "C" */
38+
#endif
39+
40+
#endif /*LV_DEMO_SRC_H*/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Music player demo
2+
3+
## Overview
4+
The music player demo shows what kind of modern, smartphone-like user interfaces can be created on LVGL. It works the best with display with 480x272 or 272x480 resolution.
5+
6+
7+
![Music player demo with LVGL embedded GUI library](https://github.com/lvgl/lv_examples/blob/master/src/lv_demo_music/screenshot1.gif?raw=true)
8+
9+
## Run the demo
10+
- In `lv_ex_conf.h` set `LV_USE_DEMO_MUSIC 1`
11+
- With `LV_DEMO_MUSIC_AUTO_PLAY` enabled a ~60 sec demo will be played.
12+
- After `lv_init()` and initializing the drivers call `lv_demo_music()`
13+
14+
## How the spectrum animation works
15+
- `assets/spectrum.py` creates an array of spectrum values from a music. 4 band are created with 33 samples/sec: bass, bass-mid, mid, mid-treble.
16+
- The spectrum meter UI does the followings:
17+
- Zoom the album cover proportionality to the current bass value
18+
- Display the 4 bands on the left side of a circle by default at 0°, 45°, 90°, 135°
19+
- Add extra bars next to the "main bars" with a cosine shape. Add more bars for the lower bands.
20+
- If the there is a large enough bass add a random offset to the position of the bars. E.g. start from 63° istead of 0°. (bars greater than 180° start again from 0°)
21+
- If there no bass add 1 to the offset of the bars (it creates a "walking" effect)
22+
- Mirror the bars to the right side of the circle
23+
24+
## Using spectrum.py
25+
- install `librosa` with `pip3 install librosa`
26+
- run `python sectrum.py my_file.mp3`
27+
- see the result in `spectrum.h`

0 commit comments

Comments
 (0)