Skip to content

Commit

Permalink
debug log touch errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Nov 6, 2020
1 parent d976fdf commit 72eedf3
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/eez/modules/mcu/stm32/touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,47 @@ static int16_t g_lastZ1Data = 0;

void touchMeasure() {
#if defined(TSC2007IPW)
static int g_errorCounter = 0;
bool isError = false;

taskENTER_CRITICAL();

uint8_t result[4];

HAL_I2C_Master_Transmit(&hi2c1, TOUCH_DEVICE_ADDRESS, (uint8_t *)&Z1_DATA_ID, 1, 5);
HAL_I2C_Master_Receive(&hi2c1, TOUCH_DEVICE_ADDRESS, result, 2, 5);
if (HAL_I2C_Master_Transmit(&hi2c1, TOUCH_DEVICE_ADDRESS, (uint8_t *)&Z1_DATA_ID, 1, 5) != HAL_OK) {
isError = true;
}
if (HAL_I2C_Master_Receive(&hi2c1, TOUCH_DEVICE_ADDRESS, result, 2, 5) != HAL_OK) {
isError = true;
}

g_lastZ1Data = (((int16_t)result[0]) << 3) | ((int16_t)result[1]);

if (g_lastZ1Data > CONF_TOUCH_Z1_THRESHOLD) {
HAL_I2C_Master_Transmit(&hi2c1, TOUCH_DEVICE_ADDRESS, (uint8_t *)&X_DATA_ID, 1, 5);
HAL_I2C_Master_Receive(&hi2c1, TOUCH_DEVICE_ADDRESS, result, 2, 5);
if (HAL_I2C_Master_Transmit(&hi2c1, TOUCH_DEVICE_ADDRESS, (uint8_t *)&X_DATA_ID, 1, 5) != HAL_OK) {
isError = true;
}
if (HAL_I2C_Master_Receive(&hi2c1, TOUCH_DEVICE_ADDRESS, result, 2, 5) != HAL_OK) {
isError = true;
}

HAL_I2C_Master_Transmit(&hi2c1, TOUCH_DEVICE_ADDRESS, (uint8_t *)&Y_DATA_ID, 1, 5);
HAL_I2C_Master_Receive(&hi2c1, TOUCH_DEVICE_ADDRESS, result + 2, 2, 5);
if (HAL_I2C_Master_Transmit(&hi2c1, TOUCH_DEVICE_ADDRESS, (uint8_t *)&Y_DATA_ID, 1, 5) != HAL_OK) {
isError = true;
}
if (HAL_I2C_Master_Receive(&hi2c1, TOUCH_DEVICE_ADDRESS, result + 2, 2, 5) != HAL_OK) {
isError = true;
}
}

taskEXIT_CRITICAL();

if (isError) {
if (g_errorCounter < 5) {
g_errorCounter++;
DebugTrace("Touch controller error detected\n");
}
}

if (g_lastZ1Data > CONF_TOUCH_Z1_THRESHOLD) {
g_lastXData = (((int16_t)result[0]) << 3) | ((int16_t)result[1]);
g_lastYData = (((int16_t)result[2]) << 3) | ((int16_t)result[3]);
Expand Down Expand Up @@ -215,4 +237,4 @@ void data_touch_raw_pressed(DataOperationEnum operation, Cursor cursor, Value &v

} // namespace eez

#endif // EEZ_PLATFORM_STM32
#endif // EEZ_PLATFORM_STM32

0 comments on commit 72eedf3

Please sign in to comment.