Skip to content

Commit 814c15c

Browse files
committed
Add lvgl_8.1.0 support for raspberry_pi pico
1 parent ea9c6c9 commit 814c15c

File tree

19 files changed

+915
-7
lines changed

19 files changed

+915
-7
lines changed

bsp/raspberry-pico/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ config PKGS_DIR
1717

1818
source "$RTT_DIR/Kconfig"
1919
source "$PKGS_DIR/Kconfig"
20+
source "libraries/Kconfig"
2021

2122
config SOC_RP2040
2223
bool

bsp/raspberry-pico/SConstruct

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ Export('rtconfig')
2727
# prepare building environment
2828
objs = PrepareBuilding(env, RTT_ROOT)
2929

30+
objs.extend(SConscript(os.path.join(os.getcwd(), 'board', 'ports', 'SConscript')))
31+
3032
# make a building
3133
DoBuilding(TARGET, objs)
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
Import('RTT_ROOT')
2-
Import('rtconfig')
31
from building import *
2+
import os
43

5-
cwd = os.path.join(str(Dir('#')), 'applications')
6-
src = Glob('*.c')
7-
CPPPATH = [cwd, str(Dir('#'))]
4+
cwd = GetCurrentDir()
5+
6+
src = ['main.c']
7+
8+
CPPPATH = [cwd]
89

910
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
1011

11-
Return('group')
12+
list = os.listdir(cwd)
13+
for item in list:
14+
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
15+
group = group + SConscript(os.path.join(item, 'SConscript'))
16+
17+
Return('group')
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from building import *
2+
import os
3+
4+
cwd = GetCurrentDir()
5+
group = []
6+
src = Glob('*.c')
7+
CPPPATH = [cwd]
8+
9+
list = os.listdir(cwd)
10+
for d in list:
11+
path = os.path.join(cwd, d)
12+
if os.path.isfile(os.path.join(path, 'SConscript')):
13+
group = group + SConscript(os.path.join(d, 'SConscript'))
14+
15+
group += DefineGroup('LVGL-port', src, depend = ['BSP_USING_LVGL'], CPPPATH = CPPPATH)
16+
Return('group')
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-10-18 Meco Man First version
9+
*/
10+
11+
#ifndef LV_CONF_H
12+
#define LV_CONF_H
13+
14+
#define LV_USE_PERF_MONITOR 1
15+
#define LV_COLOR_DEPTH 16
16+
#define LV_COLOR_16_SWAP 1
17+
18+
/* music player demo */
19+
#define LV_HOR_RES_MAX 240
20+
#define LV_VER_RES_MAX 240
21+
#define LV_USE_DEMO_RTT_MUSIC 1
22+
#define LV_DEMO_RTT_MUSIC_AUTO_PLAY 1
23+
#define LV_FONT_MONTSERRAT_12 1
24+
#define LV_FONT_MONTSERRAT_16 1
25+
26+
#endif
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-10-17 Meco Man First version
9+
*/
10+
#include <rtthread.h>
11+
#include <lvgl.h>
12+
#include <lv_port_indev.h>
13+
#define DBG_TAG "LVGL.demo"
14+
#define DBG_LVL DBG_INFO
15+
#include <rtdbg.h>
16+
17+
#ifndef LV_THREAD_STACK_SIZE
18+
#define LV_THREAD_STACK_SIZE 4096
19+
#endif
20+
21+
#ifndef LV_THREAD_PRIO
22+
#define LV_THREAD_PRIO (RT_THREAD_PRIORITY_MAX * 2 / 3)
23+
#endif
24+
25+
static void lvgl_thread(void *parameter)
26+
{
27+
extern void lv_demo_music(void);
28+
lv_demo_music();
29+
while (1)
30+
{
31+
lv_task_handler();
32+
rt_thread_mdelay(5);
33+
}
34+
}
35+
36+
static int lvgl_demo_init(void)
37+
{
38+
rt_thread_t tid;
39+
40+
tid = rt_thread_create("LVGL", lvgl_thread, RT_NULL, LV_THREAD_STACK_SIZE, LV_THREAD_PRIO, 0);
41+
if (tid == RT_NULL)
42+
{
43+
LOG_E("Fail to create 'LVGL' thread");
44+
}
45+
rt_thread_startup(tid);
46+
47+
return 0;
48+
}
49+
INIT_APP_EXPORT(lvgl_demo_init);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-10-18 Meco Man The first version
9+
* 2021-12-24 Rb Refresh using dma2d
10+
*/
11+
#include <lvgl.h>
12+
#include "drv_lcd.h"
13+
14+
/*A static or global variable to store the buffers*/
15+
static lv_disp_draw_buf_t disp_buf;
16+
static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
17+
18+
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * LV_VER_RES_MAX)
19+
20+
static const lv_color_t * buf_to_flush;
21+
22+
static lv_disp_drv_t g_disp_drv;
23+
static lv_color_t lv_disp_buf1[DISP_BUF_SIZE];
24+
25+
static void lcd_fb_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
26+
{
27+
LCD_DisplayWindows(area->x1, area->y1, area->x2, area->y2, (uint16_t*) color_p);
28+
lv_disp_flush_ready(disp_drv);
29+
}
30+
31+
void lv_port_disp_init(void)
32+
{
33+
rt_err_t result;
34+
35+
SPI_Init();
36+
LCD_Init(HORIZONTAL);
37+
38+
/*Initialize `disp_buf` with the buffer(s).*/
39+
lv_disp_draw_buf_init(&disp_buf, lv_disp_buf1, 0x00, DISP_BUF_SIZE);
40+
41+
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
42+
43+
/*Set the resolution of the display*/
44+
disp_drv.hor_res = LV_VER_RES_MAX;
45+
disp_drv.ver_res = LV_HOR_RES_MAX;
46+
47+
/*Set a display buffer*/
48+
disp_drv.draw_buf = &disp_buf;
49+
50+
/*Used to copy the buffer's content to the display*/
51+
disp_drv.flush_cb = lcd_fb_flush;
52+
53+
/*Finally register the driver*/
54+
lv_disp_drv_register(&disp_drv);
55+
56+
g_disp_drv = disp_drv;
57+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-10-18 Meco Man The first version
9+
*/
10+
#ifndef LV_PORT_DISP_H
11+
#define LV_PORT_DISP_H
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
void lv_port_disp_init(void);
18+
19+
#ifdef __cplusplus
20+
} /*extern "C"*/
21+
#endif
22+
23+
#endif
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-10-18 Meco Man The first version
9+
*/
10+
#include <lvgl.h>
11+
#include <stdbool.h>
12+
#include <rtdevice.h>
13+
14+
#define UP_KEY 2
15+
#define DOWN_KEY 18
16+
#define LEFT_KEY 16
17+
#define RIGHT_KEY 20
18+
#define CRTL_KEY 3
19+
20+
#define BUTTON0_PIN 2
21+
#define BUTTON1_PIN 18
22+
#define BUTTON2_PIN 16
23+
#define BUTTON_WKUP_PIN 20
24+
25+
/*Test if `id` button is pressed or not*/
26+
static bool button_is_pressed(uint8_t id)
27+
{
28+
switch(id)
29+
{
30+
case 0:
31+
if(rt_pin_read(BUTTON0_PIN) == PIN_LOW)
32+
return true;
33+
break;
34+
case 1:
35+
if(rt_pin_read(BUTTON1_PIN) == PIN_LOW)
36+
return true;
37+
break;
38+
case 2:
39+
if(rt_pin_read(BUTTON2_PIN) == PIN_LOW)
40+
return true;
41+
break;
42+
case 3:
43+
if(rt_pin_read(BUTTON_WKUP_PIN) == PIN_LOW)
44+
return true;
45+
break;
46+
}
47+
48+
return false;
49+
}
50+
51+
static int8_t button_get_pressed_id(void)
52+
{
53+
uint8_t i;
54+
55+
/*Check to buttons see which is being pressed*/
56+
for(i = 0; i < 4; i++)
57+
{
58+
/*Return the pressed button's ID*/
59+
if(button_is_pressed(i))
60+
{
61+
return i;
62+
}
63+
}
64+
65+
/*No button pressed*/
66+
return -1;
67+
}
68+
69+
void button_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
70+
{
71+
static uint32_t last_btn = 0; /*Store the last pressed button*/
72+
int btn_pr = button_get_pressed_id(); /*Get the ID (0,1,2...) of the pressed button*/
73+
if(btn_pr >= 0)
74+
{ /*Is there a button press? (E.g. -1 indicated no button was pressed)*/
75+
last_btn = btn_pr; /*Save the ID of the pressed button*/
76+
data->state = LV_INDEV_STATE_PRESSED; /*Set the pressed state*/
77+
}
78+
else
79+
{
80+
data->state = LV_INDEV_STATE_RELEASED; /*Set the released state*/
81+
}
82+
83+
data->btn_id = last_btn; /*Save the last button*/
84+
}
85+
86+
87+
lv_indev_t * button_indev;
88+
89+
void lv_port_indev_init(void)
90+
{
91+
static lv_indev_drv_t indev_drv;
92+
93+
/* Initialize the on-board buttons */
94+
rt_pin_mode(BUTTON0_PIN, PIN_MODE_INPUT);
95+
rt_pin_mode(BUTTON1_PIN, PIN_MODE_INPUT);
96+
rt_pin_mode(BUTTON2_PIN, PIN_MODE_INPUT);
97+
rt_pin_mode(BUTTON_WKUP_PIN, PIN_MODE_INPUT);
98+
99+
lv_indev_drv_init(&indev_drv); /*Basic initialization*/
100+
indev_drv.type = LV_INDEV_TYPE_BUTTON;
101+
indev_drv.read_cb = button_read;
102+
103+
/*Register the driver in LVGL and save the created input device object*/
104+
button_indev = lv_indev_drv_register(&indev_drv);
105+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-10-18 Meco Man The first version
9+
*/
10+
#ifndef LV_PORT_INDEV_H
11+
#define LV_PORT_INDEV_H
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
#include <lv_hal_indev.h>
18+
19+
extern lv_indev_t * button_indev;
20+
21+
void lv_port_indev_init(void);
22+
void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state);
23+
24+
#ifdef __cplusplus
25+
} /*extern "C"*/
26+
#endif
27+
28+
#endif

0 commit comments

Comments
 (0)