cmcu为stm32h743IIt6
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.1 KiB

/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2025-12-06 Administrator the first version
*/
/* lcd.c *//* lcd.c */
#include "lcd.h"
#include "lcdfont.h" // 确保该文件存在,否则注释掉字体相关函数
#include <string.h>
uint32_t g_point_color = RED;
uint32_t g_back_color = WHITE;
_lcd_dev lcddev;
1 month ago
int lcd_init(void) {
// lcddev.id = 0x7016; // 模拟 ID
1 month ago
// rt_kprintf("LCD ID:%x\r\n", lcddev.id);
if (lcdltdc.pwidth != 0) {
1 month ago
lcd_display_dir(RGB_DIR); // 横屏
}
lcd_clear(WHITE);
1 month ago
return 0;
}
1 month ago
INIT_APP_EXPORT(lcd_init);
void lcd_rgb_test(void)
{
rt_kprintf("Starting LCD RGB flash test...\n");
for (int cycle = 0; cycle < 10; cycle++) {
lcd_clear(RED); // 全屏红色
rt_thread_mdelay(500);
lcd_clear(GREEN); // 全屏绿色
rt_thread_mdelay(500);
lcd_clear(BLUE); // 全屏蓝色
rt_thread_mdelay(500);
}
lcd_clear(WHITE); // 最后恢复白色
rt_kprintf("LCD RGB test finished.\n");
}
void lcd_display_dir(uint8_t dir) {
lcddev.dir = dir;
ltdc_display_dir(dir);
lcddev.width = lcdltdc.width;
lcddev.height = lcdltdc.height;
}
void lcd_clear(uint32_t color) {
if (lcdltdc.pwidth != 0) {
ltdc_clear(color);
}
}
void lcd_draw_point(uint16_t x, uint16_t y, uint32_t color) {
if (lcdltdc.pwidth != 0) {
ltdc_draw_point(x, y, color);
}
}
void lcd_fill(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint32_t color) {
if (lcdltdc.pwidth != 0) {
ltdc_fill(sx, sy, ex, ey, color);
}
}
// === 最小实现:避免编译错误 ===
void lcd_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint32_t color) {
// 简单 Bresenham 算法(可选)
lcd_draw_point(x1, y1, color);
lcd_draw_point(x2, y2, color);
}
void lcd_draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint32_t color) {
lcd_draw_line(x1, y1, x2, y1, color);
lcd_draw_line(x1, y2, x2, y2, color);
lcd_draw_line(x1, y1, x1, y2, color);
lcd_draw_line(x2, y1, x2, y2, color);
}
void lcd_draw_circle(uint16_t x0, uint16_t y0, uint8_t r, uint32_t color) {
// 空实现或简单点
lcd_draw_point(x0, y0, color);
}
void lcd_fill_circle(uint16_t x, uint16_t y, uint16_t r, uint32_t color) {
lcd_draw_point(x, y, color);
}
void lcd_show_char(uint16_t x, uint16_t y, char chr, uint8_t size, uint8_t mode, uint32_t color) {
// 若无字体,跳过
}
void lcd_show_num(uint16_t x, uint16_t y, uint32_t num, uint8_t len, uint8_t size, uint32_t color) {}
void lcd_show_xnum(uint16_t x, uint16_t y, uint32_t num, uint8_t len, uint8_t size, uint8_t mode, uint32_t color) {}
void lcd_show_string(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t size, char *p, uint32_t color) {}
// 工具函数(若未使用可删除)
1 month ago
/*static uint32_t lcd_pow(uint8_t m, uint8_t n) {
uint32_t result = 1;
while (n--) result *= m;
return result;
1 month ago
}*/