Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
u010088926
rt-thread
提交
7cba0ea9
R
rt-thread
项目概览
u010088926
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7cba0ea9
编写于
10月 22, 2021
作者:
mysterywolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[lvgl][stm32l475] implement lvgl input driver
上级
07467724
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
125 addition
and
67 deletion
+125
-67
bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_demo.c
bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_demo.c
+33
-65
bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_disp.c
...m32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_disp.c
+2
-2
bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_indev.c
...32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_indev.c
+86
-0
bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_indev.h
...32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_indev.h
+4
-0
未找到文件。
bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_demo.c
浏览文件 @
7cba0ea9
...
...
@@ -7,46 +7,22 @@
* Date Author Notes
* 2021-10-17 Meco Man First version
*/
#include <rtthread.h>
#include <lvgl.h>
#define DBG_TAG "LVGL"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#include <lv_port_indev.h>
#ifndef LV_THREAD_STACK_SIZE
#define LV_THREAD_STACK_SIZE
2048
#define LV_THREAD_STACK_SIZE
4096
#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
);
...
...
@@ -57,51 +33,43 @@ static void btn_event_cb(lv_event_t * e)
/*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
);
lv_label_set_text_fmt
(
label
,
"
WK_UP
: %d"
,
cnt
);
}
}
/**
* Create a button with a label and react on click event.
*/
static
void
lv_example_get_started_1
(
void
)
static
void
lvgl_thread
(
void
*
parameter
)
{
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*/
/*assign buttons to coordinates*/
const
lv_point_t
points_array
[]
=
{{
0
,
0
},{
0
,
0
},{
0
,
0
},{
70
,
35
}};
lv_indev_set_button_points
(
button_indev
,
points_array
);
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_t
*
label
=
lv_label_create
(
btn
);
/*Add a label to the button*/
lv_label_set_text
(
label
,
"
WK_UP: 0"
);
/*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*/
while
(
1
)
{
lv_task_handler
();
rt_thread_mdelay
(
10
);
}
}
/**
* Create a slider and write its value on a label.
*/
static
void
lv_example_get_started_3
(
void
)
static
int
lvgl_demo_init
(
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*/
rt_thread_t
tid
;
/*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*/
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
);
bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_disp.c
浏览文件 @
7cba0ea9
...
...
@@ -16,8 +16,8 @@
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_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*/
...
...
bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_indev.c
浏览文件 @
7cba0ea9
...
...
@@ -7,8 +7,94 @@
* Date Author Notes
* 2021-10-18 Meco Man The first version
*/
#include <lvgl.h>
#include <stdbool.h>
#include <rtdevice.h>
#include <drv_gpio.h>
#define BUTTON0_PIN GET_PIN(D, 10)
#define BUTTON1_PIN GET_PIN(D, 9)
#define BUTTON2_PIN GET_PIN(D, 8)
#define BUTTON_WKUP_PIN GET_PIN(C, 13)
/*Test if `id` button is pressed or not*/
static
bool
button_is_pressed
(
uint8_t
id
)
{
switch
(
id
)
{
case
0
:
if
(
rt_pin_read
(
BUTTON0_PIN
)
==
PIN_LOW
)
return
true
;
break
;
case
1
:
if
(
rt_pin_read
(
BUTTON1_PIN
)
==
PIN_LOW
)
return
true
;
break
;
case
2
:
if
(
rt_pin_read
(
BUTTON2_PIN
)
==
PIN_LOW
)
return
true
;
break
;
case
3
:
if
(
rt_pin_read
(
BUTTON_WKUP_PIN
)
==
PIN_HIGH
)
return
true
;
break
;
}
return
false
;
}
static
int8_t
button_get_pressed_id
(
void
)
{
uint8_t
i
;
/*Check to buttons see which is being pressed*/
for
(
i
=
0
;
i
<
4
;
i
++
)
{
/*Return the pressed button's ID*/
if
(
button_is_pressed
(
i
))
{
return
i
;
}
}
/*No button pressed*/
return
-
1
;
}
void
button_read
(
lv_indev_drv_t
*
drv
,
lv_indev_data_t
*
data
)
{
static
uint32_t
last_btn
=
0
;
/*Store the last pressed button*/
int
btn_pr
=
button_get_pressed_id
();
/*Get the ID (0,1,2...) of the pressed button*/
if
(
btn_pr
>=
0
)
{
/*Is there a button press? (E.g. -1 indicated no button was pressed)*/
last_btn
=
btn_pr
;
/*Save the ID of the pressed button*/
data
->
state
=
LV_INDEV_STATE_PRESSED
;
/*Set the pressed state*/
}
else
{
data
->
state
=
LV_INDEV_STATE_RELEASED
;
/*Set the released state*/
}
data
->
btn_id
=
last_btn
;
/*Save the last button*/
}
lv_indev_t
*
button_indev
;
void
lv_port_indev_init
(
void
)
{
static
lv_indev_drv_t
indev_drv
;
/* Initialize the on-board buttons */
rt_pin_mode
(
BUTTON0_PIN
,
PIN_MODE_INPUT
);
rt_pin_mode
(
BUTTON1_PIN
,
PIN_MODE_INPUT
);
rt_pin_mode
(
BUTTON2_PIN
,
PIN_MODE_INPUT
);
rt_pin_mode
(
BUTTON_WKUP_PIN
,
PIN_MODE_INPUT
);
lv_indev_drv_init
(
&
indev_drv
);
/*Basic initialization*/
indev_drv
.
type
=
LV_INDEV_TYPE_BUTTON
;
indev_drv
.
read_cb
=
button_read
;
/*Register the driver in LVGL and save the created input device object*/
button_indev
=
lv_indev_drv_register
(
&
indev_drv
);
}
bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_port_indev.h
浏览文件 @
7cba0ea9
...
...
@@ -14,6 +14,10 @@
extern
"C"
{
#endif
#include <lv_hal_indev.h>
extern
lv_indev_t
*
button_indev
;
void
lv_port_indev_init
(
void
);
#ifdef __cplusplus
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录