Skip to content

Commit d5f2334

Browse files
committed
♻️ Adjust LCD init, contrast default, settings load
1 parent 37ee9a4 commit d5f2334

19 files changed

+137
-154
lines changed

Marlin/src/HAL/LPC1768/inc/SanityCheck.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
113113
#define _IS_RX1_1 IS_RX1
114114
#if IS_TX1(TMC_SW_SCK)
115115
#error "Serial port pins (1) conflict with other pins!"
116-
#elif HAS_WIRED_LCD
116+
#elif HAS_ROTARY_ENCODER
117117
#if IS_TX1(BTN_EN2) || IS_RX1(BTN_EN1)
118118
#error "Serial port pins (1) conflict with Encoder Buttons!"
119119
#elif ANY_TX(1, SD_SCK_PIN, LCD_PINS_D4, DOGLCD_SCK, LCD_RESET_PIN, LCD_PINS_RS, SHIFT_CLK_PIN) \

Marlin/src/MarlinCore.cpp

+10-14
Original file line numberDiff line numberDiff line change
@@ -1294,16 +1294,7 @@ void setup() {
12941294
// UI must be initialized before EEPROM
12951295
// (because EEPROM code calls the UI).
12961296

1297-
#if HAS_DWIN_E3V2_BASIC
1298-
SETUP_RUN(DWIN_Startup());
1299-
#else
1300-
SETUP_RUN(ui.init());
1301-
#if BOTH(HAS_WIRED_LCD, SHOW_BOOTSCREEN)
1302-
SETUP_RUN(ui.show_bootscreen());
1303-
const millis_t bootscreen_ms = millis();
1304-
#endif
1305-
SETUP_RUN(ui.reset_status()); // Load welcome message early. (Retained if no errors exist.)
1306-
#endif
1297+
SETUP_RUN(ui.init());
13071298

13081299
#if PIN_EXISTS(SAFE_POWER)
13091300
#if HAS_DRIVER_SAFE_POWER_PROTECT
@@ -1314,17 +1305,22 @@ void setup() {
13141305
#endif
13151306
#endif
13161307

1317-
#if ENABLED(PROBE_TARE)
1318-
SETUP_RUN(probe.tare_init());
1319-
#endif
1320-
13211308
#if BOTH(SDSUPPORT, SDCARD_EEPROM_EMULATION)
13221309
SETUP_RUN(card.mount()); // Mount media with settings before first_load
13231310
#endif
13241311

13251312
SETUP_RUN(settings.first_load()); // Load data from EEPROM if available (or use defaults)
13261313
// This also updates variables in the planner, elsewhere
13271314

1315+
#if BOTH(HAS_WIRED_LCD, SHOW_BOOTSCREEN)
1316+
SETUP_RUN(ui.show_bootscreen());
1317+
const millis_t bootscreen_ms = millis();
1318+
#endif
1319+
1320+
#if ENABLED(PROBE_TARE)
1321+
SETUP_RUN(probe.tare_init());
1322+
#endif
1323+
13281324
#if HAS_ETHERNET
13291325
SETUP_RUN(ethernet.init());
13301326
#endif

Marlin/src/gcode/lcd/M250.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* M250: Read and optionally set the LCD contrast
3232
*/
3333
void GcodeSuite::M250() {
34-
if (parser.seenval('C'))
34+
if (LCD_CONTRAST_MIN < LCD_CONTRAST_MAX && parser.seenval('C'))
3535
ui.set_contrast(parser.value_byte());
3636
else
3737
M250_report();

Marlin/src/inc/Conditionals_LCD.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@
237237
#define LCD_HEIGHT 10 // Character lines
238238
#define LCD_CONTRAST_MIN 127
239239
#define LCD_CONTRAST_MAX 255
240-
#define DEFAULT_LCD_CONTRAST 250
240+
#define LCD_CONTRAST_DEFAULT 250
241241
#define CONVERT_TO_EXT_ASCII // Use extended 128-255 symbols from ASCII table.
242242
// At this time present conversion only for cyrillic - bg, ru and uk languages.
243243
// First 7 ASCII symbols in panel font must be replaced with Marlin's special symbols.

Marlin/src/inc/Conditionals_post.h

+2-9
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@
376376
#elif EITHER(MKS_MINI_12864_V3, BTT_MINI_12864_V1)
377377
#define _LCD_CONTRAST_MIN 255
378378
#define _LCD_CONTRAST_INIT 255
379-
#define _LCD_CONTRAST_MAX 255
380379
#elif ENABLED(FYSETC_MINI_12864)
381380
#define _LCD_CONTRAST_INIT 220
382381
#elif ENABLED(ULTI_CONTROLLER)
@@ -389,18 +388,12 @@
389388
#elif ENABLED(ZONESTAR_12864OLED)
390389
#define _LCD_CONTRAST_MIN 64
391390
#define _LCD_CONTRAST_INIT 128
392-
#define _LCD_CONTRAST_MAX 255
393391
#elif IS_TFTGLCD_PANEL
394-
#define _LCD_CONTRAST_MIN 0
395392
#define _LCD_CONTRAST_INIT 250
396-
#define _LCD_CONTRAST_MAX 255
397393
#endif
398394

399395
#ifdef _LCD_CONTRAST_INIT
400396
#define HAS_LCD_CONTRAST 1
401-
#endif
402-
403-
#if HAS_LCD_CONTRAST
404397
#ifndef LCD_CONTRAST_MIN
405398
#ifdef _LCD_CONTRAST_MIN
406399
#define LCD_CONTRAST_MIN _LCD_CONTRAST_MIN
@@ -420,8 +413,8 @@
420413
#define LCD_CONTRAST_MAX 63 // ST7567 6-bits contrast
421414
#endif
422415
#endif
423-
#ifndef DEFAULT_LCD_CONTRAST
424-
#define DEFAULT_LCD_CONTRAST LCD_CONTRAST_INIT
416+
#ifndef LCD_CONTRAST_DEFAULT
417+
#define LCD_CONTRAST_DEFAULT LCD_CONTRAST_INIT
425418
#endif
426419
#endif
427420

Marlin/src/inc/Warnings.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,7 @@
559559
#if CANNOT_EMBED_CONFIGURATION
560560
#warning "Disabled CONFIGURATION_EMBEDDING because the target usually has less flash storage. Define FORCE_CONFIG_EMBED to override."
561561
#endif
562+
563+
#if HAS_LCD_CONTRAST && LCD_CONTRAST_MIN >= LCD_CONTRAST_MAX
564+
#warning "Contrast cannot be changed when LCD_CONTRAST_MIN >= LCD_CONTRAST_MAX."
565+
#endif

Marlin/src/lcd/e3v2/creality/dwin.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,9 @@ void make_name_without_ext(char *dst, char *src, size_t maxlen=MENU_CHAR_LIMIT)
18341834

18351835
void HMI_SDCardInit() { card.cdroot(); }
18361836

1837+
// Initialize or re-initialize the LCD
1838+
void MarlinUI::init_lcd() { DWIN_Startup(); }
1839+
18371840
void MarlinUI::refresh() { /* Nothing to see here */ }
18381841

18391842
#if HAS_LCD_BRIGHTNESS

Marlin/src/lcd/e3v2/enhanced/dwin.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,9 @@ void make_name_without_ext(char *dst, char *src, size_t maxlen=MENU_CHAR_LIMIT)
888888

889889
void HMI_SDCardInit() { card.cdroot(); }
890890

891+
// Initialize or re-initialize the LCD
892+
void MarlinUI::init_lcd() { DWIN_Startup(); }
893+
891894
void MarlinUI::refresh() { /* Nothing to see here */ }
892895

893896
#if HAS_LCD_BRIGHTNESS

Marlin/src/lcd/e3v2/jyersui/dwin.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4980,7 +4980,7 @@ void CrealityDWINClass::Reset_Settings() {
49804980
Redraw_Screen();
49814981
}
49824982

4983-
void MarlinUI::init() {
4983+
void MarlinUI::init_lcd() {
49844984
delay(800);
49854985
SERIAL_ECHOPGM("\nDWIN handshake ");
49864986
if (DWIN_Handshake()) SERIAL_ECHOLNPGM("ok."); else SERIAL_ECHOLNPGM("error.");

Marlin/src/lcd/e3v2/marlinui/ui_common.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ void MarlinUI::set_font(const uint8_t font_nr) {
7979
bool MarlinUI::detected() { return true; }
8080

8181
// Initialize or re-initialize the LCD
82-
void MarlinUI::init_lcd() {
83-
DWIN_Startup();
84-
}
82+
void MarlinUI::init_lcd() { DWIN_Startup(); }
8583

8684
// This LCD should clear where it will draw anew
8785
void MarlinUI::clear_lcd() {

Marlin/src/lcd/extui/ui_api.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ namespace ExtUI {
11441144

11451145
// At the moment we hook into MarlinUI methods, but this could be cleaned up in the future
11461146

1147-
void MarlinUI::init() { ExtUI::onStartup(); }
1147+
void MarlinUI::init_lcd() { ExtUI::onStartup(); }
11481148

11491149
void MarlinUI::update() { ExtUI::onIdle(); }
11501150

Marlin/src/lcd/marlinui.cpp

+72-77
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ MarlinUI ui;
4343
#if HAS_DISPLAY
4444
#include "../gcode/queue.h"
4545
#include "fontutils.h"
46-
#include "../sd/cardreader.h"
4746
#endif
4847

4948
#if ENABLED(DWIN_CREALITY_LCD)
@@ -176,6 +175,77 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
176175

177176
#endif
178177

178+
// Encoder Handling
179+
#if HAS_ENCODER_ACTION
180+
uint32_t MarlinUI::encoderPosition;
181+
volatile int8_t encoderDiff; // Updated in update_buttons, added to encoderPosition every LCD update
182+
#endif
183+
184+
void MarlinUI::init() {
185+
186+
init_lcd();
187+
188+
#if HAS_DIGITAL_BUTTONS
189+
#if BUTTON_EXISTS(EN1)
190+
SET_INPUT_PULLUP(BTN_EN1);
191+
#endif
192+
#if BUTTON_EXISTS(EN2)
193+
SET_INPUT_PULLUP(BTN_EN2);
194+
#endif
195+
#if BUTTON_EXISTS(ENC)
196+
SET_INPUT_PULLUP(BTN_ENC);
197+
#endif
198+
#if BUTTON_EXISTS(ENC_EN)
199+
SET_INPUT_PULLUP(BTN_ENC_EN);
200+
#endif
201+
#if BUTTON_EXISTS(BACK)
202+
SET_INPUT_PULLUP(BTN_BACK);
203+
#endif
204+
#if BUTTON_EXISTS(UP)
205+
SET_INPUT(BTN_UP);
206+
#endif
207+
#if BUTTON_EXISTS(DWN)
208+
SET_INPUT(BTN_DWN);
209+
#endif
210+
#if BUTTON_EXISTS(LFT)
211+
SET_INPUT(BTN_LFT);
212+
#endif
213+
#if BUTTON_EXISTS(RT)
214+
SET_INPUT(BTN_RT);
215+
#endif
216+
#endif
217+
218+
#if HAS_SHIFT_ENCODER
219+
220+
#if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
221+
222+
SET_OUTPUT(SR_DATA_PIN);
223+
SET_OUTPUT(SR_CLK_PIN);
224+
225+
#elif PIN_EXISTS(SHIFT_CLK)
226+
227+
SET_OUTPUT(SHIFT_CLK_PIN);
228+
OUT_WRITE(SHIFT_LD_PIN, HIGH);
229+
#if PIN_EXISTS(SHIFT_EN)
230+
OUT_WRITE(SHIFT_EN_PIN, LOW);
231+
#endif
232+
SET_INPUT_PULLUP(SHIFT_OUT_PIN);
233+
234+
#endif
235+
236+
#endif // HAS_SHIFT_ENCODER
237+
238+
#if BOTH(HAS_ENCODER_ACTION, HAS_SLOW_BUTTONS)
239+
slow_buttons = 0;
240+
#endif
241+
242+
update_buttons();
243+
244+
TERN_(HAS_ENCODER_ACTION, encoderDiff = 0);
245+
246+
reset_status(); // Set welcome message
247+
}
248+
179249
#if HAS_WIRED_LCD
180250

181251
#if HAS_MARLINUI_U8GLIB
@@ -184,8 +254,6 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
184254

185255
#include "lcdprint.h"
186256

187-
#include "../sd/cardreader.h"
188-
189257
#include "../module/temperature.h"
190258
#include "../module/planner.h"
191259
#include "../module/motion.h"
@@ -247,16 +315,8 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
247315
bool MarlinUI::old_is_printing;
248316
#endif
249317

250-
// Encoder Handling
251-
#if HAS_ENCODER_ACTION
252-
uint32_t MarlinUI::encoderPosition;
253-
volatile int8_t encoderDiff; // Updated in update_buttons, added to encoderPosition every LCD update
254-
#endif
255-
256318
#if ENABLED(SDSUPPORT)
257319

258-
#include "../sd/cardreader.h"
259-
260320
#if MARLINUI_SCROLL_NAME
261321
uint8_t MarlinUI::filename_scroll_pos, MarlinUI::filename_scroll_max;
262322
#endif
@@ -393,69 +453,6 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
393453

394454
#endif // HAS_LCD_MENU
395455

396-
void MarlinUI::init() {
397-
398-
init_lcd();
399-
400-
#if HAS_DIGITAL_BUTTONS
401-
#if BUTTON_EXISTS(EN1)
402-
SET_INPUT_PULLUP(BTN_EN1);
403-
#endif
404-
#if BUTTON_EXISTS(EN2)
405-
SET_INPUT_PULLUP(BTN_EN2);
406-
#endif
407-
#if BUTTON_EXISTS(ENC)
408-
SET_INPUT_PULLUP(BTN_ENC);
409-
#endif
410-
#if BUTTON_EXISTS(ENC_EN)
411-
SET_INPUT_PULLUP(BTN_ENC_EN);
412-
#endif
413-
#if BUTTON_EXISTS(BACK)
414-
SET_INPUT_PULLUP(BTN_BACK);
415-
#endif
416-
#if BUTTON_EXISTS(UP)
417-
SET_INPUT(BTN_UP);
418-
#endif
419-
#if BUTTON_EXISTS(DWN)
420-
SET_INPUT(BTN_DWN);
421-
#endif
422-
#if BUTTON_EXISTS(LFT)
423-
SET_INPUT(BTN_LFT);
424-
#endif
425-
#if BUTTON_EXISTS(RT)
426-
SET_INPUT(BTN_RT);
427-
#endif
428-
#endif
429-
430-
#if HAS_SHIFT_ENCODER
431-
432-
#if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
433-
434-
SET_OUTPUT(SR_DATA_PIN);
435-
SET_OUTPUT(SR_CLK_PIN);
436-
437-
#elif PIN_EXISTS(SHIFT_CLK)
438-
439-
SET_OUTPUT(SHIFT_CLK_PIN);
440-
OUT_WRITE(SHIFT_LD_PIN, HIGH);
441-
#if PIN_EXISTS(SHIFT_EN)
442-
OUT_WRITE(SHIFT_EN_PIN, LOW);
443-
#endif
444-
SET_INPUT_PULLUP(SHIFT_OUT_PIN);
445-
446-
#endif
447-
448-
#endif // HAS_SHIFT_ENCODER
449-
450-
#if BOTH(HAS_ENCODER_ACTION, HAS_SLOW_BUTTONS)
451-
slow_buttons = 0;
452-
#endif
453-
454-
update_buttons();
455-
456-
TERN_(HAS_ENCODER_ACTION, encoderDiff = 0);
457-
}
458-
459456
////////////////////////////////////////////
460457
///////////// Keypad Handling //////////////
461458
////////////////////////////////////////////
@@ -629,9 +626,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
629626
next_filament_display = millis() + 5000UL; // Show status message for 5s
630627
#endif
631628
goto_screen(menu_main);
632-
#if DISABLED(NO_LCD_REINIT)
633-
init_lcd(); // May revive the LCD if static electricity killed it
634-
#endif
629+
IF_DISABLED(NO_LCD_REINIT, init_lcd()); // May revive the LCD if static electricity killed it
635630
return;
636631
}
637632

0 commit comments

Comments
 (0)