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
 
338
 
339
 void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
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
 #if HAS_LCD_MENU
350
 #if HAS_LCD_MENU
342
 
351
 
343
   #include "../menu/menu.h"
352
   #include "../menu/menu.h"

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

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

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

294
   }
294
   }
295
   void Touch::wakeUp() {
295
   void Touch::wakeUp() {
296
     if (isSleeping()) {
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
         WRITE(TFT_BACKLIGHT_PIN, HIGH);
300
         WRITE(TFT_BACKLIGHT_PIN, HIGH);
299
       #endif
301
       #endif
300
     }
302
     }

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

210
   cursor.set(0, 0);
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
 #if ENABLED(TOUCH_SCREEN_CALIBRATION)
222
 #if ENABLED(TOUCH_SCREEN_CALIBRATION)
214
 
223
 
215
   void MarlinUI::touch_calibration_screen() {
224
   void MarlinUI::touch_calibration_screen() {

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

49
 #include "ili9341.h"
49
 #include "ili9341.h"
50
 #include "ili9328.h"
50
 #include "ili9328.h"
51
 
51
 
52
+#if HAS_LCD_BRIGHTNESS
53
+  #include "../marlinui.h"
54
+#endif
55
+
52
 #define DEBUG_OUT ENABLED(DEBUG_GRAPHICAL_TFT)
56
 #define DEBUG_OUT ENABLED(DEBUG_GRAPHICAL_TFT)
53
 #include "../../core/debug_out.h"
57
 #include "../../core/debug_out.h"
54
 
58
 
72
 
76
 
73
   #if PIN_EXISTS(TFT_BACKLIGHT)
77
   #if PIN_EXISTS(TFT_BACKLIGHT)
74
     WRITE(TFT_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT));
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
   #endif
82
   #endif
76
 
83
 
77
   // io.Init();
84
   // io.Init();
141
         lcd_id = 0;
148
         lcd_id = 0;
142
     }
149
     }
143
   #else
150
   #else
144
-    #error Unsupported TFT driver
151
+    #error "Unsupported TFT driver"
145
   #endif
152
   #endif
146
 
153
 
147
   #if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT)
154
   #if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT)
148
     WRITE(TFT_BACKLIGHT_PIN, HIGH);
155
     WRITE(TFT_BACKLIGHT_PIN, HIGH);
156
+    TERN_(HAS_LCD_BRIGHTNESS, ui._set_brightness());
149
   #endif
157
   #endif
150
 }
158
 }
151
 
159
 

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

122
   }
122
   }
123
   void TouchButtons::wakeUp() {
123
   void TouchButtons::wakeUp() {
124
     if (isSleeping()) {
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
         WRITE(TFT_BACKLIGHT_PIN, HIGH);
128
         WRITE(TFT_BACKLIGHT_PIN, HIGH);
127
       #endif
129
       #endif
128
     }
130
     }

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

135
 
135
 
136
   #define TFT_RESET_PIN                     PC4   // pin 33
136
   #define TFT_RESET_PIN                     PC4   // pin 33
137
   #define TFT_BACKLIGHT_PIN                 PD12  // pin 59
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
   #define DOGLCD_MOSI                       -1    // Prevent auto-define by Conditionals_post.h
140
   #define DOGLCD_MOSI                       -1    // Prevent auto-define by Conditionals_post.h
140
   #define DOGLCD_SCK                        -1
141
   #define DOGLCD_SCK                        -1
143
   #define TFT_BUFFER_SIZE                   3200
144
   #define TFT_BUFFER_SIZE                   3200
144
 #endif
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
 #if ENABLED(SDIO_SUPPORT)
152
 #if ENABLED(SDIO_SUPPORT)
147
   #define SD_SS_PIN                         -1    // else SDSS set to PA4 in M43 (spi_pins.h)
153
   #define SD_SS_PIN                         -1    // else SDSS set to PA4 in M43 (spi_pins.h)
148
 #endif
154
 #endif

Loading…
Cancel
Save