omap3530/beagle_drivers/byd_touch/common/controller.h
branchBeagle_BSP_dev
changeset 85 d93b485c1325
child 95 450a8cf0c020
equal deleted inserted replaced
84:09e266454dcf 85:d93b485c1325
       
     1 // This component and the accompanying materials are made available
       
     2 // under the terms of the License "Eclipse Public License v1.0"
       
     3 // which accompanies this distribution, and is available
       
     4 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     5 //
       
     6 // Initial Contributors:
       
     7 // lukasz.forynski@gmail.com
       
     8 //
       
     9 // Contributors:
       
    10 //
       
    11 // Description:
       
    12 // omap3530/beagle_drivers/byd_touch/common/controller.h
       
    13 //
       
    14 
       
    15 #ifndef TOUCH_KEY_CONTROLLER_H_
       
    16 #define TOUCH_KEY_CONTROLLER_H_
       
    17 
       
    18 #include <drivers/iic.h>
       
    19 #include <e32def.h>
       
    20 
       
    21 
       
    22 // controller specific constants..
       
    23 const TUint KMaxNumPoints = 3;
       
    24 typedef void (*TVoidCallback) (TAny*);
       
    25 
       
    26 
       
    27 // spi specific constants..
       
    28 const TUint KSpiPacketLength = 4;
       
    29 const TUint KStartByte = 0x56 << 1;
       
    30 const TUint KWrite     = 0;
       
    31 const TUint KRead      = 1;
       
    32 const TUint KReadCommand  = KStartByte | KRead;
       
    33 const TUint KWriteCommand = KStartByte;
       
    34 const TUint KBufGranulatity = 8;
       
    35 
       
    36 // digitizer specific settings..
       
    37 const TUint KResetPin = 93; // This setting does not change (it goes through J4/J5 connectors)
       
    38 const TUint KDataReadyPin = 133; // DAV connected to the GPIO133 (Expansion header pin 15)
       
    39 
       
    40 const TUint KSpiModule = 2; // McSPI3
       
    41 const TUint KSpiSlaveAddr0 = 2; // for data18-data23 pin functions slave address 2=>CS0..
       
    42 const TUint KSpiSlaveAddr1 = 3; // ..slave address 3=>CS1 (pref!)
       
    43 const TUint KSpiSlaveAddr = KSpiSlaveAddr1;
       
    44 
       
    45 
       
    46 const TConfigSpiV01 KHeader =
       
    47 	{
       
    48 	ESpiWordWidth_8, //iWordWidth
       
    49 	375000,//,93750, //iClkSpeed
       
    50 	ESpiPolarityHighFallingEdge, //iClkMode
       
    51 	500, // iTimeoutPeriod
       
    52 	EBigEndian, // iEndianness
       
    53 	EMsbFirst, //iBitOrder
       
    54 	2, //iTransactionWaitCycles
       
    55 	ESpiCSPinActiveLow //iCsPinActiveMode
       
    56 	};
       
    57 
       
    58 // spi interface to the controller
       
    59 class TTouchControllerInterface
       
    60 	{
       
    61 public:
       
    62 	inline TTouchControllerInterface();
       
    63 	inline TInt Read(TUint8 aRegAddress, TUint8& aValue);
       
    64 	inline TInt Write(TUint8 aRegAddress, TUint8 aValue);
       
    65 	inline TInt Write(TUint8 aRegAddress, TUint8* aValues, TInt aNumOfItems);
       
    66 
       
    67 
       
    68 private:
       
    69 	// SPI duplex transaction with two transfers for each direction
       
    70 	TPckgBuf<TConfigSpiV01> iSpiTransactionHeader;
       
    71 	TBuf8<KSpiPacketLength> iSpiWriteBuffer;
       
    72 	TBuf8<KSpiPacketLength> iSpiReadBuffer;
       
    73 	TIicBusTransfer         iSpiTxTransfer;
       
    74 	TIicBusTransfer         iSpiRxTransfer;
       
    75 	TIicBusTransaction      iSpiTransaction;
       
    76 	TInt                    iSpiBusId;
       
    77 	};
       
    78 
       
    79 class TouchController
       
    80 	{
       
    81 public:
       
    82 	enum TTouchMode
       
    83 		{
       
    84 		ESingle = 0,
       
    85 		EMulti,
       
    86 		EGesture
       
    87 		};
       
    88 
       
    89 	enum TResolution
       
    90 		{
       
    91 		ERes10Bits = 0,
       
    92 		ERes12Bits
       
    93 		};
       
    94 
       
    95 	enum TGestureType
       
    96 		{
       
    97 		EClockwiseCircumvolve = 3,
       
    98 		EDragLeft             = 4,
       
    99 		EDragRight            = 5,
       
   100 		EDragUp               = 6,
       
   101 		EDragDown             = 7,
       
   102 		EZoomOut              = 8,
       
   103 		EZoomIn               = 9
       
   104 		};
       
   105 
       
   106 	TouchController();
       
   107 	TouchController(TVoidCallback aCallback);
       
   108 
       
   109 
       
   110 	TInt HardReset();
       
   111 	TInt SoftReset();
       
   112 	TInt SetTouchMode(TTouchMode aMode);
       
   113 	TInt SetResolution(TResolution aResolution);
       
   114 	TInt SetLongerSamplingRate(TUint aRate);
       
   115 	TInt SetIrqActiveTime(TUint aIrqActiveTime);
       
   116 	TInt SetPanelVoltageStabTime(TUint aVoltageStabilizationTime);
       
   117 	TInt SetNumberOfColumns(TUint aNumberOfColumns);
       
   118 	TInt SetNumberOfRows(TUint aNumberOfRows);
       
   119 	TInt EnableWindowMode(TPoint aXpoint, TPoint aYPoint);
       
   120 	TInt DisableWindowMode();
       
   121 	TInt GetMeasurements(TPoint* aPoints, TInt& aNumPoints);
       
   122 	TInt NumOfTouches();
       
   123 
       
   124 private:
       
   125 	TInt iCtrlRegsCache[4];
       
   126 	TTouchControllerInterface iInterface;
       
   127 	TVoidCallback iCallback;
       
   128 	};
       
   129 
       
   130 
       
   131 // BF6917 Register definitions
       
   132 const TUint8 KControl_0  = 0x0; // R/W
       
   133 const TUint8 KControl_0_SWRST        = 1 << 7;  // SW reset
       
   134 const TUint8 KControl_0_RM_12        = 1 << 6; // Resolution mode 12 bits if set, 10bits otherwise
       
   135 const TUint8 KControl_0_MODE_SINGLE  = 1 << 3; // single touch mode
       
   136 const TUint8 KControl_0_MODE_MULTI   = 5 << 3; // multi-touch mode
       
   137 const TUint8 KControl_0_MODE_GESTURE = 6 << 3; // gesture mode
       
   138 const TUint8 KControl_0_MODE_MASK    = 7 << 3; // gesture mode
       
   139 
       
   140 const TUint8 KControl_0_LST_MASK     = 0x7; // Longer sampling rate: from 5 to 120 ADC clocks sampling time
       
   141 const TUint8 KControl_0_LST_5        = 0 << 0; // 5   ADC clocks sampling time
       
   142 const TUint8 KControl_0_LST_10       = 1 << 0; // 10  ADC clocks sampling time
       
   143 const TUint8 KControl_0_LST_20       = 2 << 0; // 20  ADC clocks sampling time
       
   144 const TUint8 KControl_0_LST_40       = 3 << 0; // 40  ADC clocks sampling time
       
   145 const TUint8 KControl_0_LST_60       = 4 << 0; // 60  ADC clocks sampling time
       
   146 const TUint8 KControl_0_LST_80       = 5 << 0; // 80  ADC clocks sampling time
       
   147 const TUint8 KControl_0_LST_100      = 6 << 0; // 100 ADC clocks sampling time
       
   148 const TUint8 KControl_0_LST_120      = 7 << 0; // 120 ADC clocks sampling time
       
   149 
       
   150 
       
   151 // Pen Irq Active time (sensiveness)
       
   152 const TUint8 KControl_1  = 0x1; // R/W
       
   153 const TUint8 KControl_1_PAT_SHIFT = 5;
       
   154 const TUint8 KControl_1_PAT_MASK  = 7 << 5;
       
   155 const TUint8 KControl_1_PAT_100   = 0 << 5;
       
   156 const TUint8 KControl_1_PAT_87_5  = 1 << 5;
       
   157 const TUint8 KControl_1_PAT_75    = 2 << 5;
       
   158 const TUint8 KControl_1_PAT_62_5  = 3 << 5;
       
   159 const TUint8 KControl_1_PAT_50    = 4 << 5;
       
   160 const TUint8 KControl_1_PAT_37_5  = 5 << 5;
       
   161 const TUint8 KControl_1_PAT_25    = 6 << 5;
       
   162 const TUint8 KControl_1_PAT_12_5  = 7 << 5;
       
   163 
       
   164 //  Panel Voltage stabilization Time(sensiveness)
       
   165 const TUint8 KControl_1_PVT_SHIFT = 2;
       
   166 const TUint8 KControl_1_PVT_MASK = 7 << 2;
       
   167 const TUint8 KControl_1_PVT_200  = 0 << 2;
       
   168 const TUint8 KControl_1_PVT_175  = 1 << 2;
       
   169 const TUint8 KControl_1_PVT_150  = 2 << 2;
       
   170 const TUint8 KControl_1_PVT_125  = 3 << 2;
       
   171 const TUint8 KControl_1_PVT_100  = 4 << 2;
       
   172 const TUint8 KControl_1_PVT_75   = 5 << 2;
       
   173 const TUint8 KControl_1_PVT_50   = 6 << 2;
       
   174 const TUint8 KControl_1_PVT_25   = 7 << 2;
       
   175 const TUint8 KControl_1_WS       = 1 << 0; // Window mode enables
       
   176 
       
   177 
       
   178 const TUint8 KControl_2  = 0x2; // R/W
       
   179 const TUint8 KControl_2_C_SHIFT  = 3; // number of columns
       
   180 const TUint8 KControl_2_C_MASK = 0xf8;
       
   181 const TUint8 KControl_2_PR_SHIFT = 0; // pull-up resistance
       
   182 
       
   183 
       
   184 const TUint8 KControl_3  = 0x3; // R/W
       
   185 const TUint8 KControl_3_R_SHIFT  = 4; // number of rows
       
   186 const TUint8 KControl_3_R_MASK   = 0xF0; // number of rows
       
   187 
       
   188 const TUint8 KControl_2_R_TEST   = 1 << 3; // test mode select
       
   189 const TUint8 KControl_2_PS_SHIFT = 0; // processing scale (0-7)
       
   190 
       
   191 const TUint8 KWindowXStart_Msb = 0x4; // R/W
       
   192 const TUint8 KWindowXStart_Lsb = 0x5; // R/W
       
   193 const TUint8 KWindowXStop_Msb  = 0x6; // R/W
       
   194 const TUint8 KWindowXStop_Lsb  = 0x7; // R/W
       
   195 const TUint8 KWindowYStart_Msb = 0x8; // R/W
       
   196 const TUint8 KWindowYStart_Lsb = 0x9; // R/W
       
   197 const TUint8 KWindowYStop_Msb  = 0xa; // R/W
       
   198 const TUint8 KWindowYStop_Lsb  = 0xb; // R/W
       
   199 const TUint8 KMasterReadStartAddr = 0xc; // R/W
       
   200 
       
   201 
       
   202 //  data registers
       
   203 const TUint8 KTouchNumberAndType  = 0xd; //  R, Touch number and touch type
       
   204 const TUint8 KTouchNumberAndType_SINGLE = 0 << 3;
       
   205 const TUint8 KTouchNumberAndType_MULTI  = 1 << 3;
       
   206 const TUint8 KTouchNumberAndType_TouchNMask = 7; // touch number (0 - 3)
       
   207 
       
   208 
       
   209 const TUint8 X1_H   = 0xe; //  R, High byte of x1 measurement
       
   210 const TUint8 X1_L   = 0xf; //  R, Low  byte of x1 measurement
       
   211 const TUint8 Y1_H   = 0x10; // R, High byte of y1 measurement
       
   212 const TUint8 Y1_L   = 0x11; // R, Low  byte of y1 measurement
       
   213 const TUint8 X2_H   = 0x12; // R, High byte of x2 measurement
       
   214 const TUint8 X2_L   = 0x13; // R, Low  byte of x2 measurement
       
   215 const TUint8 Y2_H   = 0x14; // R, High byte of y2 measurement
       
   216 const TUint8 Y2_L   = 0x15; // R, Low  byte of y2 measurement
       
   217 const TUint8 X3_H   = 0x16; // R, High byte of x3 measurement
       
   218 const TUint8 X3_L   = 0x17; // R, Low  byte of x3 measurement
       
   219 const TUint8 Y3_H   = 0x18; // R, High byte of y3 measurement
       
   220 const TUint8 Y3_L   = 0x19; // R, Low  byte of y3 measurement
       
   221 const TUint8 Ges_H  = 0x1a; // R, High byte of gesture information
       
   222 const TUint8 Ges_L  = 0x1b; // R, Low  byte of gesture information
       
   223 const TUint8 TEST_H = 0x1c; // R, Low byte of the test result
       
   224 const TUint8 TEST_L = 0x1d; // R, Low byte of the test result
       
   225 
       
   226 
       
   227 #endif /* TOUCH_KEY_CONTROLLER_H_ */