在GUI体验一中完成了对GUI核心部分的移植,应该说是必要的部分。如果仅限于此,也就浪费了GD32板子上那颗电阻屏触摸芯片了。下面是原理图:
用到了SPI1,那么首先是对SPI1的配置啦,先看芯片的时序确定SPI初始化中的几个参数:
void SPI1_Init() { GPIO_InitTypeDef GPIO_InitStruct; SPI_InitTypeDef SPI_InitStruct; RCC_APB2PeriphClockCmd (RCC_APB2Periph_SPI1 | RCC_APB2Periph_GPIOA,ENABLE ); GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz ; GPIO_Init(GPIOA,&GPIO_InitStruct); SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64; SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStruct.SPI_CPOL = SPI_CPOL_Low; SPI_InitStruct.SPI_CRCPolynomial = 7; SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b; SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStruct.SPI_Mode = SPI_Mode_Master; SPI_InitStruct.SPI_NSS = SPI_NSS_Soft; SPI_Init (SPI1,&SPI_InitStruct); SPI_Cmd (SPI1,ENABLE); }
GUI关于触屏的移植部分:
#include "GUI.h" #include "GUI_X.h" #include "touch.h" void GUI_TOUCH_X_ActivateX(void) { } void GUI_TOUCH_X_ActivateY(void) { } int GUI_TOUCH_X_MeasureX(void) { u16 x,y; TP_Read_XY2(&x,&y); return x; } int GUI_TOUCH_X_MeasureY(void) { u16 x,y; TP_Read_XY2(&x,&y); return y; }
#define GUI_TOUCH_AD_LEFT 270 #define GUI_TOUCH_AD_RIGHT 3766 #define GUI_TOUCH_AD_TOP 3855 #define GUI_TOUCH_AD_BOTTOM 370 #ifndef GUICONF_H #define GUICONF_H #define GUI_OS (0) /* Compile with multitasking support */ #define GUI_SUPPORT_TOUCH (1) /* Support a touch screen (req. win-manager) */ #define GUI_SUPPORT_UNICODE (1) /* Support mixed ASCII/UNICODE strings */ #define GUI_DEFAULT_FONT &GUI_Font8x16 #define GUI_ALLOC_SIZE 12500 /* Size of dynamic memory ... For WM and memory devices*/
主函数程序如下:
GUI_PID_STATE GUI_PID_STATE_GD; int main() { NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); LedPinInit(); SysTickInit(); TimerInit(99,7199); AdcInit(); GUI_Init(); GUI_SetBkColor(GUI_RED); GUI_SetColor(GUI_WHITE); GUI_Clear(); GUI_DispStringAt("liklon--->GD32107C-EVAL",1,40); GUI_DispStringAt("www.eepw.com.cn",40,60); GUI_DispStringAt("ADC:",80,80); GUI_DispStringAt("VOLTAGE:",48,120); GUI_DispStringAt("TEMPERATE:",48,160); TouchInit(); GUI_SetPenSize(10); while(1) { if(gLedRunFlag > 10) { gVoltage = gAdcVal[0] * 3.3 / 4096.0; gTemperate = gAdcVal[1] * 3.3 / 4096.0; gTemperate = (1.43 - gTemperate) / 0.0043 + 25; GUI_DispDecAt(gAdcVal[0],100,100,4); GUI_GotoXY(100,140); GUI_DispFloat(gVoltage,3); GUI_GotoXY(100,180); GUI_DispFloat(gTemperate,5); gLedRunFlag = 0; } GUI_TOUCH_GetState(&GUI_PID_STATE_GD); if(GUI_PID_STATE_GD.Pressed == 1) { GUI_DrawPoint(GUI_PID_STATE_GD.x ,GUI_PID_STATE_GD.y); } } }
效果图: