From a70eb5604c08d5bd0ebe0f79ec773ef879c809e9 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 22 Oct 2021 01:38:09 -0400 Subject: [stm32l475] upgrade lvgl porting --- .../board/ports/lvgl/SConscript | 2 +- .../board/ports/lvgl/lv_demo.c | 107 ++++++++++++++ .../board/ports/lvgl/lv_port_disp.c | 55 ++++++++ .../board/ports/lvgl/lv_port_disp.h | 23 +++ .../board/ports/lvgl/lv_port_indev.c | 14 ++ .../board/ports/lvgl/lv_port_indev.h | 23 +++ .../board/ports/lvgl/lvgl_demo.c | 154 --------------------- 7 files changed, 223 insertions(+), 155 deletions(-) create mode 100644 bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_demo.c create mode 100644 bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_disp.c create mode 100644 bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_disp.h create mode 100644 bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_indev.c create mode 100644 bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_indev.h delete mode 100644 bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lvgl_demo.c diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/SConscript b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/SConscript index 63fbfd3933..cb74975f39 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/SConscript +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/SConscript @@ -5,5 +5,5 @@ cwd = GetCurrentDir() src = Glob('*.c') CPPPATH = [cwd] -group = DefineGroup('LVGL', src, depend = ['BSP_USING_LVGL'], CPPPATH = CPPPATH) +group = DefineGroup('LVGL-port', src, depend = ['BSP_USING_LVGL'], CPPPATH = CPPPATH) Return('group') diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_demo.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_demo.c new file mode 100644 index 0000000000..5abb7d0c7a --- /dev/null +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_demo.c @@ -0,0 +1,107 @@ +/* + * 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 + +#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); + +static void lvgl_thread(void *parameter) +{ + 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_APP_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*/ +} diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_disp.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_disp.c new file mode 100644 index 0000000000..ccc64a162d --- /dev/null +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_disp.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-10-18 Meco Man The first version + */ +#include +#include + +#define MY_DISP_HOR_RES LCD_W + +/*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 * LCD_W /5]; +static lv_color_t buf_2[MY_DISP_HOR_RES * LCD_W /5]; + +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); +} + +void lv_port_disp_init(void) +{ + /*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); +} diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_disp.h b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_disp.h new file mode 100644 index 0000000000..ef39eb03cd --- /dev/null +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_disp.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-10-18 Meco Man The first version + */ +#ifndef LV_PORT_DISP_H +#define LV_PORT_DISP_H + +#ifdef __cplusplus +extern "C" { +#endif + +void lv_port_disp_init(void); + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_indev.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_indev.c new file mode 100644 index 0000000000..8c024c5a14 --- /dev/null +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_indev.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-10-18 Meco Man The first version + */ + +void lv_port_indev_init(void) +{ + +} diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_indev.h b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_indev.h new file mode 100644 index 0000000000..7599bb899d --- /dev/null +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_indev.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-10-18 Meco Man The first version + */ +#ifndef LV_PORT_INDEV_H +#define LV_PORT_INDEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +void lv_port_indev_init(void); + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lvgl_demo.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lvgl_demo.c deleted file mode 100644 index a9de28b40a..0000000000 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lvgl_demo.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * 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*/ -} -- cgit v1.3.1