最近发现使用touchgfx直接生成的项目仪表盘可以显示指针,但是使用STM32CUBEMX生成的touchgfx项目的仪表盘指针不显示问题。原因是CubeMX 可能默认没有启用 Texture Mapper。正常情况在FrontendApplicationBase.cpp文件中会有touchgfx自动添加的启动代码。
Texture Mapper(纹理映射器)在 STM32CubeMX 生成的项目中可能默认未被启用 ,这是导致指针不显示的一个非常隐蔽的原因。Texture Mapper 是 Gauge 指针实现旋转动画的底层依赖。它默认是关闭状态以节省代码空间。虽然 TouchGFX Designer 在生成新项目时会自动插入启用代码,但 STM32CubeMX 的生成流程有时会遗漏这一步,导致指针因为缺乏底层的渲染支持而无法绘制。
解决方法是在文件FrontendApplication.cpp手动添加代码:
#ifndef SIMULATOR
#include <platform/driver/lcd/LCD16bppSerialFlash.hpp>
#endif
#ifdef SIMULATOR
#include <platform/driver/lcd/LCD16bpp.hpp>
#endif
FrontendApplication::FrontendApplication(Model& m, FrontendHeap& heap)
: FrontendApplicationBase(m, heap)
{
#ifndef SIMULATOR
reinterpret_cast<touchgfx::LCD16bppSerialFlash&>(touchgfx::HAL::lcd()).enableTextureMapperAll();
reinterpret_cast<touchgfx::LCD16bppSerialFlash&>(touchgfx::HAL::lcd()).enableDecompressorL8_All();
reinterpret_cast<touchgfx::LCD16bppSerialFlash&>(touchgfx::HAL::lcd()).enableDecompressorRGB();
#endif
#ifdef SIMULATOR
reinterpret_cast<touchgfx::LCD16bpp&>(touchgfx::HAL::lcd()).enableTextureMapperAll();
reinterpret_cast<touchgfx::LCD16bpp&>(touchgfx::HAL::lcd()).enableDecompressorL8_All();
reinterpret_cast<touchgfx::LCD16bpp&>(touchgfx::HAL::lcd()).enableDecompressorRGB();
#endif
}
|