Browse Source

🚸 TFT backlight PWM / brightness (#22841)

Tanguy Pruvot 3 years ago
parent
commit
f73175d826
No account linked to committer's email address

+ 9
- 0
Marlin/src/lcd/dogm/marlinui_DOGM.cpp View File

@@ -338,6 +338,15 @@ void MarlinUI::draw_kill_screen() {
338 338
 
339 339
 void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
340 340
 
341
+#if HAS_LCD_BRIGHTNESS
342
+  void MarlinUI::_set_brightness() {
343
+    #if PIN_EXISTS(TFT_BACKLIGHT)
344
+      if (PWM_PIN(TFT_BACKLIGHT_PIN))
345
+        analogWrite(pin_t(TFT_BACKLIGHT_PIN), brightness);
346
+    #endif
347
+  }
348
+#endif
349
+
341 350
 #if HAS_LCD_MENU
342 351
 
343 352
   #include "../menu/menu.h"

+ 1
- 0
Marlin/src/lcd/language/language_fr.h View File

@@ -336,6 +336,7 @@ namespace Language_fr {
336 336
   LSTR MSG_FILAMENT_LOAD                  = _UxGT("Charger mm");
337 337
   LSTR MSG_ADVANCE_K                      = _UxGT("Avance K");
338 338
   LSTR MSG_ADVANCE_K_E                    = _UxGT("Avance K *");
339
+  LSTR MSG_BRIGHTNESS                     = _UxGT("Luminosité LCD");
339 340
   LSTR MSG_CONTRAST                       = _UxGT("Contraste LCD");
340 341
   LSTR MSG_STORE_EEPROM                   = _UxGT("Enregistrer config.");
341 342
   LSTR MSG_LOAD_EEPROM                    = _UxGT("Charger config.");

+ 3
- 1
Marlin/src/lcd/tft/touch.cpp View File

@@ -294,7 +294,9 @@ bool Touch::get_point(int16_t *x, int16_t *y) {
294 294
   }
295 295
   void Touch::wakeUp() {
296 296
     if (isSleeping()) {
297
-      #if PIN_EXISTS(TFT_BACKLIGHT)
297
+      #if HAS_LCD_BRIGHTNESS
298
+        ui._set_brightness();
299
+      #elif PIN_EXISTS(TFT_BACKLIGHT)
298 300
         WRITE(TFT_BACKLIGHT_PIN, HIGH);
299 301
       #endif
300 302
     }

+ 9
- 0
Marlin/src/lcd/tft/ui_common.cpp View File

@@ -210,6 +210,15 @@ void MarlinUI::clear_lcd() {
210 210
   cursor.set(0, 0);
211 211
 }
212 212
 
213
+#if HAS_LCD_BRIGHTNESS
214
+  void MarlinUI::_set_brightness() {
215
+    #if PIN_EXISTS(TFT_BACKLIGHT)
216
+      if (PWM_PIN(TFT_BACKLIGHT_PIN))
217
+        analogWrite(pin_t(TFT_BACKLIGHT_PIN), brightness);
218
+    #endif
219
+  }
220
+#endif
221
+
213 222
 #if ENABLED(TOUCH_SCREEN_CALIBRATION)
214 223
 
215 224
   void MarlinUI::touch_calibration_screen() {

+ 9
- 1
Marlin/src/lcd/tft_io/tft_io.cpp View File

@@ -49,6 +49,10 @@
49 49
 #include "ili9341.h"
50 50
 #include "ili9328.h"
51 51
 
52
+#if HAS_LCD_BRIGHTNESS
53
+  #include "../marlinui.h"
54
+#endif
55
+
52 56
 #define DEBUG_OUT ENABLED(DEBUG_GRAPHICAL_TFT)
53 57
 #include "../../core/debug_out.h"
54 58
 
@@ -72,6 +76,9 @@ if (lcd_id != 0xFFFFFFFF) return;
72 76
 
73 77
   #if PIN_EXISTS(TFT_BACKLIGHT)
74 78
     WRITE(TFT_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT));
79
+    #if HAS_LCD_BRIGHTNESS && DISABLED(DELAYED_BACKLIGHT_INIT)
80
+      ui._set_brightness();
81
+    #endif
75 82
   #endif
76 83
 
77 84
   // io.Init();
@@ -141,11 +148,12 @@ if (lcd_id != 0xFFFFFFFF) return;
141 148
         lcd_id = 0;
142 149
     }
143 150
   #else
144
-    #error Unsupported TFT driver
151
+    #error "Unsupported TFT driver"
145 152
   #endif
146 153
 
147 154
   #if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT)
148 155
     WRITE(TFT_BACKLIGHT_PIN, HIGH);
156
+    TERN_(HAS_LCD_BRIGHTNESS, ui._set_brightness());
149 157
   #endif
150 158
 }
151 159
 

+ 3
- 1
Marlin/src/lcd/touch/touch_buttons.cpp View File

@@ -122,7 +122,9 @@ uint8_t TouchButtons::read_buttons() {
122 122
   }
123 123
   void TouchButtons::wakeUp() {
124 124
     if (isSleeping()) {
125
-      #if PIN_EXISTS(TFT_BACKLIGHT)
125
+      #if HAS_LCD_BRIGHTNESS
126
+        ui._set_brightness();
127
+      #elif PIN_EXISTS(TFT_BACKLIGHT)
126 128
         WRITE(TFT_BACKLIGHT_PIN, HIGH);
127 129
       #endif
128 130
     }

+ 6
- 0
Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h View File

@@ -135,6 +135,7 @@
135 135
 
136 136
   #define TFT_RESET_PIN                     PC4   // pin 33
137 137
   #define TFT_BACKLIGHT_PIN                 PD12  // pin 59
138
+  #define TFT_BACKLIGHT_PWM                 150   // Brightness with alt. TIM4 chan 1 (1-255)
138 139
 
139 140
   #define DOGLCD_MOSI                       -1    // Prevent auto-define by Conditionals_post.h
140 141
   #define DOGLCD_SCK                        -1
@@ -143,6 +144,11 @@
143 144
   #define TFT_BUFFER_SIZE                   3200
144 145
 #endif
145 146
 
147
+#if defined(TFT_BACKLIGHT_PWM) && !defined(MAPLE_STM32F1)
148
+  #define HAS_LCD_BRIGHTNESS 1
149
+  #define DEFAULT_LCD_BRIGHTNESS TFT_BACKLIGHT_PWM
150
+#endif
151
+
146 152
 #if ENABLED(SDIO_SUPPORT)
147 153
   #define SD_SS_PIN                         -1    // else SDSS set to PA4 in M43 (spi_pins.h)
148 154
 #endif

Loading…
Cancel
Save