Rotary encoder cleanup (#20753)

This commit is contained in:
Scott Lahteine 2021-01-12 20:43:52 -06:00
parent bee794e598
commit 104aceb44a
30 changed files with 484 additions and 438 deletions

View File

@ -116,7 +116,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
#elif HAS_WIRED_LCD #elif HAS_WIRED_LCD
#if IS_TX1(BTN_EN2) || IS_RX1(BTN_EN1) #if IS_TX1(BTN_EN2) || IS_RX1(BTN_EN1)
#error "Serial port pins (1) conflict with Encoder Buttons!" #error "Serial port pins (1) conflict with Encoder Buttons!"
#elif ANY_TX(1, SD_SCK_PIN, LCD_PINS_D4, DOGLCD_SCK, LCD_RESET_PIN, LCD_PINS_RS, SHIFT_CLK) \ #elif ANY_TX(1, SD_SCK_PIN, LCD_PINS_D4, DOGLCD_SCK, LCD_RESET_PIN, LCD_PINS_RS, SHIFT_CLK_PIN) \
|| ANY_RX(1, LCD_SDSS, LCD_PINS_RS, SD_MISO_PIN, DOGLCD_A0, SD_SS_PIN, LCD_SDSS, DOGLCD_CS, LCD_RESET_PIN, LCD_BACKLIGHT_PIN) || ANY_RX(1, LCD_SDSS, LCD_PINS_RS, SD_MISO_PIN, DOGLCD_A0, SD_SS_PIN, LCD_SDSS, DOGLCD_CS, LCD_RESET_PIN, LCD_BACKLIGHT_PIN)
#error "Serial port pins (1) conflict with LCD pins!" #error "Serial port pins (1) conflict with LCD pins!"
#endif #endif

View File

@ -1595,7 +1595,7 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
/** /**
* ULTIPANEL encoder * ULTIPANEL encoder
*/ */
#if IS_ULTIPANEL && NONE(IS_NEWPANEL, SR_LCD_2W_NL) && !defined(SHIFT_CLK) #if IS_ULTIPANEL && NONE(IS_NEWPANEL, SR_LCD_2W_NL) && !PIN_EXISTS(SHIFT_CLK)
#error "ULTIPANEL controllers require some kind of encoder." #error "ULTIPANEL controllers require some kind of encoder."
#endif #endif

View File

@ -64,9 +64,6 @@ extern TFTGLCD lcd;
#undef BTN_EN1 #undef BTN_EN1
#undef BTN_EN2 #undef BTN_EN2
#undef BTN_ENC #undef BTN_ENC
#define BTN_EN1 -1
#define BTN_EN2 -1
#define BTN_ENC -1
#ifndef EN_C #ifndef EN_C
#define EN_C 4 // for click #define EN_C 4 // for click

234
Marlin/src/lcd/buttons.h Normal file
View File

@ -0,0 +1,234 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "../inc/MarlinConfig.h"
#if ((!HAS_ADC_BUTTONS && IS_NEWPANEL) || BUTTONS_EXIST(EN1, EN2)) && !IS_TFTGLCD_PANEL
#define HAS_ENCODER_WHEEL 1
#endif
#if HAS_ENCODER_WHEEL || ANY_BUTTON(ENC, BACK, UP, DWN, LFT, RT)
#define HAS_DIGITAL_BUTTONS 1
#endif
#if !HAS_ADC_BUTTONS && (IS_RRW_KEYPAD || (HAS_WIRED_LCD && !IS_NEWPANEL))
#define HAS_SHIFT_ENCODER 1
#endif
// I2C buttons must be read in the main thread
#if ANY(LCD_I2C_VIKI, LCD_I2C_PANELOLU2, IS_TFTGLCD_PANEL)
#define HAS_SLOW_BUTTONS 1
#endif
#if HAS_ENCODER_WHEEL
#define ENCODER_PHASE_0 0
#define ENCODER_PHASE_1 2
#define ENCODER_PHASE_2 3
#define ENCODER_PHASE_3 1
#endif
#if EITHER(HAS_DIGITAL_BUTTONS, DWIN_CREALITY_LCD)
// Wheel spin pins where BA is 00, 10, 11, 01 (1 bit always changes)
#define BLEN_A 0
#define BLEN_B 1
#define EN_A _BV(BLEN_A)
#define EN_B _BV(BLEN_B)
#define _BUTTON_PRESSED(BN) !READ(BTN_##BN)
#if BUTTON_EXISTS(ENC) || HAS_TOUCH_BUTTONS
#define BLEN_C 2
#define EN_C _BV(BLEN_C)
#endif
#if ENABLED(LCD_I2C_VIKI)
#include <LiquidTWI2.h>
#define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
// button and encoder bit positions within 'buttons'
#define B_LE (BUTTON_LEFT << B_I2C_BTN_OFFSET) // The remaining normalized buttons are all read via I2C
#define B_UP (BUTTON_UP << B_I2C_BTN_OFFSET)
#define B_MI (BUTTON_SELECT << B_I2C_BTN_OFFSET)
#define B_DW (BUTTON_DOWN << B_I2C_BTN_OFFSET)
#define B_RI (BUTTON_RIGHT << B_I2C_BTN_OFFSET)
#if BUTTON_EXISTS(ENC) // The pause/stop/restart button is connected to BTN_ENC when used
#define B_ST (EN_C) // Map the pause/stop/resume button into its normalized functional name
#define BUTTON_CLICK() (buttons & (B_MI|B_RI|B_ST)) // Pause/stop also acts as click until a proper pause/stop is implemented.
#else
#define BUTTON_CLICK() (buttons & (B_MI|B_RI))
#endif
// I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
#elif ENABLED(LCD_I2C_PANELOLU2)
#if !BUTTON_EXISTS(ENC) // Use I2C if not directly connected to a pin
#define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
#define B_MI (PANELOLU2_ENCODER_C << B_I2C_BTN_OFFSET) // requires LiquidTWI2 library v1.2.3 or later
#define BUTTON_CLICK() (buttons & B_MI)
#endif
#endif
#else
#undef BUTTON_EXISTS
#define BUTTON_EXISTS(...) false
// Dummy button, never pressed
#define _BUTTON_PRESSED(BN) false
// Shift register bits correspond to buttons:
#define BL_LE 7 // Left
#define BL_UP 6 // Up
#define BL_MI 5 // Middle
#define BL_DW 4 // Down
#define BL_RI 3 // Right
#define BL_ST 2 // Red Button
#define B_LE _BV(BL_LE)
#define B_UP _BV(BL_UP)
#define B_MI _BV(BL_MI)
#define B_DW _BV(BL_DW)
#define B_RI _BV(BL_RI)
#define B_ST _BV(BL_ST)
#ifndef BUTTON_CLICK
#define BUTTON_CLICK() (buttons & (B_MI|B_ST))
#endif
#endif
#if IS_RRW_KEYPAD
#define BTN_OFFSET 0 // Bit offset into buttons for shift register values
#define BLEN_KEYPAD_F3 0
#define BLEN_KEYPAD_F2 1
#define BLEN_KEYPAD_F1 2
#define BLEN_KEYPAD_DOWN 3
#define BLEN_KEYPAD_RIGHT 4
#define BLEN_KEYPAD_MIDDLE 5
#define BLEN_KEYPAD_UP 6
#define BLEN_KEYPAD_LEFT 7
#define EN_KEYPAD_F1 _BV(BTN_OFFSET + BLEN_KEYPAD_F1)
#define EN_KEYPAD_F2 _BV(BTN_OFFSET + BLEN_KEYPAD_F2)
#define EN_KEYPAD_F3 _BV(BTN_OFFSET + BLEN_KEYPAD_F3)
#define EN_KEYPAD_DOWN _BV(BTN_OFFSET + BLEN_KEYPAD_DOWN)
#define EN_KEYPAD_RIGHT _BV(BTN_OFFSET + BLEN_KEYPAD_RIGHT)
#define EN_KEYPAD_MIDDLE _BV(BTN_OFFSET + BLEN_KEYPAD_MIDDLE)
#define EN_KEYPAD_UP _BV(BTN_OFFSET + BLEN_KEYPAD_UP)
#define EN_KEYPAD_LEFT _BV(BTN_OFFSET + BLEN_KEYPAD_LEFT)
#define RRK(B) (keypad_buttons & (B))
#ifdef EN_C
#define BUTTON_CLICK() ((buttons & EN_C) || RRK(EN_KEYPAD_MIDDLE))
#else
#define BUTTON_CLICK() RRK(EN_KEYPAD_MIDDLE)
#endif
#endif
#ifndef EN_A
#define EN_A 0
#endif
#ifndef EN_B
#define EN_B 0
#endif
#ifndef EN_C
#define EN_C 0
#endif
#if BUTTON_EXISTS(BACK) || EITHER(HAS_TOUCH_BUTTONS, IS_TFTGLCD_PANEL)
#define BLEN_D 3
#define EN_D _BV(BLEN_D)
#else
#define EN_D 0
#endif
#define BUTTON_PRESSED(BN) (_BUTTON_PRESSED_##BN)
#if BUTTON_EXISTS(EN1)
#define _BUTTON_PRESSED_EN1 _BUTTON_PRESSED(EN1)
#else
#define _BUTTON_PRESSED_EN1 false
#endif
#if BUTTON_EXISTS(EN2)
#define _BUTTON_PRESSED_EN2 _BUTTON_PRESSED(EN2)
#else
#define _BUTTON_PRESSED_EN2 false
#endif
#if BUTTON_EXISTS(ENC_EN)
#define _BUTTON_PRESSED_ENC_EN _BUTTON_PRESSED(ENC_EN)
#else
#define _BUTTON_PRESSED_ENC_EN false
#endif
#if BUTTON_EXISTS(ENC)
#define _BUTTON_PRESSED_ENC _BUTTON_PRESSED(ENC)
#else
#define _BUTTON_PRESSED_ENC false
#endif
#if BUTTON_EXISTS(UP)
#define _BUTTON_PRESSED_UP _BUTTON_PRESSED(UP)
#else
#define _BUTTON_PRESSED_UP false
#endif
#if BUTTON_EXISTS(DWN)
#define _BUTTON_PRESSED_DWN _BUTTON_PRESSED(DWN)
#else
#define _BUTTON_PRESSED_DWN false
#endif
#if BUTTON_EXISTS(LFT)
#define _BUTTON_PRESSED_LFT _BUTTON_PRESSED(LFT)
#else
#define _BUTTON_PRESSED_LFT false
#endif
#if BUTTON_EXISTS(RT)
#define _BUTTON_PRESSED_RT _BUTTON_PRESSED(RT)
#else
#define _BUTTON_PRESSED_RT false
#endif
#if BUTTON_EXISTS(BACK)
#define _BUTTON_PRESSED_BACK _BUTTON_PRESSED(BACK)
#else
#define _BUTTON_PRESSED_BACK false
#endif
#ifndef BUTTON_CLICK
#if EN_C > 0
#define BUTTON_CLICK() (buttons & EN_C)
#else
#define BUTTON_CLICK() false
#endif
#endif
#if EN_D > 0
#define LCD_BACK_CLICKED() (buttons & EN_D)
#else
#define LCD_BACK_CLICKED() false
#endif

View File

@ -33,6 +33,7 @@
#if ENABLED(DWIN_CREALITY_LCD) #if ENABLED(DWIN_CREALITY_LCD)
#include "rotary_encoder.h" #include "rotary_encoder.h"
#include "../../buttons.h"
#include "../../../MarlinCore.h" #include "../../../MarlinCore.h"
#include "../../../HAL/shared/Delay.h" #include "../../../HAL/shared/Delay.h"
@ -43,17 +44,23 @@
#include <stdlib.h> #include <stdlib.h>
#ifndef ENCODER_PULSES_PER_STEP
#define ENCODER_PULSES_PER_STEP 4
#endif
ENCODER_Rate EncoderRate; ENCODER_Rate EncoderRate;
// Buzzer // Buzzer
void Encoder_tick(void) { void Encoder_tick() {
WRITE(BEEPER_PIN, 1); #if PIN_EXISTS(BEEPER)
WRITE(BEEPER_PIN, HIGH);
delay(10); delay(10);
WRITE(BEEPER_PIN, 0); WRITE(BEEPER_PIN, LOW);
#endif
} }
// Encoder initialization // Encoder initialization
void Encoder_Configuration(void) { void Encoder_Configuration() {
#if BUTTON_EXISTS(EN1) #if BUTTON_EXISTS(EN1)
SET_INPUT_PULLUP(BTN_EN1); SET_INPUT_PULLUP(BTN_EN1);
#endif #endif
@ -63,21 +70,21 @@ void Encoder_Configuration(void) {
#if BUTTON_EXISTS(ENC) #if BUTTON_EXISTS(ENC)
SET_INPUT_PULLUP(BTN_ENC); SET_INPUT_PULLUP(BTN_ENC);
#endif #endif
#ifdef BEEPER_PIN #if PIN_EXISTS(BEEPER)
SET_OUTPUT(BEEPER_PIN); SET_OUTPUT(BEEPER_PIN);
#endif #endif
} }
// Analyze encoder value and return state // Analyze encoder value and return state
ENCODER_DiffState Encoder_ReceiveAnalyze(void) { ENCODER_DiffState Encoder_ReceiveAnalyze() {
const millis_t now = millis(); const millis_t now = millis();
static unsigned char lastEncoderBits; static uint8_t lastEncoderBits;
unsigned char newbutton = 0; uint8_t newbutton = 0;
static signed char temp_diff = 0; static signed char temp_diff = 0;
ENCODER_DiffState temp_diffState = ENCODER_DIFF_NO; ENCODER_DiffState temp_diffState = ENCODER_DIFF_NO;
if (BUTTON_PRESSED(EN1)) newbutton |= 0x01; if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
if (BUTTON_PRESSED(EN2)) newbutton |= 0x02; if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
if (BUTTON_PRESSED(ENC)) { if (BUTTON_PRESSED(ENC)) {
static millis_t next_click_update_ms; static millis_t next_click_update_ms;
if (ELAPSED(now, next_click_update_ms)) { if (ELAPSED(now, next_click_update_ms)) {
@ -94,22 +101,22 @@ ENCODER_DiffState Encoder_ReceiveAnalyze(void) {
} }
if (newbutton != lastEncoderBits) { if (newbutton != lastEncoderBits) {
switch (newbutton) { switch (newbutton) {
case ENCODER_PHASE_0: { case ENCODER_PHASE_0:
if (lastEncoderBits == ENCODER_PHASE_3) temp_diff++; if (lastEncoderBits == ENCODER_PHASE_3) temp_diff++;
else if (lastEncoderBits == ENCODER_PHASE_1) temp_diff--; else if (lastEncoderBits == ENCODER_PHASE_1) temp_diff--;
}break; break;
case ENCODER_PHASE_1: { case ENCODER_PHASE_1:
if (lastEncoderBits == ENCODER_PHASE_0) temp_diff++; if (lastEncoderBits == ENCODER_PHASE_0) temp_diff++;
else if (lastEncoderBits == ENCODER_PHASE_2) temp_diff--; else if (lastEncoderBits == ENCODER_PHASE_2) temp_diff--;
}break; break;
case ENCODER_PHASE_2: { case ENCODER_PHASE_2:
if (lastEncoderBits == ENCODER_PHASE_1) temp_diff++; if (lastEncoderBits == ENCODER_PHASE_1) temp_diff++;
else if (lastEncoderBits == ENCODER_PHASE_3) temp_diff--; else if (lastEncoderBits == ENCODER_PHASE_3) temp_diff--;
}break; break;
case ENCODER_PHASE_3: { case ENCODER_PHASE_3:
if (lastEncoderBits == ENCODER_PHASE_2) temp_diff++; if (lastEncoderBits == ENCODER_PHASE_2) temp_diff++;
else if (lastEncoderBits == ENCODER_PHASE_0) temp_diff--; else if (lastEncoderBits == ENCODER_PHASE_0) temp_diff--;
}break; break;
} }
lastEncoderBits = newbutton; lastEncoderBits = newbutton;
} }
@ -137,9 +144,12 @@ ENCODER_DiffState Encoder_ReceiveAnalyze(void) {
} }
EncoderRate.lastEncoderTime = ms; EncoderRate.lastEncoderTime = ms;
} }
#else #else
constexpr int32_t encoderMultiplier = 1; constexpr int32_t encoderMultiplier = 1;
#endif // ENCODER_RATE_MULTIPLIER
#endif
// EncoderRate.encoderMoveValue += (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP); // EncoderRate.encoderMoveValue += (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
EncoderRate.encoderMoveValue = (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP); EncoderRate.encoderMoveValue = (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
@ -153,23 +163,23 @@ ENCODER_DiffState Encoder_ReceiveAnalyze(void) {
#if PIN_EXISTS(LCD_LED) #if PIN_EXISTS(LCD_LED)
// Take the low 24 valid bits 24Bit: G7 G6 G5 G4 G3 G2 G1 G0 R7 R6 R5 R4 R3 R2 R1 R0 B7 B6 B5 B4 B3 B2 B1 B0 // Take the low 24 valid bits 24Bit: G7 G6 G5 G4 G3 G2 G1 G0 R7 R6 R5 R4 R3 R2 R1 R0 B7 B6 B5 B4 B3 B2 B1 B0
unsigned int LED_DataArray[LED_NUM]; uint16_t LED_DataArray[LED_NUM];
// LED light operation // LED light operation
void LED_Action(void) { void LED_Action() {
LED_Control(RGB_SCALE_WARM_WHITE,0x0F); LED_Control(RGB_SCALE_WARM_WHITE,0x0F);
delay(30); delay(30);
LED_Control(RGB_SCALE_WARM_WHITE,0x00); LED_Control(RGB_SCALE_WARM_WHITE,0x00);
} }
// LED initialization // LED initialization
void LED_Configuration(void) { void LED_Configuration() {
SET_OUTPUT(LCD_LED_PIN); SET_OUTPUT(LCD_LED_PIN);
} }
// LED write data // LED write data
void LED_WriteData(void) { void LED_WriteData() {
unsigned char tempCounter_LED, tempCounter_Bit; uint8_t tempCounter_LED, tempCounter_Bit;
for (tempCounter_LED = 0; tempCounter_LED < LED_NUM; tempCounter_LED++) { for (tempCounter_LED = 0; tempCounter_LED < LED_NUM; tempCounter_LED++) {
for (tempCounter_Bit = 0; tempCounter_Bit < 24; tempCounter_Bit++) { for (tempCounter_Bit = 0; tempCounter_Bit < 24; tempCounter_Bit++) {
if (LED_DataArray[tempCounter_LED] & (0x800000 >> tempCounter_Bit)) { if (LED_DataArray[tempCounter_LED] & (0x800000 >> tempCounter_Bit)) {
@ -190,14 +200,13 @@ ENCODER_DiffState Encoder_ReceiveAnalyze(void) {
// LED control // LED control
// RGB_Scale: RGB color ratio // RGB_Scale: RGB color ratio
// luminance: brightness (0~0xFF) // luminance: brightness (0~0xFF)
void LED_Control(unsigned char RGB_Scale, unsigned char luminance) { void LED_Control(const uint8_t RGB_Scale, const uint8_t luminance) {
unsigned char temp_Counter; for (uint8_t i = 0; i < LED_NUM; i++) {
for (temp_Counter = 0; temp_Counter < LED_NUM; temp_Counter++) { LED_DataArray[i] = 0;
LED_DataArray[temp_Counter] = 0;
switch (RGB_Scale) { switch (RGB_Scale) {
case RGB_SCALE_R10_G7_B5: LED_DataArray[temp_Counter] = (luminance*10/10) << 8 | (luminance*7/10) << 16 | luminance*5/10; break; case RGB_SCALE_R10_G7_B5: LED_DataArray[i] = (luminance * 10/10) << 8 | (luminance * 7/10) << 16 | luminance * 5/10; break;
case RGB_SCALE_R10_G7_B4: LED_DataArray[temp_Counter] = (luminance*10/10) << 8 | (luminance*7/10) << 16 | luminance*4/10; break; case RGB_SCALE_R10_G7_B4: LED_DataArray[i] = (luminance * 10/10) << 8 | (luminance * 7/10) << 16 | luminance * 4/10; break;
case RGB_SCALE_R10_G8_B7: LED_DataArray[temp_Counter] = (luminance*10/10) << 8 | (luminance*8/10) << 16 | luminance*7/10; break; case RGB_SCALE_R10_G8_B7: LED_DataArray[i] = (luminance * 10/10) << 8 | (luminance * 8/10) << 16 | luminance * 7/10; break;
} }
} }
LED_WriteData(); LED_WriteData();
@ -207,45 +216,38 @@ ENCODER_DiffState Encoder_ReceiveAnalyze(void) {
// RGB_Scale: RGB color ratio // RGB_Scale: RGB color ratio
// luminance: brightness (0~0xFF) // luminance: brightness (0~0xFF)
// change_Time: gradient time (ms) // change_Time: gradient time (ms)
void LED_GraduallyControl(unsigned char RGB_Scale, unsigned char luminance, unsigned int change_Interval) { void LED_GraduallyControl(const uint8_t RGB_Scale, const uint8_t luminance, const uint16_t change_Interval) {
unsigned char temp_Counter; struct { uint8_t g, r, b; } led_data[LED_NUM];
unsigned char LED_R_Data[LED_NUM], LED_G_Data[LED_NUM], LED_B_Data[LED_NUM]; for (uint8_t i = 0; i < LED_NUM; i++) {
bool LED_R_Flag = 0, LED_G_Flag = 0, LED_B_Flag = 0;
for (temp_Counter = 0; temp_Counter < LED_NUM; temp_Counter++) {
switch (RGB_Scale) { switch (RGB_Scale) {
case RGB_SCALE_R10_G7_B5: { case RGB_SCALE_R10_G7_B5:
LED_R_Data[temp_Counter] = luminance*10/10; led_data[i] = { luminance * 7/10, luminance * 10/10, luminance * 5/10 };
LED_G_Data[temp_Counter] = luminance*7/10; break;
LED_B_Data[temp_Counter] = luminance*5/10; case RGB_SCALE_R10_G7_B4:
}break; led_data[i] = { luminance * 7/10, luminance * 10/10, luminance * 4/10 };
case RGB_SCALE_R10_G7_B4: { break;
LED_R_Data[temp_Counter] = luminance*10/10; case RGB_SCALE_R10_G8_B7:
LED_G_Data[temp_Counter] = luminance*7/10; led_data[i] = { luminance * 8/10, luminance * 10/10, luminance * 7/10 };
LED_B_Data[temp_Counter] = luminance*4/10; break;
}break;
case RGB_SCALE_R10_G8_B7: {
LED_R_Data[temp_Counter] = luminance*10/10;
LED_G_Data[temp_Counter] = luminance*8/10;
LED_B_Data[temp_Counter] = luminance*7/10;
}break;
} }
} }
for (temp_Counter = 0; temp_Counter < LED_NUM; temp_Counter++) {
if ((unsigned char)(LED_DataArray[temp_Counter] >> 8) > LED_R_Data[temp_Counter]) LED_DataArray[temp_Counter] -= 0x000100; struct { bool g, r, b; } led_flag = { false, false, false };
else if ((unsigned char)(LED_DataArray[temp_Counter] >> 8) < LED_R_Data[temp_Counter]) LED_DataArray[temp_Counter] += 0x000100; for (uint8_t i = 0; i < LED_NUM; i++) {
while (1) { while (1) {
else LED_R_Flag = 1; const uint8_t g = uint8_t(LED_DataArray[i] >> 16),
if ((unsigned char)(LED_DataArray[temp_Counter]>>16) > LED_G_Data[temp_Counter]) LED_DataArray[temp_Counter] -= 0x010000; r = uint8_t(LED_DataArray[i] >> 8),
else if ((unsigned char)(LED_DataArray[temp_Counter]>>16) < LED_G_Data[temp_Counter]) LED_DataArray[temp_Counter] += 0x010000; b = uint8_t(LED_DataArray[i]);
else LED_G_Flag = 1; if (g == led_data[i].g) led_flag.g = true;
if ((unsigned char)LED_DataArray[temp_Counter] > LED_B_Data[temp_Counter]) LED_DataArray[temp_Counter] -= 0x000001; else LED_DataArray[i] += (g > led_data[i].g) ? -0x010000 : 0x010000;
else if ((unsigned char)LED_DataArray[temp_Counter] < LED_B_Data[temp_Counter]) LED_DataArray[temp_Counter] += 0x000001; if (r == led_data[i].r) led_flag.r = true;
else LED_B_Flag = 1; else LED_DataArray[i] += (r > led_data[i].r) ? -0x000100 : 0x000100;
} if (b == led_data[i].b) led_flag.b = true;
else LED_DataArray[i] += (b > led_data[i].b) ? -0x000001 : 0x000001;
LED_WriteData(); LED_WriteData();
if (LED_R_Flag && LED_G_Flag && LED_B_Flag) break; if (led_flag.r && led_flag.g && led_flag.b) break;
else delay(change_Interval); delay(change_Interval);
}
} }
} }

View File

@ -34,15 +34,6 @@
/*********************** Encoder Set ***********************/ /*********************** Encoder Set ***********************/
#define ENCODER_PHASE_0 0
#define ENCODER_PHASE_1 2
#define ENCODER_PHASE_2 3
#define ENCODER_PHASE_3 1
#define ENCODER_PULSES_PER_STEP 4
#define BUTTON_PRESSED(BN) !READ(BTN_## BN)
typedef struct { typedef struct {
bool enabled = false; bool enabled = false;
int encoderMoveValue = 0; int encoderMoveValue = 0;
@ -59,10 +50,10 @@ typedef enum {
} ENCODER_DiffState; } ENCODER_DiffState;
// Encoder initialization // Encoder initialization
void Encoder_Configuration(void); void Encoder_Configuration();
// Analyze encoder value and return state // Analyze encoder value and return state
ENCODER_DiffState Encoder_ReceiveAnalyze(void); ENCODER_DiffState Encoder_ReceiveAnalyze();
/*********************** Encoder LED ***********************/ /*********************** Encoder LED ***********************/
@ -82,23 +73,23 @@ ENCODER_DiffState Encoder_ReceiveAnalyze(void);
extern unsigned int LED_DataArray[LED_NUM]; extern unsigned int LED_DataArray[LED_NUM];
// LED light operation // LED light operation
void LED_Action(void); void LED_Action();
// LED initialization // LED initialization
void LED_Configuration(void); void LED_Configuration();
// LED write data // LED write data
void LED_WriteData(void); void LED_WriteData();
// LED control // LED control
// RGB_Scale: RGB color ratio // RGB_Scale: RGB color ratio
// luminance: brightness (0~0xFF) // luminance: brightness (0~0xFF)
void LED_Control(unsigned char RGB_Scale, unsigned char luminance); void LED_Control(const uint8_t RGB_Scale, const uint8_t luminance);
// LED gradient control // LED gradient control
// RGB_Scale: RGB color ratio // RGB_Scale: RGB color ratio
// luminance: brightness (0~0xFF) // luminance: brightness (0~0xFF)
// change_Time: gradient time (ms) // change_Time: gradient time (ms)
void LED_GraduallyControl(unsigned char RGB_Scale, unsigned char luminance, unsigned int change_Interval); void LED_GraduallyControl(const uint8_t RGB_Scale, const uint8_t luminance, const uint16_t change_Interval);
#endif // LCD_LED #endif // LCD_LED

View File

@ -468,19 +468,10 @@ void lv_encoder_pin_init() {
#if ANY_BUTTON(EN1, EN2, ENC, BACK) #if ANY_BUTTON(EN1, EN2, ENC, BACK)
uint8_t newbutton = 0; uint8_t newbutton = 0;
#if BUTTON_EXISTS(EN1)
if (BUTTON_PRESSED(EN1)) newbutton |= EN_A; if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
#endif
#if BUTTON_EXISTS(EN2)
if (BUTTON_PRESSED(EN2)) newbutton |= EN_B; if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
#endif
#if BUTTON_EXISTS(ENC)
if (BUTTON_PRESSED(ENC)) newbutton |= EN_C; if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
#endif
#if BUTTON_EXISTS(BACK)
if (BUTTON_PRESSED(BACK)) newbutton |= EN_D; if (BUTTON_PRESSED(BACK)) newbutton |= EN_D;
#endif
#else #else
@ -488,7 +479,6 @@ void lv_encoder_pin_init() {
#endif #endif
static uint8_t buttons = 0; static uint8_t buttons = 0;
buttons = newbutton; buttons = newbutton;
static uint8_t lastEncoderBits; static uint8_t lastEncoderBits;

View File

@ -76,8 +76,8 @@
#define INFO_FONT_HEIGHT (INFO_FONT_ASCENT + INFO_FONT_DESCENT) #define INFO_FONT_HEIGHT (INFO_FONT_ASCENT + INFO_FONT_DESCENT)
#define INFO_FONT_WIDTH 6 #define INFO_FONT_WIDTH 6
#define SETCURSOR(col, row) lcd_moveto((col) * (MENU_FONT_WIDTH), ((row) + 1) * (MENU_FONT_HEIGHT)) #define LCD_COL_X(col) (( (col)) * (MENU_FONT_WIDTH))
#define SETCURSOR_RJ(len, row) lcd_moveto(LCD_PIXEL_WIDTH - (len) * (MENU_FONT_WIDTH), ((row) + 1) * (MENU_FONT_HEIGHT)) #define LCD_ROW_Y(row) ((1 + (row)) * (MENU_FONT_HEIGHT))
#else #else
@ -94,11 +94,15 @@
#define LCD_PIXEL_WIDTH LCD_WIDTH #define LCD_PIXEL_WIDTH LCD_WIDTH
#define LCD_PIXEL_HEIGHT LCD_HEIGHT #define LCD_PIXEL_HEIGHT LCD_HEIGHT
#define SETCURSOR(col, row) lcd_moveto(col, row) #define LCD_COL_X(col) (col)
#define SETCURSOR_RJ(len, row) SETCURSOR(LCD_WIDTH - (len), row) #define LCD_ROW_Y(row) (row)
#endif #endif
#define LCD_COL_X_RJ(len) (LCD_PIXEL_WIDTH - LCD_COL_X(len))
#define LCD_BOTTOM_ROW (LCD_PIXEL_HEIGHT - 1)
#define SETCURSOR(col, row) lcd_moveto(LCD_COL_X(col), LCD_ROW_Y(row))
#define SETCURSOR_RJ(len, row) lcd_moveto(LCD_COL_X_RJ(len), LCD_ROW_Y(row))
#define SETCURSOR_X(col) SETCURSOR(col, _lcdLineNr) #define SETCURSOR_X(col) SETCURSOR(col, _lcdLineNr)
#define SETCURSOR_X_RJ(len) SETCURSOR_RJ(len, _lcdLineNr) #define SETCURSOR_X_RJ(len) SETCURSOR_RJ(len, _lcdLineNr)
#define START_OF_UTF8_CHAR(C) (((C) & 0xC0u) != 0x80U) #define START_OF_UTF8_CHAR(C) (((C) & 0xC0u) != 0x80U)

View File

@ -342,7 +342,6 @@ void MarlinUI::init() {
init_lcd(); init_lcd();
#if HAS_DIGITAL_BUTTONS #if HAS_DIGITAL_BUTTONS
#if BUTTON_EXISTS(EN1) #if BUTTON_EXISTS(EN1)
SET_INPUT_PULLUP(BTN_EN1); SET_INPUT_PULLUP(BTN_EN1);
#endif #endif
@ -352,15 +351,12 @@ void MarlinUI::init() {
#if BUTTON_EXISTS(ENC) #if BUTTON_EXISTS(ENC)
SET_INPUT_PULLUP(BTN_ENC); SET_INPUT_PULLUP(BTN_ENC);
#endif #endif
#if BUTTON_EXISTS(ENC_EN) #if BUTTON_EXISTS(ENC_EN)
SET_INPUT_PULLUP(BTN_ENC_EN); SET_INPUT_PULLUP(BTN_ENC_EN);
#endif #endif
#if BUTTON_EXISTS(BACK) #if BUTTON_EXISTS(BACK)
SET_INPUT_PULLUP(BTN_BACK); SET_INPUT_PULLUP(BTN_BACK);
#endif #endif
#if BUTTON_EXISTS(UP) #if BUTTON_EXISTS(UP)
SET_INPUT(BTN_UP); SET_INPUT(BTN_UP);
#endif #endif
@ -373,8 +369,7 @@ void MarlinUI::init() {
#if BUTTON_EXISTS(RT) #if BUTTON_EXISTS(RT)
SET_INPUT(BTN_RT); SET_INPUT(BTN_RT);
#endif #endif
#endif
#endif // !HAS_DIGITAL_BUTTONS
#if HAS_SHIFT_ENCODER #if HAS_SHIFT_ENCODER
@ -383,14 +378,14 @@ void MarlinUI::init() {
SET_OUTPUT(SR_DATA_PIN); SET_OUTPUT(SR_DATA_PIN);
SET_OUTPUT(SR_CLK_PIN); SET_OUTPUT(SR_CLK_PIN);
#elif defined(SHIFT_CLK) #elif PIN_EXISTS(SHIFT_CLK)
SET_OUTPUT(SHIFT_CLK); SET_OUTPUT(SHIFT_CLK_PIN);
OUT_WRITE(SHIFT_LD, HIGH); OUT_WRITE(SHIFT_LD_PIN, HIGH);
#if defined(SHIFT_EN) && SHIFT_EN >= 0 #if PIN_EXISTS(SHIFT_EN)
OUT_WRITE(SHIFT_EN, LOW); OUT_WRITE(SHIFT_EN_PIN, LOW);
#endif #endif
SET_INPUT_PULLUP(SHIFT_OUT); SET_INPUT_PULLUP(SHIFT_OUT_PIN);
#endif #endif
@ -830,11 +825,7 @@ millis_t next_lcd_update_ms;
#endif #endif
inline bool can_encode() { inline bool can_encode() {
#if BUTTON_EXISTS(ENC_EN) return !BUTTON_PRESSED(ENC_EN); // Update encoder only when ENC_EN is not LOW (pressed)
return !BUTTON_PRESSED(ENC_EN); // Update position only when ENC_EN is HIGH
#else
return true;
#endif
} }
void MarlinUI::update() { void MarlinUI::update() {
@ -890,11 +881,10 @@ void MarlinUI::update() {
else if (!wait_for_unclick && (buttons & EN_C)) // OK button, if not waiting for a debounce release: else if (!wait_for_unclick && (buttons & EN_C)) // OK button, if not waiting for a debounce release:
do_click(); do_click();
} }
else // keep wait_for_unclick value // keep wait_for_unclick value
#endif
#endif // HAS_TOUCH_BUTTONS if (!touch_buttons) {
{
// Integrated LCD click handling via button_pressed // Integrated LCD click handling via button_pressed
if (!external_control && button_pressed()) { if (!external_control && button_pressed()) {
if (!wait_for_unclick) do_click(); // Handle the click if (!wait_for_unclick) do_click(); // Handle the click
@ -1198,19 +1188,10 @@ void MarlinUI::update() {
#if ANY_BUTTON(EN1, EN2, ENC, BACK) #if ANY_BUTTON(EN1, EN2, ENC, BACK)
uint8_t newbutton = 0; uint8_t newbutton = 0;
#if BUTTON_EXISTS(EN1)
if (BUTTON_PRESSED(EN1)) newbutton |= EN_A; if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
#endif
#if BUTTON_EXISTS(EN2)
if (BUTTON_PRESSED(EN2)) newbutton |= EN_B; if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
#endif
#if BUTTON_EXISTS(ENC)
if (can_encode() && BUTTON_PRESSED(ENC)) newbutton |= EN_C; if (can_encode() && BUTTON_PRESSED(ENC)) newbutton |= EN_C;
#endif
#if BUTTON_EXISTS(BACK)
if (BUTTON_PRESSED(BACK)) newbutton |= EN_D; if (BUTTON_PRESSED(BACK)) newbutton |= EN_D;
#endif
#else #else
@ -1225,40 +1206,26 @@ void MarlinUI::update() {
const int8_t pulses = epps * encoderDirection; const int8_t pulses = epps * encoderDirection;
if (false) { if (BUTTON_PRESSED(UP)) {
// for the else-ifs below
}
#if BUTTON_EXISTS(UP)
else if (BUTTON_PRESSED(UP)) {
encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * pulses; encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * pulses;
next_button_update_ms = now + 300; next_button_update_ms = now + 300;
} }
#endif
#if BUTTON_EXISTS(DWN)
else if (BUTTON_PRESSED(DWN)) { else if (BUTTON_PRESSED(DWN)) {
encoderDiff = -(ENCODER_STEPS_PER_MENU_ITEM) * pulses; encoderDiff = -(ENCODER_STEPS_PER_MENU_ITEM) * pulses;
next_button_update_ms = now + 300; next_button_update_ms = now + 300;
} }
#endif
#if BUTTON_EXISTS(LFT)
else if (BUTTON_PRESSED(LFT)) { else if (BUTTON_PRESSED(LFT)) {
encoderDiff = -pulses; encoderDiff = -pulses;
next_button_update_ms = now + 300; next_button_update_ms = now + 300;
} }
#endif
#if BUTTON_EXISTS(RT)
else if (BUTTON_PRESSED(RT)) { else if (BUTTON_PRESSED(RT)) {
encoderDiff = pulses; encoderDiff = pulses;
next_button_update_ms = now + 300; next_button_update_ms = now + 300;
} }
#endif
#endif // UP || DWN || LFT || RT #endif // UP || DWN || LFT || RT
buttons = (newbutton buttons = (newbutton | TERN0(HAS_SLOW_BUTTONS, slow_buttons)
#if HAS_SLOW_BUTTONS
| slow_buttons
#endif
#if BOTH(HAS_TOUCH_BUTTONS, HAS_ENCODER_ACTION) #if BOTH(HAS_TOUCH_BUTTONS, HAS_ENCODER_ACTION)
| (touch_buttons & TERN(HAS_ENCODER_WHEEL, ~(EN_A | EN_B), 0xFF)) | (touch_buttons & TERN(HAS_ENCODER_WHEEL, ~(EN_A | EN_B), 0xFF))
#endif #endif
@ -1284,13 +1251,13 @@ void MarlinUI::update() {
* The rotary encoder part is also independent of the LCD chipset. * The rotary encoder part is also independent of the LCD chipset.
*/ */
uint8_t val = 0; uint8_t val = 0;
WRITE(SHIFT_LD, LOW); WRITE(SHIFT_LD_PIN, LOW);
WRITE(SHIFT_LD, HIGH); WRITE(SHIFT_LD_PIN, HIGH);
LOOP_L_N(i, 8) { LOOP_L_N(i, 8) {
val >>= 1; val >>= 1;
if (READ(SHIFT_OUT)) SBI(val, 7); if (READ(SHIFT_OUT_PIN)) SBI(val, 7);
WRITE(SHIFT_CLK, HIGH); WRITE(SHIFT_CLK_PIN, HIGH);
WRITE(SHIFT_CLK, LOW); WRITE(SHIFT_CLK_PIN, LOW);
} }
TERN(REPRAPWORLD_KEYPAD, keypad_buttons, buttons) = ~val; TERN(REPRAPWORLD_KEYPAD, keypad_buttons, buttons) = ~val;
#endif #endif
@ -1306,11 +1273,6 @@ void MarlinUI::update() {
#if HAS_ENCODER_WHEEL #if HAS_ENCODER_WHEEL
static uint8_t lastEncoderBits; static uint8_t lastEncoderBits;
#define encrot0 0
#define encrot1 2
#define encrot2 3
#define encrot3 1
// Manage encoder rotation // Manage encoder rotation
#define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: encoderDiff += encoderDirection; break; case _E2: encoderDiff -= encoderDirection; } #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: encoderDiff += encoderDirection; break; case _E2: encoderDiff -= encoderDirection; }
@ -1319,10 +1281,10 @@ void MarlinUI::update() {
if (buttons & EN_B) enc |= B10; if (buttons & EN_B) enc |= B10;
if (enc != lastEncoderBits) { if (enc != lastEncoderBits) {
switch (enc) { switch (enc) {
case encrot0: ENCODER_SPIN(encrot3, encrot1); break; case ENCODER_PHASE_0: ENCODER_SPIN(ENCODER_PHASE_3, ENCODER_PHASE_1); break;
case encrot1: ENCODER_SPIN(encrot0, encrot2); break; case ENCODER_PHASE_1: ENCODER_SPIN(ENCODER_PHASE_0, ENCODER_PHASE_2); break;
case encrot2: ENCODER_SPIN(encrot1, encrot3); break; case ENCODER_PHASE_2: ENCODER_SPIN(ENCODER_PHASE_1, ENCODER_PHASE_3); break;
case encrot3: ENCODER_SPIN(encrot2, encrot0); break; case ENCODER_PHASE_3: ENCODER_SPIN(ENCODER_PHASE_2, ENCODER_PHASE_0); break;
} }
#if BOTH(HAS_LCD_MENU, AUTO_BED_LEVELING_UBL) #if BOTH(HAS_LCD_MENU, AUTO_BED_LEVELING_UBL)
external_encoder(); external_encoder();

View File

@ -25,6 +25,8 @@
#include "../module/motion.h" #include "../module/motion.h"
#include "buttons.h"
#if HAS_BUZZER #if HAS_BUZZER
#include "../libs/buzzer.h" #include "../libs/buzzer.h"
#endif #endif
@ -40,20 +42,6 @@
#if EITHER(HAS_LCD_MENU, ULTIPANEL_FEEDMULTIPLY) #if EITHER(HAS_LCD_MENU, ULTIPANEL_FEEDMULTIPLY)
#define HAS_ENCODER_ACTION 1 #define HAS_ENCODER_ACTION 1
#endif #endif
#if ((!HAS_ADC_BUTTONS && IS_NEWPANEL) || BUTTONS_EXIST(EN1, EN2)) && !IS_TFTGLCD_PANEL
#define HAS_ENCODER_WHEEL 1
#endif
#if HAS_ENCODER_WHEEL || ANY_BUTTON(ENC, BACK, UP, DWN, LFT, RT)
#define HAS_DIGITAL_BUTTONS 1
#endif
#if !HAS_ADC_BUTTONS && (IS_RRW_KEYPAD || (HAS_WIRED_LCD && !IS_NEWPANEL))
#define HAS_SHIFT_ENCODER 1
#endif
// I2C buttons must be read in the main thread
#if ANY(LCD_I2C_VIKI, LCD_I2C_PANELOLU2, IS_TFTGLCD_PANEL)
#define HAS_SLOW_BUTTONS 1
#endif
#if E_MANUAL > 1 #if E_MANUAL > 1
#define MULTI_MANUAL 1 #define MULTI_MANUAL 1
@ -114,130 +102,6 @@
#endif // HAS_WIRED_LCD #endif // HAS_WIRED_LCD
#if IS_RRW_KEYPAD
#define BTN_OFFSET 0 // Bit offset into buttons for shift register values
#define BLEN_KEYPAD_F3 0
#define BLEN_KEYPAD_F2 1
#define BLEN_KEYPAD_F1 2
#define BLEN_KEYPAD_DOWN 3
#define BLEN_KEYPAD_RIGHT 4
#define BLEN_KEYPAD_MIDDLE 5
#define BLEN_KEYPAD_UP 6
#define BLEN_KEYPAD_LEFT 7
#define EN_KEYPAD_F1 _BV(BTN_OFFSET + BLEN_KEYPAD_F1)
#define EN_KEYPAD_F2 _BV(BTN_OFFSET + BLEN_KEYPAD_F2)
#define EN_KEYPAD_F3 _BV(BTN_OFFSET + BLEN_KEYPAD_F3)
#define EN_KEYPAD_DOWN _BV(BTN_OFFSET + BLEN_KEYPAD_DOWN)
#define EN_KEYPAD_RIGHT _BV(BTN_OFFSET + BLEN_KEYPAD_RIGHT)
#define EN_KEYPAD_MIDDLE _BV(BTN_OFFSET + BLEN_KEYPAD_MIDDLE)
#define EN_KEYPAD_UP _BV(BTN_OFFSET + BLEN_KEYPAD_UP)
#define EN_KEYPAD_LEFT _BV(BTN_OFFSET + BLEN_KEYPAD_LEFT)
#define RRK(B) (keypad_buttons & (B))
#ifdef EN_C
#define BUTTON_CLICK() ((buttons & EN_C) || RRK(EN_KEYPAD_MIDDLE))
#else
#define BUTTON_CLICK() RRK(EN_KEYPAD_MIDDLE)
#endif
#endif // IS_RRW_KEYPAD
#if HAS_DIGITAL_BUTTONS
// Wheel spin pins where BA is 00, 10, 11, 01 (1 bit always changes)
#define BLEN_A 0
#define BLEN_B 1
#define EN_A _BV(BLEN_A)
#define EN_B _BV(BLEN_B)
#define BUTTON_PRESSED(BN) !READ(BTN_## BN)
#if BUTTON_EXISTS(ENC) || HAS_TOUCH_BUTTONS
#define BLEN_C 2
#define EN_C _BV(BLEN_C)
#endif
#if ENABLED(LCD_I2C_VIKI)
#include <LiquidTWI2.h>
#define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
// button and encoder bit positions within 'buttons'
#define B_LE (BUTTON_LEFT << B_I2C_BTN_OFFSET) // The remaining normalized buttons are all read via I2C
#define B_UP (BUTTON_UP << B_I2C_BTN_OFFSET)
#define B_MI (BUTTON_SELECT << B_I2C_BTN_OFFSET)
#define B_DW (BUTTON_DOWN << B_I2C_BTN_OFFSET)
#define B_RI (BUTTON_RIGHT << B_I2C_BTN_OFFSET)
#if BUTTON_EXISTS(ENC) // The pause/stop/restart button is connected to BTN_ENC when used
#define B_ST (EN_C) // Map the pause/stop/resume button into its normalized functional name
#define BUTTON_CLICK() (buttons & (B_MI|B_RI|B_ST)) // Pause/stop also acts as click until a proper pause/stop is implemented.
#else
#define BUTTON_CLICK() (buttons & (B_MI|B_RI))
#endif
// I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
#elif ENABLED(LCD_I2C_PANELOLU2)
#if !BUTTON_EXISTS(ENC) // Use I2C if not directly connected to a pin
#define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
#define B_MI (PANELOLU2_ENCODER_C << B_I2C_BTN_OFFSET) // requires LiquidTWI2 library v1.2.3 or later
#define BUTTON_CLICK() (buttons & B_MI)
#endif
#endif
#else
#undef BUTTON_EXISTS
#define BUTTON_EXISTS(...) false
// Shift register bits correspond to buttons:
#define BL_LE 7 // Left
#define BL_UP 6 // Up
#define BL_MI 5 // Middle
#define BL_DW 4 // Down
#define BL_RI 3 // Right
#define BL_ST 2 // Red Button
#define B_LE _BV(BL_LE)
#define B_UP _BV(BL_UP)
#define B_MI _BV(BL_MI)
#define B_DW _BV(BL_DW)
#define B_RI _BV(BL_RI)
#define B_ST _BV(BL_ST)
#ifndef BUTTON_CLICK
#define BUTTON_CLICK() (buttons & (B_MI|B_ST))
#endif
#endif
#if BUTTON_EXISTS(BACK) || EITHER(HAS_TOUCH_BUTTONS, IS_TFTGLCD_PANEL)
#define BLEN_D 3
#define EN_D _BV(BLEN_D)
#define LCD_BACK_CLICKED() (buttons & EN_D)
#else
#define LCD_BACK_CLICKED() false
#endif
#ifndef BUTTON_CLICK
#ifdef EN_C
#define BUTTON_CLICK() (buttons & EN_C)
#else
#define BUTTON_CLICK() false
#endif
#endif
#if HAS_MARLINUI_U8GLIB #if HAS_MARLINUI_U8GLIB
enum MarlinFont : uint8_t { enum MarlinFont : uint8_t {
FONT_STATUSMENU = 1, FONT_STATUSMENU = 1,
@ -556,6 +420,8 @@ public:
#if HAS_TOUCH_BUTTONS #if HAS_TOUCH_BUTTONS
static uint8_t touch_buttons; static uint8_t touch_buttons;
static uint8_t repeat_delay; static uint8_t repeat_delay;
#else
static constexpr uint8_t touch_buttons = 0;
#endif #endif
#if ENABLED(ENCODER_RATE_MULTIPLIER) #if ENABLED(ENCODER_RATE_MULTIPLIER)

View File

@ -31,7 +31,8 @@ XPT2046 touchIO;
#include "../tft_io/touch_calibration.h" #include "../tft_io/touch_calibration.h"
#endif #endif
#include "../marlinui.h" // For EN_C bit mask #include "../buttons.h" // For EN_C bit mask
#include "../marlinui.h" // For ui.refresh
#include "../tft_io/tft_io.h" #include "../tft_io/tft_io.h"
#define DOGM_AREA_LEFT TFT_PIXEL_OFFSET_X #define DOGM_AREA_LEFT TFT_PIXEL_OFFSET_X
@ -66,7 +67,6 @@ uint8_t TouchButtons::read_buttons() {
y = uint16_t((uint32_t(y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y; y = uint16_t((uint32_t(y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y;
#endif #endif
// Touch within the button area simulates an encoder button // Touch within the button area simulates an encoder button
if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT) if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT)
return WITHIN(x, BUTTOND_X_LO, BUTTOND_X_HI) ? EN_D return WITHIN(x, BUTTOND_X_LO, BUTTOND_X_HI) ? EN_D

View File

@ -459,10 +459,10 @@
#if !IS_NEWPANEL #if !IS_NEWPANEL
// Buttons attached to a shift register // Buttons attached to a shift register
// Not wired yet // Not wired yet
//#define SHIFT_CLK 38 //#define SHIFT_CLK_PIN 38
//#define SHIFT_LD 42 //#define SHIFT_LD_PIN 42
//#define SHIFT_OUT 40 //#define SHIFT_OUT_PIN 40
//#define SHIFT_EN 17 //#define SHIFT_EN_PIN 17
#endif #endif
#endif #endif
@ -608,9 +608,9 @@
// Buttons are directly attached to AUX-2 // Buttons are directly attached to AUX-2
#if IS_RRW_KEYPAD #if IS_RRW_KEYPAD
#define SHIFT_OUT 40 #define SHIFT_OUT_PIN 40
#define SHIFT_CLK 44 #define SHIFT_CLK_PIN 44
#define SHIFT_LD 42 #define SHIFT_LD_PIN 42
#define BTN_EN1 64 #define BTN_EN1 64
#define BTN_EN2 59 #define BTN_EN2 59
#define BTN_ENC 63 #define BTN_ENC 63

View File

@ -354,15 +354,15 @@
#if IS_NEWPANEL #if IS_NEWPANEL
#if IS_RRW_KEYPAD #if IS_RRW_KEYPAD
#define SHIFT_OUT P0_18 // (51) (MOSI) J3-10 & AUX-3 #define SHIFT_OUT_PIN P0_18 // (51) (MOSI) J3-10 & AUX-3
#define SHIFT_CLK P0_15 // (52) (SCK) J3-9 & AUX-3 #define SHIFT_CLK_PIN P0_15 // (52) (SCK) J3-9 & AUX-3
#define SHIFT_LD P1_31 // (49) J3-1 & AUX-3 (NOT 5V tolerant) #define SHIFT_LD_PIN P1_31 // (49) J3-1 & AUX-3 (NOT 5V tolerant)
#endif #endif
#else #else
//#define SHIFT_CLK P3_26 // (31) J3-2 & AUX-4 //#define SHIFT_CLK_PIN P3_26 // (31) J3-2 & AUX-4
//#define SHIFT_LD P3_25 // (33) J3-4 & AUX-4 //#define SHIFT_LD_PIN P3_25 // (33) J3-4 & AUX-4
//#define SHIFT_OUT P2_11 // (35) J3-3 & AUX-4 //#define SHIFT_OUT_PIN P2_11 // (35) J3-3 & AUX-4
//#define SHIFT_EN P1_22 // (41) J5-4 & AUX-4 //#define SHIFT_EN_PIN P1_22 // (41) J5-4 & AUX-4
#endif #endif
#if ANY(VIKI2, miniVIKI) #if ANY(VIKI2, miniVIKI)

View File

@ -147,14 +147,14 @@
#define DOGLCD_A0 P2_06 // (59) J3-8 & AUX-2 #define DOGLCD_A0 P2_06 // (59) J3-8 & AUX-2
#if IS_RRW_KEYPAD #if IS_RRW_KEYPAD
#define SHIFT_OUT P0_18 // (51) (MOSI) J3-10 & AUX-3 #define SHIFT_OUT_PIN P0_18 // (51) (MOSI) J3-10 & AUX-3
#define SHIFT_CLK P0_15 // (52) (SCK) J3-9 & AUX-3 #define SHIFT_CLK_PIN P0_15 // (52) (SCK) J3-9 & AUX-3
#define SHIFT_LD P1_31 // (49) not 5V tolerant J3-1 & AUX-3 #define SHIFT_LD_PIN P1_31 // (49) not 5V tolerant J3-1 & AUX-3
#elif !IS_NEWPANEL #elif !IS_NEWPANEL
//#define SHIFT_OUT P2_11 // (35) J3-3 & AUX-4 //#define SHIFT_OUT_PIN P2_11 // (35) J3-3 & AUX-4
//#define SHIFT_CLK P3_26 // (31) J3-2 & AUX-4 //#define SHIFT_CLK_PIN P3_26 // (31) J3-2 & AUX-4
//#define SHIFT_LD P3_25 // (33) J3-4 & AUX-4 //#define SHIFT_LD_PIN P3_25 // (33) J3-4 & AUX-4
//#define SHIFT_EN P1_22 // (41) J5-4 & AUX-4 //#define SHIFT_EN_PIN P1_22 // (41) J5-4 & AUX-4
#endif #endif
#if ANY(VIKI2, miniVIKI) #if ANY(VIKI2, miniVIKI)

View File

@ -149,9 +149,9 @@
#define BTN_ENC 27 #define BTN_ENC 27
// Hardware buttons for manual movement of XYZ // Hardware buttons for manual movement of XYZ
#define SHIFT_OUT 19 #define SHIFT_OUT_PIN 19
#define SHIFT_LD 18 #define SHIFT_LD_PIN 18
#define SHIFT_CLK 17 #define SHIFT_CLK_PIN 17
//#define UI1 31 //#define UI1 31
//#define UI2 22 //#define UI2 22

View File

@ -156,9 +156,9 @@
#define BTN_ENC 38 #define BTN_ENC 38
// Hardware buttons for manual movement of XYZ // Hardware buttons for manual movement of XYZ
#define SHIFT_OUT 42 #define SHIFT_OUT_PIN 42
#define SHIFT_LD 41 #define SHIFT_LD_PIN 41
#define SHIFT_CLK 40 #define SHIFT_CLK_PIN 40
//#define UI1 43 //#define UI1 43
//#define UI2 37 //#define UI2 37

View File

@ -146,10 +146,10 @@
#else // !IS_NEWPANEL #else // !IS_NEWPANEL
#define SHIFT_CLK 38 #define SHIFT_CLK_PIN 38
#define SHIFT_LD 42 #define SHIFT_LD_PIN 42
#define SHIFT_OUT 40 #define SHIFT_OUT_PIN 40
#define SHIFT_EN 17 #define SHIFT_EN_PIN 17
#define LCD_PINS_RS 16 #define LCD_PINS_RS 16
#define LCD_PINS_ENABLE 5 #define LCD_PINS_ENABLE 5

View File

@ -156,10 +156,10 @@
#else #else
// Buttons attached to a shift register // Buttons attached to a shift register
#define SHIFT_CLK 38 #define SHIFT_CLK_PIN 38
#define SHIFT_LD 42 #define SHIFT_LD_PIN 42
#define SHIFT_OUT 40 #define SHIFT_OUT_PIN 40
#define SHIFT_EN 17 #define SHIFT_EN_PIN 17
#define LCD_PINS_RS 16 #define LCD_PINS_RS 16
#define LCD_PINS_ENABLE 5 #define LCD_PINS_ENABLE 5

View File

@ -146,10 +146,10 @@
#define BTN_ENC 43 #define BTN_ENC 43
#else #else
// Buttons attached to shift register of reprapworld keypad v1.1 // Buttons attached to shift register of reprapworld keypad v1.1
#define SHIFT_CLK 63 #define SHIFT_CLK_PIN 63
#define SHIFT_LD 42 #define SHIFT_LD_PIN 42
#define SHIFT_OUT 17 #define SHIFT_OUT_PIN 17
#define SHIFT_EN 17 #define SHIFT_EN_PIN 17
#endif #endif
#endif // HAS_WIRED_LCD #endif // HAS_WIRED_LCD

View File

@ -162,10 +162,10 @@
#define LCD_PINS_D6 39 #define LCD_PINS_D6 39
#define LCD_PINS_D7 15 #define LCD_PINS_D7 15
#define SHIFT_CLK 43 #define SHIFT_CLK_PIN 43
#define SHIFT_LD 35 #define SHIFT_LD_PIN 35
#define SHIFT_OUT 34 #define SHIFT_OUT_PIN 34
#define SHIFT_EN 44 #define SHIFT_EN_PIN 44
#if MB(MEGATRONICS_31, MEGATRONICS_32) #if MB(MEGATRONICS_31, MEGATRONICS_32)
#define SD_DETECT_PIN 56 #define SD_DETECT_PIN 56

View File

@ -833,17 +833,17 @@
#if PIN_EXISTS(SERVO3) #if PIN_EXISTS(SERVO3)
REPORT_NAME_DIGITAL(__LINE__, SERVO3_PIN) REPORT_NAME_DIGITAL(__LINE__, SERVO3_PIN)
#endif #endif
#if defined(SHIFT_CLK) && SHIFT_CLK >= 0 #if PIN_EXISTS(SHIFT_CLK)
REPORT_NAME_DIGITAL(__LINE__, SHIFT_CLK) REPORT_NAME_DIGITAL(__LINE__, SHIFT_CLK_PIN)
#endif #endif
#if defined(SHIFT_EN) && SHIFT_EN >= 0 #if PIN_EXISTS(SHIFT_EN)
REPORT_NAME_DIGITAL(__LINE__, SHIFT_EN) REPORT_NAME_DIGITAL(__LINE__, SHIFT_EN_PIN)
#endif #endif
#if defined(SHIFT_LD) && SHIFT_LD >= 0 #if PIN_EXISTS(SHIFT_LD)
REPORT_NAME_DIGITAL(__LINE__, SHIFT_LD) REPORT_NAME_DIGITAL(__LINE__, SHIFT_LD_PIN)
#endif #endif
#if defined(SHIFT_OUT) && SHIFT_OUT >= 0 #if PIN_EXISTS(SHIFT_OUT)
REPORT_NAME_DIGITAL(__LINE__, SHIFT_OUT) REPORT_NAME_DIGITAL(__LINE__, SHIFT_OUT_PIN)
#endif #endif
#if PIN_EXISTS(SLED) #if PIN_EXISTS(SLED)
REPORT_NAME_DIGITAL(__LINE__, SLED_PIN) REPORT_NAME_DIGITAL(__LINE__, SLED_PIN)

View File

@ -239,10 +239,10 @@
// Buttons attached to a shift register // Buttons attached to a shift register
// Not wired yet // Not wired yet
//#define SHIFT_CLK 38 //#define SHIFT_CLK_PIN 38
//#define SHIFT_LD 42 //#define SHIFT_LD_PIN 42
//#define SHIFT_OUT 40 //#define SHIFT_OUT_PIN 40
//#define SHIFT_EN 17 //#define SHIFT_EN_PIN 17
#define LCD_PINS_RS 75 #define LCD_PINS_RS 75
#define LCD_PINS_ENABLE 17 #define LCD_PINS_ENABLE 17

View File

@ -504,10 +504,10 @@
#if !IS_NEWPANEL #if !IS_NEWPANEL
// Buttons attached to a shift register // Buttons attached to a shift register
// Not wired yet // Not wired yet
//#define SHIFT_CLK 38 //#define SHIFT_CLK_PIN 38
//#define SHIFT_LD 42 //#define SHIFT_LD_PIN 42
//#define SHIFT_OUT 40 //#define SHIFT_OUT_PIN 40
//#define SHIFT_EN 17 //#define SHIFT_EN_PIN 17
#endif #endif
#endif #endif
@ -722,9 +722,9 @@
#endif // HAS_WIRED_LCD #endif // HAS_WIRED_LCD
#if IS_RRW_KEYPAD && !HAS_ADC_BUTTONS #if IS_RRW_KEYPAD && !HAS_ADC_BUTTONS
#define SHIFT_OUT 40 #define SHIFT_OUT_PIN 40
#define SHIFT_CLK 44 #define SHIFT_CLK_PIN 44
#define SHIFT_LD 42 #define SHIFT_LD_PIN 42
#ifndef BTN_EN1 #ifndef BTN_EN1
#define BTN_EN1 64 #define BTN_EN1 64
#endif #endif

View File

@ -342,10 +342,10 @@
#if !IS_NEWPANEL #if !IS_NEWPANEL
// Buttons attached to a shift register // Buttons attached to a shift register
// Not wired yet // Not wired yet
//#define SHIFT_CLK 38 //#define SHIFT_CLK_PIN 38
//#define SHIFT_LD 42 //#define SHIFT_LD_PIN 42
//#define SHIFT_OUT 40 //#define SHIFT_OUT_PIN 40
//#define SHIFT_EN 17 //#define SHIFT_EN_PIN 17
#endif #endif
#endif #endif
@ -491,9 +491,9 @@
// Buttons are directly attached to AUX-2 // Buttons are directly attached to AUX-2
#if IS_RRW_KEYPAD #if IS_RRW_KEYPAD
#define SHIFT_OUT 40 #define SHIFT_OUT_PIN 40
#define SHIFT_CLK 44 #define SHIFT_CLK_PIN 44
#define SHIFT_LD 42 #define SHIFT_LD_PIN 42
#define BTN_EN1 64 #define BTN_EN1 64
#define BTN_EN2 59 #define BTN_EN2 59
#define BTN_ENC 63 #define BTN_ENC 63

View File

@ -142,10 +142,10 @@
#else // !IS_NEWPANEL - Old style panel with shift register #else // !IS_NEWPANEL - Old style panel with shift register
// Buttons attached to a shift register // Buttons attached to a shift register
#define SHIFT_CLK 38 #define SHIFT_CLK_PIN 38
#define SHIFT_LD 42 #define SHIFT_LD_PIN 42
#define SHIFT_OUT 40 #define SHIFT_OUT_PIN 40
#define SHIFT_EN 17 #define SHIFT_EN_PIN 17
#define LCD_PINS_RS 16 #define LCD_PINS_RS 16
#define LCD_PINS_ENABLE 5 #define LCD_PINS_ENABLE 5

View File

@ -197,10 +197,10 @@
#else // !IS_NEWPANEL - Old style panel with shift register #else // !IS_NEWPANEL - Old style panel with shift register
// Buttons attached to a shift register // Buttons attached to a shift register
#define SHIFT_CLK 38 #define SHIFT_CLK_PIN 38
#define SHIFT_LD 42 #define SHIFT_LD_PIN 42
#define SHIFT_OUT 40 #define SHIFT_OUT_PIN 40
#define SHIFT_EN 17 #define SHIFT_EN_PIN 17
#define LCD_PINS_RS 16 #define LCD_PINS_RS 16
#define LCD_PINS_ENABLE 5 #define LCD_PINS_ENABLE 5

View File

@ -69,9 +69,9 @@
#undef ADC_KEYPAD_PIN #undef ADC_KEYPAD_PIN
#undef BEEPER_PIN #undef BEEPER_PIN
#undef SHIFT_OUT #undef SHIFT_OUT_PIN
#undef SHIFT_CLK #undef SHIFT_CLK_PIN
#undef SHIFT_LD #undef SHIFT_LD_PIN
#undef BTN_EN1 #undef BTN_EN1
#undef BTN_EN2 #undef BTN_EN2
#undef BTN_ENC #undef BTN_ENC

View File

@ -363,10 +363,10 @@
#if !IS_NEWPANEL #if !IS_NEWPANEL
// Buttons attached to a shift register // Buttons attached to a shift register
// Not wired yet // Not wired yet
//#define SHIFT_CLK 38 //#define SHIFT_CLK_PIN 38
//#define SHIFT_LD 42 //#define SHIFT_LD_PIN 42
//#define SHIFT_OUT 40 //#define SHIFT_OUT_PIN 40
//#define SHIFT_EN 17 //#define SHIFT_EN_PIN 17
#endif #endif
#endif #endif
@ -567,9 +567,9 @@
// Buttons are directly attached to AUX-2 // Buttons are directly attached to AUX-2
#if IS_RRW_KEYPAD #if IS_RRW_KEYPAD
// TO TEST // TO TEST
//#define SHIFT_OUT 40 //#define SHIFT_OUT_PIN 40
//#define SHIFT_CLK 44 //#define SHIFT_CLK_PIN 44
//#define SHIFT_LD 42 //#define SHIFT_LD_PIN 42
//#define BTN_EN1 56 // Mega/Due:64 - AGCM4:56 //#define BTN_EN1 56 // Mega/Due:64 - AGCM4:56
//#define BTN_EN2 72 // Mega/Due:59 - AGCM4:72 //#define BTN_EN2 72 // Mega/Due:59 - AGCM4:72
//#define BTN_ENC 55 // Mega/Due:63 - AGCM4:55 //#define BTN_ENC 55 // Mega/Due:63 - AGCM4:55

View File

@ -146,10 +146,10 @@
#define BEEPER_PIN PC1 // 33 #define BEEPER_PIN PC1 // 33
// Buttons attached to a shift register // Buttons attached to a shift register
// Not wired yet // Not wired yet
//#define SHIFT_CLK PC6 // 38 //#define SHIFT_CLK_PIN PC6 // 38
//#define SHIFT_LD PC10 // 42 //#define SHIFT_LD_PIN PC10 // 42
//#define SHIFT_OUT PC8 // 40 //#define SHIFT_OUT_PIN PC8 // 40
//#define SHIFT_EN PA1 // 17 //#define SHIFT_EN_PIN PA1 // 17
#endif #endif
#endif #endif
@ -260,9 +260,9 @@
#define BTN_EN1 PE0 // 64 #define BTN_EN1 PE0 // 64
#define BTN_EN2 PD11 // 59 #define BTN_EN2 PD11 // 59
#define BTN_ENC PD15 // 63 #define BTN_ENC PD15 // 63
#define SHIFT_OUT PC8 // 40 #define SHIFT_OUT_PIN PC8 // 40
#define SHIFT_CLK PC12 // 44 #define SHIFT_CLK_PIN PC12 // 44
#define SHIFT_LD PC10 // 42 #define SHIFT_LD_PIN PC10 // 42
#elif ENABLED(PANEL_ONE) #elif ENABLED(PANEL_ONE)
#define BTN_EN1 PD11 // 59 // AUX2 PIN 3 #define BTN_EN1 PD11 // 59 // AUX2 PIN 3
#define BTN_EN2 PD15 // 63 // AUX2 PIN 4 #define BTN_EN2 PD15 // 63 // AUX2 PIN 4

View File

@ -146,7 +146,7 @@
#endif #endif
#if IS_RRW_KEYPAD #if IS_RRW_KEYPAD
#define SHIFT_OUT 40 #define SHIFT_OUT_PIN 40
#define SHIFT_CLK 44 #define SHIFT_CLK_PIN 44
#define SHIFT_LD 42 #define SHIFT_LD_PIN 42
#endif #endif