Browse Source

🐛 Fix TFT backlight [STM32] (#23062)

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

+ 3
- 1
Marlin/src/HAL/STM32/fast_pwm.cpp View File

@@ -28,11 +28,13 @@
28 28
 #include "timers.h"
29 29
 
30 30
 void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
31
+  if (!PWM_PIN(pin)) return;            // Don't proceed if no hardware timer
32
+
31 33
   PinName pin_name = digitalPinToPinName(pin);
32 34
   TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM);
35
+
33 36
   uint16_t adj_val = Instance->ARR * v / v_size;
34 37
   if (invert) adj_val = Instance->ARR - adj_val;
35
-
36 38
   switch (get_pwm_channel(pin_name)) {
37 39
     case TIM_CHANNEL_1: LL_TIM_OC_SetCompareCH1(Instance, adj_val); break;
38 40
     case TIM_CHANNEL_2: LL_TIM_OC_SetCompareCH2(Instance, adj_val); break;

+ 1
- 0
Marlin/src/HAL/STM32F1/fast_pwm.cpp View File

@@ -28,6 +28,7 @@
28 28
 #include "timers.h"
29 29
 
30 30
 void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
31
+  if (!PWM_PIN(pin)) return;
31 32
   timer_dev *timer = PIN_MAP[pin].timer_device;
32 33
   uint16_t max_val = timer->regs.bas->ARR * v / v_size;
33 34
   if (invert) max_val = v_size - max_val;

+ 3
- 1
Marlin/src/lcd/dogm/marlinui_DOGM.cpp View File

@@ -339,12 +339,14 @@ void MarlinUI::draw_kill_screen() {
339 339
 void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
340 340
 
341 341
 #if HAS_LCD_BRIGHTNESS
342
+
342 343
   void MarlinUI::_set_brightness() {
343 344
     #if PIN_EXISTS(TFT_BACKLIGHT)
344 345
       if (PWM_PIN(TFT_BACKLIGHT_PIN))
345
-        set_pwm_duty(pin_t(TFT_BACKLIGHT_PIN), brightness);
346
+        analogWrite(pin_t(TFT_BACKLIGHT_PIN), backlight ? brightness : 0);
346 347
     #endif
347 348
   }
349
+
348 350
 #endif
349 351
 
350 352
 #if HAS_LCD_MENU

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

@@ -210,12 +210,14 @@ void MarlinUI::clear_lcd() {
210 210
 }
211 211
 
212 212
 #if HAS_LCD_BRIGHTNESS
213
+
213 214
   void MarlinUI::_set_brightness() {
214 215
     #if PIN_EXISTS(TFT_BACKLIGHT)
215 216
       if (PWM_PIN(TFT_BACKLIGHT_PIN))
216
-        set_pwm_duty(pin_t(TFT_BACKLIGHT_PIN), brightness);
217
+        analogWrite(pin_t(TFT_BACKLIGHT_PIN), backlight ? brightness : 0);
217 218
     #endif
218 219
   }
220
+
219 221
 #endif
220 222
 
221 223
 #if ENABLED(TOUCH_SCREEN_CALIBRATION)

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

@@ -152,8 +152,7 @@ if (lcd_id != 0xFFFFFFFF) return;
152 152
   #endif
153 153
 
154 154
   #if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT)
155
-    WRITE(TFT_BACKLIGHT_PIN, HIGH);
156
-    TERN_(HAS_LCD_BRIGHTNESS, ui._set_brightness());
155
+    TERN(HAS_LCD_BRIGHTNESS, ui._set_brightness(), WRITE(TFT_BACKLIGHT_PIN, HIGH));
157 156
   #endif
158 157
 }
159 158
 

+ 11
- 3
Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h View File

@@ -89,9 +89,17 @@
89 89
 #define HEATER_BED_PIN                      PA8   // pin 67 (Hot Bed Mosfet)
90 90
 
91 91
 #define FAN_PIN                             PA15  // pin 77 (4cm Fan)
92
-#define FAN_SOFT_PWM                              // Required to avoid issues with heating or STLink
93
-#define FAN_MIN_PWM                           35  // Fan will not start in 1-30 range
94
-#define FAN_MAX_PWM                          255
92
+#ifdef MAPLE_STM32F1
93
+  #define FAN_SOFT_PWM                            // Required to avoid issues with heating or STLink
94
+  #define FAN_MIN_PWM                         35  // Fan will not start in 1-30 range
95
+  #define FAN_MAX_PWM                        255
96
+#else
97
+  #define FAST_PWM_FAN                            // STM32 Variant allow TIMER2 Hardware PWM
98
+  #define FAST_PWM_FAN_FREQUENCY           31400  // This frequency allow a good range, fan starts at 3%, half noise at 50%
99
+  #define NEEDS_HARDWARE_PWM                   1
100
+  #define FAN_MIN_PWM                          5
101
+  #define FAN_MAX_PWM                        255
102
+#endif
95 103
 
96 104
 //#define BEEPER_PIN                        PD13  // pin 60 (Servo PWM output 5V/GND on Board V0G+) made for BL-Touch sensor
97 105
                                                   // Can drive a PC Buzzer, if connected between PWM and 5V pins

Loading…
Cancel
Save