Skip to content

Commit e1948c8

Browse files
committed
1.使用RTT的编程规范修改注释 2.readme文件新增注意事项以及原作者信息
1 parent 36674b5 commit e1948c8

File tree

7 files changed

+885
-782
lines changed

7 files changed

+885
-782
lines changed
Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
#### 1.简介
1+
#### 1. 简介
22

3-
用于GD32F470立创开发板配套RGB LCD屏幕的驱动,支持触摸。
4-
#### 2.在 ENV 中的开启
5-
ps:建议全部开启
3+
用于 GD32F470 立创开发板配套 RGB LCD 屏幕的驱动,支持触摸。
4+
5+
> **原作者:LCKFB**
6+
> 本驱动最初由 LCKFB 开发,由 godmial 移植到本BSP。
7+
8+
#### 2. 在 ENV 中的开启
9+
ps:建议全部开启
610
```
711
Hardware Drivers Config --->
812
Board extended module Drivers --->
@@ -13,11 +17,28 @@ Hardware Drivers Config --->
1317
- [*]Enable GPU
1418
- [*]Enable DRAW PANEL EXAMPLE
1519
```
16-
#### 3.注意事项
17-
1.如果屏幕出现刷新抖动,触摸屏出现连点的情况,可以尝试在 `libraries\GD32F4xx_Firmware_Library\CMSIS\GD\GD32F4xx\Source\system_gd32f4xx.c`将时钟值修改为
18-
`#define __SYSTEM_CLOCK_240M_PLL_25M_HXTAL (uint32_t)(240000000)`然后重新编译即可
1920

20-
#### 4.联系方式
21+
#### 3. 注意事项
22+
23+
1. 如果屏幕出现刷新抖动,触摸屏出现连点的情况,可以尝试在 `libraries\GD32F4xx_Firmware_Library\CMSIS\GD\GD32F4xx\Source\system_gd32f4xx.c` 将时钟值修改为
24+
`#define __SYSTEM_CLOCK_240M_PLL_25M_HXTAL (uint32_t)(240000000)`
25+
然后重新编译即可
26+
27+
2. 由于代码格式审查原因,本驱动未包含中文显示函数。但可直接移植官方源码中的中文显示函数进行使用。
28+
29+
3. 为避免 `scons` 命令编译不通过,代码使用了如下代码段以适配不同编译器:
30+
```
31+
#if defined(__CC_ARM) || defined(__ARMCC_VERSION)
32+
// Keil MDK
33+
uint16_t ltdc_lcd_framebuf0[800][480] __attribute__((at(LCD_FRAME_BUF_ADDR)));
34+
#elif defined(__GNUC__)
35+
// GCC (RT-Thread)
36+
uint16_t ltdc_lcd_framebuf0[10][10]; // 此行为避免 scons 编译错误而添加
37+
#endif
38+
39+
40+
41+
#### 4. 联系方式
2142
22-
- 维护:godmial
43+
- 维护:godmial
2344
- 主页:<https://github.com/godmial>
Lines changed: 55 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2025-05-23 godmial Refactor to conform to RT-Thread coding style.
9+
*/
10+
111
#include <board.h>
212
#include <rthw.h>
313
#include <rtthread.h>
@@ -6,7 +16,7 @@
616

717
#define COLOR_MAX 14
818

9-
//像素最大放大倍数
19+
/* Maximum magnification of pixels */
1020
#define PIXEL_SIZE_MAX 20
1121

1222
typedef struct button_struct
@@ -17,24 +27,26 @@ typedef struct button_struct
1727
uint16_t h;
1828
uint16_t color;
1929
uint16_t value;
20-
} _widget_object_struct;
21-
22-
uint16_t color_buf[COLOR_MAX] = {GRAYBLUE, BLACK, BLUE, BRED, GRED, GBLUE, RED, MAGENTA, GREEN, YELLOW, CYAN, BROWN, BRRED, GRAY};
23-
_widget_object_struct button_clear, button_color, button_pixel, button_eraser;
24-
25-
26-
/**********************************************************
27-
* 函 数 名 称:widget_object_init
28-
* 函 数 功 能:控件对象初始化
29-
* 传 入 参 数:obj:要初始化的控件
30-
* xywh:控件的(x,y)起点坐标 w宽h高
31-
* color:控件颜色
32-
* value:控件值
33-
* 函 数 返 回:无
34-
* 作 者:LCKFB
35-
* 备 注:无
36-
**********************************************************/
37-
void widget_object_init(_widget_object_struct *obj, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color, uint16_t value)
30+
} widget_object_t;
31+
32+
uint16_t color_buf[COLOR_MAX] = {GRAYBLUE, BLACK, BLUE, BRED, GRED, GBLUE, RED, MAGENTA, GREEN, YELLOW, CYAN, BROWN, BRRED, GRAY};
33+
widget_object_t button_clear, button_color, button_pixel, button_eraser;
34+
35+
36+
/**
37+
* @brief Initialize a widget button with given properties.
38+
*
39+
* @param obj Pointer to the widget object.
40+
* @param x X coordinate of the top-left corner.
41+
* @param y Y coordinate of the top-left corner.
42+
* @param w Width of the widget.
43+
* @param h Height of the widget.
44+
* @param color Color value of the widget.
45+
* @param value Initial value of the widget.
46+
*
47+
* @return None.
48+
*/
49+
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)
3850
{
3951
obj->x = x;
4052
obj->y = y;
@@ -45,171 +57,131 @@ void widget_object_init(_widget_object_struct *obj, uint16_t x, uint16_t y, uint
4557
}
4658

4759

48-
/**********************************************************
49-
* 函 数 名 称:ui_init
50-
* 函 数 功 能:UI界面初始化
51-
* 传 入 参 数:无
52-
* 函 数 返 回:无
53-
* 作 者:LCKFB
54-
* 注:无
55-
**********************************************************/
60+
/**
61+
* @brief Initialize and display the user interface.
62+
*
63+
* This function draws the control buttons for clear, color,
64+
* pixel size, and eraser on the screen.
65+
*
66+
* @return None.
67+
*/
5668
void ui_init(void)
5769
{
5870
char temp_buf[20] = {0};
5971

60-
//绘制[清除]按钮
61-
//绘制一个圆角按钮
6272
tli_show_button(button_clear.x, button_clear.y, button_clear.w, button_clear.h, 12, button_clear.color);
63-
//绘制圆角按钮的文本
6473
tli_show_string(button_clear.x + 20, button_clear.y + 20, WHITE, button_clear.color, 2, "clear", 0);
6574

66-
//绘制[颜色]按钮
67-
//绘制一个圆角按钮
6875
tli_show_button(button_color.x, button_color.y, button_color.w, button_color.h, 12, button_color.color);
69-
//绘制圆角按钮的文本
7076
tli_show_string(button_color.x + 20, button_color.y + 20, WHITE, button_color.color, 2, "color", 0);
7177

72-
//绘制[像素]按钮
73-
//绘制一个圆角按钮
7478
tli_show_button(button_pixel.x, button_pixel.y, button_pixel.w, button_pixel.h, 12, button_pixel.color);
7579
if (button_pixel.value == 0)
7680
{
77-
//绘制圆角按钮的文本
7881
tli_show_string(button_pixel.x + 20, button_pixel.y + 20, WHITE, button_pixel.color, 2, "pixel", 0);
7982
button_pixel.value = 1;
8083
}
8184
else
8285
{
83-
//绘制居中显示的字符串
8486
sprintf(temp_buf, "%d", button_pixel.value);
8587
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);
8688
}
8789

88-
//绘制[擦除]按钮
89-
//绘制一个圆角按钮
9090
tli_show_button(button_eraser.x, button_eraser.y, button_eraser.w, button_eraser.h, 12, button_eraser.color);
91-
//绘制圆角按钮的文本
9291
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);
9392
}
9493

94+
/**
95+
* @brief Main routine to test the drawing panel with touch interaction.
96+
*
97+
* Initializes LCD and touch interface, sets up buttons and handles user input
98+
* to draw or erase on the screen based on touch events.
99+
*
100+
* @return Always returns 0.
101+
*/
95102
int draw_panel_test(void)
96103
{
97104
int touch_state = 0;
98105
char color_num = 0;
99106
char pixel_size = 0;
100107

101-
// 屏幕初始化
102108
lcd_disp_config();
103-
// 触摸初始化
104109
FT5206_Init();
105-
//全屏清屏
106-
tli_draw_Rectangle(0, 0, 800, 480, WHITE, 1);
107-
110+
tli_draw_rectangle(0, 0, 800, 480, WHITE, 1);
108111

109-
//初始化[清除]按钮的xywh
110112
widget_object_init(&button_clear, 800 - 130, 480 - 80, 120, 70, BLUE, 0);
111-
//初始化[颜色]按钮的xywh
112113
widget_object_init(&button_color, 10, 480 - 80, 120, 70, BLUE, 0);
113-
//初始化[像素]按钮的xywh
114114
widget_object_init(&button_pixel, 400 - 60, 480 - 80, 120, 70, BLUE, pixel_size);
115-
//初始化[橡皮擦]按钮的xywh
116115
widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLUE, 0);
117116

118-
//UI显示
119117
ui_init();
120118

121119
while (1)
122120
{
123-
//触摸扫描
124121
touch_state = FT5206_Scan(0);
125-
//如果屏幕被触摸
126122
if (touch_state == 1)
127123
{
128-
//[颜色]按钮被按下
129124
if (tp_dev.x[0] >= button_color.x && tp_dev.x[0] <= (button_color.x + button_color.w))
130125
{
131126
if (tp_dev.y[0] >= button_color.y && tp_dev.y[0] <= (button_color.y + button_color.h))
132127
{
133-
//判断是否松手
134128
letgo_scan(0, button_color.x, button_color.y, (button_color.x + button_color.w), (button_color.y + button_color.h));
135-
//改变颜色
136129
color_num = (color_num + 1) % COLOR_MAX;
137-
//重新设置[颜色]按钮的背景色
138130
widget_object_init(&button_color, button_color.x, button_color.y, button_color.w, button_color.h, color_buf[color_num], 0);
139-
//UI重新显示
140131
ui_init();
141132
}
142133
}
143-
//[清除]按钮被按下
144134
if (tp_dev.x[0] >= button_clear.x && tp_dev.x[0] <= (button_clear.x + button_clear.w))
145135
{
146136
if (tp_dev.y[0] >= button_clear.y && tp_dev.y[0] <= (button_clear.y + button_clear.h))
147137
{
148-
//判断是否松手
149138
letgo_scan(0, button_clear.x, button_clear.y, (button_clear.x + button_clear.w), (button_clear.y + button_clear.h));
150-
//清屏为背景色
151-
tli_draw_Rectangle(0, 0, 800, 480, WHITE, 1);
152-
//UI重新显示
139+
tli_draw_rectangle(0, 0, 800, 480, WHITE, 1);
153140
ui_init();
154141
}
155142
}
156-
//[像素]按钮被按下
157143
if (tp_dev.x[0] >= button_pixel.x && tp_dev.x[0] <= (button_pixel.x + button_pixel.w))
158144
{
159145
if (tp_dev.y[0] >= button_pixel.y && tp_dev.y[0] <= (button_pixel.y + button_pixel.h))
160146
{
161-
//判断是否松手
162147
letgo_scan(0, button_pixel.x, button_pixel.y, (button_pixel.x + button_pixel.w), (button_pixel.y + button_pixel.h));
163-
//像素放大倍数自增
164148
pixel_size++;
165-
//如果像素放大倍数大于最大倍数
166149
if (pixel_size > PIXEL_SIZE_MAX) pixel_size = 1;
167-
//重新设置[颜色]按钮的背景色
168150
widget_object_init(&button_pixel, button_pixel.x, button_pixel.y, button_pixel.w, button_pixel.h, button_pixel.color, pixel_size);
169-
//UI重新显示
170151
ui_init();
171152
}
172153
}
173154

174-
//[擦除]按钮被按下
175155
if (tp_dev.x[0] >= button_eraser.x && tp_dev.x[0] <= (button_eraser.x + button_eraser.w))
176156
{
177157
if (tp_dev.y[0] >= button_eraser.y && tp_dev.y[0] <= (button_eraser.y + button_eraser.h))
178158
{
179-
//判断是否松手
180159
letgo_scan(0, button_eraser.x, button_eraser.y, (button_eraser.x + button_eraser.w), (button_eraser.y + button_eraser.h));
181-
//修改擦除按钮的状态
182160
button_eraser.value = !button_eraser.value;
183-
//如果是擦除状态
184161
if (button_eraser.value)
185162
{
186-
//初始化[橡皮擦]按钮的xywh颜色修改为黑色
187163
widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLACK, button_eraser.value);
188164
}
189165
else
190166
{
191-
//初始化[橡皮擦]按钮的xywh颜色修改为蓝色
192167
widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLUE, button_eraser.value);
193168
}
194-
//UI重新显示
169+
195170
ui_init();
196171
}
197172
}
198173

199-
//如果不是擦除状态
174+
200175
if (!button_eraser.value)
201176
{
202-
//绘制触摸点
203-
//根据[颜色]按钮的背景色设置触摸点的颜色
204-
point_enlargement(tp_dev.x[0], tp_dev.y[0], color_buf[color_num], button_pixel.value);
177+
tli_point_enlarge(tp_dev.x[0], tp_dev.y[0], color_buf[color_num], button_pixel.value);
205178
}
206179
else
207180
{
208-
//擦除
209-
point_enlargement(tp_dev.x[0], tp_dev.y[0], WHITE, button_pixel.value);
181+
tli_point_enlarge(tp_dev.x[0], tp_dev.y[0], WHITE, button_pixel.value);
210182
}
211183
}
212184
}
213185
}
214-
// MSH_CMD_EXPORT(draw_panel_test, draw panel test)
215-
INIT_COMPONENT_EXPORT(draw_panel_test);
186+
187+
INIT_COMPONENT_EXPORT(draw_panel_test);

0 commit comments

Comments
 (0)