Skip to content

[qemu-a9] add lvgl support. #5350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion bsp/qemu-vexpress-a9/drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ config RT_USING_UART1
bool "Enable UART1"
default y

config BSP_USING_LVGL
bool "Enable LVGL"
default n

config BSP_DRV_CLCD
bool "CLCD driver"
depends on PKG_USING_GUIENGINE
depends on PKG_USING_GUIENGINE || BSP_USING_LVGL
default y

config BSP_DRV_MOUSE
bool "MOUSE driver"
depends on PKG_USING_GUIENGINE || BSP_USING_LVGL
default y

if BSP_DRV_CLCD
Expand Down
34 changes: 31 additions & 3 deletions bsp/qemu-vexpress-a9/drivers/drv_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#define DBG_LVL DBG_INFO
#include "rtdbg.h"

#ifdef BSP_DRV_MOUSE

#define MOUSE_ADDRESS (0x10007000)
#define MOUSE_IRQ_NUM (IRQ_VEXPRESS_A9_MOUSE)
#define MOUSE_XMAX (BSP_LCD_WIDTH)
Expand All @@ -34,9 +36,15 @@
#define MOUSE_BUTTON_WHELL (0x80)

#ifdef PKG_USING_GUIENGINE

#include <rtgui/event.h>
#include <rtgui/rtgui_server.h>
#elif defined(PKG_USING_LITTLEVGL2RTT)
#include <littlevgl2rtt.h>
#elif defined(PKG_USING_LVGL)
#include <lvgl.h>
#include <lv_port_indev.h>
static rt_bool_t touch_down = RT_FALSE;
#endif

typedef rt_uint32_t virtual_addr_t;

Expand Down Expand Up @@ -110,6 +118,7 @@ static rt_uint32_t emouse_id;

void push_event_touch_move(int x, int y)
{
#ifdef PKG_USING_GUIENGINE
struct rtgui_event_mouse emouse;

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

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

void push_event_touch_begin(int x, int y)
{
#ifdef PKG_USING_GUIENGINE
struct rtgui_event_mouse emouse;

emouse_id = rt_tick_get();
Expand All @@ -143,10 +158,17 @@ void push_event_touch_begin(int x, int y)
emouse.id = emouse_id;
LOG_D("[line]:%d down event id:%d x:%d y:%d", __LINE__, emouse.id, x, y);
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
#elif defined(PKG_USING_LITTLEVGL2RTT)
littlevgl2rtt_send_input_event(x, y, LITTLEVGL2RTT_INPUT_DOWN);
#elif defined(PKG_USING_LVGL)
touch_down = RT_TRUE;
lv_port_indev_input(x, y, (touch_down == RT_TRUE) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL);
#endif
}

void push_event_touch_end(int x, int y)
{
#ifdef PKG_USING_GUIENGINE
struct rtgui_event_mouse emouse;

emouse.parent.sender = RT_NULL;
Expand All @@ -158,9 +180,15 @@ void push_event_touch_end(int x, int y)
emouse.y = y;
emouse.ts = rt_tick_get();
emouse.id = emouse_id;

LOG_D("[line]:%d up event id:%d x:%d y:%d", __LINE__, emouse.id, x, y);
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
#elif defined(PKG_USING_LITTLEVGL2RTT)
littlevgl2rtt_send_input_event(x, y, LITTLEVGL2RTT_INPUT_MOVE);
#elif defined(PKG_USING_LVGL)
touch_down = RT_FALSE;
lv_port_indev_input(x, y, (touch_down == RT_TRUE) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL);
#endif
}

static void mouse_pl050_interrupt(int irq, void * data)
Expand Down Expand Up @@ -243,7 +271,7 @@ int rt_hw_mouse_init(void)
((read32(virt + 0xfe8) & 0xff) << 16) |
((read32(virt + 0xfe4) & 0xff) << 8) |
((read32(virt + 0xfe0) & 0xff) << 0));

if(((id >> 12) & 0xff) != 0x41 || (id & 0xfff) != 0x050)
{
LOG_E("read id fail id:0x%08x", id);
Expand Down
6 changes: 6 additions & 0 deletions bsp/qemu-vexpress-a9/drivers/lvgl/.ignore_format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# files format check exclude path, please follow the instructions below to modify;
# If you need to exclude an entire folder, add the folder path in dir_path;
# If you need to exclude a file, add the path to the file in file_path.

dir_path:
- demo
18 changes: 18 additions & 0 deletions bsp/qemu-vexpress-a9/drivers/lvgl/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from building import *
import os

cwd = GetCurrentDir()
group = []
src = Glob('*.c')
CPPPATH = [cwd]
CPPDEFINES = ['STM32F4']

list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
group = group + SConscript(os.path.join(d, 'SConscript'))

group += DefineGroup('LVGL-port', src, depend = ['BSP_USING_LVGL'], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)

Return('group')
19 changes: 19 additions & 0 deletions bsp/qemu-vexpress-a9/drivers/lvgl/demo/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import rtconfig

from building import *

cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')

path = [cwd]
path += [cwd + '/src']

src += Glob('src/lv_demo_music/*.c')
src += Glob('src/lv_demo_music/assets/*.c')

path += [cwd + '/src/lv_demo_music']
path += [cwd + '/src/lv_demo_music/assets']

group = DefineGroup('LVGL-demo', src, depend = ['BSP_USING_LVGL'], CPPPATH = path)

Return('group')
81 changes: 81 additions & 0 deletions bsp/qemu-vexpress-a9/drivers/lvgl/demo/lv_demo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* @file lv_examples.h
*
*/

#ifndef LV_DEMO_H
#define LV_DEMO_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
* INCLUDES
*********************/

/*If "lv_conf.h" is available from here try to use it later.*/
#ifdef __has_include
# if __has_include("lvgl.h")
# ifndef LV_LVGL_H_INCLUDE_SIMPLE
# define LV_LVGL_H_INCLUDE_SIMPLE
# endif
# endif
#endif

#ifdef __has_include
# if __has_include("lv_demo_conf.h")
# ifndef LV_DEMO_CONF_INCLUDE_SIMPLE
# define LV_DEMO_CONF_INCLUDE_SIMPLE
# endif
# endif
#endif

#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
#include <lvgl.h>
#else
#include <lvgl.h>
#endif

#if defined(LV_DEMO_CONF_PATH)
#define __LV_TO_STR_AUX(x) #x
#define __LV_TO_STR(x) __LV_TO_STR_AUX(x)
#include __LV_TO_STR(LV_DEMO_CONF_PATH)
#undef __LV_TO_STR_AUX
#undef __LV_TO_STR
#elif defined(LV_DEMO_CONF_INCLUDE_SIMPLE)
#include "lv_demo_conf.h"
#else
#include <lv_conf.h>
#endif

#include "src/lv_demo_music/lv_demo_music.h"


/*********************
* DEFINES
*********************/
/*Test lvgl version*/
#if LV_VERSION_CHECK(8, 0, 0) == 0
#error "lv_demo: Wrong lvgl version"
#endif

/**********************
* TYPEDEFS
**********************/

/**********************
* GLOBAL PROTOTYPES
**********************/


/**********************
* MACROS
**********************/


#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /*LV_DEMO_H*/
40 changes: 40 additions & 0 deletions bsp/qemu-vexpress-a9/drivers/lvgl/demo/src/lv_demo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @file lv_examples.h
* This file exists only to be compatible with Arduino's library structure
*/

#ifndef LV_DEMO_SRC_H
#define LV_DEMO_SRC_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
* INCLUDES
*********************/

#include "../lv_demo.h"

/*********************
* DEFINES
*********************/

/**********************
* TYPEDEFS
**********************/

/**********************
* GLOBAL PROTOTYPES
**********************/

/**********************
* MACROS
**********************/


#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /*LV_DEMO_SRC_H*/
27 changes: 27 additions & 0 deletions bsp/qemu-vexpress-a9/drivers/lvgl/demo/src/lv_demo_music/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Music player demo

## Overview
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.


![Music player demo with LVGL embedded GUI library](https://github.com/lvgl/lv_examples/blob/master/src/lv_demo_music/screenshot1.gif?raw=true)

## Run the demo
- In `lv_ex_conf.h` set `LV_USE_DEMO_MUSIC 1`
- With `LV_DEMO_MUSIC_AUTO_PLAY` enabled a ~60 sec demo will be played.
- After `lv_init()` and initializing the drivers call `lv_demo_music()`

## How the spectrum animation works
- `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.
- The spectrum meter UI does the followings:
- Zoom the album cover proportionality to the current bass value
- Display the 4 bands on the left side of a circle by default at 0°, 45°, 90°, 135°
- Add extra bars next to the "main bars" with a cosine shape. Add more bars for the lower bands.
- 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°)
- If there no bass add 1 to the offset of the bars (it creates a "walking" effect)
- Mirror the bars to the right side of the circle

## Using spectrum.py
- install `librosa` with `pip3 install librosa`
- run `python sectrum.py my_file.mp3`
- see the result in `spectrum.h`
Loading