Skip to content

ft6x36.c error in code results in touch not giving correct co-ordinates solved. #118

Closed
@wreyford

Description

@wreyford

I ran into a problem when I updated to master branch using LVGL8.3
Amongst many issues, this was my last stumbling block.

The touch was giving incorrect coordinates, making it unusable.
For my ILI9488, using capacitive touch over I2C, with kconfig:

#
# Touchpanel Configuration (FT6X06)
#
CONFIG_LV_FT6X36_SWAPXY=y
# CONFIG_LV_FT6X36_INVERT_X is not set
CONFIG_LV_FT6X36_INVERT_Y=y
# end of Touchpanel Configuration (FT6X06)

I got incorrect X values

The reason for this is, that in the code line 118 to 136:

    last_x = ((data_buf[1] & FT6X36_MSB_MASK) << 8) | (data_buf[2] & FT6X36_LSB_MASK);
    last_y = ((data_buf[3] & FT6X36_MSB_MASK) << 8) | (data_buf[4] & FT6X36_LSB_MASK);

#if CONFIG_LV_FT6X36_INVERT_X
    last_x =  LV_HOR_RES - last_x;
#endif
#if CONFIG_LV_FT6X36_INVERT_Y
    last_y = LV_VER_RES - last_y;
#endif
#if CONFIG_LV_FT6X36_SWAPXY
    int16_t swap_buf = last_x;
    last_x = last_y;
    last_y = swap_buf;
#endif
    data->point.x = last_x;
    data->point.y = last_y;
    data->state = LV_INDEV_STATE_PR;
    ESP_LOGD(TAG, "X=%u Y=%u", data->point.x, data->point.y);
    return false;

needs to be:

    last_x = ((data_buf[1] & FT6X36_MSB_MASK) << 8) | (data_buf[2] & FT6X36_LSB_MASK);
    last_y = ((data_buf[3] & FT6X36_MSB_MASK) << 8) | (data_buf[4] & FT6X36_LSB_MASK);

#if CONFIG_LV_FT6X36_SWAPXY
    int16_t swap_buf = last_x;
    last_x = last_y;
    last_y = swap_buf;
#endif
#if CONFIG_LV_FT6X36_INVERT_X
    last_x =  LV_HOR_RES - last_x;
#endif
#if CONFIG_LV_FT6X36_INVERT_Y
    last_y = LV_VER_RES - last_y;
#endif
    data->point.x = last_x;
    data->point.y = last_y;
    data->state = LV_INDEV_STATE_PR;
    ESP_LOGI(TAG, "X=%u Y=%u", data->point.x, data->point.y);
    return false;

As you can see you must first swap the XY, before inverting, or if inverting y then swopping it, results in you incorrectly inverting x. Now the LV_HOR_RES or LV_VERT_RES is incorrect for that axis, and get crazy values!

My proposed fix fixes the issue for me.
Please check and fix if you agree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions