X-Git-Url: http://git.rohieb.name/hackover2013-badge-firmware.git/blobdiff_plain/9d18e10afb2439a6a9ba6978a799259746a837b7..fb861656fa4e46219dc85d6af998fd13d3c6b9f6:/drivers/lcd/tft/touchscreen.c diff --git a/drivers/lcd/tft/touchscreen.c b/drivers/lcd/tft/touchscreen.c index 20e9a19..bb7371a 100644 --- a/drivers/lcd/tft/touchscreen.c +++ b/drivers/lcd/tft/touchscreen.c @@ -194,7 +194,8 @@ tsTouchData_t tsRenderCalibrationScreen(uint16_t x, uint16_t y, uint16_t radius) bool valid = false; while (!valid) { - error = tsRead(&data); + // Set calibration flag for ts read + error = tsRead(&data, true); if (!error && data.valid) { valid = true; @@ -213,7 +214,7 @@ tsTouchData_t tsRenderCalibrationScreen(uint16_t x, uint16_t y, uint16_t radius) @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 @@ -262,7 +263,6 @@ int setCalibrationMatrix( tsPoint_t * displayPtr, tsPoint_t * screenPtr, tsMatri 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); } @@ -284,7 +284,7 @@ int setCalibrationMatrix( tsPoint_t * displayPtr, tsPoint_t * screenPtr, tsMatri /**************************************************************************/ int getDisplayPoint( tsPoint_t * displayPtr, tsPoint_t * screenPtr, tsMatrix_t * matrixPtr ) { - int retValue = 0 ; + int retValue = TS_ERROR_NONE ; if( matrixPtr->Divider != 0 ) { @@ -300,7 +300,9 @@ int getDisplayPoint( tsPoint_t * displayPtr, tsPoint_t * screenPtr, tsMatrix_t * } 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 @@ -351,14 +353,25 @@ void tsInit(void) _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; @@ -401,9 +414,20 @@ tsTouchError_t tsRead(tsTouchData_t* data) 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; @@ -509,7 +533,7 @@ tsTouchError_t tsWaitForEvent(tsTouchData_t* data, uint32_t timeoutMS) { if (!_tsInitialised) tsInit(); - tsRead(data); + tsRead(data, false); // Return the results right away if reading is valid if (data->valid) @@ -531,7 +555,7 @@ tsTouchError_t tsWaitForEvent(tsTouchData_t* data, uint32_t timeoutMS) { return TS_ERROR_TIMEOUT; } - tsRead(data); + tsRead(data, false); } } // No systick rollover will occur ... calculate timeout the simple way @@ -545,7 +569,7 @@ tsTouchError_t tsWaitForEvent(tsTouchData_t* data, uint32_t timeoutMS) { return TS_ERROR_TIMEOUT; } - tsRead(data); + tsRead(data, false); } } } @@ -554,7 +578,7 @@ tsTouchError_t tsWaitForEvent(tsTouchData_t* data, uint32_t timeoutMS) { while (data->valid == false) { - tsRead(data); + tsRead(data, false); } }