Skip to content

Commit

Permalink
🚸 TFT backlight PWM / brightness (MarlinFirmware#22841)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot authored and thinkyhead committed Oct 3, 2021
1 parent 34c9f64 commit 064f91e
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 3 deletions.
9 changes: 9 additions & 0 deletions Marlin/src/lcd/dogm/marlinui_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/lcd/language/language_fr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/lcd/tft/touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions Marlin/src/lcd/tft/ui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
10 changes: 9 additions & 1 deletion Marlin/src/lcd/tft_io/tft_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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();
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/lcd/touch/touch_buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 064f91e

Please sign in to comment.