Skip to content

Commit 8e50ef5

Browse files
liuxianliangBernardXiong
authored andcommitted
[add] proting 'lvgl' for stm32f407-atk-explorer.
1 parent 8ab54c3 commit 8e50ef5

File tree

21 files changed

+3021
-75
lines changed

21 files changed

+3021
-75
lines changed

bsp/stm32/stm32f407-atk-explorer/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
| COM3 | 支持 | |
4545
| MPU6050 | 支持 | |
4646
| Flash | 支持 | |
47-
| SRAM | 支持 | |
47+
| SRAM | 支持 | LVGL 会使用到,但此时不能启用 RT_USING_MEMHEAP_AS_HEAP 内存算法 |
48+
| TFTLCD | 支持 | F407 不带 LTDC 外设,所以需要使用 MCU LCD,而不能直接驱动 RGB 屏幕 |
49+
| LCD-TOUCH | 支持 | 仅测试过 GT9147, 其他触摸驱动需要添加适配 |
4850
| SD卡 | 支持 | 支持FATFS文件系统 |
4951
| W25Q128 | 支持 | 支持LittleFS文件系统 |
5052
| 以太网 | 支持 | |
@@ -53,7 +55,7 @@
5355
| GPIO | 支持 | PA0, PA1... PH1 ---> PIN: 0, 1...144 |
5456
| UART | 支持 | UART1/2/3 |
5557
| SPI | 支持 | SPI1/2/3 |
56-
| I2C | 支持 | 软件 I2C |
58+
| I2C | 支持 | 软件 I2C1, I2C2[仅触摸屏使用] |
5759
| ADC | 支持 | |
5860
| RTC | 支持 | 支持外部晶振和内部低速时钟 |
5961
| WDT | 支持 | |
@@ -129,4 +131,4 @@ msh >
129131

130132
维护人:
131133

132-
- [guozhanxin](https://github.com/Guozhanxin)
134+
- [guozhanxin](https://github.com/Guozhanxin)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from building import *
2+
import os
3+
4+
cwd = GetCurrentDir()
5+
group = []
6+
src = Glob('*.c')
7+
CPPPATH = [cwd]
8+
9+
list = os.listdir(cwd)
10+
for d in list:
11+
path = os.path.join(cwd, d)
12+
if os.path.isfile(os.path.join(path, 'SConscript')):
13+
group = group + SConscript(os.path.join(d, 'SConscript'))
14+
15+
group += DefineGroup('LVGL-port', src, depend = ['PKG_USING_LVGL'], CPPPATH = CPPPATH)
16+
Return('group')
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from building import *
2+
import os
3+
4+
cwd = GetCurrentDir()
5+
group = []
6+
src = Glob('*.c')
7+
CPPPATH = [cwd]
8+
9+
list = os.listdir(cwd)
10+
for d in list:
11+
path = os.path.join(cwd, d)
12+
if os.path.isfile(os.path.join(path, 'SConscript')):
13+
group = group + SConscript(os.path.join(d, 'SConscript'))
14+
15+
group += DefineGroup('LVGL-port', src, depend = ['PKG_USING_LVGL'], CPPPATH = CPPPATH)
16+
Return('group')
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <lvgl.h>
2+
#include "lv_demo_calendar.h"
3+
#include <board.h>
4+
#include <drv_lcd.h>
5+
6+
static void event_handler(lv_event_t * e)
7+
{
8+
lv_event_code_t code = lv_event_get_code(e);
9+
lv_obj_t * obj = lv_event_get_current_target(e);
10+
11+
if(code == LV_EVENT_VALUE_CHANGED) {
12+
lv_calendar_date_t date;
13+
if(lv_calendar_get_pressed_date(obj, &date)) {
14+
LV_LOG_USER("Clicked date: %02d.%02d.%d", date.day, date.month, date.year);
15+
}
16+
}
17+
}
18+
19+
void lv_demo_calendar(void)
20+
{
21+
lv_obj_t * calendar = lv_calendar_create(lv_scr_act());
22+
lv_obj_set_size(calendar, LCD_W, LCD_H);
23+
lv_obj_align(calendar, LV_ALIGN_CENTER, 0, 0);
24+
lv_obj_add_event_cb(calendar, event_handler, LV_EVENT_ALL, NULL);
25+
26+
lv_calendar_set_today_date(calendar, 2021, 02, 23);
27+
lv_calendar_set_showed_date(calendar, 2021, 02);
28+
29+
/*Highlight a few days*/
30+
static lv_calendar_date_t highlighted_days[3]; /*Only its pointer will be saved so should be static*/
31+
highlighted_days[0].year = 2021;
32+
highlighted_days[0].month = 02;
33+
highlighted_days[0].day = 6;
34+
35+
highlighted_days[1].year = 2021;
36+
highlighted_days[1].month = 02;
37+
highlighted_days[1].day = 11;
38+
39+
highlighted_days[2].year = 2022;
40+
highlighted_days[2].month = 02;
41+
highlighted_days[2].day = 22;
42+
43+
lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3);
44+
45+
#if LV_USE_CALENDAR_HEADER_DROPDOWN
46+
lv_calendar_header_dropdown_create(calendar);
47+
#elif LV_USE_CALENDAR_HEADER_ARROW
48+
lv_calendar_header_arrow_create(calendar);
49+
#endif
50+
lv_calendar_set_showed_date(calendar, 2021, 10);
51+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef __LV_DEMO_CALENDAR_H__
2+
#define __LV_DEMO_CALENDAR_H__
3+
4+
void lv_demo_calendar(void);
5+
6+
#endif
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 0
15+
#define LV_COLOR_DEPTH 16
16+
#define LV_USE_PERF_MONITOR 1
17+
18+
#include <rtconfig.h>
19+
#define LV_HOR_RES_MAX 800
20+
#define LV_VER_RES_MAX 480
21+
#define LV_USE_DEMO_RTT_MUSIC 1
22+
#define LV_DEMO_RTT_MUSIC_AUTO_PLAY 1
23+
#define LV_FONT_MONTSERRAT_12 1
24+
#define LV_FONT_MONTSERRAT_16 1
25+
26+
#endif
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
#include <rtthread.h>
11+
#include <lvgl.h>
12+
#include <lv_port_indev.h>
13+
#include <lv_demo_calendar.h>
14+
#define DBG_TAG "LVGL.demo"
15+
#define DBG_LVL DBG_INFO
16+
#include <rtdbg.h>
17+
18+
#ifndef LV_THREAD_STACK_SIZE
19+
#define LV_THREAD_STACK_SIZE 4096
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 lvgl_thread(void *parameter)
27+
{
28+
/*assign buttons to coordinates*/
29+
const lv_point_t points_array[] = {{200,35},{0,0},{70,35},{0,0}};
30+
lv_indev_set_button_points(button_indev, points_array);
31+
32+
/* display demo; you may replace with your LVGL application at here */
33+
#ifdef PKG_USING_LV_MUSIC_DEMO
34+
extern void lv_demo_music(void);
35+
lv_demo_music();
36+
#else
37+
lv_demo_calendar();
38+
#endif
39+
40+
/* handle the tasks of LVGL */
41+
while(1)
42+
{
43+
lv_task_handler();
44+
rt_thread_mdelay(10);
45+
}
46+
}
47+
48+
static int lvgl_demo_init(void)
49+
{
50+
rt_thread_t tid;
51+
rt_device_t lcd = RT_NULL;
52+
53+
lcd = rt_device_find("lcd");
54+
rt_device_init(lcd);
55+
56+
tid = rt_thread_create("LVGL", lvgl_thread, RT_NULL, LV_THREAD_STACK_SIZE, LV_THREAD_PRIO, 0);
57+
if(tid == RT_NULL)
58+
{
59+
LOG_E("Fail to create 'LVGL' thread");
60+
}
61+
rt_thread_startup(tid);
62+
63+
return 0;
64+
}
65+
INIT_APP_EXPORT(lvgl_demo_init);
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 The first version
9+
*/
10+
#include <lvgl.h>
11+
#include <board.h>
12+
#include <drv_lcd.h>
13+
14+
// #define MY_DISP_HOR_RES LCD_W
15+
// #define DISP_BUFFER_LINES 70
16+
17+
/*A static or global variable to store the buffers*/
18+
static lv_disp_draw_buf_t disp_buf;
19+
20+
/*Descriptor of a display driver*/
21+
static lv_disp_drv_t disp_drv;
22+
23+
/*Static or global buffer(s). The second buffer is optional*/
24+
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
25+
#pragma location=0x68000000
26+
lv_color_t buf_1[LCD_H * LCD_W];
27+
#elif defined ( __CC_ARM ) /* MDK ARM Compiler */
28+
__attribute__((at(0x68000000))) lv_color_t buf_1[LCD_H * LCD_W];
29+
#elif defined ( __CLANG_ARM ) /* MDK ARM Compiler v6 */
30+
__attribute__((section(".ARM.__at_0x68000000"))) lv_color_t buf_1[LCD_H * LCD_W];
31+
#elif defined ( __GNUC__ ) /* GNU Compiler */
32+
lv_color_t buf_1[LCD_H * LCD_W] __attribute__((section(".MCUlcdgrambysram")));
33+
#ifdef RT_USING_MEMHEAP_AS_HEAP
34+
#error "You should modify this logic, such as use 'rt_malloc' to create lvgl buf"
35+
#endif
36+
#endif
37+
38+
/*Flush the content of the internal buffer the specific area on the display
39+
*You can use DMA or any hardware acceleration to do this operation in the background but
40+
*'lv_disp_flush_ready()' has to be called when finished.*/
41+
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
42+
{
43+
/* color_p is a buffer pointer; the buffer is provided by LVGL */
44+
lcd_fill_array(area->x1, area->y1, area->x2, area->y2, color_p);
45+
46+
/*IMPORTANT!!!
47+
*Inform the graphics library that you are ready with the flushing*/
48+
lv_disp_flush_ready(disp_drv);
49+
}
50+
51+
void lv_port_disp_init(void)
52+
{
53+
/*Initialize `disp_buf` with the buffer(s). With only one buffer use NULL instead buf_2 */
54+
lv_disp_draw_buf_init(&disp_buf, buf_1, NULL, LCD_H * LCD_W);
55+
56+
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
57+
58+
/*Set the resolution of the display*/
59+
disp_drv.hor_res = LCD_W;
60+
disp_drv.ver_res = LCD_H;
61+
62+
/*Set a display buffer*/
63+
disp_drv.draw_buf = &disp_buf;
64+
65+
/*Used to copy the buffer's content to the display*/
66+
disp_drv.flush_cb = disp_flush;
67+
68+
/*Finally register the driver*/
69+
lv_disp_drv_register(&disp_drv);
70+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 The first version
9+
*/
10+
#ifndef LV_PORT_DISP_H
11+
#define LV_PORT_DISP_H
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
void lv_port_disp_init(void);
18+
19+
#ifdef __cplusplus
20+
} /*extern "C"*/
21+
#endif
22+
23+
#endif
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 The first version
9+
*/
10+
#include <lvgl.h>
11+
#include <stdbool.h>
12+
#include <rtdevice.h>
13+
#include <board.h>
14+
#include <drv_lcd.h>
15+
16+
static lv_indev_state_t last_state = LV_INDEV_STATE_REL;
17+
static rt_int16_t last_x = 0;
18+
static rt_int16_t last_y = 0;
19+
20+
static void input_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
21+
{
22+
data->point.x = last_x;
23+
data->point.y = last_y;
24+
data->state = last_state;
25+
}
26+
27+
void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state)
28+
{
29+
last_state = state;
30+
last_x = LCD_W - y;
31+
last_y = x;
32+
}
33+
34+
lv_indev_t * button_indev;
35+
36+
void lv_port_indev_init(void)
37+
{
38+
static lv_indev_drv_t indev_drv;
39+
40+
lv_indev_drv_init(&indev_drv); /*Basic initialization*/
41+
indev_drv.type = LV_INDEV_TYPE_POINTER;
42+
indev_drv.read_cb = input_read;
43+
44+
/*Register the driver in LVGL and save the created input device object*/
45+
button_indev = lv_indev_drv_register(&indev_drv);
46+
}

0 commit comments

Comments
 (0)