static_pwm_clock: Don't rely on custom stm32_timer_output mcu code

Use the regular hardware pwm interface instead of relying on a custom
interface.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2026-01-02 18:33:22 -05:00
parent abda66d6ef
commit 8bca4cbcd9

View file

@ -11,16 +11,15 @@ class PrinterClockOutputPin:
self.name = config.get_name()
self.printer = config.get_printer()
ppins = self.printer.lookup_object('pins')
mcu_pin = ppins.lookup_pin(config.get('pin'), can_invert=True)
self.mcu = mcu_pin["chip"]
self.pin = mcu_pin["pin"]
self.invert = mcu_pin["invert"]
self.mcu_pin = ppins.setup_pin('pwm', config.get('pin'))
self.mcu = self.mcu_pin.get_mcu()
self.frequency = config.getfloat('frequency', 100, above=(1/0.3),
maxval=520000000)
self.mcu_pin.setup_cycle_time(1. / self.frequency, True)
self.mcu_pin.setup_max_duration(0.)
self.mcu_pin.setup_start_value(0.5, 0.5)
self.mcu.register_config_callback(self._build_config)
def _build_config(self):
self.mcu.lookup_command(
"stm32_timer_output pin=%u cycle_ticks=%u on_ticks=%hu")
mcu_freq = self.mcu.seconds_to_clock(1.0)
cycle_ticks = int(mcu_freq // self.frequency)
# validate frequency
@ -33,15 +32,10 @@ class PrinterClockOutputPin:
""" % (mcu_freq, mcu_freq_rev, self.name, self.frequency)
raise self.printer.config_error(msg)
value = int(0.5 * cycle_ticks)
if self.invert:
value = cycle_ticks - value
if value/cycle_ticks < 0.4:
logging.warning("[%s] pulse width < 40%%" % (self.name))
if value/cycle_ticks > 0.6:
logging.warning("[%s] pulse width > 60%%" % (self.name))
self.mcu.add_config_cmd(
"stm32_timer_output pin=%s cycle_ticks=%d on_ticks=%d"
% (self.pin, cycle_ticks, value))
def load_config_prefix(config):
return PrinterClockOutputPin(config)