Skip to content

Commit f96ee3c

Browse files
authored
Merge pull request #5204 from mysterywolf/l47555
[stm32l475] port for LVGL
2 parents abf8812 + d4991d9 commit f96ee3c

File tree

10 files changed

+268
-22
lines changed

10 files changed

+268
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
Import('RTT_ROOT')
2-
Import('rtconfig')
31
from building import *
2+
import os
43

54
cwd = GetCurrentDir()
65
src = Glob('*.c')
7-
CPPPATH = [cwd, ]
6+
CPPPATH = [cwd]
87

98
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
109

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+
1116
Return('group')

bsp/stm32/stm32f407-atk-explorer/applications/SConscript

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import rtconfig
2-
import os
31
from building import *
2+
import os
43

54
cwd = GetCurrentDir()
6-
CPPPATH = [cwd, str(Dir('#'))]
7-
src = Split("""
8-
main.c
9-
""")
5+
CPPPATH = [cwd]
6+
src = Glob('*.c')
107

118
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
129

Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
from building import *
2+
import os
23

3-
cwd = GetCurrentDir()
4+
cwd = GetCurrentDir()
45

56
src = Split('''
67
main.c
78
''')
89

9-
if GetDepend(['BSP_USING_SPI_LCD']):
10+
if GetDepend(['BSP_USING_LCD_SAMPLE']):
1011
src += ['lcd_sample.c']
1112

1213
if GetDepend(['PKG_USING_NRF24L01']):
1314
src += ['nrf24l01_init.c']
1415

15-
CPPPATH = [str(Dir('#')), cwd]
16+
CPPPATH = [cwd]
1617

1718
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
1819

20+
list = os.listdir(cwd)
21+
for d in list:
22+
path = os.path.join(cwd, d)
23+
if os.path.isfile(os.path.join(path, 'SConscript')):
24+
group = group + SConscript(os.path.join(d, 'SConscript'))
25+
1926
Return('group')

bsp/stm32/stm32l475-atk-pandora/applications/lcd_sample.c

-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include <rtthread.h>
1212
#include <rtdevice.h>
1313
#include <board.h>
14-
15-
#ifdef BSP_USING_SPI_LCD
1614
#include <drv_lcd.h>
1715
#include <rttlogo.h>
1816

@@ -45,4 +43,3 @@ static int lcd_sample(void)
4543
return RT_EOK;
4644
}
4745
INIT_APP_EXPORT(lcd_sample);
48-
#endif /* BSP_USING_SPI_LCD */

bsp/stm32/stm32l475-atk-pandora/board/Kconfig

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ menu "Onboard Peripheral Drivers"
3535
select BSP_USING_SPI3
3636
default n
3737

38+
config BSP_USING_LCD_SAMPLE
39+
bool "Enable LCD sample"
40+
depends on BSP_USING_SPI_LCD
41+
depends on !BSP_USING_LVGL
42+
default n
43+
44+
config BSP_USING_LVGL
45+
bool "Enable LVGL for LCD"
46+
select BSP_USING_SPI_LCD
47+
select PKG_USING_LVGL
48+
default n
49+
3850
config BSP_USING_SDCARD
3951
bool "Enable SDCARD (spi1)"
4052
select BSP_USING_SPI

bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c

+55-6
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
* 2018-08-14 flybreak the first version
99
* 2018-09-18 balanceTWK add sleep mode function
1010
* 2018-09-27 ZYLX optimized display speed
11+
* 2021-10-17 Meco Man add lcd_fill_array()
1112
*/
1213

1314
#include <rtdevice.h>
1415
#include "drv_spi.h"
15-
#include "drv_lcd.h"
16+
#include <drv_lcd.h>
1617
#include "drv_lcd_font.h"
17-
#include "drv_gpio.h"
18+
#include <drv_gpio.h>
1819

19-
#define DBG_SECTION_NAME "LCD"
20-
#define DBG_COLOR
21-
#define DBG_LEVEL DBG_LOG
20+
#define DBG_TAG "drv.lcd"
21+
#define DBG_LVL DBG_INFO
2222
#include <rtdbg.h>
2323

2424
#define LCD_PWR_PIN GET_PIN(B, 7)
@@ -375,7 +375,7 @@ void lcd_fill(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_ui
375375
rt_uint32_t size = 0, size_remain = 0;
376376
rt_uint8_t *fill_buf = RT_NULL;
377377

378-
size = (x_end - x_start) * (y_end - y_start) * 2;
378+
size = (x_end - x_start + 1) * (y_end - y_start + 1) * 2;
379379

380380
if (size > LCD_CLEAR_SEND_NUMBER)
381381
{
@@ -426,6 +426,55 @@ void lcd_fill(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_ui
426426
}
427427
}
428428

429+
/**
430+
* full color array on the lcd.
431+
*
432+
* @param x_start start of x position
433+
* @param y_start start of y position
434+
* @param x_end end of x position
435+
* @param y_end end of y position
436+
* @param color Fill color array's pointer
437+
*
438+
* @return void
439+
*/
440+
void lcd_fill_array(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_uint16_t y_end, void *pcolor)
441+
{
442+
rt_uint32_t size = 0, size_remain = 0;
443+
444+
size = (x_end - x_start + 1) * (y_end - y_start + 1) * 2;
445+
446+
if (size > LCD_CLEAR_SEND_NUMBER)
447+
{
448+
/* the number of remaining to be filled */
449+
size_remain = size - LCD_CLEAR_SEND_NUMBER;
450+
size = LCD_CLEAR_SEND_NUMBER;
451+
}
452+
453+
lcd_address_set(x_start, y_start, x_end, y_end);
454+
455+
/* fast fill */
456+
while (1)
457+
{
458+
rt_pin_write(LCD_DC_PIN, PIN_HIGH);
459+
rt_spi_send(spi_dev_lcd, pcolor, size);
460+
461+
/* Fill completed */
462+
if (size_remain == 0)
463+
break;
464+
465+
/* calculate the number of fill next time */
466+
if (size_remain > LCD_CLEAR_SEND_NUMBER)
467+
{
468+
size_remain = size_remain - LCD_CLEAR_SEND_NUMBER;
469+
}
470+
else
471+
{
472+
size = size_remain;
473+
size_remain = 0;
474+
}
475+
}
476+
}
477+
429478
/**
430479
* display a line on the lcd.
431480
*

bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void lcd_draw_circle(rt_uint16_t x0, rt_uint16_t y0, rt_uint8_t r);
5050
void lcd_draw_line(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2);
5151
void lcd_draw_rectangle(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2);
5252
void lcd_fill(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_uint16_t y_end, rt_uint16_t color);
53-
53+
void lcd_fill_array(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_uint16_t y_end, void *pcolor);
5454
void lcd_show_num(rt_uint16_t x, rt_uint16_t y, rt_uint32_t num, rt_uint8_t len, rt_uint32_t size);
5555
rt_err_t lcd_show_string(rt_uint16_t x, rt_uint16_t y, rt_uint32_t size, const char *fmt, ...);
5656
rt_err_t lcd_show_image(rt_uint16_t x, rt_uint16_t y, rt_uint16_t length, rt_uint16_t wide, const rt_uint8_t *p);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from building import *
2+
3+
cwd = GetCurrentDir()
4+
5+
src = Glob('*.c')
6+
CPPPATH = [cwd]
7+
8+
group = DefineGroup('LVGL', src, depend = ['BSP_USING_LVGL'], CPPPATH = CPPPATH)
9+
Return('group')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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_COLOR_16_SWAP 1
15+
16+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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+
11+
#include <rtthread.h>
12+
#include <lvgl.h>
13+
#include <drv_lcd.h>
14+
#define DBG_TAG "LVGL"
15+
#define DBG_LVL DBG_INFO
16+
#include <rtdbg.h>
17+
18+
#ifndef LV_THREAD_STACK_SIZE
19+
#define LV_THREAD_STACK_SIZE 2048
20+
#endif
21+
22+
#ifndef LV_THREAD_PRIO
23+
#define LV_THREAD_PRIO (RT_THREAD_PRIORITY_MAX*2/3)
24+
#endif
25+
26+
static void lv_example_get_started_1(void);
27+
static void lv_example_get_started_3(void);
28+
29+
#define MY_DISP_HOR_RES 240 /* 240*240 */
30+
31+
/*A static or global variable to store the buffers*/
32+
static lv_disp_draw_buf_t disp_buf;
33+
34+
/*Static or global buffer(s). The second buffer is optional*/
35+
static lv_color_t buf_1[MY_DISP_HOR_RES * 10];
36+
static lv_color_t buf_2[MY_DISP_HOR_RES * 10];
37+
38+
static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
39+
40+
/*Flush the content of the internal buffer the specific area on the display
41+
*You can use DMA or any hardware acceleration to do this operation in the background but
42+
*'lv_disp_flush_ready()' has to be called when finished.*/
43+
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
44+
{
45+
lcd_fill_array(area->x1, area->y1, area->x2, area->y2, color_p);
46+
47+
/*IMPORTANT!!!
48+
*Inform the graphics library that you are ready with the flushing*/
49+
lv_disp_flush_ready(disp_drv);
50+
}
51+
52+
static void lvgl_thread(void *parameter)
53+
{
54+
lv_init();
55+
56+
/*Initialize `disp_buf` with the buffer(s). With only one buffer use NULL instead buf_2 */
57+
lv_disp_draw_buf_init(&disp_buf, buf_1, buf_2, MY_DISP_HOR_RES*10);
58+
59+
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
60+
61+
/*Set the resolution of the display*/
62+
disp_drv.hor_res = MY_DISP_HOR_RES;
63+
disp_drv.ver_res = MY_DISP_HOR_RES;
64+
65+
/*Set a display buffer*/
66+
disp_drv.draw_buf = &disp_buf;
67+
68+
/*Used to copy the buffer's content to the display*/
69+
disp_drv.flush_cb = disp_flush;
70+
71+
/*Finally register the driver*/
72+
lv_disp_drv_register(&disp_drv);
73+
74+
lv_example_get_started_1();
75+
lv_example_get_started_3();
76+
77+
while(1)
78+
{
79+
lv_task_handler();
80+
rt_thread_mdelay(10);
81+
}
82+
}
83+
84+
static int lvgl_demo_init(void)
85+
{
86+
rt_thread_t tid;
87+
88+
tid = rt_thread_create("lvgl", lvgl_thread, RT_NULL, LV_THREAD_STACK_SIZE, LV_THREAD_PRIO, 0);
89+
rt_thread_startup(tid);
90+
91+
return 0;
92+
}
93+
INIT_COMPONENT_EXPORT(lvgl_demo_init);
94+
95+
/* ------------------- demo1 ----------------------- */
96+
97+
static void btn_event_cb(lv_event_t * e)
98+
{
99+
lv_event_code_t code = lv_event_get_code(e);
100+
lv_obj_t * btn = lv_event_get_target(e);
101+
if(code == LV_EVENT_CLICKED) {
102+
static uint8_t cnt = 0;
103+
cnt++;
104+
105+
/*Get the first child of the button which is the label and change its text*/
106+
lv_obj_t * label = lv_obj_get_child(btn, 0);
107+
lv_label_set_text_fmt(label, "Button: %d", cnt);
108+
}
109+
}
110+
111+
/**
112+
* Create a button with a label and react on click event.
113+
*/
114+
static void lv_example_get_started_1(void)
115+
{
116+
lv_obj_t * btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/
117+
lv_obj_set_pos(btn, 10, 10); /*Set its position*/
118+
lv_obj_set_size(btn, 120, 50); /*Set its size*/
119+
lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); /*Assign a callback to the button*/
120+
121+
lv_obj_t * label = lv_label_create(btn); /*Add a label to the button*/
122+
lv_label_set_text(label, "Button"); /*Set the labels text*/
123+
lv_obj_center(label);
124+
}
125+
126+
/* ------------------- demo3 ----------------------- */
127+
128+
static lv_obj_t * label;
129+
130+
static void slider_event_cb(lv_event_t * e)
131+
{
132+
lv_obj_t * slider = lv_event_get_target(e);
133+
134+
/*Refresh the text*/
135+
lv_label_set_text_fmt(label, "%d", (int)lv_slider_get_value(slider));
136+
lv_obj_align_to(label, slider, LV_ALIGN_OUT_TOP_MID, 0, -15); /*Align top of the slider*/
137+
}
138+
139+
/**
140+
* Create a slider and write its value on a label.
141+
*/
142+
static void lv_example_get_started_3(void)
143+
{
144+
/*Create a slider in the center of the display*/
145+
lv_obj_t * slider = lv_slider_create(lv_scr_act());
146+
lv_obj_set_width(slider, 200); /*Set the width*/
147+
lv_obj_center(slider); /*Align to the center of the parent (screen)*/
148+
lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL); /*Assign an event function*/
149+
150+
/*Create a label below the slider*/
151+
label = lv_label_create(lv_scr_act());
152+
lv_label_set_text(label, "0");
153+
lv_obj_align_to(label, slider, LV_ALIGN_OUT_TOP_MID, 0, -15); /*Align top of the slider*/
154+
}

0 commit comments

Comments
 (0)