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
 #include "timers.h"
28
 #include "timers.h"
29
 
29
 
30
 void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
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
   PinName pin_name = digitalPinToPinName(pin);
33
   PinName pin_name = digitalPinToPinName(pin);
32
   TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM);
34
   TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM);
35
+
33
   uint16_t adj_val = Instance->ARR * v / v_size;
36
   uint16_t adj_val = Instance->ARR * v / v_size;
34
   if (invert) adj_val = Instance->ARR - adj_val;
37
   if (invert) adj_val = Instance->ARR - adj_val;
35
-
36
   switch (get_pwm_channel(pin_name)) {
38
   switch (get_pwm_channel(pin_name)) {
37
     case TIM_CHANNEL_1: LL_TIM_OC_SetCompareCH1(Instance, adj_val); break;
39
     case TIM_CHANNEL_1: LL_TIM_OC_SetCompareCH1(Instance, adj_val); break;
38
     case TIM_CHANNEL_2: LL_TIM_OC_SetCompareCH2(Instance, adj_val); break;
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
 #include "timers.h"
28
 #include "timers.h"
29
 
29
 
30
 void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
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
   timer_dev *timer = PIN_MAP[pin].timer_device;
32
   timer_dev *timer = PIN_MAP[pin].timer_device;
32
   uint16_t max_val = timer->regs.bas->ARR * v / v_size;
33
   uint16_t max_val = timer->regs.bas->ARR * v / v_size;
33
   if (invert) max_val = v_size - max_val;
34
   if (invert) max_val = v_size - max_val;

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

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
341
 #if HAS_LCD_BRIGHTNESS
342
+
342
   void MarlinUI::_set_brightness() {
343
   void MarlinUI::_set_brightness() {
343
     #if PIN_EXISTS(TFT_BACKLIGHT)
344
     #if PIN_EXISTS(TFT_BACKLIGHT)
344
       if (PWM_PIN(TFT_BACKLIGHT_PIN))
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
     #endif
347
     #endif
347
   }
348
   }
349
+
348
 #endif
350
 #endif
349
 
351
 
350
 #if HAS_LCD_MENU
352
 #if HAS_LCD_MENU

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

210
 }
210
 }
211
 
211
 
212
 #if HAS_LCD_BRIGHTNESS
212
 #if HAS_LCD_BRIGHTNESS
213
+
213
   void MarlinUI::_set_brightness() {
214
   void MarlinUI::_set_brightness() {
214
     #if PIN_EXISTS(TFT_BACKLIGHT)
215
     #if PIN_EXISTS(TFT_BACKLIGHT)
215
       if (PWM_PIN(TFT_BACKLIGHT_PIN))
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
     #endif
218
     #endif
218
   }
219
   }
220
+
219
 #endif
221
 #endif
220
 
222
 
221
 #if ENABLED(TOUCH_SCREEN_CALIBRATION)
223
 #if ENABLED(TOUCH_SCREEN_CALIBRATION)

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

152
   #endif
152
   #endif
153
 
153
 
154
   #if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT)
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
   #endif
156
   #endif
158
 }
157
 }
159
 
158
 

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

89
 #define HEATER_BED_PIN                      PA8   // pin 67 (Hot Bed Mosfet)
89
 #define HEATER_BED_PIN                      PA8   // pin 67 (Hot Bed Mosfet)
90
 
90
 
91
 #define FAN_PIN                             PA15  // pin 77 (4cm Fan)
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
 //#define BEEPER_PIN                        PD13  // pin 60 (Servo PWM output 5V/GND on Board V0G+) made for BL-Touch sensor
104
 //#define BEEPER_PIN                        PD13  // pin 60 (Servo PWM output 5V/GND on Board V0G+) made for BL-Touch sensor
97
                                                   // Can drive a PC Buzzer, if connected between PWM and 5V pins
105
                                                   // Can drive a PC Buzzer, if connected between PWM and 5V pins

Loading…
Cancel
Save