📄 mx1touch.cpp
字号:
#if defined(PEGSMX)
SendPegInputMessage(&TouchMesg);
#else
PegThing::MessageQueue()->Push(TouchMesg);
#endif
OldXPos = XPos;
OldYPos = YPos;
wLastState = TS_TOUCH_SENT; // keep track of current state
}
}
else
{
// here if the screen is NOT touched:
if (wLastState & TS_TOUCH_SENT) // was touch message sent?
{
wLastState = 0;
TouchMesg.wType = PM_LBUTTONUP;
TouchMesg.Point.x = OldXPos;
TouchMesg.Point.y = OldYPos;
TouchMesg.iData = 0;
#if defined(PEGSMX)
SendPegInputMessage(&TouchMesg);
#else
PegThing::MessageQueue()->Push(TouchMesg);
#endif
}
}
}
}
} // End of Extern 'C'
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// For the SMX and QUADROS operating systems, the touch task stack space
// is taken care of for us during task creation. For PrKernel and ThreadX,
// we define the stack space for our touch task below.
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
#if defined(PEG_PRKERNEL) || defined(PEGX)
#define PEG_TOUCH_STACK_SIZE PEG_STACK_SIZE
#define PEG_TOUCH_PRIORITY PEG_PRIORITY
PEGLONG gbTouchTaskStack[PEG_TOUCH_STACK_SIZE / sizeof(PEGLONG)];
#if defined(PEGX)
TX_THREAD PegTouchThread;
#endif
#endif
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// InitializeTouchScreen-
//
// This is the external entry point. This should be called first thing
// by the application software, or once during startup.
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
void InitializeTouchScreen(void)
{
#if defined(PEGSMX)
// start the touch task:
TouchTask = create_task((CODE_PTR) PegTouchTask, LO, 8 * 1024);
BUILD_HT(PegTouchTask, "PegTouch");
startx(TouchTask);
#elif defined(PEG_PRKERNEL)
// start the touch task:
T_CTSK TaskInfo;
TaskInfo.tskatr = TA_ACT;
TaskInfo.exinf = 0;
TaskInfo.task = (FP) PegTouchTask;
TaskInfo.itskpri = PEG_TOUCH_PRIORITY;
TaskInfo.stksz = PEG_TOUCH_STACK_SIZE;
TaskInfo.stk = gbPegTouchTaskStack;
acre_tsk(&TaskInfo);
#elif defined(PEG_QUADROS)
// For RTXC Quadros, the TouchTask is already started for us
// as part of system initialization, nothing to do here.
#elif defined(PEGX)
tx_thread_create(&PegTouchThread, "TouchTask", PegTouchTask,
0, gbTouchTaskStack, PEG_TOUCH_STACK_SIZE, PEG_PRIORITY,
0, 0, TX_AUTO_START);
#endif
// Don't return until touch screen is calibrated, to prevent
// PEG from starting up too soon:
while(!TouchCal.IsCalibrated)
{
TOUCH_DELAY(50);
}
}
/*--------------------------------------------------------------------------*/
// The group of functions below are are implemented once for each supported
// operating system. The functions are:
//
// InstallTouchInterruptHandler()
// TouchInterruptHandler()
// WaitTouchDataReady()
/*--------------------------------------------------------------------------*/
extern "C" {
#if defined(PEGSMX)
/*--------------------------------------------------------------------------*/
// Running with MicroDigital SMX RTOS
/*--------------------------------------------------------------------------*/
SCB_PTR PegTouchSem;
/*--------------------------------------------------------------------------*/
void PegTouchLsr(void)
{
signalx(PegTouchSem);
}
/*--------------------------------------------------------------------------*/
void InstallTouchInterruptHandler(void)
{
PegTouchSem = create_sema(1, NULL);
bspSetIRQVect(PEN_DATA_IRQ, TouchInterruptHandler);
bspConfigureIRQ(PEN_DATA_IRQ);
bspUnmaskIRQ(PEN_DATA_IRQ);
}
/*--------------------------------------------------------------------------*/
void TouchInterruptHandler(void)
{
// We interrupt on the input FIFO full. This means we have
// 12 16-bit readings. Read them all into local copy, and disable
// the ASP module to save power:
PEGINT Loop;
for (Loop = 0; Loop < ASP_FIFO_DEPTH; Loop++)
{
TouchResponseVals[Loop] = (PEGUSHORT) (pTouchRegs->DataIn);
}
// go back to idle mode
pTouchRegs->Control = ASP_INIT_VAL;
// start the high-level service routine (interrupts enabled)
INVOKE(PegTouchLsr, 0);
}
/*--------------------------------------------------------------------------*/
void WaitTouchDataReady(void)
{
test(PegTouchSem, INF);
}
#elif defined(PEG_QUADROS)
/*--------------------------------------------------------------------------*/
// Running with RTXC QUADROS RTOS
// This is the same block of functions implemented for RTXC Quadros RTOS
/*--------------------------------------------------------------------------*/
#include "stdlib.h"
#include "mc9328mxl.h"
#include "kcounter.h"
#include "ktask.h"
void SetInterruptPriority(int IntNum, int Priority);
/*--------------------------------------------------------------------------*/
void InstallTouchInterruptHandler(void)
{
*AitcEnnum = PEN_DATA_IRQ;
SetInterruptPriority(PEN_DATA_IRQ, 10);
}
/*--------------------------------------------------------------------------*/
void TouchInterruptHandler(void)
{
// We interrupt on the input FIFO full. This means we have
// 12 16-bit readings. Read them all into local copy, and disable
// the ASP module to save power:
PEGINT Loop;
for (Loop = 0; Loop < ASP_FIFO_DEPTH; Loop++)
{
TouchResponseVals[Loop] = (PEGUSHORT) (pTouchRegs->DataIn);
}
// go back to idle mode
pTouchRegs->Control = ASP_INIT_VAL;
IS_ResumeTask(PegTouch);
}
/*--------------------------------------------------------------------------*/
void WaitTouchDataReady(void)
{
KS_SuspendTask(SELFTASK);
}
#elif defined(PEG_PRKERNEL)
/*--------------------------------------------------------------------------*/
// Running with eSOL PrKernel RTOS
ID gPegTouchSemId;
/*--------------------------------------------------------------------------*/
void InstallTouchInterruptHandler(void)
{
T_CSEM SemInfo;
SemInfo.sematr = TA_TPRI;
SemInfo.isemcnt = 0;
SemInfo.maxsem = 1;
gPegTouchSemId = acre_sem(&SemInfo);
// install interrupt handler for PrKernel:
T_DINH TouchDinh;
TouchDinh.inhatr = 0;
TouchDinh.inthdr = (FP) PegTouchIsr;
def_inh(1, &TouchDinh);
ena_int(PEN_DATA_IRQ);
}
/*--------------------------------------------------------------------------*/
void TouchInterruptHandler(void)
{
// We interrupt on the input FIFO full. This means we have
// 12 16-bit readings. Read them all into local copy, and disable
// the ASP module to save power:
PEGINT Loop;
for (Loop = 0; Loop < ASP_FIFO_DEPTH; Loop++)
{
TouchResponseVals[Loop] = (PEGUSHORT) (pTouchRegs->DataIn);
}
// go back to idle mode
pTouchRegs->Control = ASP_INIT_VAL;
isig_sem(gPegTouchSemId);
}
/*--------------------------------------------------------------------------*/
void WaitTouchDataReady(void)
{
wai_sem(gPegTouchSemId);
}
#elif defined(PEGX)
/*--------------------------------------------------------------------------*/
// Running with ThreadX RTOS
/*--------------------------------------------------------------------------*/
void InstallTouchInterruptHandler(void)
{
tx_vector_steal(PEN_DATA_IRQ, TouchInterruptHandler);
}
/*--------------------------------------------------------------------------*/
void TouchInterruptHandler(void)
{
tx_thread_context_save();
// We interrupt on the input FIFO full. This means we have
// 12 16-bit readings. Read them all into local copy, and disable
// the ASP module to save power:
PEGINT Loop;
for (Loop = 0; Loop < ASP_FIFO_DEPTH; Loop++)
{
TouchResponseVals[Loop] = (PEGUSHORT) (pTouchRegs->DataIn);
}
// go back to idle mode
pTouchRegs->Control = ASP_INIT_VAL;
tx_semaphore_put(PegTouchSem);
tx_thread_context_restore();
}
/*--------------------------------------------------------------------------*/
void WaitTouchDataReady(void)
{
tx_semaphore_get(PegTouchSem);
}
#endif // end of the RTOS tests
} // end of extern C
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -