From f73175d8263033d1feb1045af67e7230c844aab0 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 27 Sep 2021 21:01:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20TFT=20backlight=20PWM=20/=20brig?= =?UTF-8?q?htness=20(#22841)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/lcd/dogm/marlinui_DOGM.cpp | 9 +++++++++ Marlin/src/lcd/language/language_fr.h | 1 + Marlin/src/lcd/tft/touch.cpp | 4 +++- Marlin/src/lcd/tft/ui_common.cpp | 9 +++++++++ Marlin/src/lcd/tft_io/tft_io.cpp | 10 +++++++++- Marlin/src/lcd/touch/touch_buttons.cpp | 4 +++- Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h | 6 ++++++ 7 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index 98173da8f3..f1c5eebbb5 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -338,6 +338,15 @@ void MarlinUI::draw_kill_screen() { void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop +#if HAS_LCD_BRIGHTNESS + void MarlinUI::_set_brightness() { + #if PIN_EXISTS(TFT_BACKLIGHT) + if (PWM_PIN(TFT_BACKLIGHT_PIN)) + analogWrite(pin_t(TFT_BACKLIGHT_PIN), brightness); + #endif + } +#endif + #if HAS_LCD_MENU #include "../menu/menu.h" diff --git a/Marlin/src/lcd/language/language_fr.h b/Marlin/src/lcd/language/language_fr.h index be8daaa3dc..a99659bf18 100644 --- a/Marlin/src/lcd/language/language_fr.h +++ b/Marlin/src/lcd/language/language_fr.h @@ -336,6 +336,7 @@ namespace Language_fr { LSTR MSG_FILAMENT_LOAD = _UxGT("Charger mm"); LSTR MSG_ADVANCE_K = _UxGT("Avance K"); LSTR MSG_ADVANCE_K_E = _UxGT("Avance K *"); + LSTR MSG_BRIGHTNESS = _UxGT("Luminosité LCD"); LSTR MSG_CONTRAST = _UxGT("Contraste LCD"); LSTR MSG_STORE_EEPROM = _UxGT("Enregistrer config."); LSTR MSG_LOAD_EEPROM = _UxGT("Charger config."); diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index 7262536e77..dc1f2ecb6c 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -294,7 +294,9 @@ bool Touch::get_point(int16_t *x, int16_t *y) { } void Touch::wakeUp() { if (isSleeping()) { - #if PIN_EXISTS(TFT_BACKLIGHT) + #if HAS_LCD_BRIGHTNESS + ui._set_brightness(); + #elif PIN_EXISTS(TFT_BACKLIGHT) WRITE(TFT_BACKLIGHT_PIN, HIGH); #endif } diff --git a/Marlin/src/lcd/tft/ui_common.cpp b/Marlin/src/lcd/tft/ui_common.cpp index a5f41874b0..41862b5ad8 100644 --- a/Marlin/src/lcd/tft/ui_common.cpp +++ b/Marlin/src/lcd/tft/ui_common.cpp @@ -210,6 +210,15 @@ void MarlinUI::clear_lcd() { cursor.set(0, 0); } +#if HAS_LCD_BRIGHTNESS + void MarlinUI::_set_brightness() { + #if PIN_EXISTS(TFT_BACKLIGHT) + if (PWM_PIN(TFT_BACKLIGHT_PIN)) + analogWrite(pin_t(TFT_BACKLIGHT_PIN), brightness); + #endif + } +#endif + #if ENABLED(TOUCH_SCREEN_CALIBRATION) void MarlinUI::touch_calibration_screen() { diff --git a/Marlin/src/lcd/tft_io/tft_io.cpp b/Marlin/src/lcd/tft_io/tft_io.cpp index 707232b4bb..6ec3bedcdf 100644 --- a/Marlin/src/lcd/tft_io/tft_io.cpp +++ b/Marlin/src/lcd/tft_io/tft_io.cpp @@ -49,6 +49,10 @@ #include "ili9341.h" #include "ili9328.h" +#if HAS_LCD_BRIGHTNESS + #include "../marlinui.h" +#endif + #define DEBUG_OUT ENABLED(DEBUG_GRAPHICAL_TFT) #include "../../core/debug_out.h" @@ -72,6 +76,9 @@ if (lcd_id != 0xFFFFFFFF) return; #if PIN_EXISTS(TFT_BACKLIGHT) WRITE(TFT_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT)); + #if HAS_LCD_BRIGHTNESS && DISABLED(DELAYED_BACKLIGHT_INIT) + ui._set_brightness(); + #endif #endif // io.Init(); @@ -141,11 +148,12 @@ if (lcd_id != 0xFFFFFFFF) return; lcd_id = 0; } #else - #error Unsupported TFT driver + #error "Unsupported TFT driver" #endif #if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT) WRITE(TFT_BACKLIGHT_PIN, HIGH); + TERN_(HAS_LCD_BRIGHTNESS, ui._set_brightness()); #endif } diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp index 9d9d6efeb2..feaba8483b 100644 --- a/Marlin/src/lcd/touch/touch_buttons.cpp +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -122,7 +122,9 @@ uint8_t TouchButtons::read_buttons() { } void TouchButtons::wakeUp() { if (isSleeping()) { - #if PIN_EXISTS(TFT_BACKLIGHT) + #if HAS_LCD_BRIGHTNESS + ui._set_brightness(); + #elif PIN_EXISTS(TFT_BACKLIGHT) WRITE(TFT_BACKLIGHT_PIN, HIGH); #endif } diff --git a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h index b25badca56..34fbdaf02f 100644 --- a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h +++ b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h @@ -135,6 +135,7 @@ #define TFT_RESET_PIN PC4 // pin 33 #define TFT_BACKLIGHT_PIN PD12 // pin 59 + #define TFT_BACKLIGHT_PWM 150 // Brightness with alt. TIM4 chan 1 (1-255) #define DOGLCD_MOSI -1 // Prevent auto-define by Conditionals_post.h #define DOGLCD_SCK -1 @@ -143,6 +144,11 @@ #define TFT_BUFFER_SIZE 3200 #endif +#if defined(TFT_BACKLIGHT_PWM) && !defined(MAPLE_STM32F1) + #define HAS_LCD_BRIGHTNESS 1 + #define DEFAULT_LCD_BRIGHTNESS TFT_BACKLIGHT_PWM +#endif + #if ENABLED(SDIO_SUPPORT) #define SD_SS_PIN -1 // else SDSS set to PA4 in M43 (spi_pins.h) #endif