Rotary encoder cleanup (#20753)
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
|
||||
#include "../module/motion.h"
|
||||
|
||||
#include "buttons.h"
|
||||
|
||||
#if HAS_BUZZER
|
||||
#include "../libs/buzzer.h"
|
||||
#endif
|
||||
@@ -40,20 +42,6 @@
|
||||
#if EITHER(HAS_LCD_MENU, ULTIPANEL_FEEDMULTIPLY)
|
||||
#define HAS_ENCODER_ACTION 1
|
||||
#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
|
||||
#define MULTI_MANUAL 1
|
||||
@@ -114,130 +102,6 @@
|
||||
|
||||
#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
|
||||
enum MarlinFont : uint8_t {
|
||||
FONT_STATUSMENU = 1,
|
||||
@@ -556,6 +420,8 @@ public:
|
||||
#if HAS_TOUCH_BUTTONS
|
||||
static uint8_t touch_buttons;
|
||||
static uint8_t repeat_delay;
|
||||
#else
|
||||
static constexpr uint8_t touch_buttons = 0;
|
||||
#endif
|
||||
|
||||
#if ENABLED(ENCODER_RATE_MULTIPLIER)
|
||||
|
||||
Reference in New Issue
Block a user