diff --git a/Marlin/src/HAL/STM32/fast_pwm.cpp b/Marlin/src/HAL/STM32/fast_pwm.cpp index d4d695b969..4d450374d3 100644 --- a/Marlin/src/HAL/STM32/fast_pwm.cpp +++ b/Marlin/src/HAL/STM32/fast_pwm.cpp @@ -28,11 +28,13 @@ #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*/) { + if (!PWM_PIN(pin)) return; // Don't proceed if no hardware timer + PinName pin_name = digitalPinToPinName(pin); TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM); + uint16_t adj_val = Instance->ARR * v / v_size; if (invert) adj_val = Instance->ARR - adj_val; - switch (get_pwm_channel(pin_name)) { case TIM_CHANNEL_1: LL_TIM_OC_SetCompareCH1(Instance, adj_val); break; case TIM_CHANNEL_2: LL_TIM_OC_SetCompareCH2(Instance, adj_val); break; diff --git a/Marlin/src/HAL/STM32F1/fast_pwm.cpp b/Marlin/src/HAL/STM32F1/fast_pwm.cpp index 6a9d7e8a19..5171c11545 100644 --- a/Marlin/src/HAL/STM32F1/fast_pwm.cpp +++ b/Marlin/src/HAL/STM32F1/fast_pwm.cpp @@ -28,6 +28,7 @@ #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*/) { + if (!PWM_PIN(pin)) return; timer_dev *timer = PIN_MAP[pin].timer_device; uint16_t max_val = timer->regs.bas->ARR * v / v_size; if (invert) max_val = v_size - max_val; diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index f339cad706..59c74148ad 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -339,12 +339,14 @@ void MarlinUI::draw_kill_screen() { void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop #if HAS_LCD_BRIGHTNESS + void MarlinUI::_set_brightness() { #if PIN_EXISTS(TFT_BACKLIGHT) 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 #if HAS_LCD_MENU diff --git a/Marlin/src/lcd/tft/ui_common.cpp b/Marlin/src/lcd/tft/ui_common.cpp index 85ae21e867..acc91f51fa 100644 --- a/Marlin/src/lcd/tft/ui_common.cpp +++ b/Marlin/src/lcd/tft/ui_common.cpp @@ -210,12 +210,14 @@ void MarlinUI::clear_lcd() { } #if HAS_LCD_BRIGHTNESS + void MarlinUI::_set_brightness() { #if PIN_EXISTS(TFT_BACKLIGHT) 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 #if ENABLED(TOUCH_SCREEN_CALIBRATION) diff --git a/Marlin/src/lcd/tft_io/tft_io.cpp b/Marlin/src/lcd/tft_io/tft_io.cpp index 6ec3bedcdf..acb78c3e6e 100644 --- a/Marlin/src/lcd/tft_io/tft_io.cpp +++ b/Marlin/src/lcd/tft_io/tft_io.cpp @@ -152,8 +152,7 @@ if (lcd_id != 0xFFFFFFFF) return; #endif #if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT) - WRITE(TFT_BACKLIGHT_PIN, HIGH); - TERN_(HAS_LCD_BRIGHTNESS, ui._set_brightness()); + TERN(HAS_LCD_BRIGHTNESS, ui._set_brightness(), WRITE(TFT_BACKLIGHT_PIN, HIGH)); #endif } diff --git a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h index 7585a6e289..3a8019a27e 100644 --- a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h +++ b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h @@ -89,9 +89,17 @@ #define HEATER_BED_PIN PA8 // pin 67 (Hot Bed Mosfet) #define FAN_PIN PA15 // pin 77 (4cm Fan) -#define FAN_SOFT_PWM // Required to avoid issues with heating or STLink -#define FAN_MIN_PWM 35 // Fan will not start in 1-30 range -#define FAN_MAX_PWM 255 +#ifdef MAPLE_STM32F1 + #define FAN_SOFT_PWM // Required to avoid issues with heating or STLink + #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 // Can drive a PC Buzzer, if connected between PWM and 5V pins