bool valid = false;
while (!valid)
{
- error = tsRead(&data);
+ // Set calibration flag for ts read
+ error = tsRead(&data, true);
if (!error && data.valid)
{
valid = true;
@note This is based on the public domain touch screen calibration code
written by Carlos E. Vidales (copyright (c) 2001).
- For more inforormation, see the following app notes:
+ For more information, see the following app notes:
- AN2173 - Touch Screen Control and Calibration
Svyatoslav Paliy, Cypress Microsystems
eepromWriteS32(CFG_EEPROM_TOUCHSCREEN_CAL_DN, matrixPtr->Dn);
eepromWriteS32(CFG_EEPROM_TOUCHSCREEN_CAL_EN, matrixPtr->En);
eepromWriteS32(CFG_EEPROM_TOUCHSCREEN_CAL_FN, matrixPtr->Fn);
- eepromWriteS32(CFG_EEPROM_TOUCHSCREEN_CAL_FN, matrixPtr->Fn);
eepromWriteS32(CFG_EEPROM_TOUCHSCREEN_CAL_DIVIDER, matrixPtr->Divider);
eepromWriteU8(CFG_EEPROM_TOUCHSCREEN_CALIBRATED, 1);
}
/**************************************************************************/
int getDisplayPoint( tsPoint_t * displayPtr, tsPoint_t * screenPtr, tsMatrix_t * matrixPtr )
{
- int retValue = 0 ;
+ int retValue = TS_ERROR_NONE ;
if( matrixPtr->Divider != 0 )
{
}
else
{
- retValue = -1 ;
+ // ToDo: Default values required or you can never read LCD position!
+ // return TS_ERROR_NOTCALIBRATED;
+ return -1;
}
// Adjust value if the screen is in landscape mode
_tsMatrix.Fn = eepromReadS32(CFG_EEPROM_TOUCHSCREEN_CAL_FN);
_tsMatrix.Divider = eepromReadS32(CFG_EEPROM_TOUCHSCREEN_CAL_DIVIDER);
}
+ else
+ {
+ // You may want to run the touch screen calibration sequence
+ // here since the ts has apparently never been calibrated!
+ // tsCalibrate();
+ }
}
/**************************************************************************/
/*!
@brief Reads the current X, Y and Z co-ordinates of the touch screen
+
+ @param[in] calibrating
+ Set to 1 if the read attempt is for calibration data.
+ No attempt will be made to correlate the touch screen
+ and LCD co-ordinates.
*/
/**************************************************************************/
-tsTouchError_t tsRead(tsTouchData_t* data)
+tsTouchError_t tsRead(tsTouchData_t* data, uint8_t calibrating)
{
uint32_t x1, x2, y1, y2, z1, z2;
tsPoint_t location, touch;
touch.x = x1;
touch.y = y1;
- getDisplayPoint( &location, &touch, &_tsMatrix) ;
- data->xlcd = location.x;
- data->ylcd = location.y;
+ // Only calculate the relative LCD value if this isn't for calibration
+ if (!calibrating)
+ {
+ getDisplayPoint( &location, &touch, &_tsMatrix) ;
+ data->xlcd = location.x;
+ data->ylcd = location.y;
+ }
+ else
+ {
+ // Assign some false values, but only xraw and yraw are
+ // used for calibration
+ data->xlcd = 0;
+ data->ylcd = 0;
+ }
data->valid = true;
return TS_ERROR_NONE;
{
if (!_tsInitialised) tsInit();
- tsRead(data);
+ tsRead(data, false);
// Return the results right away if reading is valid
if (data->valid)
{
return TS_ERROR_TIMEOUT;
}
- tsRead(data);
+ tsRead(data, false);
}
}
// No systick rollover will occur ... calculate timeout the simple way
{
return TS_ERROR_TIMEOUT;
}
- tsRead(data);
+ tsRead(data, false);
}
}
}
{
while (data->valid == false)
{
- tsRead(data);
+ tsRead(data, false);
}
}