From fa4b7ec8fdb45e533e17283d4537d50ee4e7dbb2 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 15 Oct 2021 15:14:30 -0400 Subject: [PATCH 1/4] [stm32][bsp] The sconscript script in the application folder increases the recursion searching capability --- bsp/stm32/stm32f103-blue-pill/applications/SConscript | 11 ++++++++--- .../stm32f407-atk-explorer/applications/SConscript | 9 +++------ .../stm32l475-atk-pandora/applications/SConscript | 11 +++++++++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/bsp/stm32/stm32f103-blue-pill/applications/SConscript b/bsp/stm32/stm32f103-blue-pill/applications/SConscript index ef1c39fd83..d6acfac79f 100644 --- a/bsp/stm32/stm32f103-blue-pill/applications/SConscript +++ b/bsp/stm32/stm32f103-blue-pill/applications/SConscript @@ -1,11 +1,16 @@ -Import('RTT_ROOT') -Import('rtconfig') from building import * +import os cwd = GetCurrentDir() src = Glob('*.c') -CPPPATH = [cwd, ] +CPPPATH = [cwd] group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH) +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')) + Return('group') diff --git a/bsp/stm32/stm32f407-atk-explorer/applications/SConscript b/bsp/stm32/stm32f407-atk-explorer/applications/SConscript index d229539fc7..64381a1679 100644 --- a/bsp/stm32/stm32f407-atk-explorer/applications/SConscript +++ b/bsp/stm32/stm32f407-atk-explorer/applications/SConscript @@ -1,12 +1,9 @@ -import rtconfig -import os from building import * +import os cwd = GetCurrentDir() -CPPPATH = [cwd, str(Dir('#'))] -src = Split(""" -main.c -""") +CPPPATH = [cwd] +src = Glob('*.c') group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH) diff --git a/bsp/stm32/stm32l475-atk-pandora/applications/SConscript b/bsp/stm32/stm32l475-atk-pandora/applications/SConscript index f45bd21bc2..77d927a66b 100644 --- a/bsp/stm32/stm32l475-atk-pandora/applications/SConscript +++ b/bsp/stm32/stm32l475-atk-pandora/applications/SConscript @@ -1,6 +1,7 @@ from building import * +import os -cwd = GetCurrentDir() +cwd = GetCurrentDir() src = Split(''' main.c @@ -12,8 +13,14 @@ if GetDepend(['BSP_USING_SPI_LCD']): if GetDepend(['PKG_USING_NRF24L01']): src += ['nrf24l01_init.c'] -CPPPATH = [str(Dir('#')), cwd] +CPPPATH = [cwd] group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH) +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')) + Return('group') From 655d8dc768484917a0ae056f9d46a3ddf725a241 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 17 Oct 2021 03:45:17 -0400 Subject: [PATCH 2/4] [bsp][stm32][l475] add lcd_fill_array() --- .../board/ports/drv_lcd.c | 61 +++++++++++++++++-- .../board/ports/drv_lcd.h | 2 +- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c index 6ec90f880c..7a48c7e7e6 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c @@ -8,17 +8,17 @@ * 2018-08-14 flybreak the first version * 2018-09-18 balanceTWK add sleep mode function * 2018-09-27 ZYLX optimized display speed + * 2021-10-17 Meco Man add lcd_fill_array() */ #include #include "drv_spi.h" -#include "drv_lcd.h" +#include #include "drv_lcd_font.h" -#include "drv_gpio.h" +#include -#define DBG_SECTION_NAME "LCD" -#define DBG_COLOR -#define DBG_LEVEL DBG_LOG +#define DBG_TAG "drv.lcd" +#define DBG_LVL DBG_INFO #include #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 rt_uint32_t size = 0, size_remain = 0; rt_uint8_t *fill_buf = RT_NULL; - size = (x_end - x_start) * (y_end - y_start) * 2; + size = (x_end - x_start + 1) * (y_end - y_start + 1) * 2; if (size > LCD_CLEAR_SEND_NUMBER) { @@ -426,6 +426,55 @@ void lcd_fill(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_ui } } +/** + * full color array on the lcd. + * + * @param x_start start of x position + * @param y_start start of y position + * @param x_end end of x position + * @param y_end end of y position + * @param color Fill color array's pointer + * + * @return void + */ +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) +{ + rt_uint32_t size = 0, size_remain = 0; + + size = (x_end - x_start + 1) * (y_end - y_start + 1) * 2; + + if (size > LCD_CLEAR_SEND_NUMBER) + { + /* the number of remaining to be filled */ + size_remain = size - LCD_CLEAR_SEND_NUMBER; + size = LCD_CLEAR_SEND_NUMBER; + } + + lcd_address_set(x_start, y_start, x_end, y_end); + + /* fast fill */ + while (1) + { + rt_pin_write(LCD_DC_PIN, PIN_HIGH); + rt_spi_send(spi_dev_lcd, pcolor, size); + + /* Fill completed */ + if (size_remain == 0) + break; + + /* calculate the number of fill next time */ + if (size_remain > LCD_CLEAR_SEND_NUMBER) + { + size_remain = size_remain - LCD_CLEAR_SEND_NUMBER; + } + else + { + size = size_remain; + size_remain = 0; + } + } +} + /** * display a line on the lcd. * diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.h b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.h index 394305012e..021c010f20 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.h +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.h @@ -50,7 +50,7 @@ void lcd_draw_circle(rt_uint16_t x0, rt_uint16_t y0, rt_uint8_t r); void lcd_draw_line(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2); void lcd_draw_rectangle(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2); 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); - +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); void lcd_show_num(rt_uint16_t x, rt_uint16_t y, rt_uint32_t num, rt_uint8_t len, rt_uint32_t size); rt_err_t lcd_show_string(rt_uint16_t x, rt_uint16_t y, rt_uint32_t size, const char *fmt, ...); 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); From ff4e819dfd41a8ba5ad32a20a726350de0fa4619 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 17 Oct 2021 12:01:29 -0400 Subject: [PATCH 3/4] [stm32][l745] add lvgl demo --- .../applications/lvgl_demo.c | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 bsp/stm32/stm32l475-atk-pandora/applications/lvgl_demo.c diff --git a/bsp/stm32/stm32l475-atk-pandora/applications/lvgl_demo.c b/bsp/stm32/stm32l475-atk-pandora/applications/lvgl_demo.c new file mode 100644 index 0000000000..a9de28b40a --- /dev/null +++ b/bsp/stm32/stm32l475-atk-pandora/applications/lvgl_demo.c @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-10-17 Meco Man First version + */ + +#include +#include +#include +#define DBG_TAG "LVGL" +#define DBG_LVL DBG_INFO +#include + +#ifndef LV_THREAD_STACK_SIZE +#define LV_THREAD_STACK_SIZE 2048 +#endif + +#ifndef LV_THREAD_PRIO +#define LV_THREAD_PRIO (RT_THREAD_PRIORITY_MAX*2/3) +#endif + +static void lv_example_get_started_1(void); +static void lv_example_get_started_3(void); + +#define MY_DISP_HOR_RES 240 /* 240*240 */ + +/*A static or global variable to store the buffers*/ +static lv_disp_draw_buf_t disp_buf; + +/*Static or global buffer(s). The second buffer is optional*/ +static lv_color_t buf_1[MY_DISP_HOR_RES * 10]; +static lv_color_t buf_2[MY_DISP_HOR_RES * 10]; + +static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/ + +/*Flush the content of the internal buffer the specific area on the display + *You can use DMA or any hardware acceleration to do this operation in the background but + *'lv_disp_flush_ready()' has to be called when finished.*/ +static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) +{ + lcd_fill_array(area->x1, area->y1, area->x2, area->y2, color_p); + + /*IMPORTANT!!! + *Inform the graphics library that you are ready with the flushing*/ + lv_disp_flush_ready(disp_drv); +} + +static void lvgl_thread(void *parameter) +{ + lv_init(); + + /*Initialize `disp_buf` with the buffer(s). With only one buffer use NULL instead buf_2 */ + lv_disp_draw_buf_init(&disp_buf, buf_1, buf_2, MY_DISP_HOR_RES*10); + + lv_disp_drv_init(&disp_drv); /*Basic initialization*/ + + /*Set the resolution of the display*/ + disp_drv.hor_res = MY_DISP_HOR_RES; + disp_drv.ver_res = MY_DISP_HOR_RES; + + /*Set a display buffer*/ + disp_drv.draw_buf = &disp_buf; + + /*Used to copy the buffer's content to the display*/ + disp_drv.flush_cb = disp_flush; + + /*Finally register the driver*/ + lv_disp_drv_register(&disp_drv); + + lv_example_get_started_1(); + lv_example_get_started_3(); + + while(1) + { + lv_task_handler(); + rt_thread_mdelay(10); + } +} + +static int lvgl_demo_init(void) +{ + rt_thread_t tid; + + tid = rt_thread_create("lvgl", lvgl_thread, RT_NULL, LV_THREAD_STACK_SIZE, LV_THREAD_PRIO, 0); + rt_thread_startup(tid); + + return 0; +} +INIT_COMPONENT_EXPORT(lvgl_demo_init); + +/* ------------------- demo1 ----------------------- */ + +static void btn_event_cb(lv_event_t * e) +{ + lv_event_code_t code = lv_event_get_code(e); + lv_obj_t * btn = lv_event_get_target(e); + if(code == LV_EVENT_CLICKED) { + static uint8_t cnt = 0; + cnt++; + + /*Get the first child of the button which is the label and change its text*/ + lv_obj_t * label = lv_obj_get_child(btn, 0); + lv_label_set_text_fmt(label, "Button: %d", cnt); + } +} + +/** + * Create a button with a label and react on click event. + */ +static void lv_example_get_started_1(void) +{ + lv_obj_t * btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/ + lv_obj_set_pos(btn, 10, 10); /*Set its position*/ + lv_obj_set_size(btn, 120, 50); /*Set its size*/ + lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); /*Assign a callback to the button*/ + + lv_obj_t * label = lv_label_create(btn); /*Add a label to the button*/ + lv_label_set_text(label, "Button"); /*Set the labels text*/ + lv_obj_center(label); +} + +/* ------------------- demo3 ----------------------- */ + +static lv_obj_t * label; + +static void slider_event_cb(lv_event_t * e) +{ + lv_obj_t * slider = lv_event_get_target(e); + + /*Refresh the text*/ + lv_label_set_text_fmt(label, "%d", (int)lv_slider_get_value(slider)); + lv_obj_align_to(label, slider, LV_ALIGN_OUT_TOP_MID, 0, -15); /*Align top of the slider*/ +} + +/** + * Create a slider and write its value on a label. + */ +static void lv_example_get_started_3(void) +{ + /*Create a slider in the center of the display*/ + lv_obj_t * slider = lv_slider_create(lv_scr_act()); + lv_obj_set_width(slider, 200); /*Set the width*/ + lv_obj_center(slider); /*Align to the center of the parent (screen)*/ + lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL); /*Assign an event function*/ + + /*Create a label below the slider*/ + label = lv_label_create(lv_scr_act()); + lv_label_set_text(label, "0"); + lv_obj_align_to(label, slider, LV_ALIGN_OUT_TOP_MID, 0, -15); /*Align top of the slider*/ +} From d4991d9d501019d3bdb7c5cdcc7f00ee6f947d13 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 18 Oct 2021 14:09:03 -0400 Subject: [PATCH 4/4] [l475] port for LVGL --- .../applications/SConscript | 2 +- .../applications/lcd_sample.c | 3 --- bsp/stm32/stm32l475-atk-pandora/board/Kconfig | 12 ++++++++++++ .../board/ports/lvgl/SConscript | 9 +++++++++ .../board/ports/lvgl/lv_conf.h | 16 ++++++++++++++++ .../ports/lvgl}/lvgl_demo.c | 0 6 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/SConscript create mode 100644 bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_conf.h rename bsp/stm32/stm32l475-atk-pandora/{applications => board/ports/lvgl}/lvgl_demo.c (100%) diff --git a/bsp/stm32/stm32l475-atk-pandora/applications/SConscript b/bsp/stm32/stm32l475-atk-pandora/applications/SConscript index 77d927a66b..e87f545100 100644 --- a/bsp/stm32/stm32l475-atk-pandora/applications/SConscript +++ b/bsp/stm32/stm32l475-atk-pandora/applications/SConscript @@ -7,7 +7,7 @@ src = Split(''' main.c ''') -if GetDepend(['BSP_USING_SPI_LCD']): +if GetDepend(['BSP_USING_LCD_SAMPLE']): src += ['lcd_sample.c'] if GetDepend(['PKG_USING_NRF24L01']): diff --git a/bsp/stm32/stm32l475-atk-pandora/applications/lcd_sample.c b/bsp/stm32/stm32l475-atk-pandora/applications/lcd_sample.c index a89c5e0b9c..54d440f7f3 100644 --- a/bsp/stm32/stm32l475-atk-pandora/applications/lcd_sample.c +++ b/bsp/stm32/stm32l475-atk-pandora/applications/lcd_sample.c @@ -11,8 +11,6 @@ #include #include #include - -#ifdef BSP_USING_SPI_LCD #include #include @@ -45,4 +43,3 @@ static int lcd_sample(void) return RT_EOK; } INIT_APP_EXPORT(lcd_sample); -#endif /* BSP_USING_SPI_LCD */ diff --git a/bsp/stm32/stm32l475-atk-pandora/board/Kconfig b/bsp/stm32/stm32l475-atk-pandora/board/Kconfig index e8a0713647..48fa68dd15 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/Kconfig +++ b/bsp/stm32/stm32l475-atk-pandora/board/Kconfig @@ -35,6 +35,18 @@ menu "Onboard Peripheral Drivers" select BSP_USING_SPI3 default n + config BSP_USING_LCD_SAMPLE + bool "Enable LCD sample" + depends on BSP_USING_SPI_LCD + depends on !BSP_USING_LVGL + default n + + config BSP_USING_LVGL + bool "Enable LVGL for LCD" + select BSP_USING_SPI_LCD + select PKG_USING_LVGL + default n + config BSP_USING_SDCARD bool "Enable SDCARD (spi1)" select BSP_USING_SPI diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/SConscript b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/SConscript new file mode 100644 index 0000000000..63fbfd3933 --- /dev/null +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/SConscript @@ -0,0 +1,9 @@ +from building import * + +cwd = GetCurrentDir() + +src = Glob('*.c') +CPPPATH = [cwd] + +group = DefineGroup('LVGL', src, depend = ['BSP_USING_LVGL'], CPPPATH = CPPPATH) +Return('group') diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_conf.h b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_conf.h new file mode 100644 index 0000000000..c3ff474e58 --- /dev/null +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_conf.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-10-18 Meco Man First version + */ + +#ifndef LV_CONF_H +#define LV_CONF_H + +#define LV_COLOR_16_SWAP 1 + +#endif diff --git a/bsp/stm32/stm32l475-atk-pandora/applications/lvgl_demo.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lvgl_demo.c similarity index 100% rename from bsp/stm32/stm32l475-atk-pandora/applications/lvgl_demo.c rename to bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lvgl_demo.c