Skip to content

Commit d2d71ca

Browse files
robbycandrathinkyhead
authored andcommitted
Clean up Touch pins. Better up/down touch response. (MarlinFirmware#14900)
1 parent 8cc0b4b commit d2d71ca

File tree

7 files changed

+45
-24
lines changed

7 files changed

+45
-24
lines changed

Marlin/src/feature/touch/xpt2046.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ void XPT2046::init(void) {
6363
uint8_t XPT2046::read_buttons() {
6464
int16_t tsoffsets[4] = { 0 };
6565

66-
static uint32_t touchtimeout = 0;
67-
if (PENDING(millis(), touchtimeout)) return 0;
68-
touchtimeout = millis() + 80; // ideally want to set this lower for the games... 30 or 40.
69-
7066
if (tsoffsets[0] + tsoffsets[1] == 0) {
7167
// Not yet set, so use defines as fallback...
7268
tsoffsets[0] = XPT2046_X_CALIBRATION;
@@ -84,10 +80,10 @@ uint8_t XPT2046::read_buttons() {
8480

8581
if (y < 175 || y > 234) return 0;
8682

87-
if (WITHIN(x, 11, 109)) encoderDiff = -(ENCODER_STEPS_PER_MENU_ITEM) * ENCODER_PULSES_PER_STEP;
88-
else if (WITHIN(x, 111, 209)) encoderDiff = ENCODER_STEPS_PER_MENU_ITEM * ENCODER_PULSES_PER_STEP;
89-
else if (WITHIN(x, 211, 309)) return EN_C;
90-
return 0;
83+
return WITHIN(x, 11, 109) ? EN_A
84+
: WITHIN(x, 111, 209) ? EN_B
85+
: WITHIN(x, 211, 309) ? EN_C
86+
: 0;
9187
}
9288

9389
bool XPT2046::isTouched() {

Marlin/src/lcd/ultralcd.cpp

+39-7
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,42 @@ void MarlinUI::update() {
764764

765765
// If the action button is pressed...
766766
static bool wait_for_unclick; // = 0
767-
if (!external_control && button_pressed()) {
768-
if (!wait_for_unclick) { // If not waiting for a debounce release:
769-
wait_for_unclick = true; // - Set debounce flag to ignore continous clicks
770-
lcd_clicked = !wait_for_user && !no_reentry; // - Keep the click if not waiting for a user-click
771-
wait_for_user = false; // - Any click clears wait for user
772-
quick_feedback(); // - Always make a click sound
767+
if (touch_buttons) {
768+
if (buttons & EN_C) {
769+
if (!wait_for_unclick) { // If not waiting for a debounce release:
770+
wait_for_unclick = true; // - Set debounce flag to ignore continous clicks
771+
lcd_clicked = !wait_for_user && !no_reentry; // - Keep the click if not waiting for a user-click
772+
wait_for_user = false; // - Any click clears wait for user
773+
quick_feedback(); // - Always make a click sound
774+
}
775+
}
776+
else if (buttons & (EN_A | EN_B)) { // Ignore the encoder if clicked, to prevent "slippage"
777+
const millis_t ms = millis();
778+
if (ELAPSED(ms, next_button_update_ms)) {
779+
next_button_update_ms = ms + 50;
780+
encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP);
781+
if (buttons & EN_A) encoderDiff *= -1;
782+
if (!wait_for_unclick) {
783+
next_button_update_ms += 250;
784+
#if HAS_BUZZER
785+
buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
786+
#endif
787+
wait_for_unclick = true; // - Set debounce flag to ignore continous clicks
788+
}
789+
}
790+
}
791+
}
792+
else {
793+
//
794+
// Integrated LCD click handling via button_pressed()
795+
//
796+
if (!external_control && button_pressed()) {
797+
if (!wait_for_unclick) { // If not waiting for a debounce release:
798+
wait_for_unclick = true; // - Set debounce flag to ignore continous clicks
799+
lcd_clicked = !wait_for_user && !no_reentry; // - Keep the click if not waiting for a user-click
800+
wait_for_user = false; // - Any click clears wait for user
801+
quick_feedback(); // - Always make a click sound
802+
}
773803
}
774804
}
775805
else wait_for_unclick = false;
@@ -784,7 +814,9 @@ void MarlinUI::update() {
784814
#endif // HAS_LCD_MENU
785815

786816
#if ENABLED(INIT_SDCARD_ON_BOOT)
787-
817+
//
818+
// SPI SD Card detection (and first card init when the LCD is present)
819+
//
788820
const uint8_t sd_status = (uint8_t)IS_SD_INSERTED();
789821
if (sd_status != lcd_sd_status && detected()) {
790822

Marlin/src/lcd/ultralcd.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151

152152
#define BUTTON_PRESSED(BN) !READ(BTN_## BN)
153153

154-
#if BUTTON_EXISTS(ENC)
154+
#if BUTTON_EXISTS(ENC) || ENABLED(TOUCH_BUTTONS)
155155
#define BLEN_C 2
156156
#define EN_C _BV(BLEN_C)
157157
#endif

Marlin/src/pins/stm32/pins_JGAURORA_A5S_A1.h

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@
122122
// Touch support
123123
//
124124
#if ENABLED(TOUCH_BUTTONS)
125-
#define BTN_ENC PA11 // Real pin needed to enable encoder's push button functionality used by touch screen. PA11 gives stable value.
126125
#define TOUCH_CS_PIN PA4
127126
#define TOUCH_INT_PIN PC4
128127
#endif

Marlin/src/pins/stm32/pins_LONGER3D_LK.h

-4
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@
136136
#define TOUCH_MOSI_PIN PB14 // pin 53
137137
#define TOUCH_MISO_PIN PB15 // pin 54
138138
#define TOUCH_INT_PIN PC6 // pin 63 (PenIRQ coming from ADS7843)
139-
140-
#define BTN_ENC PB0 // pin 35 unconnected pin on Alfawise. (PC13 to try)
141-
#define BTN_EN1 -1 // Real pin is needed to enable encoder's push button
142-
#define BTN_EN2 -1 // functionality used by touch screen
143139
#endif
144140

145141
//

Marlin/src/pins/stm32/pins_MKS_ROBIN_MINI.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125
#define LCD_BACKLIGHT_PIN PD13
126126

127127
#if ENABLED(TOUCH_BUTTONS)
128-
#define BTN_ENC PB3 // Not connected. TODO: Replace this hack to enable button code
129128
#define TOUCH_CS_PIN PC2
130129
#endif
131130
#endif
@@ -134,7 +133,7 @@
134133
#define MOTOR_CURRENT_PWM_XY_PIN PA6
135134
#define MOTOR_CURRENT_PWM_Z_PIN PA7
136135
#define MOTOR_CURRENT_PWM_E_PIN PB0
137-
#define MOTOR_CURRENT_PWM_RANGE 65535 // (255 * (1000mA / 65535)) * 257 = 1000 is equal 1.6v Vref in turn equal 1Amp
136+
#define MOTOR_CURRENT_PWM_RANGE 1500 // (255 * (1000mA / 65535)) * 257 = 1000 is equal 1.6v Vref in turn equal 1Amp
138137
#define DEFAULT_PWM_MOTOR_CURRENT { 1030, 1030, 1030 } // 1.05Amp per driver, here is XY, Z and E. This values determined empirically.
139138

140139
// This is a kind of workaround in case native marlin "digipot" interface won't work.

Marlin/src/pins/stm32/pins_MKS_ROBIN_NANO.h

-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@
129129
#define LCD_BACKLIGHT_PIN PD13
130130

131131
#if ENABLED(TOUCH_BUTTONS)
132-
#define BTN_ENC PC13 // Not connected. TODO: Replace this hack to enable button code
133132
#define TOUCH_CS_PIN PA7
134133
#endif
135134
#endif

0 commit comments

Comments
 (0)