diff --git a/Marlin/src/gcode/lcd/M250.cpp b/Marlin/src/gcode/lcd/M250.cpp index 618e3d5d6c..900ffe909b 100644 --- a/Marlin/src/gcode/lcd/M250.cpp +++ b/Marlin/src/gcode/lcd/M250.cpp @@ -31,7 +31,7 @@ */ void GcodeSuite::M250() { if (parser.seenval('C')) - ui.set_contrast(parser.value_int()); + ui.set_contrast(parser.value_byte()); else M250_report(); } diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 023bf46426..1395be8a0a 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -500,6 +500,20 @@ #define HAS_DWIN_E3V2 1 #endif +// E3V2 extras +#if HAS_DWIN_E3V2 || IS_DWIN_MARLINUI + #define SERIAL_CATCHALL 0 + #ifndef LCD_SERIAL_PORT + #if MB(BTT_SKR_MINI_E3_V1_0, BTT_SKR_MINI_E3_V1_2, BTT_SKR_MINI_E3_V2_0, BTT_SKR_E3_TURBO) + #define LCD_SERIAL_PORT 1 + #else + #define LCD_SERIAL_PORT 3 // Creality 4.x board + #endif + #endif + #define HAS_LCD_BRIGHTNESS 1 + #define LCD_BRIGHTNESS_MAX 250 +#endif + #if IS_ULTRA_LCD #define HAS_WIRED_LCD 1 #if ENABLED(DOGLCD) @@ -1111,17 +1125,6 @@ #define HAS_ETHERNET 1 #endif -#if EITHER(HAS_DWIN_E3V2, IS_DWIN_MARLINUI) - #define SERIAL_CATCHALL 0 - #ifndef LCD_SERIAL_PORT - #if MB(BTT_SKR_MINI_E3_V1_0, BTT_SKR_MINI_E3_V1_2, BTT_SKR_MINI_E3_V2_0, BTT_SKR_E3_TURBO) - #define LCD_SERIAL_PORT 1 - #else - #define LCD_SERIAL_PORT 3 // Creality 4.x board - #endif - #endif -#endif - // Fallback Stepper Driver types that don't depend on Configuration_adv.h #ifndef X_DRIVER_TYPE #define X_DRIVER_TYPE A4988 diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 5c1aa5321f..533122d98d 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -421,11 +421,6 @@ #endif #endif -#if EITHER(HAS_DWIN_E3V2, IS_DWIN_MARLINUI) - #define HAS_LCD_BRIGHTNESS 1 - #define MAX_LCD_BRIGHTNESS 31 -#endif - /** * Override the SD_DETECT_STATE set in Configuration_adv.h * and enable sharing of onboard SD host drives (all platforms but AGCM4) diff --git a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp index 712e76e86f..9617b3775d 100644 --- a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp @@ -376,12 +376,9 @@ void MarlinUI::clear_lcd() { lcd.clear_buffer(); } -int16_t MarlinUI::contrast; // Initialized by settings.load() - -void MarlinUI::set_contrast(const int16_t value) { - contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX); - lcd.setContrast(contrast); -} +#if HAS_LCD_CONTRAST + void MarlinUI::_set_contrast() { lcd.setContrast(contrast); } +#endif static void center_text_P(PGM_P pstart, uint8_t y) { uint8_t len = utf8_strlen_P(pstart); diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index 33bb3e4b92..98173da8f3 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -93,14 +93,7 @@ U8G_CLASS u8g; #endif #if HAS_LCD_CONTRAST - - int16_t MarlinUI::contrast = DEFAULT_LCD_CONTRAST; - - void MarlinUI::set_contrast(const int16_t value) { - contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX); - u8g.setContrast(contrast); - } - + void MarlinUI::_set_contrast() { u8g.setContrast(contrast); } #endif void MarlinUI::set_font(const MarlinFont font_nr) { diff --git a/Marlin/src/lcd/e3v2/common/dwin_api.cpp b/Marlin/src/lcd/e3v2/common/dwin_api.cpp index 480b98d3fd..d89b22a7aa 100644 --- a/Marlin/src/lcd/e3v2/common/dwin_api.cpp +++ b/Marlin/src/lcd/e3v2/common/dwin_api.cpp @@ -78,14 +78,16 @@ bool DWIN_Handshake() { && databuf[3] == 'K' ); } -// Set the backlight brightness -// brightness: (0x00-0x1F) -void DWIN_LCD_Brightness(const uint8_t brightness) { - size_t i = 0; - DWIN_Byte(i, 0x30); - DWIN_Byte(i, _MAX(brightness, 0x1F)); - DWIN_Send(i); -} +#if HAS_LCD_BRIGHTNESS + // Set LCD backlight (from DWIN Enhanced) + // brightness: 0x00-0xFF + void DWIN_LCD_Brightness(const uint8_t brightness) { + size_t i = 0; + DWIN_Byte(i, 0x30); + DWIN_Byte(i, brightness); + DWIN_Send(i); + } +#endif // Set screen display direction // dir: 0=0°, 1=90°, 2=180°, 3=270° diff --git a/Marlin/src/lcd/e3v2/common/dwin_api.h b/Marlin/src/lcd/e3v2/common/dwin_api.h index dd9560a60f..6fc90f040b 100644 --- a/Marlin/src/lcd/e3v2/common/dwin_api.h +++ b/Marlin/src/lcd/e3v2/common/dwin_api.h @@ -90,9 +90,11 @@ bool DWIN_Handshake(); // DWIN startup void DWIN_Startup(); -// Set the backlight brightness -// brightness: (0x00-0xFF) -void DWIN_LCD_Brightness(const uint8_t brightness); +#if HAS_LCD_BRIGHTNESS + // Set the backlight brightness + // brightness: (0x00-0xFF) + void DWIN_LCD_Brightness(const uint8_t brightness); +#endif // Set screen display direction // dir: 0=0°, 1=90°, 2=180°, 3=270° diff --git a/Marlin/src/lcd/e3v2/creality/dwin.cpp b/Marlin/src/lcd/e3v2/creality/dwin.cpp index 05aa9f0ec3..6a2d4cd5fe 100644 --- a/Marlin/src/lcd/e3v2/creality/dwin.cpp +++ b/Marlin/src/lcd/e3v2/creality/dwin.cpp @@ -1816,6 +1816,10 @@ void HMI_SDCardInit() { card.cdroot(); } void MarlinUI::refresh() { /* Nothing to see here */ } +#if HAS_LCD_BRIGHTNESS + void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); } +#endif + #if ENABLED(SCROLL_LONG_FILENAMES) char shift_name[LONG_FILENAME_LENGTH + 1]; diff --git a/Marlin/src/lcd/e3v2/enhanced/dwin.cpp b/Marlin/src/lcd/e3v2/enhanced/dwin.cpp index 80348e4418..c673e4f144 100644 --- a/Marlin/src/lcd/e3v2/enhanced/dwin.cpp +++ b/Marlin/src/lcd/e3v2/enhanced/dwin.cpp @@ -865,6 +865,10 @@ void HMI_SDCardInit() { card.cdroot(); } void MarlinUI::refresh() { /* Nothing to see here */ } +#if HAS_LCD_BRIGHTNESS + void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); } +#endif + #define ICON_Folder ICON_More #if ENABLED(SCROLL_LONG_FILENAMES) @@ -2186,9 +2190,8 @@ void SetPID(celsius_t t, heater_id_t h) { #endif #if HAS_LCD_BRIGHTNESS - void ApplyBrightness() { ui.set_brightness(HMI_value.Value); } - void LiveBrightness() { DWIN_LCD_Brightness(HMI_value.Value); } - void SetBrightness() { SetIntOnClick(MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS, ui.brightness, ApplyBrightness, LiveBrightness); } + void LiveBrightness() { ui.set_brightness(HMI_value.Value); } + void SetBrightness() { SetIntOnClick(LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, ui.brightness, nullptr, LiveBrightness); } #endif #if ENABLED(SOUND_MENU_ITEM) diff --git a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp index 55aee49f82..eccbe8d141 100644 --- a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp @@ -2717,7 +2717,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Float(ui.brightness, row, false, 1); } else - Modify_Value(ui.brightness, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS, 1, ui.refresh_brightness); + Modify_Value(ui.brightness, LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, 1, ui.refresh_brightness); break; case VISUAL_TIME_FORMAT: if (draw) { @@ -3879,7 +3879,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Float(ui.brightness, row, false, 1); } else - Modify_Value(ui.brightness, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS, 1, ui.refresh_brightness); + Modify_Value(ui.brightness, LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, 1, ui.refresh_brightness); break; } break; @@ -4800,6 +4800,10 @@ void CrealityDWINClass::Update() { void MarlinUI::update() { CrealityDWIN.Update(); } +#if HAS_LCD_BRIGHTNESS + void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); } +#endif + void CrealityDWINClass::State_Update() { if ((print_job_timer.isRunning() || print_job_timer.isPaused()) != printing) { if (!printing) Start_Print(card.isFileOpen() || TERN0(POWER_LOSS_RECOVERY, recovery.valid())); diff --git a/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp b/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp index 45c1fa3122..09458401be 100644 --- a/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp +++ b/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp @@ -254,6 +254,10 @@ void MarlinUI::draw_status_message(const bool blink) { #endif } +#if HAS_LCD_BRIGHTNESS + void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); } +#endif + #if HAS_LCD_MENU #include "../../menu/menu.h" diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 0fb6902e80..1a4863a3b1 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -95,16 +95,23 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP; } #endif +#if HAS_LCD_CONTRAST + uint8_t MarlinUI::contrast; // Initialized by settings.load() + + void MarlinUI::set_contrast(const uint8_t value) { + contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX); + _set_contrast(); + } +#endif + #if HAS_LCD_BRIGHTNESS uint8_t MarlinUI::brightness = DEFAULT_LCD_BRIGHTNESS; bool MarlinUI::backlight = true; void MarlinUI::set_brightness(const uint8_t value) { backlight = !!value; - if (backlight) brightness = constrain(value, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS); - // Set brightness on enabled LCD here - TERN_(DWIN_CREALITY_LCD_ENHANCED, DWIN_LCD_Brightness(brightness)); - TERN_(DWIN_CREALITY_LCD_JYERSUI, DWIN_LCD_Brightness(backlight ? brightness : 0)); + if (backlight) brightness = constrain(value, LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX); + _set_brightness(); } #endif diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index 49ecd89957..270ee3afce 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -247,17 +247,18 @@ public: #endif #if HAS_LCD_BRIGHTNESS - #ifndef MIN_LCD_BRIGHTNESS - #define MIN_LCD_BRIGHTNESS 1 + #ifndef LCD_BRIGHTNESS_MIN + #define LCD_BRIGHTNESS_MIN 1 #endif - #ifndef MAX_LCD_BRIGHTNESS - #define MAX_LCD_BRIGHTNESS 255 + #ifndef LCD_BRIGHTNESS_MAX + #define LCD_BRIGHTNESS_MAX 255 #endif #ifndef DEFAULT_LCD_BRIGHTNESS - #define DEFAULT_LCD_BRIGHTNESS MAX_LCD_BRIGHTNESS + #define DEFAULT_LCD_BRIGHTNESS LCD_BRIGHTNESS_MAX #endif static uint8_t brightness; static bool backlight; + static void _set_brightness(); // Implementation-specific static void set_brightness(const uint8_t value); FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); } #endif @@ -425,8 +426,9 @@ public: static uint8_t lcd_status_update_delay; #if HAS_LCD_CONTRAST - static int16_t contrast; - static void set_contrast(const int16_t value); + static uint8_t contrast; + static void _set_contrast(); // Implementation-specific + static void set_contrast(const uint8_t value); FORCE_INLINE static void refresh_contrast() { set_contrast(contrast); } #endif diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index 44c99dd0a9..c9227724ab 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -528,8 +528,11 @@ void menu_configuration() { #endif #endif + #if HAS_LCD_BRIGHTNESS + EDIT_ITEM_FAST(uint8, MSG_BRIGHTNESS, &ui.brightness, LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, ui.refresh_brightness, true); + #endif #if HAS_LCD_CONTRAST - EDIT_ITEM(int3, MSG_CONTRAST, &ui.contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, ui.refresh_contrast, true); + EDIT_ITEM_FAST(uint8, MSG_CONTRAST, &ui.contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, ui.refresh_contrast, true); #endif #if ENABLED(FWRETRACT) SUBMENU(MSG_RETRACT, menu_config_retract); diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index 8e4c758854..0a7a194a3b 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -345,7 +345,7 @@ typedef struct SettingsDataStruct { // // HAS_LCD_CONTRAST // - int16_t lcd_contrast; // M250 C + uint8_t lcd_contrast; // M250 C // // HAS_LCD_BRIGHTNESS @@ -1006,7 +1006,7 @@ void MarlinSettings::postprocess() { // { _FIELD_TEST(lcd_contrast); - const int16_t lcd_contrast = TERN(HAS_LCD_CONTRAST, ui.contrast, 127); + const uint8_t lcd_contrast = TERN(HAS_LCD_CONTRAST, ui.contrast, 127); EEPROM_WRITE(lcd_contrast); } @@ -1869,7 +1869,7 @@ void MarlinSettings::postprocess() { // { _FIELD_TEST(lcd_contrast); - int16_t lcd_contrast; + uint8_t lcd_contrast; EEPROM_READ(lcd_contrast); if (!validating) { TERN_(HAS_LCD_CONTRAST, ui.set_contrast(lcd_contrast)); diff --git a/buildroot/tests/STM32F103RET6_creality b/buildroot/tests/STM32F103RET6_creality index 8ce4f57cf8..d530f7b851 100755 --- a/buildroot/tests/STM32F103RET6_creality +++ b/buildroot/tests/STM32F103RET6_creality @@ -24,7 +24,7 @@ opt_enable DWIN_CREALITY_LCD_JYERSUI AUTO_BED_LEVELING_BILINEAR PROBE_MANUALLY exec_test $1 $2 "Ender 3 v2 with JyersUI" "$3" use_example_configs "Creality/Ender-3 V2/MarlinUI" -opt_add SDCARD_EEPROM_EMULATION NOZZLE_AS_PROBE AUTO_BED_LEVELING_BILINEAR Z_SAFE_HOMING +opt_add SDCARD_EEPROM_EMULATION AUTO_BED_LEVELING_BILINEAR Z_SAFE_HOMING exec_test $1 $2 "Ender 3 v2 with MarlinUI" "$3" restore_configs