You are on page 1of 25

STM32F4 EMWIN

ALIENTEK STemWin

EMWIN
V1.0
ALIENTEK STM32F4 EMWIN

http://shop62057469.taobao.com
www.openedv.com
: 333121886

STM32F4 EMWIN
ALIENTEK STemWin

STemWin ................................................ 3

1.1 ..................................................................................................... 4
1.2 .................................................................................................. 8
1.3 ...................................................................................................... 9
1.4 ......................................................................................................... 12
1.5 ............................................................................................ 17
1.6 ............................................................................................................ 19
STemWin ............................................... 20

2.1 .................................................................................................... 21
2.2 ......................................................................... 21
2.3 ............................................................................................ 24
2.4 ............................................................................................................ 24

STM32F4 EMWIN
ALIENTEK STemWin

STemWin
M3 MCU UCGUI UIUCGUI
emWin
STemWin SEGGER ST emWin
ST STemWin
STemWin ST STM32F407
STemWin 2.8 3.5 4.3

1.1
1.2
1.3
1.4
1.5
1.6

STM32F4 EMWIN
ALIENTEK STemWin

1.1
1)
STemWin
STemWin

STemWin
1 HARDWARE LCD lcd.h lcd.c
ILI93xx.h ILI93xx.c
2 ILI93xx.c LCD_Init TFTLCD_Init
3 ILI93xx.h LCD LCD TFTLCD
LCD TFTLCD
// NOR/SRAM Bank1.sector4, HADDR[27,26]=11 A6
// STM32 ! 111 1110=0X7E
#define LCD_BASE
((u32)(0x6C000000 | 0X0000007E))
#define LCD
((LCD_TypeDef *) LCD_BASE)
4STM32F4xx FPUSTemWin STM32F4 FPU ST
DSP STM32F4xx M4 MCU STiemWin
STM32F4xx FPU DSP STM32F1xx M3 MCU

ST STM32F4xx DSP : http://www


.st.com/web/en/catalog/tools/FM147/CL1794/SC961/SS1743/PF257901?s_searchtype=keyword#
1.1.1 1.4.0

1.1.1 STM32F4xx
Libraries 1.1.2 STM32F4xx
DSP DSP CMSIS CMSIS FWLIB
CMSIS 133M DSP
Include Lib Include
Lib DSP ARMG++GCC KEIL
ARM IAR GCC

STM32F4 EMWIN
ALIENTEK STemWin

1.1.2 STM32F4xx
STM32F4 FPU FPU system_stm32f4xx.c
SystemInit() FPU 1.1.3

1.1.3 FPU
1.1.3 FPU __FPU_PRESENT __FPU_USED 1
arm_math.h
DSP ARM_MATH_CM4 __CC_ARM
1.1.4 __FPU_PRESENT__FPU_USEDARM_MATH_CM4
__CC_ARM

1.1.4 __FPU_PRESENT __FPU_USED


keil FPU 1.1.5

STM32F4 EMWIN
ALIENTEK STemWin

1.1.5 FPU
DSP CMSIS Include
arm_math.h Lib ARM arm_cortexM4lf_math.lib
DSP ARM
lib lib arm_cortexM4lf_math.lib
CMSIS 11M 1.1.6
STemWin

1.1.6 DSP
2 STemWin
STemWinSTemWin ST
http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/LN1734/PF259225?
s_searchtype=partnumber 1.1.7 STemWin 1.1.2 5.22
emWin:6,->EMWIN ->STemWin

STM32F4 EMWIN
ALIENTEK STemWin

1.1.7 STemWin
STemWin_Library_V1.1.2STiemWin

STemWin STemWin_Library_V1.1.2 Libraries STemWinLibrary522


STemWin 1.1.8
5.22 emWin

1.1.8 STemWin
STemWinLibrary522 6 1.1.1
1.1.1 STemWin

Config
Documentation

LCD emWin
STemWin

inc

STiemWin

Lib

STemWin

OS

OS

Software

STM32F4 EMWIN
ALIENTEK STemWin

1.2
STemWin STemWin
EMWIN STemWin EMWIN
1.2.1 STemWin

1.2.1 STemWin
1.2.1 STemWin 1.2.1
1.2.1

GUI_X.c

GUI /

GUIConf.c

GUI

GUIConf.h

GUI

GUIDRV_Template.c

GUI

LCDConf_FlexColor_Template.c

LCD

STemWin522_CM4_Keil.lib

STemWin

OS

Config

Lib

STemWin STemWinLibrary522 Lib 1.2.2 STemWin


OS OS Lib
OS OS KEIL
STemWin522_CM4_OS_Keil.lib STemWin522_CM4_Keil.lib
MCU
STiemWin STemWin522_CM4_Keil.lib
STemWinLibrary522 6
Documentation Software

LCDConf.h LCDConf.h
STemWin Config LCDConf.h

STM32F4 EMWIN
ALIENTEK STemWin

1.2.2 STemWin

1.3
1) GUIConf.h
GUIConf.h
GUIConf.h
#ifndef GUICONF_H
#define GUICONF_H
#define GUI_NUM_LAYERS
#define GUI_OS
#define GUI_SUPPORT_TOUCH
#define GUI_DEFAULT_FONT
#define GUI_SUPPORT_MOUSE
#define GUI_WINSUPPORT
#define GUI_SUPPORT_MEMDEV
#define GUI_SUPPORT_DEVICES

2
//
(0)
//
(0)
//
&GUI_Font6x8
//
(1)
//
(1)
//
(1)
//
(1)
//

#endif
2) GUIConf.c
GUIConf.c STemWin
STemWin 1M SRAMGUIConf.c
USE_EXRAM SRAM
#include "GUI.h"
#include "sram.h"
#include "malloc.h"

STM32F4 EMWIN
ALIENTEK STemWin

#define USE_EXRAM 0// SRAM


#define GUI_NUMBYTES (100*1024) // EMWIN
#define GUI_BLOCKSIZE 0X80 //
//GUI_X_Config
//, emwin
void GUI_X_Config(void)
{
if(USE_EXRAM) // RAM
{
// SRAM GUI_NUMBYTES
U32 *aMemory = mymalloc(SRAMEX,GUI_NUMBYTES);
//
GUI_ALLOC_AssignMemory((void*)aMemory, GUI_NUMBYTES);
//,,
GUI_ALLOC_SetAvBlockSize(GUI_BLOCKSIZE);
GUI_SetDefaultFont(GUI_FONT_6X8); //
}else // RAM
{
// RAM GUI_NUMBYTES
U32 *aMemory = mymalloc(SRAMIN,GUI_NUMBYTES);
//
GUI_ALLOC_AssignMemory((U32 *)aMemory, GUI_NUMBYTES);
//,,
GUI_ALLOC_SetAvBlockSize(GUI_BLOCKSIZE);
GUI_SetDefaultFont(GUI_FONT_6X8); //
}
}
3) GUIDRV_Template.c
STemWin
16BPP STemWin

_FillRect()
_SetPixelIndex()_DrawBitLine16BPP()_GetPixelIndex()
LCD LCD_ReadPoint()
4) LCDConf_FlexColor_Template.c
LcdWriteReg()
LcdWriteData()LcdWriteDataMultiple()
LcdReadDataMultiple()
LCD_X_Config() LCD_X_DisplayDriver() 6 STemWin LCD
IC 4 STemWin LCD
LCD IC STemWin 4
LCD TFTLCD_Init() LCD
GUIDRV_Template.c STemWin 4

10

STM32F4 EMWIN
ALIENTEK STemWin

LCD_X_Config() LCD_X_DisplayDriver()LCD_X_Config()

//,,
void LCD_X_Config(void)
{
//
GUI_DEVICE_CreateAndLink(&GUIDRV_Template_API, GUICC_M565, 0, 0);
if(lcddev.id == 0X5510) //0X5510 4.3 800x480
{
LCD_SetSizeEx
(0, lcddev.width, lcddev.height);
LCD_SetVSizeEx (0, lcddev.width, lcddev.height);
}else if(lcddev.id == 0X5310 || lcddev.id == 0X6804) //0X5510 0X6804 3.5 320x480
{
LCD_SetSizeEx
(0, lcddev.width, lcddev.height);
LCD_SetVSizeEx (0, lcddev.width, lcddev.height);
}else
// 2.8 320X240
{
LCD_SetSizeEx
(0, lcddev.width, lcddev.height);
LCD_SetVSizeEx (0, lcddev.width, lcddev.height);
}
}
GUI_DEVICE_CreateAndLink()

STemWin IC
emWin
STemWin emWin
GUICC_M565 RGB565
LCD IC
5)
STemWin

int main(void)
{
delay_init(168);
//
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //
uart_init(115200);
//
LED_Init();
//LED
TFTLCD_Init();
//LCD
FSMC_SRAM_Init();
//SRAM
mem_init(SRAMIN);
//
mem_init(SRAMEX);
//
mem_init(SRAMCCM);
// CCM

11

STM32F4 EMWIN
ALIENTEK STemWin

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC,ENABLE);// CRC
GUI_Init();
//STemWin
GUI_SetBkColor(GUI_BLUE);
//
GUI_SetColor(GUI_YELLOW);
//
GUI_Clear();
//
GUI_SetFont(&GUI_Font24_ASCII); //
GUI_DispStringAt("Hello Word!",0,0); //
while(1);
}
STiemWin CRC STemWin

LCD (0,0)Hello Word! LCD TFTLCD_Init()


LCD_Scan_Dir() 1.3.1

1.3.1

1.4
STemWin
1

#include "lcd.h"#include
"ILI93xx.h"
2 GUI_X_Touch_Analog.c
GUI_X_Touch_Analog.c
GUI_TOUCH_X_ActivateX() GUI_TOUCH_X_ActivateY() GUI_TOUCH_X_MeasureX()
GUI_TOUCH_X_MeasureY()
X Y AD GUI_TOUCH_X_MeasureX
int GUI_TOUCH_X_MeasureX(void)

12

STM32F4 EMWIN
ALIENTEK STemWin

{
u8 buf[4];
int32_t lost_x;
static u8 mode;
if(lcddev.id == 0X5510) //
{
OTT2001A_RD_Reg(OTT_GSTID_REG,&mode,1);
if(mode & 0X1F) //
{
OTT2001A_RD_Reg(0X0100,buf,4);// x[0],y[0]
tp_dev.x[0] = (((u16)buf[2]<<8)+buf[3])*OTT_SCAL_X;
lost_x = tp_dev.x[0];
if(lost_x >479 ) lost_x =479;
else if(lost_x < 0) lost_x=0;
}else lost_x = 0;
return lost_x;
}else
{
return TP_Read_XOY(0XD0); //CMD_RDX=0XD0
}
}
LCD ID

TP_Read_XOY() X AD GUI_TOUCH_X_MeasureY()
GUI_TOUCH_X_MeasureX()
3 GUIConf.h LCDConf_FlexColor_Template.c
GUIConf.h GUI_SUPPORT_TOUCH 1 STemWin
LCDConf_FlexColor_Template.c
#define TOUCH_AD_TOP
160 //!!!!
#define TOUCH_AD_BOTTOM
3990
#define TOUCH_AD_LEFT
160
#define TOUCH_AD_RIGHT
3990
AD
STemWin
void Mytouch_MainTask(void)
{
GUI_PID_STATE TouchState;
int
xPhys;
int
yPhys;
GUI_Init();
GUI_SetFont(&GUI_Font20_ASCII);
GUI_CURSOR_Show();
GUI_CURSOR_Select(&GUI_CursorCrossL);

13

STM32F4 EMWIN
ALIENTEK STemWin

GUI_SetBkColor(GUI_WHITE);
GUI_SetColor(GUI_BLACK);
GUI_Clear();
GUI_DispString("Measurement of\nA/D converter values");
while (1)
{
GUI_TOUCH_GetState(&TouchState); // Get the touch position in pixel
xPhys = GUI_TOUCH_GetxPhys();
// Get the A/D mesurement result in x
yPhys = GUI_TOUCH_GetyPhys();
// Get the A/D mesurement result in y
GUI_SetColor(GUI_BLUE);
GUI_DispStringAt("Analog input:\n", 0, 20);
GUI_GotoY(GUI_GetDispPosY() + 2);
GUI_DispString("x:");
GUI_DispDec(xPhys, 4);
GUI_DispString(", y:");
GUI_DispDec(yPhys, 4);
GUI_SetColor(GUI_RED);
GUI_GotoY(GUI_GetDispPosY() + 4);
GUI_DispString("\nPosition:\n");
GUI_GotoY(GUI_GetDispPosY() + 2);
GUI_DispString("x:");
GUI_DispDec(TouchState.x,4);
GUI_DispString(", y:");
GUI_DispDec(TouchState.y,4);
delay_ms(50);
};
}
AD LCD
1.4.1 AD

14

STM32F4 EMWIN
ALIENTEK STemWin

1.4.1 AD
LCDConf_FlexColor_Template.c LCD_X_Config()

void LCD_X_Config(void)
{
//
GUI_DEVICE_CreateAndLink(&GUIDRV_Template_API, GUICC_M565, 0, 0);
if(lcddev.id == 0X5510) //0X5510 4.3 800x480
{
LCD_SetSizeEx
(0, lcddev.width, lcddev.height);
LCD_SetVSizeEx (0, lcddev.width, lcddev.height);
if(lcddev.dir == 0) //
{
GUI_TOUCH_Calibrate(GUI_COORD_X,0,480,0,479);

15

STM32F4 EMWIN
ALIENTEK STemWin

GUI_TOUCH_Calibrate(GUI_COORD_Y,0,800,0,799);
}else //
{
GUI_TOUCH_SetOrientation(GUI_SWAP_XY|GUI_MIRROR_Y);
GUI_TOUCH_Calibrate(GUI_COORD_X,0,480,0,479);
GUI_TOUCH_Calibrate(GUI_COORD_Y,0,800,0,799);
}
}else if(lcddev.id == 0X5310 || lcddev.id == 0X6804) //0X5510 0X6804 3.5 320x480
{
LCD_SetSizeEx
(0, lcddev.width, lcddev.height);
LCD_SetVSizeEx (0, lcddev.width, lcddev.height);
if(lcddev.dir == 0) //
{
GUI_TOUCH_Calibrate(GUI_COORD_X,0,320,3931,226);
GUI_TOUCH_Calibrate(GUI_COORD_Y,0,480,3821,196);
}else //
{
GUI_TOUCH_SetOrientation(GUI_SWAP_XY|GUI_MIRROR_Y);
GUI_TOUCH_Calibrate(GUI_COORD_X,0,320,3931,226);
GUI_TOUCH_Calibrate(GUI_COORD_Y,0,480,3821,196);
}
}else
// 2.8 320X240
{
LCD_SetSizeEx
(0, lcddev.width, lcddev.height);
LCD_SetVSizeEx (0, lcddev.width, lcddev.height);
if(lcddev.dir == 0) //
{
GUI_TOUCH_Calibrate(GUI_COORD_X,0,240 ,155,3903);
GUI_TOUCH_Calibrate(GUI_COORD_Y,0,320 188,3935);
}else //
{
GUI_TOUCH_SetOrientation(GUI_SWAP_XY|GUI_MIRROR_Y);
GUI_TOUCH_Calibrate(GUI_COORD_X,0,240,155,3903);
GUI_TOUCH_Calibrate(GUI_COORD_Y,0,320,188,3935);
}
}
}

GUI_TOUCH_Calibrate() X,Y GUI_TOUCH_SetOrientation()


emWin

16

STM32F4 EMWIN
ALIENTEK STemWin

1.5
STemWin Demo
Demo
Demo GUI_TOUCH_Exec()
3 4
GUI_TOUCH_Exec() 3 4
// 3
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3,TIM_IT_Update)==SET) //
{
OS_TimeMS++;
}
TIM_ClearITPendingBit(TIM3,TIM_IT_Update); //
}
// 4
void TIM4_IRQHandler(void)
{
if(TIM_GetITStatus(TIM4,TIM_IT_Update)==SET) //
{
TIM_ClearITPendingBit(TIM4,TIM_IT_Update); //
GUI_TOUCH_Exec();
}
}
3 OS_TimeMS

Demo

Demo
GUIDEMO.c
bsp.h bsp.h
1.5.1

17

STM32F4 EMWIN
ALIENTEK STemWin

1.5.1 Demo

GUI GUIDEMO_Main() CRC


int main(void)
{
delay_init(168);
//
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //
uart_init(115200);
//
LED_Init();
//LED
TFTLCD_Init();
//LCD
TP_Init();
//
FSMC_SRAM_Init();
//SRAM
TIM3_Int_Init(999,83);
//1KHz 3 1ms
mem_init(SRAMIN);
mem_init(SRAMEX);
mem_init(SRAMCCM);

//
//
// CCM

18

STM32F4 EMWIN
ALIENTEK STemWin

TIM4_Int_Init(499,839);
//,200HZ.
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC,ENABLE);// CRC
WM_SetCreateFlags(WM_CF_MEMDEV);
GUI_Init();
GUIDEMO_Main();
while(1);
}
STemWin startup_stm32f40_41xxx.s
1.5.2

1.5.2

1.6
STemWin 1.5.3

1.5.3 STemWin

19

STM32F4 EMWIN
ALIENTEK STemWin

STemWin
STemWin

STemWin UCOS II UCOS II ALIENTEK STM32F4


UCOS

2.1
2.2
2.3
2.4

20

STM32F4 EMWIN
ALIENTEK STemWin

2.1
UCOS II
UCOS II
UCOS ALIENTEK STM32F4 UCOS
UCOSII UCOSII OS_TICKS_PER_SEC 1000
1ms
UCOS II 200
UCOS II 2.1.1

2.1.1 UCOS II

2.2
GUI_X.c GUI_X_UCOSII.c
GUI_X.c
GUI_X_UCOSII.c
2.2.1

2.2.1 GUI_X_UCOSII.c

21

STM32F4 EMWIN
ALIENTEK STemWin

GUI_X_UCOSII.c
1)
int GUI_X_GetTime(void) {
return ((int)OSTimeGet()); //, 1ms
}
//GUI
void GUI_X_Delay(int period) {
INT32U ticks;
ticks = (period * 1000) / OS_TICKS_PER_SEC;
OSTimeDly(ticks);
}
STemWin STemWin
UCOS II
2)
void GUI_X_InitOS(void)
{
DispSem = OSSemCreate(1);
// 1
EventMbox = OSMboxCreate((void*)0); //
}
void GUI_X_Lock(void)
{
INT8U err;
OSSemPend(DispSem,0,&err); //
}
void GUI_X_Unlock(void)
{
OSSemPost(DispSem);
//
}
void GUI_X_WaitEvent(void)
{
INT8U err;
(void)OSMboxPend(EventMbox,0,&err); //
}
void GUI_X_SignalEvent(void)
{
(void)OSMboxPost(EventMbox,(void*)1); //
}
5
GUI_X_InitOS()
GUI_X_Lock()GUI_X_Unlock()
GUI_X_WaitEvent()
GUI_X_SignalEvent()

22

STM32F4 EMWIN
ALIENTEK STemWin

static void CheckInit(void)


{
if(KeyIsInited == OS_FALSE){
KeyIsInited = OS_TRUE;
GUI_X_Init();
}
}
void GUI_X_Init(void)
KeySem = OSSemCreate(0); // 0
}
int GUI_X_GetKey(void)
{
int r;
r = KeyPressed;
CheckInit();
KeyPressed = 0;
return (r);
}
int GUI_X_WaitKey(void)
{
int r;
INT8U err;
CheckInit();
if(KeyPressed == 0)
{
OSSemPend(KeySem,0,&err); //
}
r = KeyPressed;
KeyPressed = 0;
return (r);
}
void GUI_X_StoreKey(int k)
{
KeyPressed = k;
OSSemPost(KeySem);
}
4
STemWin STemWin522_CM4_Keil.lib
STemWin522_CM4_OS_Keil.lib
GUIConf.h GUI_OS GUI_OS 1
STemWin 2.2.2

23

STM32F4 EMWIN
ALIENTEK STemWin

2.2.2 GUIConf.h

2.3
Demo main.c 4 2.3.1
2.3.1

start_task
emwindemo_task

STemWin 3
Demo

touch_task

GUI_TOUCH_Exec()

led0_task

LED

main.c

int main(void)
{
delay_init();
//
NVIC_Configuration();
//
uart_init(115200);
//
TFTLCD_Init();
// LCD
TP_Init();
//
LED_Init();
//LED
FSMC_SRAM_Init();
//SRAM
mem_init(SRAMIN);
// RAM
mem_init(SRAMEX);
// RAM
mem_init(SRAMCCM);
//CCM
OSInit();
// UCOS
OSTaskCreate(start_task,
//start_task
(void*)0,
//
(OS_STK*)&START_TASK_STK[START_STK_SIZE-1], //
START_TASK_PRIO);
//
OSStart(); // UCOS
}
start_task
3 4 3 STemWin
4 UCOS II UCOS II
STemWin

2.4
LCD 2.4.1
24

STM32F4 EMWIN
ALIENTEK STemWin

Demo LED0

2.4.1

25