🐛 Fix TFT backlight [STM32] (#23062)
This commit is contained in:
		
				
					committed by
					
						
						Scott Lahteine
					
				
			
			
				
	
			
			
			
						parent
						
							89ec1c71f0
						
					
				
				
					commit
					fd136d5501
				
			@@ -28,11 +28,13 @@
 | 
				
			|||||||
#include "timers.h"
 | 
					#include "timers.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
 | 
					void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
 | 
				
			||||||
 | 
					  if (!PWM_PIN(pin)) return;            // Don't proceed if no hardware timer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  PinName pin_name = digitalPinToPinName(pin);
 | 
					  PinName pin_name = digitalPinToPinName(pin);
 | 
				
			||||||
  TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM);
 | 
					  TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  uint16_t adj_val = Instance->ARR * v / v_size;
 | 
					  uint16_t adj_val = Instance->ARR * v / v_size;
 | 
				
			||||||
  if (invert) adj_val = Instance->ARR - adj_val;
 | 
					  if (invert) adj_val = Instance->ARR - adj_val;
 | 
				
			||||||
 | 
					 | 
				
			||||||
  switch (get_pwm_channel(pin_name)) {
 | 
					  switch (get_pwm_channel(pin_name)) {
 | 
				
			||||||
    case TIM_CHANNEL_1: LL_TIM_OC_SetCompareCH1(Instance, adj_val); break;
 | 
					    case TIM_CHANNEL_1: LL_TIM_OC_SetCompareCH1(Instance, adj_val); break;
 | 
				
			||||||
    case TIM_CHANNEL_2: LL_TIM_OC_SetCompareCH2(Instance, adj_val); break;
 | 
					    case TIM_CHANNEL_2: LL_TIM_OC_SetCompareCH2(Instance, adj_val); break;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,6 +28,7 @@
 | 
				
			|||||||
#include "timers.h"
 | 
					#include "timers.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
 | 
					void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
 | 
				
			||||||
 | 
					  if (!PWM_PIN(pin)) return;
 | 
				
			||||||
  timer_dev *timer = PIN_MAP[pin].timer_device;
 | 
					  timer_dev *timer = PIN_MAP[pin].timer_device;
 | 
				
			||||||
  uint16_t max_val = timer->regs.bas->ARR * v / v_size;
 | 
					  uint16_t max_val = timer->regs.bas->ARR * v / v_size;
 | 
				
			||||||
  if (invert) max_val = v_size - max_val;
 | 
					  if (invert) max_val = v_size - max_val;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -339,12 +339,14 @@ void MarlinUI::draw_kill_screen() {
 | 
				
			|||||||
void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
 | 
					void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if HAS_LCD_BRIGHTNESS
 | 
					#if HAS_LCD_BRIGHTNESS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void MarlinUI::_set_brightness() {
 | 
					  void MarlinUI::_set_brightness() {
 | 
				
			||||||
    #if PIN_EXISTS(TFT_BACKLIGHT)
 | 
					    #if PIN_EXISTS(TFT_BACKLIGHT)
 | 
				
			||||||
      if (PWM_PIN(TFT_BACKLIGHT_PIN))
 | 
					      if (PWM_PIN(TFT_BACKLIGHT_PIN))
 | 
				
			||||||
        set_pwm_duty(pin_t(TFT_BACKLIGHT_PIN), brightness);
 | 
					        analogWrite(pin_t(TFT_BACKLIGHT_PIN), backlight ? brightness : 0);
 | 
				
			||||||
    #endif
 | 
					    #endif
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if HAS_LCD_MENU
 | 
					#if HAS_LCD_MENU
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -210,12 +210,14 @@ void MarlinUI::clear_lcd() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if HAS_LCD_BRIGHTNESS
 | 
					#if HAS_LCD_BRIGHTNESS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void MarlinUI::_set_brightness() {
 | 
					  void MarlinUI::_set_brightness() {
 | 
				
			||||||
    #if PIN_EXISTS(TFT_BACKLIGHT)
 | 
					    #if PIN_EXISTS(TFT_BACKLIGHT)
 | 
				
			||||||
      if (PWM_PIN(TFT_BACKLIGHT_PIN))
 | 
					      if (PWM_PIN(TFT_BACKLIGHT_PIN))
 | 
				
			||||||
        set_pwm_duty(pin_t(TFT_BACKLIGHT_PIN), brightness);
 | 
					        analogWrite(pin_t(TFT_BACKLIGHT_PIN), backlight ? brightness : 0);
 | 
				
			||||||
    #endif
 | 
					    #endif
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
 | 
					#if ENABLED(TOUCH_SCREEN_CALIBRATION)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -152,8 +152,7 @@ if (lcd_id != 0xFFFFFFFF) return;
 | 
				
			|||||||
  #endif
 | 
					  #endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  #if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT)
 | 
					  #if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT)
 | 
				
			||||||
    WRITE(TFT_BACKLIGHT_PIN, HIGH);
 | 
					    TERN(HAS_LCD_BRIGHTNESS, ui._set_brightness(), WRITE(TFT_BACKLIGHT_PIN, HIGH));
 | 
				
			||||||
    TERN_(HAS_LCD_BRIGHTNESS, ui._set_brightness());
 | 
					 | 
				
			||||||
  #endif
 | 
					  #endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -89,9 +89,17 @@
 | 
				
			|||||||
#define HEATER_BED_PIN                      PA8   // pin 67 (Hot Bed Mosfet)
 | 
					#define HEATER_BED_PIN                      PA8   // pin 67 (Hot Bed Mosfet)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define FAN_PIN                             PA15  // pin 77 (4cm Fan)
 | 
					#define FAN_PIN                             PA15  // pin 77 (4cm Fan)
 | 
				
			||||||
#define FAN_SOFT_PWM                              // Required to avoid issues with heating or STLink
 | 
					#ifdef MAPLE_STM32F1
 | 
				
			||||||
#define FAN_MIN_PWM                           35  // Fan will not start in 1-30 range
 | 
					  #define FAN_SOFT_PWM                            // Required to avoid issues with heating or STLink
 | 
				
			||||||
#define FAN_MAX_PWM                          255
 | 
					  #define FAN_MIN_PWM                         35  // Fan will not start in 1-30 range
 | 
				
			||||||
 | 
					  #define FAN_MAX_PWM                        255
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					  #define FAST_PWM_FAN                            // STM32 Variant allow TIMER2 Hardware PWM
 | 
				
			||||||
 | 
					  #define FAST_PWM_FAN_FREQUENCY           31400  // This frequency allow a good range, fan starts at 3%, half noise at 50%
 | 
				
			||||||
 | 
					  #define NEEDS_HARDWARE_PWM                   1
 | 
				
			||||||
 | 
					  #define FAN_MIN_PWM                          5
 | 
				
			||||||
 | 
					  #define FAN_MAX_PWM                        255
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//#define BEEPER_PIN                        PD13  // pin 60 (Servo PWM output 5V/GND on Board V0G+) made for BL-Touch sensor
 | 
					//#define BEEPER_PIN                        PD13  // pin 60 (Servo PWM output 5V/GND on Board V0G+) made for BL-Touch sensor
 | 
				
			||||||
                                                  // Can drive a PC Buzzer, if connected between PWM and 5V pins
 | 
					                                                  // Can drive a PC Buzzer, if connected between PWM and 5V pins
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user