平台:战舰F1大板
OS :UCOSII 2.98
STemwin5.22
LCD : 正点原子3.5寸 NT35310 XPT2046
PS:下载EMWIN-UCOSIII扩展例程后触摸屏校准时的数据都是4095,换了一个2.8的屏读到的数据也是4095
触摸屏移植上去后在下面两个函数能读到触摸数据
int GUI_TOUCH_X_MeasureX(void) {
int result;
result = TouchReadXY(XPT2046_RDX);
return result;
}
int GUI_TOUCH_X_MeasureY(void) {
int result;
result = TouchReadXY(XPT2046_RDY);
return result;
}
10ms定时调用GUI_TOUCH_Exec()
static void tmrCb_Touch(void *p_tmr, void *p_arg)
{
(void)p_arg;
GUI_TOUCH_Exec();
}
触摸校准和demo任务
void EmWinDemo(void *p_arg)
{
WM_SetCreateFlags(WM_CF_MEMDEV);
GUI_Init();
TouchCalibrate();
for(;;)
{
GUIDEMO_Main();
}
}
当程序执行到TouchCalibrate.c里这个函数时,获取的State成员变量总是为0,可是GUI_TOUCH_X_MeasureY(),GUI_TOUCH_X_MeasureX()有数据读出来。
static void _WaitForPressedState(int Pressed) {
GUI_PID_STATE State;
do {
GUI_TOUCH_GetState(&State);
GUI_Delay(1);
if (State.Pressed == Pressed) {
int TimeStart = GUI_GetTime();
do {
GUI_TOUCH_GetState(&State);
GUI_Delay(1);
if (State.Pressed != Pressed) {
break;
} else if ((GUI_GetTime() - 50) > TimeStart) {
return;
}
} while (1);
}
} while (1);
}
大神们帮帮忙
====================================TouchCalibrate.c=========================================
[mw_shl_code=c,true]#include "GUI.h"
#include "touch_calibrate.h"
/********************************************************************
*
* Static data
*
*********************************************************************
*/
static const char * _acPos[] = {
"(upper left position)",
"(lower right position)"
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _WaitForPressedState
*
* Purpose:
* Waits until the touch is in the given pressed state for at least 250 ms
*/
static void _WaitForPressedState(int Pressed) {
GUI_PID_STATE State;
do {
GUI_TOUCH_GetState(&State);
GUI_Delay(1);
if (State.Pressed == Pressed) {
int TimeStart = GUI_GetTime();
do {
GUI_TOUCH_GetState(&State);
GUI_Delay(1);
if (State.Pressed != Pressed) {
break;
} else if ((GUI_GetTime() - 50) > TimeStart) {
return;
}
} while (1);
}
} while (1);
}
/*********************************************************************
*
* _DispStringCentered
*
* Purpose:
* Shows the given text horizontally and vertically centered
*/
static void _DispStringCentered(const char * pString) {
GUI_RECT Rect;
Rect.x0 = Rect.y0 = 0;
Rect.x1 = LCD_GetXSize() - 1;
Rect.y1 = LCD_GetYSize() - 1;
GUI_DispStringInRect(pString, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
}
/*********************************************************************
*
* _GetPhysValues
*
* Purpose:
* Asks the user to press the touch screen at the given position
* and returns the physical A/D values
*/
static void _GetPhysValues(int LogX, int LogY, int * pPhysX, int * pPhysY, const char * pString) {
char acText[] = "Press here";
GUI_RECT Rect;
int FontSizeY, Align;
FontSizeY = GUI_GetFontSizeY();
GUI_Clear();
GUI_SetColor(GUI_BLACK);
_DispStringCentered("Runtime calibration,\n"
"please touch the screen\n"
"at the center of the ring."); /* Ask user to press the touch */
/* Calculate the rectangle for the string */
Rect.y0 = LogY - FontSizeY;
Rect.y1 = LogY + FontSizeY;
if (LogX < LCD_GetXSize() / 2) {
Rect.x0 = LogX + 15;
Rect.x1 = LCD_GetXSize();
Align = GUI_TA_LEFT;
} else {
Rect.x0 = 0;
Rect.x1 = LogX - 15;
Align = GUI_TA_RIGHT;
}
/* Show the text nearby the ring */
GUI_DispStringInRect(acText, &Rect, Align | GUI_TA_TOP);
GUI_DispStringInRect(pString, &Rect, Align | GUI_TA_BOTTOM);
/* Draw the ring */
GUI_FillCircle(LogX, LogY, 10);
GUI_SetColor(GUI_WHITE);
GUI_FillCircle(LogX, LogY, 5);
GUI_SetColor(GUI_BLACK);
/* Wait until touch is pressed */
_WaitForPressedState(1);
*pPhysX = GUI_TOUCH_GetxPhys();
*pPhysY = GUI_TOUCH_GetyPhys();
/* Wait until touch is released */
_WaitForPressedState(0);
}
/********************************************************************
*
* _Explain
*
* Purpose:
* Shows a text to give a short explanation of the sample program
*/
static void _Explain(void) {
_DispStringCentered("This sample shows how\n"
"a touch screen can be\n"
"calibrated at run time.\n"
"Please press the touch\n"
"screen to continue...");
GUI_DispStringHCenterAt("TOUCH_Calibrate", LCD_GetXSize() / 2, 5);
_WaitForPressedState(1);
_WaitForPressedState(0);
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void TouchCalibrate(void)
{
int aPhysX[2], aPhysY[2], aLogX[2], aLogY[2], i;
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
GUI_SetColor(GUI_BLACK);
GUI_SetFont(&GUI_Font13B_ASCII);
_Explain();
/* Set the logical values */
aLogX[0] = 15;
aLogY[0] = 15;
aLogX[1] = LCD_GetXSize() - 15;
aLogY[1] = LCD_GetYSize() - 15;
/* Get the physical values of the AD converter for 2 positions */
for (i = 0; i < 2; i++) {
_GetPhysValues(aLogX, aLogY, &aPhysX, &aPhysY, _acPos);
}
/* Use the physical values to calibrate the touch screen */
GUI_TOUCH_Calibrate(0, aLogX[0], aLogX[1], aPhysX[0], aPhysX[1]); /* Calibrate X-axis */
GUI_TOUCH_Calibrate(1, aLogY[0], aLogY[1], aPhysY[0], aPhysY[1]); /* Calibrate Y-axis */
/* Display the result */
GUI_CURSOR_Show();
GUI_Clear();
_DispStringCentered("Congratulation, your\n"
"touch screen has been\n"
"calibrated. Please use\n"
"the cursor to test\n"
"the calibration...");
GUI_Delay(500);
/* Let the user play */
// while(1) {
// GUI_PID_STATE State;
// GUI_TOUCH_GetState(&State);
// if (State.Pressed == 1) {
// GUI_FillCircle(State.x, State.y, 3);
// }
// GUI_Delay(10);
// }
}
[/mw_shl_code]
================================main.c==================================================
[mw_shl_code=c,true]#include "stm32f10x.h"
#include "ucos_ii.h"
#include "app_cfg.h"
#include "bsp.h"
#include "touch_calibrate.h"
#include "GUIDEMO.h"
static OS_STK LedRunStatusStk[START_UP_TASK_STK_SIZE];
static OS_STK EmWinDemoStk[EMWIN_DEMO_TASK_STK_SIZE];
static OS_STK StartUpTaskStk[START_UP_TASK_STK_SIZE];
int main(void)
{
BSPInit();
OSInit();
OSTaskCreate(StartUpTask,
(void*)0,
&StartUpTaskStk[START_UP_TASK_STK_SIZE-1],
START_UP_TASK_PRIO
);
OSStart();
return 0;
}
/**
** ????????????????
** LED????
**/
static void LedRunStatusTask(void *p_arg)
{
for(;;)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_5);
OSTimeDly(100);
GPIO_SetBits(GPIOB,GPIO_Pin_5);
OSTimeDly(100);
GPIO_ResetBits(GPIOB,GPIO_Pin_5);
OSTimeDly(100);
GPIO_SetBits(GPIOB,GPIO_Pin_5);
OSTimeDly(2000);
}
}
/**
** wmWin Demo ????
**/
extern void GUIDEMO_Main(void);
void EmWinDemo(void *p_arg)
{
WM_SetCreateFlags(WM_CF_MEMDEV);
GUI_Init();
TouchCalibrate();
for(;;)
{
GUIDEMO_Main();
}
}
/* ???????????????? GUI_TOUCH_Exec() 100??×ó?? */
static void tmrCb_Touch(void *p_tmr, void *p_arg)
{
(void)p_arg;
GUI_TOUCH_Exec();
}
/**
** ????????
**
**/
void StartUpTask(void *p_arg)
{
INT8U err;
OS_TMR *tmr_tp;
OSTaskCreate(
LedRunStatusTask,
(void*)0,
&LedRunStatusStk[LED_RUN_STATUS_TASK_STK_SIZE-1],
LED_RUN_STATUS_TASK_PRIO);
OSTaskCreate(
EmWinDemo,
(void*)0,
&EmWinDemoStk[EMWIN_DEMO_TASK_STK_SIZE-1],
EMWIN_DEMO_TASK_PRIO);
tmr_tp = OSTmrCreate(
1, //
1,
OS_TMR_OPT_PERIODIC,
&tmrCb_Touch,
(void *)0,
(INT8U *)"touch exec",
&err);
OSTmrStart(tmr_tp,&err);
OSTaskDel(OS_PRIO_SELF);
}
[/mw_shl_code]
|