Skip to content

Commit

Permalink
fixes MarlinFirmware#21089 "BUTTON_CLICK" redefined warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ellensp committed Feb 16, 2021
1 parent fd24779 commit c8a16c6
Showing 1 changed file with 30 additions and 40 deletions.
70 changes: 30 additions & 40 deletions Marlin/src/lcd/buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,37 @@
#define ENCODER_PHASE_3 1
#endif

#if EITHER(HAS_DIGITAL_BUTTONS, DWIN_CREALITY_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

#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
Expand All @@ -62,9 +91,7 @@
#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'
Expand All @@ -84,21 +111,15 @@
// 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

Expand All @@ -122,37 +143,6 @@
#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
Expand Down

0 comments on commit c8a16c6

Please sign in to comment.