STemwin 系列(二)STM32 HAL庫 跑個分(刷屏速度)

在上一篇的基礎上 https://blog.csdn.net/so_cracy/article/details/80228595

加入以下代碼:

/* 包含頭文件 ----------------------------------------------------------------*/
#include "GUI.h"
#include "DIALOG.h"
#include "stdio.h"


/* 私有類型定義 --------------------------------------------------------------*/
/* 私有宏定義 ----------------------------------------------------------------*/
/* 私有變量 ------------------------------------------------------------------*/
static const GUI_COLOR _aColor[8] = {
  0x000000, 
  0x0000FF, 
  0x00FF00, 
  0x00FFFF, 
  0xFF0000, 
  0xFF00FF, 
  0xFFFF00, 
  0xFFFFFF
};


U32 Stop_Test = 0;


/* 擴展變量 ------------------------------------------------------------------*/
/* 私有函數原形 --------------------------------------------------------------*/
/* 函數體 --------------------------------------------------------------------*/


/**
  * 函數功能: 獲取每秒像素值
  * 輸入參數: 無
  * 返 回 值: U32:每秒像素值
  * 說    明: 無
  */
static U32 _GetPixelsPerSecond(void) {
  GUI_COLOR Color, BkColor;
  U32 x0, y0, x1, y1, xSize, ySize;
  I32 t, t0;
  U32 Cnt, PixelsPerSecond, PixelCnt;
  
  /* Find an area which is not obstructed by any windows */
  xSize   = LCD_GetXSize();
  ySize   = LCD_GetYSize();
  Cnt     = 0;
  x0      = 0;
  x1      = xSize - 1;
  y0      = 65;
  y1      = ySize - 60 - 1;
  Color   = GUI_GetColor();
  BkColor = GUI_GetBkColor();
  GUI_SetColor(BkColor);
  
  /* Repeat fill as often as possible in 100 ms */
  t0 = GUI_GetTime();
  do {
    GUI_FillRect(x0, y0, x1, y1);
    Cnt++;
    t = GUI_GetTime();    
  } while ((t - (t0 + 100)) <= 0);
  
  /* Compute result */
  t -= t0;
  PixelCnt = (x1 - x0 + 1) * (y1 - y0 + 1) * Cnt;
  PixelsPerSecond = PixelCnt / t * 1000;   
  GUI_SetColor(Color);
  return PixelsPerSecond;
}


/**
  * 函數功能: 運行刷屏速度測試程序
  * 輸入參數: 無
  * 返 回 值: int:每秒像素值
  * 說    明: 無
  */
int Run_SpeedTest(void) {
  int      TimeStart, i;
  U32      PixelsPerSecond;
  unsigned aColorIndex[8];
  int      xSize, ySize, vySize;
  GUI_RECT Rect, ClipRect;
  xSize  = LCD_GetXSize();
  ySize  = LCD_GetYSize();
  vySize = LCD_GetVYSize();
#if GUI_SUPPORT_CURSOR
  GUI_CURSOR_Hide();
#endif
  if (vySize > ySize)
  {
    ClipRect.x0 = 0;
    ClipRect.y0 = 0;
    ClipRect.x1 = xSize;
    ClipRect.y1 = ySize;
    GUI_SetClipRect(&ClipRect);
  }
  
  Stop_Test = 0;
  
  for (i = 0; i< 8; i++)
  {
    aColorIndex[i] = GUI_Color2Index(_aColor[i]);
  }  
  TimeStart = GUI_GetTime();
  for (i = 0; ((GUI_GetTime() - TimeStart) < 5000) &&( Stop_Test == 0); i++)
  {
    GUI_SetColorIndex(aColorIndex[i&7]);
    
    /* Calculate random positions */
    Rect.x0 = (GUI_GetTime()/(i%25)) % xSize - xSize / 2;
    Rect.y0 = (GUI_GetTime()/(i%25)) % ySize - ySize / 2;
    Rect.x1 = Rect.x0 + 20 + (GUI_GetTime()/(i%25)) % xSize;
    Rect.y1 = Rect.y0 + 20 + (GUI_GetTime()/(i%25)) % ySize;


    GUI_FillRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1);
    
    /* Clip rectangle to visible area and add the number of pixels (for speed computation) */
    if (Rect.x1 >= xSize)
    {
      Rect.x1 = xSize - 1;
    }
    
    if (Rect.y1 >= ySize)
    {
      Rect.y1 = ySize - 1;
    }
    
    if (Rect.x0 < 0 )
    {
      Rect.x0 = 0;
    }
    
    if (Rect.y1 < 0)
    {
      Rect.y1 = 0;
    }
    
    GUI_Exec();
    
    /* Allow short breaks so we do not use all available CPU time ... */
  }
  PixelsPerSecond = _GetPixelsPerSecond();
  GUI_SetClipRect(NULL);
  return PixelsPerSecond;
}


/**
  * 函數功能: 刷屏測試函數
  * 輸入參數: 無
  * 返 回 值: 無
  * 說    明: 無
  */
void SpeedTest(void)
{
char temp[50]={0};
int cpu_speed = 0;
Stop_Test = 0;
  /* 運行刷屏測試函數 */
cpu_speed = Run_SpeedTest();
/* 清屏 */
GUI_Clear();
  /* 顯示刷屏測試結果 */
sprintf(temp, "%d  Pixels/s ", cpu_speed); 
GUI_SetColor(GUI_BLUE);
GUI_SetFont(GUI_FONT_32B_ASCII);
GUI_DispStringHCenterAt(temp,LCD_GetXSize()/2,LCD_GetYSize()/2-16);

}

主函數運行:


結果如圖:


這TM的只有25W分,怎麼忍受得了!!

來優化以下,最影響速度的也就一個地方:


FSMC的數據、地址的建立時間等

生成再跑個分看看:


瞬間翻了10倍有木有


最快速度了:


還有其它加快速度的方法,以後再說了!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章