/*---------------------------------------------------------------------------* * Routine: TS_EXC7200_Configure *---------------------------------------------------------------------------* * Description: * The SPI bus and GPIO device are being declared. * Inputs: * void *aW -- Particular SPI workspace * Outputs: * T_uezError -- Error code *---------------------------------------------------------------------------*/ T_uezError TS_EXC7200_Configure(T_uezDeviceWorkspace *aW) { T_EXC7200Workspace *p = (T_EXC7200Workspace *)aW; UEZSemaphoreGrab(p->iSemWaitForTouch, 0); UEZGPIOSetMux(p->iResetPin, 0);//Set to GPIO UEZGPIOOutput(p->iResetPin); UEZGPIOClear(p->iResetPin); UEZTaskDelay(1); UEZGPIOConfigureInterruptCallback( UEZ_GPIO_PORT_FROM_PORT_PIN(p->iInteruptPin), TS_EXC7200_InterruptISR, p); UEZGPIOEnableIRQ(p->iInteruptPin, GPIO_INTERRUPT_FALLING_EDGE); UEZGPIOSet(p->iResetPin); T_uezDevice i2c; I2C_Request request; T_uezError error; TUInt8 dataIn[10]; TUInt8 dataOut[10] = { 0x03, 0x06, 0x0A, 0x04, 0x36, 0x3f, 0x01, 9, 0, 0}; request.iAddr = EXC7200_I2C_ADDRESS; request.iSpeed = EXC7200_I2C_SPEED; request.iReadData = dataIn; request.iReadLength = 10; request.iWriteData = dataOut; request.iWriteLength = 10; UEZI2COpen(p->iI2CBus, &i2c); error = UEZI2CTransaction(i2c, &request); return UEZ_ERROR_NONE; }
/*---------------------------------------------------------------------------* * Routine: TS_MC_AR1020_Poll *---------------------------------------------------------------------------* * Description: * Take a reading from the TSC2406 and put in reading structure. * Inputs: * void *aW -- Workspace * T_uezTSReading *aReading -- Pointer to final reading * Outputs: * T_uezError -- Error code *---------------------------------------------------------------------------*/ T_uezError TS_MC_AR1020_Poll(void *aWorkspace, T_uezTSReading *aReading) { T_MC_AR1020Workspace *p = (T_MC_AR1020Workspace *) aWorkspace; T_uezError error; I2C_Request r; T_uezDevice i2c2; TUInt8 data[5] = {0,0,0,0,0}; HAL_GPIOPort **p_gpio; const TUInt32 pin = 15; TUInt32 Read = 0; TUInt32 x; TUInt32 y; HALInterfaceFind("GPIO2", (T_halWorkspace **)&p_gpio); (*p_gpio)->SetInputMode(p_gpio, 1<<pin); (*p_gpio)->SetMux(p_gpio, pin, 0); // set to GPIO (*p_gpio)->Read(p_gpio, 1<<pin, &Read); if ( Read == 0) { (aReading->iFlags) = (p->iLastTouch) ; return UEZ_ERROR_NONE; } else { r.iAddr = AR1020_I2C_ADDRESS; r.iSpeed = AR1020_I2C_SPEED; r.iWriteData = 0; r.iWriteLength = 0; r.iWriteTimeout = UEZ_TIMEOUT_INFINITE; r.iReadData = data; r.iReadLength = 5; r.iReadTimeout = UEZ_TIMEOUT_INFINITE; error = UEZI2COpen("I2C2", &i2c2); UEZI2CTransaction(i2c2, &r); UEZI2CClose(i2c2); x = data[4]; x = (x <<7); x = x | data[3]; y = data[2]; y = (y <<7); y = y | data[1]; //if(p->iIsCalibrating) //for testing printf("%04x _ %04X\r\n", x, y); if((data[0] & 0x01)== 0x01) { (aReading->iFlags) = (p->iLastTouch) = TSFLAG_PEN_DOWN; (aReading->iX) = (p->iLastX)= x; (aReading->iY) = (p->iLastY)= y; if ((!p->iIsCalibrating) && (p->iHaveCalibration)) { // Convert X & Y coordinates TS_MC_AR1020_ApplyCalibration( p, x, y, (TUInt32 *) &aReading->iX, (TUInt32 *) &aReading->iY); } } else { (aReading->iFlags) = (p->iLastTouch)= 0; (aReading->iX) = (p->iLastX); (aReading->iY) = (p->iLastY); TS_MC_AR1020_ApplyCalibration( p, (p->iLastX), (p->iLastY), (TUInt32 *) &aReading->iX, (TUInt32 *) &aReading->iY); } return error; } }