Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ tag: workflow
path: .github
owners: supper thomas(supperthomas)<78900636@qq.com>, Bingru Zhang(Rbb666)<751061401@qq.com>, Yuqiang Wang(kurisaW)<2053731441@qq.com>

tag: gd32470z-lckfb-lcd
path: bsp/gd32/arm/gd32470z-lckfb/board/ports
owners: Wu Ying Xiang(godmial)<2633967641@qq.com>
2 changes: 1 addition & 1 deletion bsp/gd32/arm/gd32470z-lckfb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ GD32470Z-LCKFB梁山派是立创开发板推出的一款GD32F470系列的开发
| GPIO | 支持 | PA0, PA1... ---> PIN: 0, 1...113 |
| UART | 支持 | UART0 - UART7 |
| **扩展模块** | **支持情况** | **备注** |
| 暂无 | 暂不支持 | 暂不支持 |
| LCD+触摸屏 | 支持 | 暂不支持中文显示(因 Keil5 编码限制),使用方法请查看bsp\gd32\arm\gd32470z-lckfb\board\ports\README.md |

## 使用说明

Expand Down
3 changes: 3 additions & 0 deletions bsp/gd32/arm/gd32470z-lckfb/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@ objs.extend(SConscript(os.path.join(libraries_path_prefix, gd32_library, 'SConsc
# include drivers
objs.extend(SConscript(os.path.join(libraries_path_prefix, 'gd32_drivers', 'SConscript')))

# include lcd and drivers
objs.extend(SConscript(os.path.join(RTT_ROOT, 'bsp', 'gd32', 'arm', 'gd32470z-lckfb', 'board', 'ports', 'SConscript')))

# make a building
DoBuilding(TARGET, objs)
31 changes: 31 additions & 0 deletions bsp/gd32/arm/gd32470z-lckfb/board/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,37 @@ endmenu

menu "Board extended module Drivers"

menuconfig BSP_USING_LCD
bool "Enable LCD"
select RT_USING_LCD
default n
if BSP_USING_LCD

config BSP_USING_TLI
bool "Enable TLI"
default y

config BSP_USING_SDRAM
bool "Enable SDRAM"
select RT_USING_SDRAM
default y

config BSP_USING_TOUCH
bool "Enable TOUCH"
select RT_USING_TOUCH
default n

config BSP_USING_GPU
bool "Enable GPU"
select RT_USING_GPU
default y

config BSP_USING_DRAW_PANEL_EXAMPLE
bool "Enable DRAW PANEL EXAMPLE"
select RT_USING_DRAW_PANEL_EXAMPLE
default n
endif

endmenu

endmenu
44 changes: 44 additions & 0 deletions bsp/gd32/arm/gd32470z-lckfb/board/ports/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#### 1. 简介

用于 GD32F470 立创开发板配套 RGB LCD 屏幕的驱动,支持触摸。

> **原作者:LCKFB**
> 本驱动最初由 LCKFB 开发,由 godmial 移植到本BSP。

#### 2. 在 ENV 中的开启
ps:建议全部开启
```
Hardware Drivers Config --->
Board extended module Drivers --->
Enable LCD --->
- [*]Enable TLI
- [*]Enable SDRAM
- [*]Enable TOUCH
- [*]Enable GPU
- [*]Enable DRAW PANEL EXAMPLE
```

#### 3. 注意事项

1. 如果屏幕出现刷新抖动,触摸屏出现连点的情况,可以尝试在 `libraries\GD32F4xx_Firmware_Library\CMSIS\GD\GD32F4xx\Source\system_gd32f4xx.c` 将时钟值修改为
`#define __SYSTEM_CLOCK_240M_PLL_25M_HXTAL (uint32_t)(240000000)`
然后重新编译即可

2. 由于代码格式审查原因,本驱动未包含中文显示函数。但可直接移植官方源码中的中文显示函数进行使用。

3. 为避免 `scons` 命令编译不通过,代码使用了如下代码段以适配不同编译器:
```
#if defined(__CC_ARM) || defined(__ARMCC_VERSION)
// Keil MDK
uint16_t ltdc_lcd_framebuf0[800][480] __attribute__((at(LCD_FRAME_BUF_ADDR)));
#elif defined(__GNUC__)
// GCC (RT-Thread)
uint16_t ltdc_lcd_framebuf0[10][10]; // 此行为避免 scons 编译错误而添加
#endif



#### 4. 联系方式

- 维护:godmial
- 主页:<https://github.com/godmial>
25 changes: 25 additions & 0 deletions bsp/gd32/arm/gd32470z-lckfb/board/ports/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Import('RTT_ROOT')
Import('rtconfig')
from building import *

cwd = GetCurrentDir()

# add the general drivers.
src = Split("""
""")

# add lcd drivers.
if GetDepend('BSP_USING_LCD'):
src += ['drv_lcd.c']

if GetDepend('BSP_USING_TOUCH'):
src += ['drv_touch.c']

if GetDepend('BSP_USING_DRAW_PANEL_EXAMPLE'):
src += ['draw_panel.c']

path = [cwd]

group = DefineGroup('Applications', src, depend = [''], CPPPATH = path)

Return('group')
187 changes: 187 additions & 0 deletions bsp/gd32/arm/gd32470z-lckfb/board/ports/draw_panel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*
* Copyright (c) 2006-2025, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2025-05-23 godmial Refactor to conform to RT-Thread coding style.
*/

#include <board.h>
#include <rthw.h>
#include <rtthread.h>
#include "drv_lcd.h"
#include "drv_touch.h"

#define COLOR_MAX 14

/* Maximum magnification of pixels */
#define PIXEL_SIZE_MAX 20

typedef struct button_struct
{
uint16_t x;
uint16_t y;
uint16_t w;
uint16_t h;
uint16_t color;
uint16_t value;
} widget_object_t;

uint16_t color_buf[COLOR_MAX] = {GRAYBLUE, BLACK, BLUE, BRED, GRED, GBLUE, RED, MAGENTA, GREEN, YELLOW, CYAN, BROWN, BRRED, GRAY};
widget_object_t button_clear, button_color, button_pixel, button_eraser;


/**
* @brief Initialize a widget button with given properties.
*
* @param obj Pointer to the widget object.
* @param x X coordinate of the top-left corner.
* @param y Y coordinate of the top-left corner.
* @param w Width of the widget.
* @param h Height of the widget.
* @param color Color value of the widget.
* @param value Initial value of the widget.
*
* @return None.
*/
void widget_object_init(widget_object_t *obj, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color, uint16_t value)
{
obj->x = x;
obj->y = y;
obj->h = h;
obj->w = w;
obj->color = color;
obj->value = value;
}


/**
* @brief Initialize and display the user interface.
*
* This function draws the control buttons for clear, color,
* pixel size, and eraser on the screen.
*
* @return None.
*/
void ui_init(void)
{
char temp_buf[20] = {0};

tli_show_button(button_clear.x, button_clear.y, button_clear.w, button_clear.h, 12, button_clear.color);
tli_show_string(button_clear.x + 20, button_clear.y + 20, WHITE, button_clear.color, 2, "clear", 0);

tli_show_button(button_color.x, button_color.y, button_color.w, button_color.h, 12, button_color.color);
tli_show_string(button_color.x + 20, button_color.y + 20, WHITE, button_color.color, 2, "color", 0);

tli_show_button(button_pixel.x, button_pixel.y, button_pixel.w, button_pixel.h, 12, button_pixel.color);
if (button_pixel.value == 0)
{
tli_show_string(button_pixel.x + 20, button_pixel.y + 20, WHITE, button_pixel.color, 2, "pixel", 0);
button_pixel.value = 1;
}
else
{
sprintf(temp_buf, "%d", button_pixel.value);
tli_show_string(button_pixel.x + (button_pixel.w / 2) - (strlen(temp_buf) / 2 * 16), button_pixel.y + 20, WHITE, button_pixel.color, 2, (uint8_t *)temp_buf, 0);
}

tli_show_button(button_eraser.x, button_eraser.y, button_eraser.w, button_eraser.h, 12, button_eraser.color);
tli_show_string(button_eraser.x + (button_eraser.w / 2) - (strlen("eraser") / 2 * 16), button_eraser.y + 20, WHITE, button_eraser.color, 2, "eraser", 0);
}

/**
* @brief Main routine to test the drawing panel with touch interaction.
*
* Initializes LCD and touch interface, sets up buttons and handles user input
* to draw or erase on the screen based on touch events.
*
* @return Always returns 0.
*/
int draw_panel_test(void)
{
int touch_state = 0;
char color_num = 0;
char pixel_size = 0;

lcd_disp_config();
FT5206_Init();
tli_draw_rectangle(0, 0, 800, 480, WHITE, 1);

widget_object_init(&button_clear, 800 - 130, 480 - 80, 120, 70, BLUE, 0);
widget_object_init(&button_color, 10, 480 - 80, 120, 70, BLUE, 0);
widget_object_init(&button_pixel, 400 - 60, 480 - 80, 120, 70, BLUE, pixel_size);
widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLUE, 0);

ui_init();

while (1)
{
touch_state = FT5206_Scan(0);
if (touch_state == 1)
{
if (tp_dev.x[0] >= button_color.x && tp_dev.x[0] <= (button_color.x + button_color.w))
{
if (tp_dev.y[0] >= button_color.y && tp_dev.y[0] <= (button_color.y + button_color.h))
{
letgo_scan(0, button_color.x, button_color.y, (button_color.x + button_color.w), (button_color.y + button_color.h));
color_num = (color_num + 1) % COLOR_MAX;
widget_object_init(&button_color, button_color.x, button_color.y, button_color.w, button_color.h, color_buf[color_num], 0);
ui_init();
}
}
if (tp_dev.x[0] >= button_clear.x && tp_dev.x[0] <= (button_clear.x + button_clear.w))
{
if (tp_dev.y[0] >= button_clear.y && tp_dev.y[0] <= (button_clear.y + button_clear.h))
{
letgo_scan(0, button_clear.x, button_clear.y, (button_clear.x + button_clear.w), (button_clear.y + button_clear.h));
tli_draw_rectangle(0, 0, 800, 480, WHITE, 1);
ui_init();
}
}
if (tp_dev.x[0] >= button_pixel.x && tp_dev.x[0] <= (button_pixel.x + button_pixel.w))
{
if (tp_dev.y[0] >= button_pixel.y && tp_dev.y[0] <= (button_pixel.y + button_pixel.h))
{
letgo_scan(0, button_pixel.x, button_pixel.y, (button_pixel.x + button_pixel.w), (button_pixel.y + button_pixel.h));
pixel_size++;
if (pixel_size > PIXEL_SIZE_MAX) pixel_size = 1;
widget_object_init(&button_pixel, button_pixel.x, button_pixel.y, button_pixel.w, button_pixel.h, button_pixel.color, pixel_size);
ui_init();
}
}

if (tp_dev.x[0] >= button_eraser.x && tp_dev.x[0] <= (button_eraser.x + button_eraser.w))
{
if (tp_dev.y[0] >= button_eraser.y && tp_dev.y[0] <= (button_eraser.y + button_eraser.h))
{
letgo_scan(0, button_eraser.x, button_eraser.y, (button_eraser.x + button_eraser.w), (button_eraser.y + button_eraser.h));
button_eraser.value = !button_eraser.value;
if (button_eraser.value)
{
widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLACK, button_eraser.value);
}
else
{
widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLUE, button_eraser.value);
}

ui_init();
}
}


if (!button_eraser.value)
{
tli_point_enlarge(tp_dev.x[0], tp_dev.y[0], color_buf[color_num], button_pixel.value);
}
else
{
tli_point_enlarge(tp_dev.x[0], tp_dev.y[0], WHITE, button_pixel.value);
}
}
}
}

INIT_COMPONENT_EXPORT(draw_panel_test);
Loading