Skip to content

Commit

Permalink
mcu: Remove support for set_pwm() cycle_time parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin O'Connor <[email protected]>
  • Loading branch information
KevinOConnor committed Jan 24, 2024
1 parent fd2feff commit 43a9685
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 32 deletions.
4 changes: 2 additions & 2 deletions klippy/extras/multi_pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def setup_cycle_time(self, cycle_time, hardware_pwm=False):
def set_digital(self, print_time, value):
for mcu_pin in self.mcu_pins:
mcu_pin.set_digital(print_time, value)
def set_pwm(self, print_time, value, cycle_time=None):
def set_pwm(self, print_time, value):
for mcu_pin in self.mcu_pins:
mcu_pin.set_pwm(print_time, value, cycle_time)
mcu_pin.set_pwm(print_time, value)

def load_config_prefix(config):
return PrinterMultiPin(config)
2 changes: 1 addition & 1 deletion klippy/extras/replicape.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _build_config(self):
cmd_queue = self._mcu.alloc_command_queue()
self._set_cmd = self._mcu.lookup_command(
"queue_pca9685_out oid=%c clock=%u value=%hu", cq=cmd_queue)
def set_pwm(self, print_time, value, cycle_time=None):
def set_pwm(self, print_time, value):
clock = self._mcu.print_time_to_clock(print_time)
if self._invert:
value = 1. - value
Expand Down
2 changes: 1 addition & 1 deletion klippy/extras/sx1509.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def setup_start_value(self, start_value, shutdown_value):
shutdown_value = 1. - shutdown_value
self._start_value = max(0., min(1., start_value))
self._shutdown_value = max(0., min(1., shutdown_value))
def set_pwm(self, print_time, value, cycle_time=None):
def set_pwm(self, print_time, value):
self._sx1509.set_register(self._i_on_reg, ~int(255 * value)
if not self._invert
else int(255 * value) & 0xFF)
Expand Down
37 changes: 9 additions & 28 deletions klippy/mcu.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ def __init__(self, mcu, pin_params):
self._pin = pin_params['pin']
self._invert = pin_params['invert']
self._start_value = self._shutdown_value = float(self._invert)
self._last_clock = self._last_cycle_ticks = 0
self._last_clock = 0
self._pwm_max = 0.
self._set_cmd = self._set_cycle_ticks = None
self._set_cmd = None
def get_mcu(self):
return self._mcu
def setup_max_duration(self, max_duration):
Expand Down Expand Up @@ -441,40 +441,21 @@ def _build_config(self):
self._mcu.add_config_cmd(
"set_digital_out_pwm_cycle oid=%d cycle_ticks=%d"
% (self._oid, cycle_ticks))
self._last_cycle_ticks = cycle_ticks
self._pwm_max = float(cycle_ticks)
svalue = int(self._start_value * cycle_ticks + 0.5)
self._mcu.add_config_cmd(
"queue_digital_out oid=%d clock=%d on_ticks=%d"
% (self._oid, self._last_clock, svalue), is_init=True)
self._set_cmd = self._mcu.lookup_command(
"queue_digital_out oid=%c clock=%u on_ticks=%u", cq=cmd_queue)
self._set_cycle_ticks = self._mcu.lookup_command(
"set_digital_out_pwm_cycle oid=%c cycle_ticks=%u", cq=cmd_queue)
def set_pwm(self, print_time, value, cycle_time=None):
clock = self._mcu.print_time_to_clock(print_time)
minclock = self._last_clock
self._last_clock = clock
def set_pwm(self, print_time, value):
if self._invert:
value = 1. - value
if self._hardware_pwm:
v = int(max(0., min(1., value)) * self._pwm_max + 0.5)
self._set_cmd.send([self._oid, clock, v],
minclock=minclock, reqclock=clock)
return
# Soft pwm update
if cycle_time is None:
cycle_time = self._cycle_time
cycle_ticks = self._mcu.seconds_to_clock(cycle_time)
if cycle_ticks != self._last_cycle_ticks:
if cycle_ticks >= 1<<31:
raise self._mcu.get_printer().command_error(
"PWM cycle time too large")
self._set_cycle_ticks.send([self._oid, cycle_ticks],
minclock=minclock, reqclock=clock)
self._last_cycle_ticks = cycle_ticks
on_ticks = int(max(0., min(1., value)) * float(cycle_ticks) + 0.5)
self._set_cmd.send([self._oid, clock, on_ticks],
minclock=minclock, reqclock=clock)
v = int(max(0., min(1., value)) * self._pwm_max + 0.5)
clock = self._mcu.print_time_to_clock(print_time)
self._set_cmd.send([self._oid, clock, v],
minclock=self._last_clock, reqclock=clock)
self._last_clock = clock

class MCU_adc:
def __init__(self, mcu, pin_params):
Expand Down

0 comments on commit 43a9685

Please sign in to comment.