📄 touchdrv.c
字号:
> // 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
>
>
>
> /*--------------------------------------------------------------------------*/
> /*--------------------------------------------------------------------------*/
> // MX1TOUCH- Touch Screen driver written to utilize the FreeScale MX1
> // built-in touch controller.
> //
> //
> // Notes:
> //
> // This driver has been tested with the MX1 ADS eval board exclusively.
> /*--------------------------------------------------------------------------*/
> /*--------------------------------------------------------------------------*/
>
> #ifndef _MX1TOUCH_
> #define _MX1TOUCH_
>
> #include "peg.hpp"
>
> /*--------------------------------------------------------------------------*/
> /*--------------------------------------------------------------------------*/
> // ASP registers
>
> typedef struct {
> volatile PEGULONG DataIn;
> volatile PEGULONG Spare1[3];
> volatile PEGULONG Control;
> volatile PEGULONG SampleRate;
> volatile PEGULONG IntCtrl;
> volatile PEGULONG Status;
> volatile PEGULONG Spare2[3];
> volatile PEGULONG ClockDiv;
> volatile PEGULONG Compare;
> volatile PEGULONG FIFOPtr;
> } ASP_REG_BLOCK;
>
>
> /*--------------------------------------------------------------------------*/
> // Delay values- User defined delay values. These values are currently
> // in 10ms ticks, which is the timebase used when creating this driver.
> // You can adjust these values if needed for your system.
> /*--------------------------------------------------------------------------*/
>
> #if defined(PEGSMX)
>
> #define TOUCH_POLLING_PERIOD 3 // Polling Interval
> #define TOUCH_SETTLE_DELAY 10 // How long to settle on a value?
>
> #define TOUCH_NOISE_LIMIT 500 // some variation in consecutive ATOD
> // readings is normal. A lot of variation
> // indicates the screen is settling and
> // the user is just touching or releasing.
> // How much variation between reads is OK
> // is determined by this variable
>
>
> #define TOUCH_DELAY(a) count(a, ticks, INF);
>
> #elif defined(PEG_QUADROS)
>
> #define TOUCH_POLLING_PERIOD 3 // Polling Interval
> #define TOUCH_SETTLE_DELAY 5 // How long to settle on a value?
>
> #define TOUCH_NOISE_LIMIT 400 // some variation in consecutive ATOD
> // readings is normal. A lot of variation
> // indicates the screen is settling and
> // the user is just touching or releasing.
> // How much variation between reads is OK
> // is determined by this variable
>
> #define TOUCH_DELAY(a) KS_SleepTask(COUNTER1, a);
>
> #elif defined(PEG_PRKERNEL)
>
> #define TOUCH_POLLING_PERIOD 3 // Polling Interval
> #define TOUCH_SETTLE_DELAY 5 // How long to settle on a value?
>
> #define TOUCH_NOISE_LIMIT 400 // some variation in consecutive ATOD
> // readings is normal. A lot of variation
> // indicates the screen is settling and
> // the user is just touching or releasing.
> // How much variation between reads is OK
> // is determined by this variable
>
> #define TOUCH_DELAY(a) dly_tsk(a);
>
> #endif
>
> /*--------------------------------------------------------------------------*/
> // Miscellaneous definitions used in the driver code...
> /*--------------------------------------------------------------------------*/
>
> #define PEN_DOWN_IRQ 46
> #define PEN_UP_IRQ 5
> #define PEN_DATA_IRQ 33
>
> #define ASP_FIFO_DEPTH 12
>
> #define ASP_INIT_VAL 0x02005001; // init value, not enabled
> #define ASP_ENABLE 0x02005003; // turn on ASP module
>
> #define ASP_DMCNT 6 // decimation count
> #define ASP_BIT_SEL 0 // starting bit of FIR output
> #define ASP_IDLE_CNT 2 // idle clocks between samples
> #define ASP_DATA_SETUP 2 // delay after switch change
>
>
>
> #define TS_TOUCHED 0x8000 // Touch State Last Touched
> #define TS_TOUCH_SENT 0x4000 // PM_LBUTTONDOWN was sent
>
>
> /*--------------------------------------------------------------------------*/
> // TOUCH_CAL_DATA
> //
> // Calibration data used to convert raw ATOD values into pixel coords
> /*--------------------------------------------------------------------------*/
> typedef struct
> {
> PEGUSHORT RawXVals[4];
> PEGUSHORT RawYVals[4];
> PEGINT ScreenWidth;
> PEGINT ScreenHeight;
> PEGINT CenterX;
> PEGINT CenterY;
> PEGBOOL IsCalibrated;
>
> } TOUCH_CAL_DATA;
>
> /*--------------------------------------------------------------------------*/
> // indexes into TOUCH_CAL_DATA
> /*--------------------------------------------------------------------------*/
>
> #define TC_UL 0
> #define TC_LL 1
> #define TC_UR 2
> #define TC_LR 3
>
> void TouchConfigureHardware(void); // called first
> void CalibrateTouchScreen(void); // called second
> void TouchSample(PEGUSHORT *pPutX, PEGUSHORT *pPutY);
>
>
> #endif
>
>
>
>
>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -