这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 企业专区 » GD32 » GD32107C-EVAL移植GUI体验(二)

共3条 1/1 1 跳转至

GD32107C-EVAL移植GUI体验(二)

高工
2015-04-03 02:36:28     打赏

在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);

}


关于触摸芯片的驱动程序,有兴趣的在导航帖中查看。这里主要体验一下GD32的SPI功能,以及在GUI上加入触摸功能。在使用过程中,GD32的SPI功能也是不虚STM32。用起来还是挺方便的,没出啥问题。


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);
      }
	}
}



效果图:





关键词: GD32107C-EVAL     彩屏     实验    

高工
2015-04-03 14:28:31     打赏
2楼
玩转触摸,不错。。。。

院士
2015-04-03 20:16:29     打赏
3楼
这个动画演示的效果真棒啊

共3条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]