Advertisement
Guest User

Untitled

a guest
Jul 10th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.25 KB | None | 0 0
  1. //
  2. // Copyright (c) Microsoft Corporation.  All rights reserved.
  3. //
  4. //
  5. // Use of this sample source code is subject to the terms of the Microsoft
  6. // license agreement under which you licensed this sample source code. If
  7. // you did not accept the terms of the license agreement, you are not
  8. // authorized to use this sample source code. For the terms of the license,
  9. // please see the license agreement between you and Microsoft or, if applicable,
  10. // see the LICENSE.RTF on your install media or the root of your tools installation.
  11. // THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
  12. //
  13. // All rights reserved ADENEO EMBEDDED 2010
  14. // Copyright (c) 2007, 2008 BSQUARE Corporation. All rights reserved.
  15.  
  16. /*
  17. ================================================================================
  18. *             Texas Instruments OMAP(TM) Platform Software
  19. * (c) Copyright Texas Instruments, Incorporated. All Rights Reserved.
  20. *
  21. * Use of this software is controlled by the terms and conditions found
  22. * in the license agreement under which this software has been supplied.
  23. *
  24. ================================================================================
  25. */
  26.  
  27. #ifndef __TOUCHPDD_H
  28. #define __TOUCHPDD_H
  29.  
  30. // undef here since these are already defined.
  31. #undef ZONE_INIT
  32. #undef ZONE_ERROR
  33.  
  34. #include <tchddsi.h>
  35.  
  36. //------------------------------------------------------------------------------
  37. // Sample rate during polling.
  38. #define DEFAULT_SAMPLE_RATE                 200               // Hz.
  39. #define TOUCHPANEL_SAMPLE_RATE_LOW          DEFAULT_SAMPLE_RATE
  40. #define TOUCHPANEL_SAMPLE_RATE_HIGH         DEFAULT_SAMPLE_RATE
  41. #define DEFAULT_THREAD_PRIORITY             109
  42.  
  43. // Number of samples to discard when pen is initially down
  44. #define DEFAULT_INITIAL_SAMPLES_DROPPED    1
  45.  
  46. #define RK_HARDWARE_DEVICEMAP_TOUCH     (TEXT("HARDWARE\\DEVICEMAP\\TOUCH"))
  47. #define RV_CALIBRATION_DATA             (TEXT("CalibrationData"))
  48.  
  49. #define DIFF_X_MAX            10
  50. #define DIFF_Y_MAX            10
  51.  
  52. #define FILTEREDSAMPLESIZE              3
  53. #define SAMPLESIZE                      1
  54.  
  55. #define DEFAULT_DEVICE_ADDRESS          0 //CS0 of SPI1
  56.  
  57. #define COMMAND_EN_TOUCH                  0x800000
  58. #define COMMAND_XPOS                      0xD00000
  59. #define COMMAND_YPOS                      0x900000
  60. #define POWER_MASK                        0x010000
  61.  
  62. #define MAX_PTS                     3
  63. #define DELTA                       30
  64.  
  65. #define CAL_DELTA_RESET             20
  66. #define CAL_HOLD_STEADY_TIME        1500
  67. #define RANGE_MIN                   0
  68. #define RANGE_MAX                   4096
  69.  
  70. #if defined(BSP_LCD_PRISM0700W) || defined(BSP_LVDS_PRISM1010W)
  71. #define RANGE_MIN_X                 0
  72. #define RANGE_MAX_X                 2275
  73.  
  74. #define RANGE_MIN_Y                 0
  75. #define RANGE_MAX_Y                 1275
  76. #endif
  77.  
  78. //------------------------------------------------------------------------------
  79. // local data structures
  80. //
  81.  
  82. typedef struct
  83. {
  84.     BOOL        bInitialized;
  85.  
  86.     DWORD       nSampleRate;
  87.     DWORD       nInitialSamplesDropped;
  88.     LONG        nPenGPIO;
  89.     DWORD       PenUpDebounceMS;
  90.     LONG        nSPIAddr;
  91.     LONG        nSPIBaudrate;
  92.     LONG        nSPIWordlength;
  93.  
  94.     DWORD       dwSysIntr;
  95.     DWORD       dwSamplingTimeOut;
  96.     BOOL        bTerminateIST;
  97.     HANDLE      hTouchPanelEvent;
  98.     DWORD       dwPowerState;
  99.     HANDLE      hIST;
  100.     HANDLE      hGPIO;
  101.     HANDLE      hSPI;
  102. #if defined(BSP_LCD_PRISM0700W) || defined(BSP_LVDS_PRISM1010W)
  103.     HANDLE      hI2C;
  104. #endif
  105.     LONG        nPenIRQ;
  106.     DWORD       dwISTPriority;
  107. }TOUCH_DEVICE;
  108.  
  109.  
  110. //------------------------------------------------------------------------------
  111. //  Device registry parameters
  112. static const DEVICE_REGISTRY_PARAM s_deviceRegParams[] = {
  113.     {
  114.         L"SampleRate", PARAM_DWORD, FALSE, offset(TOUCH_DEVICE, nSampleRate),
  115.         fieldsize(TOUCH_DEVICE, nSampleRate), (VOID*)DEFAULT_SAMPLE_RATE
  116.     },
  117.     {
  118.         L"PenGPIO", PARAM_DWORD, TRUE, offset(TOUCH_DEVICE, nPenGPIO),
  119.         fieldsize(TOUCH_DEVICE, nPenGPIO), 0
  120.     },
  121.     {
  122.         L"PenUpDebounceMS", PARAM_DWORD, FALSE, offset(TOUCH_DEVICE, PenUpDebounceMS),
  123.         fieldsize(TOUCH_DEVICE, PenUpDebounceMS), (VOID*)40
  124.     },
  125.     {
  126.         L"SPIAddr", PARAM_DWORD, FALSE, offset(TOUCH_DEVICE, nSPIAddr),
  127.         fieldsize(TOUCH_DEVICE, nSPIAddr), 0
  128.     },
  129.     {
  130.         L"InitialSamplesDropped", PARAM_DWORD, FALSE, offset(TOUCH_DEVICE, nInitialSamplesDropped),
  131.         fieldsize(TOUCH_DEVICE, nInitialSamplesDropped), (VOID*)DEFAULT_INITIAL_SAMPLES_DROPPED
  132.     },
  133.     {
  134.         L"Priority256", PARAM_DWORD, FALSE, offset(TOUCH_DEVICE, dwISTPriority),
  135.         fieldsize(TOUCH_DEVICE, dwISTPriority), (VOID*)DEFAULT_THREAD_PRIORITY
  136.     },
  137.     {
  138.         L"SysIntr", PARAM_DWORD, FALSE, offset(TOUCH_DEVICE, dwSysIntr),
  139.         fieldsize(TOUCH_DEVICE, dwSysIntr), (VOID*)SYSINTR_NOP
  140.     }
  141. };
  142.  
  143. //------------------------------------------------------------------------------
  144. // global variables
  145. //
  146. static TOUCH_DEVICE s_TouchDevice =  {
  147.     FALSE,                                          //bInitialized
  148.     DEFAULT_SAMPLE_RATE,                            //nSampleRate
  149.     0,                                              //nInitialSamplesDropped
  150.     0,                                              //nPenGPIO
  151.     0,                                              //PenUpDebounceMS
  152.     0,                                              //nSPIAddr
  153.     0,                                              //nSPIBaudrate
  154.     0,                                              //nSPIWordlength
  155.     SYSINTR_NOP,                                    //dwSysIntr
  156.     0,                                              //dwSamplingTimeOut
  157.     FALSE,                                          //bTerminateIST
  158.     0,                                              //hTouchPanelEvent
  159.     D0,                                             //dwPowerState
  160.     0,                                              //hIST
  161.     0,                                              //hGPIO
  162.     0,                                              //hSPI
  163. #if defined(BSP_LCD_PRISM0700W) || defined(BSP_LVDS_PRISM1010W)
  164.     0,                                              //hI2C
  165. #endif
  166.     0,                                              //nPenIRQ
  167.     DEFAULT_THREAD_PRIORITY                         //dwISTPriority
  168. };
  169.  
  170. // Internal functions.
  171. static HRESULT PDDCalibrationThread();
  172. void PDDStartCalibrationThread();
  173.  
  174. BOOL PDDGetTouchIntPinState( VOID );
  175. #if defined(BSP_LCD_PRISM0700W) || defined(BSP_LVDS_PRISM1010W)
  176. BOOL PDDGetTouchData(UINT32 * pxPos1, UINT32 * pyPos1, UINT32 * pxPos2, UINT32 * pyPos2, UINT8 * pTip);
  177. #else
  178. BOOL PDDGetTouchData(UINT32 * pxPos, UINT32 * pyPos);
  179. #endif
  180. BOOL PDDGetRegistrySettings( PDWORD );
  181. BOOL PDDInitializeHardware(LPCTSTR pszActiveKey );
  182. VOID PDDDeinitializeHardware( VOID );
  183. VOID  PDDTouchPanelDisable();
  184. BOOL  PDDTouchPanelEnable();
  185. ULONG PDDTouchIST(PVOID   reserved);
  186. void PDDTouchPanelPowerHandler(BOOL boff);
  187.  
  188. //TCH PDD DDSI functions
  189. extern "C" DWORD WINAPI TchPdd_Init(
  190.     LPCTSTR pszActiveKey,
  191.     TCH_MDD_INTERFACE_INFO* pMddIfc,
  192.     TCH_PDD_INTERFACE_INFO* pPddIfc,
  193.     DWORD hMddContext
  194.     );
  195.  
  196. void WINAPI TchPdd_Deinit(DWORD hPddContext);
  197. void WINAPI TchPdd_PowerUp(DWORD hPddContext);
  198. void WINAPI TchPdd_PowerDown(DWORD hPddContext);
  199. BOOL WINAPI TchPdd_Ioctl(
  200.     DWORD hPddContext,
  201.     DWORD dwCode,
  202.     PBYTE pBufIn,
  203.     DWORD dwLenIn,
  204.     PBYTE pBufOut,
  205.     DWORD dwLenOut,
  206.     PDWORD pdwActualOut
  207.     );
  208.  
  209. #if defined(BSP_LCD_PRISM0700W) || defined(BSP_LVDS_PRISM1010W)
  210. //
  211. //    Converts touch panel sample flags and X,Y to a primary CETOUCHINPUT sample.
  212. //
  213. //    Returns FALSE if there is no conversion.
  214. //
  215. __inline BOOL PrismConvertTouchPanelToTouchInput(
  216.     TOUCH_PANEL_SAMPLE_FLAGS    Flags,
  217.     INT                         X,
  218.     INT                         Y,
  219.     PCETOUCHINPUT               pInput,
  220.     INT                         Id
  221.     )
  222. {
  223.     static BOOL s_fPreviousSampleDown = FALSE;
  224.     static INT  s_xPrevious;
  225.     static INT  s_yPrevious;
  226.  
  227.     BOOL fRet = FALSE;
  228.  
  229.     if ( (Flags & (TouchSampleIgnore | TouchSampleValidFlag)) == TouchSampleValidFlag )
  230.     {
  231.         DWORD TouchInputFlags = 0;
  232.  
  233.         if (Flags & TouchSampleDownFlag)
  234.         {
  235.             TouchInputFlags |= TOUCHEVENTF_INRANGE;
  236.  
  237.             if (s_fPreviousSampleDown)
  238.             {
  239.                 TouchInputFlags |= TOUCHEVENTF_MOVE;
  240.             }
  241.             else
  242.             {
  243.                 TouchInputFlags |= TOUCHEVENTF_DOWN;
  244.                 s_fPreviousSampleDown = TRUE;
  245.             }
  246.  
  247.             s_xPrevious = X;
  248.             s_yPrevious = Y;
  249.         }
  250.         else
  251.         {
  252.             TouchInputFlags |= TOUCHEVENTF_UP;
  253.             s_fPreviousSampleDown = FALSE;
  254.  
  255.             // X and Y coordinates on up were allowed to invalid.
  256.             // Replace with the previous X,Y
  257.             X = s_xPrevious;
  258.             Y = s_yPrevious;
  259.         }
  260.  
  261.         if (Flags & TouchSampleIsCalibratedFlag)
  262.         {
  263.             TouchInputFlags |= TOUCHEVENTF_CALIBRATED;
  264.         }
  265.  
  266.         memset(pInput, 0, sizeof(*pInput));
  267.         pInput->x = X;
  268.         pInput->y = Y;
  269.         pInput->dwFlags = TouchInputFlags;
  270.         pInput->dwID = Id;
  271.  
  272.         fRet = TRUE;
  273.     }
  274.  
  275.     return fRet;
  276. }
  277. #endif
  278. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement