【ST NUCLEO-U5A5ZJ-Q开发板测评】移植TouchGFX实现数字时钟
<div class='showpostmsg'> 本帖最后由 lugl4313820 于 2024-2-6 15:13 编辑<p>【硬件】】</p>
<p>1、ST NUCLEO-U5A5ZJ-Q开发板</p>
<p>2、OLED </p>
<p>【开发软件】</p>
<p>1、STM32CubeIDE</p>
<p>2、TouchGFX 4.23.1</p>
<p>【实现步骤】</p>
<p>1、移植OLED到开发板上,在我的帖子已经实现:<a href="https://bbs.eeworld.com.cn/thread-1271716-1-1.html">【ST NUCLEO-U5A5ZJ-Q开发板测评】深度体验I2C驱动OLED屏 </a></p>
<p>2、配置CRC<br />
3、打开TIM7为touchgfx提供刷新心跳:</p>
<p> 同时开启中断。</p>
<p>4、配置TouchGFX为单色、宽度为128个像素,高度为64个像素</p>
<p> 配置好后生成代码。</p>
<p>5、生成工程后,打开toucgfx Desiger,放入一背景为白色,同时添加一个数字时钟,然后生成代码。</p>
<p> 到此工程配置结事。</p>
<p>【代码添加】</p>
<p>1、打开TouchFGXHAL.cpp添加ssd1306的头文件以及#include <touchgfx/hal/OSWrappers.hpp>获取像素头文件</p>
<p> 2、更新void TouchGFXHAL::flushFrameBuffer(const touchgfx::Rect& rect)代码如下:</p>
<pre>
<code>/**
* This function is called whenever the framework has performed a partial draw.
*
* @param rect The area of the screen that has been drawn, expressed in absolute coordinates.
*
* <a href="home.php?mod=space&uid=418085" target="_blank">@see </a>flushFrameBuffer().
*/
void TouchGFXHAL::flushFrameBuffer(const touchgfx::Rect& rect)
{
// Calling parent implementation of flushFrameBuffer(const touchgfx::Rect& rect).
//
// To overwrite the generated implementation, omit call to parent function
// and implemented needed functionality here.
// Please note, HAL::flushFrameBuffer(const touchgfx::Rect& rect) must
// be called to notify the touchgfx framework that flush has been performed.
// To calculate he start adress of rect,
// use advanceFrameBufferToRect(uint8_t* fbPtr, const touchgfx::Rect& rect)
// defined in TouchGFXGeneratedHAL.cpp
TouchGFXGeneratedHAL::flushFrameBuffer(rect);
const unsigned char* bitmap = (const unsigned char*) getClientFrameBuffer();
ssd1306_Fill(Black);
ssd1306_DrawBitmap(0, 0, bitmap, 128, 64, White);
ssd1306_UpdateScreen();
}</code></pre>
<p>代码的主要功能是先创建一个bitmap的缓冲区,把touchgfx的图像读进这个数组,然后把图片写入ssd1306。</p>
<p>2、添加同步信号:</p>
<pre>
<code>extern "C"
void touchgfxSignalVSync(void)
{
/* VSync has occurred, increment TouchGFX engine vsync counter */
touchgfx::HAL::getInstance()->vSync();
/* VSync has occurred, signal TouchGFX engine */
touchgfx::OSWrappers::signalVSync();
}</code></pre>
<p>4、在main.c中添加TIM7的中断回调函数,内容如下:</p>
<pre>
<code>/* USER CODE BEGIN 4 */
extern void touchgfxSignalVSync(void);
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM7)
{
touchgfxSignalVSync();
}
}
/* USER CODE END 4 */</code></pre>
<p>在回调函数中,我们检测到定时回调,然后更新一次图像。</p>
<p>5、在主函数中我们调用MX_TouchGFX_Process();就可以实现即定功能。</p>
<pre>
<code>while (1)
{
/* USER CODE END WHILE */
MX_TouchGFX_Process();
/* USER CODE BEGIN 3 */
}</code></pre>
<p>6、添加时钟更新代码,先在screen.hpp中,声明handleTicktEven函数,并声明tick,秒时分四个变量:</p>
<pre>
<code>class screenView : public screenViewBase
{
public:
screenView();
virtual ~screenView() {}
virtual void setupScreen();
virtual void tearDownScreen();
virtual void handleTickEvent();
protected:
int tickCounter;
int digitalHours;
int digitalMinutes;
int digitalSeconds;
};</code></pre>
<p>7、在screenview.cpp中我们实现handleTickEvernt函数,计数到达1秒后更新数字时钟,从面实现数据时钟:</p>
<pre>
<code>#include <gui/screen_screen/screenView.hpp>
screenView::screenView():tickCounter(0),digitalSeconds(0),digitalMinutes(0),digitalHours(0)
{
}
void screenView::setupScreen()
{
screenViewBase::setupScreen();
}
void screenView::tearDownScreen()
{
screenViewBase::tearDownScreen();
}
void screenView::handleTickEvent()
{
tickCounter++;
if (tickCounter % 60 == 0)
{
if (++digitalSeconds >= 60)
{
digitalSeconds = 0;
if (++digitalMinutes >= 60)
{
digitalMinutes = 0;
if (++digitalHours >= 24)
{
digitalHours = 0;
}
}
}
// Update the clock
digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
}
}</code></pre>
<p>这样我们编译下载到开发板就可以实现基于touchGFX的数字时钟了:</p>
<div>5657389f90f74d5e3ce80bb0fa2d2ad0<br />
</div>
<div> </div>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p> </p>
<p>有了toucgfx可以随便搞中文,再也不需要去手工字库了。</p>
<p>附工程源码,希望对大家有用!</p>
<div></div>
页:
[1]