UI模拟器使用手册

**背景:**最新使用新的UI模拟器导入单片机,记录使用流程,方便以后忘记了来看看

使用步骤:

1.打开UI模拟器,画出所需的UI

2.生成代码

3.植入MCU的前提,已经实现了LCD屏幕的初始化,如ST7789v等

新建ui_port.c,补全两个关键函数

复制代码
/* *****************************************************************************
 Copyright (C) : 2000-2026, unit
 ******************************************************************************
 File Name     : ui_port.c
 Version       : ver 1.0
 Author        : phh
 Created       : 2026/11/06
 Description   : STM32 UI Designer 生成代码 -> APM32 BSP 适配层

                 实现生成器要求但工程里原本不存在的两个函数:
                     LCD_DrawPoint()
                     LCD_Fill()

                 设计取舍:
                 1. 不缓存"当前窗口"。Bsp_Lcd_Fill 以及 emWin 的
                    _SetPixelIndex/_DrawBitLine16BPP 都会修改 GRAM 窗口指针,
                    跨模块同步缓存状态的耦合成本远大于收益。
                 2. LCD_Fill 不逐像素循环, 直接复用 Bsp_Lcd_Fill 的
                    "一次开窗 + N 次连续写", 比逐点快约 11 倍。

***************************************************************************** */

/* ----------------------------------------------*
 * header files                                  *
 *---------------------------------------------- */
#include "ui_port.h"

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */

/* ----------------------------------------------*
 * routines' implementations                     *
 *---------------------------------------------- */

/* ****************************************************************************
 Prototype     : LCD_DrawPoint
 Description   : 绘制单个像素
 Input         : x, y   坐标 (闭区间边界)
                 color  RGB565 颜色
 Output        : None
 Return Value  : 原样返回 color
 Calls         : Bsp_Lcd_SetWindow(), LCD_WRITE_DAT()
 Called By     : ui_lcd.c 的 LCD_ShowChar / LCD_ShowChinese12 / LCD_ShowChinese16

 History
 1.Date        : 2026/11/06
   Author      : phh
   Modification: Created function

**************************************************************************** */
uint16_t LCD_DrawPoint(uint16_t x, uint16_t y, uint16_t color)
{
    /* 生成器不做越界检查, 这里兜住: 直接丢弃屏外像素。
     * 若放任写入, ST7789 的 GRAM 窗口会回卷, 造成整屏错位。 */
    if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT))
    {
        return color;
    }

    /* 开 1x1 窗口: 内部依次发 0x2A(CASET) / 0x2B(RASET) / 0x2C(RAMWR) */
    Bsp_Lcd_SetWindow(x, y, x, y);
    LCD_WRITE_DAT(UI_RGB(color));

    return color;
}

/* ****************************************************************************
 Prototype     : LCD_Fill
 Description   : 矩形区域填充 (闭区间)
 Input         : xsta, ysta  起始坐标
                 xend, yend  结束坐标 (均为闭区间)
                 color       RGB565 颜色
 Output        : None
 Return Value  : None
 Calls         : Bsp_Lcd_Fill()
 Called By     : ui_lcd.c 的 LCD_ShowLine / LCD_ShowPicture / LCD_ShowPicture565
                 / LCD_ShowRectangles

 History
 1.Date        : 2026/11/06
   Author      : phh
   Modification: Created function

**************************************************************************** */
void LCD_Fill(uint16_t xsta, uint16_t ysta,
              uint16_t xend, uint16_t yend,
              uint16_t color)
{
    /* 生成器统一用 uint16_t 传参, 但 LCD_ShowLine 在 thick>1 或 style==3 时
     * 会计算 x0 - thick/2, 结果为负时被隐式转换成 6553x 这种伪大数。
     * 这里按 int16_t 解读, 才能正确识别并丢弃。 */
    int16_t x0 = (int16_t)xsta;
    int16_t y0 = (int16_t)ysta;
    int16_t x1 = (int16_t)xend;
    int16_t y1 = (int16_t)yend;

    /* 反绕保护: 保证左上角在前 */
    if (x0 > x1) { int16_t t = x0; x0 = x1; x1 = t; }
    if (y0 > y1) { int16_t t = y0; y0 = y1; y1 = t; }

    /* 完全在屏幕外 -> 直接返回 */
    if ((x0 >= (int16_t)LCD_WIDTH)  || (y0 >= (int16_t)LCD_HEIGHT)) return;
    if ((x1 < 0) || (y1 < 0)) return;

    /* 裁剪到屏幕内 */
    if (x0 < 0) x0 = 0;
    if (y0 < 0) y0 = 0;

    /* 关键钳位: Bsp_Lcd_Fill 内部没有任何越界判断,
     * 结束坐标一旦超过 LCD_WIDTH-1, 像素计数会变多且窗口回卷, 必然花屏。 */
    if (x1 > (int16_t)(LCD_WIDTH  - 1)) x1 = (int16_t)(LCD_WIDTH  - 1);
    if (y1 > (int16_t)(LCD_HEIGHT - 1)) y1 = (int16_t)(LCD_HEIGHT - 1);

    Bsp_Lcd_Fill((uint16_t)x0, (uint16_t)y0,
                 (uint16_t)x1, (uint16_t)y1,
                 UI_RGB(color));
}

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */

5.初始化后,直接调用ui_draw_screen1,实际效果

6.补充变化的图标及字库在空屏幕,如屏幕3,不然切换图标时没有对应字库

相关推荐
小熊在忙fpga19 分钟前
单片机处理浮点型:单精度(float)和双精度(double)
单片机·嵌入式硬件
LCG米1 小时前
FreeRTOS 队列 FromISR 实战:STM32 中断收发、队列深度定标与 portYIELD 延迟排查
stm32·单片机·嵌入式硬件·freertos·中断·fromisr
蓝悦无人机2 小时前
Figma组件库搭建教程(实战篇)
前端·ui·figma
R190_65892 小时前
A‑29P 神经网络 AI 回声消除 DSP 模组深度解析与工程实战
嵌入式硬件·aec回声消除·dsp音频·ai‑enc降噪·对讲终端开发
manduic3 小时前
车载导航启动慢怎么解 64Mb NOR Flash选型
单片机·嵌入式硬件
zhongben_keji3 小时前
APP 无障碍与适老化改造工程实践:语义、视觉、交互三层落地
ui·ci/cd·自动化
都在酒里13 小时前
STM32 板卡产测:烧录、序列号、校准与留档
stm32·单片机·嵌入式硬件
意法半导体STM3217 小时前
【官方原创】初识STM32CubeCLI:基于命令行的STM32工具链
stm32·单片机·stm32cubeide·stm32cubeclt·stm32工具链
BT-BOX19 小时前
基于STM32的锂电池充电监测电路Proteus仿真设计介绍
stm32·嵌入式硬件·proteus