[应用相关] AT32F403A例程之-STemWin移植

[复制链接]
1059|11
 楼主| 舒伯特玫瑰 发表于 2023-9-28 15:59 | 显示全部楼层 |阅读模式
STemWin下载
STemWin可以在ST官网下载:
https://www.st.com/content/st_com/zh/search.html#q=STEMWIN-t=tools-page=1

二、STemWin的LCD接口介绍
移植STemWin有两种方法,
第一种:用户接口,
在LCDConf_FlexColor_Template.c 中的LCD_X_Config函数中的设置为

GUI_DEVICE_CreateAndLink(&GUIDRV_Template_API, GUICC_M565, 0, 0);
1
第二种,STemWin接口

GUI_DEVICE_CreateAndLink(GUIDRV_FLEXCOLOR, GUICC_M565, 0, 0);


本例程主要介绍第一种接口的使用方法。

 楼主| 舒伯特玫瑰 发表于 2023-9-28 16:00 | 显示全部楼层
雅特力AT32F403A工程准备

772006515328387b8a.png
 楼主| 舒伯特玫瑰 发表于 2023-9-28 16:00 | 显示全部楼层
四、雅特力AT32F403A的LCD调试。
本例程STemWin用的是用户接口,所以要先调试好LCD,准备好三个函数

1.第一个画点函数:
LCD_DrawPoint(u16 x,u16 y,u16 color);
1
2.第二个读点函数:
u16  LCD_ReadPoint(u16 x,u16 y);
1
3.第三个填充函数:
void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color);
 楼主| 舒伯特玫瑰 发表于 2023-9-28 16:00 | 显示全部楼层
五、STemWin文件移植
1.在雅特力AT32F403A工程中添加以下文件

86610651532a50f80e.png
 楼主| 舒伯特玫瑰 发表于 2023-9-28 16:01 | 显示全部楼层
六、STemWin文件修改
1.LCDConf_FlexColor_Template.c
修改现实屏大小

#define XSIZE_PHYS  320+1 // To be adapted to x-screen size
#define YSIZE_PHYS  240+1 // To be adapted to y-screen size
 楼主| 舒伯特玫瑰 发表于 2023-9-28 16:01 | 显示全部楼层
修改用户接口
  1. void LCD_X_Config(void)
  2. {
  3. //  GUI_DEVICE * pDevice;
  4. //  CONFIG_FLEXCOLOR Config = {0};
  5. //  GUI_PORT_API PortAPI = {0};
  6.   //
  7.   // Set display driver and color conversion
  8.   //设定用户接口模式
  9.   GUI_DEVICE_CreateAndLink(&GUIDRV_Template_API, GUICC_M565, 0, 0);
  10.   //
  11.   // Display driver configuration, required for Lin-driver
  12.   //
  13.   LCD_SetSizeEx (0, XSIZE_PHYS , YSIZE_PHYS);
  14.   LCD_SetVSizeEx(0, VXSIZE_PHYS, VYSIZE_PHYS);
  15. //  //
  16. //  // Orientation
  17. //  //
  18. //  Config.Orientation = GUI_SWAP_XY | GUI_MIRROR_Y;
  19. //  GUIDRV_FlexColor_Config(pDevice, &Config);
  20. //  //
  21. //  // Set controller and operation mode
  22. //  //
  23. //  PortAPI.pfWrite16_A0  = LcdWriteReg;
  24. //  PortAPI.pfWrite16_A1  = LcdWriteData;
  25. //  PortAPI.pfWriteM16_A1 = LcdWriteDataMultiple;
  26. //  PortAPI.pfReadM16_A1  = LcdReadDataMultiple;
  27. //  GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66708, GUIDRV_FLEXCOLOR_M16C0B16);

  28. }
 楼主| 舒伯特玫瑰 发表于 2023-9-28 16:01 | 显示全部楼层
2.GUIDRV_Template.c
这个文件要修改三个函数

第一个加入LCD_DrawPoint(x,y,PixelIndex);:
  1. static void _SetPixelIndex(GUI_DEVICE * pDevice, int x, int y, int PixelIndex) {
  2.     //
  3.     // Convert logical into physical coordinates (Dep. on LCDConf.h)
  4.     //
  5.     #if (LCD_MIRROR_X == 1) || (LCD_MIRROR_Y == 1) || (LCD_SWAP_XY == 1)
  6.       int xPhys, yPhys;

  7.       xPhys = LOG2PHYS_X(x, y);
  8.       yPhys = LOG2PHYS_Y(x, y);
  9.     #else
  10.       #define xPhys x
  11.       #define yPhys y
  12.     #endif
  13.     GUI_USE_PARA(pDevice);
  14.     GUI_USE_PARA(x);
  15.     GUI_USE_PARA(y);
  16.     GUI_USE_PARA(PixelIndex);
  17.     {
  18.       //
  19.       // Write into hardware ... Adapt to your system
  20.       //
  21.       // TBD by customer...
  22.       //
  23.       LCD_DrawPoint(x,y,PixelIndex);
  24.     }
  25.     #if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)
  26.       #undef xPhys
  27.       #undef yPhys
  28.     #endif
  29. }
 楼主| 舒伯特玫瑰 发表于 2023-9-28 16:01 | 显示全部楼层
第二个加入PixelIndex = LCD_ReadPoint(x,y);:
  1. static unsigned int _GetPixelIndex(GUI_DEVICE * pDevice, int x, int y) {
  2.   unsigned int PixelIndex;
  3.     //
  4.     // Convert logical into physical coordinates (Dep. on LCDConf.h)
  5.     //
  6.     #if (LCD_MIRROR_X == 1) || (LCD_MIRROR_Y == 1) || (LCD_SWAP_XY == 1)
  7.       int xPhys, yPhys;

  8.       xPhys = LOG2PHYS_X(x, y);
  9.       yPhys = LOG2PHYS_Y(x, y);
  10.     #else
  11.       #define xPhys x
  12.       #define yPhys y
  13.     #endif
  14.     GUI_USE_PARA(pDevice);
  15.     GUI_USE_PARA(x);
  16.     GUI_USE_PARA(y);
  17.     {
  18.       //
  19.       // Write into hardware ... Adapt to your system
  20.       //
  21.       // TBD by customer...
  22.       //
  23.       PixelIndex = LCD_ReadPoint(x,y);
  24.     }
  25.     #if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)
  26.       #undef xPhys
  27.       #undef yPhys
  28.     #endif
  29.   return PixelIndex;
  30. }
 楼主| 舒伯特玫瑰 发表于 2023-9-28 16:08 | 显示全部楼层
第三个加入LCD_Fill(x0,y0,x1,y1,LCD_COLORINDEX);:

  1. static void _FillRect(GUI_DEVICE * pDevice, int x0, int y0, int x1, int y1)
  2. {
  3.     LCD_Fill(x0,y0,x1,y1,LCD_COLORINDEX);
  4. //  LCD_PIXELINDEX PixelIndex;
  5. //  int x;

  6. //  PixelIndex = LCD__GetColorIndex();
  7. //  if (GUI_pContext->DrawMode & LCD_DRAWMODE_XOR) {
  8. //    for (; y0 <= y1; y0++) {
  9. //      for (x = x0; x <= x1; x++) {
  10. //        _XorPixel(pDevice, x, y0);
  11. //      }
  12. //    }
  13. //  } else {
  14. //    for (; y0 <= y1; y0++) {
  15. //      for (x = x0; x <= x1; x++) {
  16. //        _SetPixelIndex(pDevice, x, y0, PixelIndex);
  17. //      }
  18. //    }
  19. //  }
  20. }
 楼主| 舒伯特玫瑰 发表于 2023-9-28 16:08 | 显示全部楼层
3.GUIConf.c
修改内存大小:
#define GUI_NUMBYTES  40*1024
该处使用的url网络请求的数据。
 楼主| 舒伯特玫瑰 发表于 2023-9-28 16:08 | 显示全部楼层
4.at32f403a_407_int.c
修改systick定时器中断:
  1. extern __IO int32_t OS_TimeMS;
  2. void SysTick_Handler(void)
  3. {
  4.   OS_TimeMS++;
  5.   
  6.         if(OS_TimeMS%100 == 0)
  7.         {
  8.       LED2_BL;//加个LED指示一下
  9.         }  
  10. }
 楼主| 舒伯特玫瑰 发表于 2023-9-28 16:09 | 显示全部楼层
5.main.c测试
代码如下(示例):
  1. #include "at32f403a_407_clock.h"
  2. #include "Drv_Delay.h"
  3. #include "Drv_Uart.h"
  4. #include "Drv_Led.h"
  5. #include "Drv_LCD.h"
  6. #include "WM.h"
  7. #include "GUI.h"
  8. #include "GUIDEMO.h"

  9. int  main(void)
  10. {
  11.     system_clock_config();
  12.     uart_print_init(115200);
  13.           LCD_Init();       
  14.     LCD_Back(BLUE);

  15.     systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV);
  16.     SysTick_Config(system_core_clock / 1000U);          //开启Systick中断
  17.     crm_periph_clock_enable(CRM_CRC_PERIPH_CLOCK, TRUE); //打开CRC时钟
  18.     WM_SetCreateFlags(WM_CF_MEMDEV);                  //允许存储器
  19.    
  20.     GUI_Init();                       //初始化GUI
  21.     GUI_SetBkColor(GUI_BLUE);         //设置背景色为蓝色
  22.     GUI_SetColor(GUI_WHITE);          //设置前景色为白色
  23.     GUI_Clear();                      //清屏

  24.     GUI_SetFont(&GUI_Font8x16x3x3);        //字体设置
  25.     GUI_DispStringAt("Hello World!",20,50);
  26.   
  27.     while(1){}


  28. }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

53

主题

266

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部