舒伯特玫瑰 发表于 2023-9-28 15:59

AT32F403A例程之-STemWin移植

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工程准备

舒伯特玫瑰 发表于 2023-9-28 16:00

四、雅特力AT32F403A的LCD调试。
本例程STemWin用的是用户接口,所以要先调试好LCD,准备好三个函数

1.第一个画点函数:
LCD_DrawPoint(u16 x,u16 y,u16 color);
1
2.第二个读点函数:
u16LCD_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工程中添加以下文件


舒伯特玫瑰 发表于 2023-9-28 16:01

六、STemWin文件修改
1.LCDConf_FlexColor_Template.c
修改现实屏大小

#define XSIZE_PHYS320+1 // To be adapted to x-screen size
#define YSIZE_PHYS240+1 // To be adapted to y-screen size

舒伯特玫瑰 发表于 2023-9-28 16:01

修改用户接口
void LCD_X_Config(void)
{
//GUI_DEVICE * pDevice;
//CONFIG_FLEXCOLOR Config = {0};
//GUI_PORT_API PortAPI = {0};
//
// Set display driver and color conversion
//设定用户接口模式
GUI_DEVICE_CreateAndLink(&GUIDRV_Template_API, GUICC_M565, 0, 0);
//
// Display driver configuration, required for Lin-driver
//
LCD_SetSizeEx (0, XSIZE_PHYS , YSIZE_PHYS);
LCD_SetVSizeEx(0, VXSIZE_PHYS, VYSIZE_PHYS);
////
//// Orientation
////
//Config.Orientation = GUI_SWAP_XY | GUI_MIRROR_Y;
//GUIDRV_FlexColor_Config(pDevice, &Config);
////
//// Set controller and operation mode
////
//PortAPI.pfWrite16_A0= LcdWriteReg;
//PortAPI.pfWrite16_A1= LcdWriteData;
//PortAPI.pfWriteM16_A1 = LcdWriteDataMultiple;
//PortAPI.pfReadM16_A1= LcdReadDataMultiple;
//GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66708, GUIDRV_FLEXCOLOR_M16C0B16);

}

舒伯特玫瑰 发表于 2023-9-28 16:01

2.GUIDRV_Template.c
这个文件要修改三个函数

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

      xPhys = LOG2PHYS_X(x, y);
      yPhys = LOG2PHYS_Y(x, y);
    #else
      #define xPhys x
      #define yPhys y
    #endif
    GUI_USE_PARA(pDevice);
    GUI_USE_PARA(x);
    GUI_USE_PARA(y);
    GUI_USE_PARA(PixelIndex);
    {
      //
      // Write into hardware ... Adapt to your system
      //
      // TBD by customer...
      //
      LCD_DrawPoint(x,y,PixelIndex);
    }
    #if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)
      #undef xPhys
      #undef yPhys
    #endif
}

舒伯特玫瑰 发表于 2023-9-28 16:01

第二个加入PixelIndex = LCD_ReadPoint(x,y);:static unsigned int _GetPixelIndex(GUI_DEVICE * pDevice, int x, int y) {
unsigned int PixelIndex;
    //
    // Convert logical into physical coordinates (Dep. on LCDConf.h)
    //
    #if (LCD_MIRROR_X == 1) || (LCD_MIRROR_Y == 1) || (LCD_SWAP_XY == 1)
      int xPhys, yPhys;

      xPhys = LOG2PHYS_X(x, y);
      yPhys = LOG2PHYS_Y(x, y);
    #else
      #define xPhys x
      #define yPhys y
    #endif
    GUI_USE_PARA(pDevice);
    GUI_USE_PARA(x);
    GUI_USE_PARA(y);
    {
      //
      // Write into hardware ... Adapt to your system
      //
      // TBD by customer...
      //
      PixelIndex = LCD_ReadPoint(x,y);
    }
    #if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)
      #undef xPhys
      #undef yPhys
    #endif
return PixelIndex;
}

舒伯特玫瑰 发表于 2023-9-28 16:08

第三个加入LCD_Fill(x0,y0,x1,y1,LCD_COLORINDEX);:

static void _FillRect(GUI_DEVICE * pDevice, int x0, int y0, int x1, int y1)
{
    LCD_Fill(x0,y0,x1,y1,LCD_COLORINDEX);
//LCD_PIXELINDEX PixelIndex;
//int x;

//PixelIndex = LCD__GetColorIndex();
//if (GUI_pContext->DrawMode & LCD_DRAWMODE_XOR) {
//    for (; y0 <= y1; y0++) {
//      for (x = x0; x <= x1; x++) {
//      _XorPixel(pDevice, x, y0);
//      }
//    }
//} else {
//    for (; y0 <= y1; y0++) {
//      for (x = x0; x <= x1; x++) {
//      _SetPixelIndex(pDevice, x, y0, PixelIndex);
//      }
//    }
//}
}

舒伯特玫瑰 发表于 2023-9-28 16:08

3.GUIConf.c
修改内存大小:
#define GUI_NUMBYTES40*1024
该处使用的url网络请求的数据。

舒伯特玫瑰 发表于 2023-9-28 16:08

4.at32f403a_407_int.c
修改systick定时器中断:
extern __IO int32_t OS_TimeMS;
void SysTick_Handler(void)
{
OS_TimeMS++;

        if(OS_TimeMS%100 == 0)
        {
      LED2_BL;//加个LED指示一下
        }
}

舒伯特玫瑰 发表于 2023-9-28 16:09

5.main.c测试
代码如下(示例):
#include "at32f403a_407_clock.h"
#include "Drv_Delay.h"
#include "Drv_Uart.h"
#include "Drv_Led.h"
#include "Drv_LCD.h"
#include "WM.h"
#include "GUI.h"
#include "GUIDEMO.h"

intmain(void)
{
    system_clock_config();
    uart_print_init(115200);
        LCD_Init();       
    LCD_Back(BLUE);

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

    GUI_SetFont(&GUI_Font8x16x3x3);      //字体设置
    GUI_DispStringAt("Hello World!",20,50);

    while(1){}


}
页: [1]
查看完整版本: AT32F403A例程之-STemWin移植