提交 6fe83d4a 编写于 作者: mysterywolf's avatar mysterywolf 提交者: guo

[lvgl][stm32f407] 优化LVGL初始化流程

上级 1b4f16f7
......@@ -12,5 +12,6 @@ for d in list:
if os.path.isfile(os.path.join(path, 'SConscript')):
group = group + SConscript(os.path.join(d, 'SConscript'))
group = group + DefineGroup('LVGL-port', src, depend = ['BSP_USING_LVGL'], CPPPATH = CPPPATH)
group = group + DefineGroup('LVGL-demo', src, depend = ['BSP_USING_LVGL', 'BSP_USING_LVGL_DEMO'], CPPPATH = CPPPATH)
Return('group')
/*
* 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
* 2022-05-10 Meco Man improve rt-thread initialization process
*/
#include <lvgl.h>
void lv_user_gui_init(void)
{
/* display demo; you may replace with your LVGL application at here */
extern void lv_demo_calendar(void);
lv_demo_calendar();
}
#include <lvgl.h>
#include "lv_demo_calendar.h"
#include <board.h>
#include <drv_lcd.h>
......
#ifndef __LV_DEMO_CALENDAR_H__
#define __LV_DEMO_CALENDAR_H__
void lv_demo_calendar(void);
#endif
/*
* 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 <rtthread.h>
#include <lvgl.h>
#include <lv_port_indev.h>
#include <lv_demo_calendar.h>
#define DBG_TAG "LVGL.demo"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#ifndef LV_THREAD_STACK_SIZE
#define LV_THREAD_STACK_SIZE 4096
#endif
#ifndef LV_THREAD_PRIO
#define LV_THREAD_PRIO (RT_THREAD_PRIORITY_MAX*2/3)
#endif
static void lvgl_thread(void *parameter)
{
/*assign buttons to coordinates*/
const lv_point_t points_array[] = {{200,35},{0,0},{70,35},{0,0}};
lv_indev_set_button_points(button_indev, points_array);
/* display demo; you may replace with your LVGL application at here */
#ifdef PKG_USING_LV_MUSIC_DEMO
extern void lv_demo_music(void);
lv_demo_music();
#else
lv_demo_calendar();
#endif
/* handle the tasks of LVGL */
while(1)
{
lv_task_handler();
rt_thread_mdelay(10);
}
}
static int lvgl_demo_init(void)
{
rt_thread_t tid;
rt_device_t lcd = RT_NULL;
lcd = rt_device_find("lcd");
rt_device_init(lcd);
tid = rt_thread_create("LVGL", lvgl_thread, RT_NULL, LV_THREAD_STACK_SIZE, LV_THREAD_PRIO, 0);
if(tid == RT_NULL)
{
LOG_E("Fail to create 'LVGL' thread");
}
rt_thread_startup(tid);
return 0;
}
INIT_APP_EXPORT(lvgl_demo_init);
/*
* 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
......@@ -13,6 +13,8 @@
#include <board.h>
#include <drv_lcd.h>
lv_indev_t *touch_indev;
static lv_indev_state_t last_state = LV_INDEV_STATE_REL;
static rt_int16_t last_x = 0;
static rt_int16_t last_y = 0;
......@@ -31,8 +33,6 @@ void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state)
last_y = x;
}
lv_indev_t * button_indev;
void lv_port_indev_init(void)
{
static lv_indev_drv_t indev_drv;
......@@ -42,5 +42,5 @@ void lv_port_indev_init(void)
indev_drv.read_cb = input_read;
/*Register the driver in LVGL and save the created input device object*/
button_indev = lv_indev_drv_register(&indev_drv);
touch_indev = lv_indev_drv_register(&indev_drv);
}
/*
* 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
#include <lv_hal_indev.h>
extern lv_indev_t * button_indev;
void lv_port_indev_init(void);
void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif
......@@ -38,12 +38,12 @@ menu "Onboard Peripheral Drivers"
select BSP_USING_FMC
default n
config BSP_USING_MCU_LCD
config BSP_USING_ONBOARD_LCD
bool "Enable ATK LCD"
select BSP_USING_SRAM
default n
if BSP_USING_MCU_LCD
config BSP_USING_MCU_LCD_TEST
if BSP_USING_ONBOARD_LCD
config BSP_USING_ONBOARD_LCD_TEST
bool "Enable lcd fill test"
default y
endif
......@@ -60,11 +60,17 @@ menu "Onboard Peripheral Drivers"
config BSP_USING_LVGL
bool "Enable LVGL for LCD"
select BSP_USING_MCU_LCD
select BSP_USING_ONBOARD_LCD
select BSP_USING_TOUCH
select PKG_USING_LVGL
default n
if BSP_USING_LVGL
config BSP_USING_LVGL_DEMO
bool "Enable LVGL demo"
default n
endif
config BSP_USING_SPI_FLASH
bool "Enable SPI FLASH (W25Q128 spi1)"
select BSP_USING_SPI
......
......@@ -29,7 +29,7 @@ if GetDepend(['BSP_USING_FS']):
if GetDepend(['BSP_USING_SRAM']):
src += Glob('ports/drv_sram.c')
if GetDepend(['BSP_USING_MCU_LCD']):
if GetDepend(['BSP_USING_ONBOARD_LCD']):
src += Glob('ports/drv_lcd.c')
if GetDepend(['BSP_USING_TOUCH']):
......
......@@ -1945,7 +1945,7 @@ int drv_lcd_hw_init(void)
}
INIT_DEVICE_EXPORT(drv_lcd_hw_init);
#ifdef BSP_USING_MCU_LCD_TEST
#ifdef BSP_USING_ONBOARD_LCD_TEST
void lcd_auto_fill(void *para)
{
int num = (int)para;
......
......@@ -8,9 +8,18 @@
* 2018-02-08 Zhangyihong the first version
*/
#include <rtconfig.h>
#ifdef BSP_USING_TOUCH
#include "drv_touch.h"
#include <string.h>
#ifdef BSP_USING_TOUCH
#define DBG_ENABLE
#define DBG_SECTION_NAME "touch"
#define DBG_LEVEL DBG_INFO
#define DBG_COLOR
#include <rtdbg.h>
#ifdef PKG_USING_GUIENGINE
#include <rtgui/event.h>
#include <rtgui/rtgui_server.h>
......@@ -18,20 +27,14 @@
#include <littlevgl2rtt.h>
#elif defined(PKG_USING_LVGL)
#include <lvgl.h>
#include <lv_port_indev.h>
extern void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state);
static rt_bool_t touch_down = RT_FALSE;
#endif
#define BSP_TOUCH_SAMPLE_HZ (50)
#endif /* PKG_USING_GUIENGINE */
#define DBG_ENABLE
#define DBG_SECTION_NAME "TOUCH"
#define DBG_LEVEL DBG_INFO
#define DBG_COLOR
#include <rtdbg.h>
#define BSP_TOUCH_SAMPLE_HZ (50)
static rt_list_t driver_list;
void rt_touch_drivers_register(touch_drv_t drv)
{
rt_list_insert_before(&driver_list, &drv->list);
......@@ -44,7 +47,6 @@ static void post_down_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
emouse.parent.sender = RT_NULL;
emouse.wid = RT_NULL;
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN;
emouse.x = x;
......@@ -67,7 +69,6 @@ static void post_motion_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
emouse.parent.sender = RT_NULL;
emouse.wid = RT_NULL;
emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN;
emouse.parent.type = RTGUI_EVENT_MOUSE_MOTION;
emouse.x = x;
......@@ -79,7 +80,7 @@ static void post_motion_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
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
#endif /* PKG_USING_GUIENGINE */
}
static void post_up_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
......@@ -89,7 +90,6 @@ static void post_up_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
emouse.parent.sender = RT_NULL;
emouse.wid = RT_NULL;
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP;
emouse.x = x;
......@@ -102,7 +102,7 @@ static void post_up_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
#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
#endif /* PKG_USING_GUIENGINE */
}
static void touch_thread_entry(void *parameter)
......@@ -204,5 +204,4 @@ static int touc_bg_init(void)
}
INIT_APP_EXPORT(touc_bg_init);
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册