Skip to content

Improve XPT2046 touch handling and calibration UI #27892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 9, 2025

Conversation

staff1010
Copy link
Contributor

Description

This PR addresses two related areas of the touch interface:

  1. XPT2046 Touch Controller Enhancement:
    Implements a recommendation from the XPT2046 datasheet which states:

    "It is recommended that the processor mask the interrupt PENIRQ is associated with whenever the processor sends a control byte to the XPT2046. This prevents false triggering of interrupts when the PENIRQ output is disabled."

    The implementation modifies the XPT2046 differential mode setting based on whether a dedicated touch interrupt pin is defined. When no such pin exists, it uses mode 0x01, which helps prevent false interrupt triggering.

  2. Touch Calibration UI Improvements:

    • Ensures proper UI cleanup before launching the calibration screen
    • Fixes the positioning of the return button on the calibration result screen
    • Improves overall user flow during the calibration process

Testing confirms these changes significantly improve the touch experience, particularly on hardware configurations without a dedicated touch interrupt pin.

Requirements

  • Hardware using XPT2046 touch controller
  • MKS UI interface with touch calibration capability

Benefits

  • Improved touch responsiveness and stability
  • Reduced false touch detections
  • Better alignment with hardware datasheet recommendations
  • Enhanced calibration UI experience
  • Proper screen transitions during calibration

Configurations

The changes automatically adapt based on the existing pin configuration and require no special configuration to test.

Related Issues

  • Addresses touch responsiveness issues in configurations without dedicated touch interrupt pins
  • Fixes UI consistency issues during touch calibration

staff1010 and others added 14 commits April 30, 2025 11:36
- Update LVGL library to version 6.1.2
- Fix image rendering issues (lvgl/lvgl#8166)
- Implement hash table for faster image lookup and rendering
- Optimize SPI flash operations by removing redundant initializations
- Improve memory management with adjusted buffer sizes
- Enhance drawing routines with configurable parameters
- Add image cache invalidation for better UI consistency
- Optimize flash memory usage for improved performance
- Implement XPT2046 datasheet recommendations for PENIRQ handling
- Modify differential mode based on touch interrupt pin availability
- Fix touch calibration UI issues and improve screen transitions
- Adjust return button position for better user experience
@thinkyhead thinkyhead force-pushed the bugfix-2.1.x branch 3 times, most recently from 3791e7d to 6ea4a16 Compare June 2, 2025 21:51
@thinkyhead thinkyhead force-pushed the bugfix-2.1.x branch 2 times, most recently from 37ad06f to ed48888 Compare June 9, 2025 03:31
@@ -86,7 +86,7 @@ void lv_update_touch_calibration_screen() {
// end calibration
str = stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED);
touch_calibration.calibration_end();
lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_TC_RETURN);
lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, 180, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_TC_RETURN);
Copy link
Member

@thinkyhead thinkyhead Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this button unique or following a similar layout to others? Can its size / position be expressed in terms of (updated names) BTN_SIZE_X and INTERVAL_W?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The position of this return button on the calibration interface is slightly different from that of other interfaces. If it is the same, it will overlap with the calibration coordinates. The name of its location can be represented by a separate macro.

@@ -46,7 +46,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {

void lv_draw_about() {
scr = lv_screen_create(ABOUT_UI);
lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_A_RETURN);
lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_SIZE_X * 3 + INTERVAL_W * 4, BTN_SIZE_Y + INTERVAL_H + titleHeight, event_handler, ID_A_RETURN);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming INTERVAL_V => INTERVAL_W because X goes with Width (or Horizontal), Y goes with Height (or Vertical). So either these bitmaps are rotated 90° with X being vertical and Y being horizontal, or these defines are name-swapped.

#define BTN_Y_PIXEL 140 // TFT_screen.btn_y_pixel
#define INTERVAL_W 2 // TFT_screen.gap_v // 2
#define BTN_SIZE_X 117 // TFT_screen.btn_x_pixel
#define BTN_SIZE_Y 140 // TFT_screen.btn_y_pixel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume that PIXEL refers to pixel-size, because these defines are used in multiplication.

@thinkyhead
Copy link
Member

If you concur with my renaming of some defines, I can merge those separately ahead of this.

@thinkyhead thinkyhead merged commit c09638f into MarlinFirmware:bugfix-2.1.x Jun 9, 2025
66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants