mirror of https://github.com/Desuuuu/klipper.git
chipmisc: Support start values on pca9685 pins
Default the pca9685 enable line on if any of the pins attached to it have a non-zero start value. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
3833669c3a
commit
47e458210e
|
@ -254,8 +254,8 @@ class pca9685_pwm:
|
||||||
self._start_value = max(0., min(1., start_value))
|
self._start_value = max(0., min(1., start_value))
|
||||||
self._shutdown_value = max(0., min(1., shutdown_value))
|
self._shutdown_value = max(0., min(1., shutdown_value))
|
||||||
self._is_static = is_static
|
self._is_static = is_static
|
||||||
if self._shutdown_value:
|
self._replicape.note_pwm_start_value(
|
||||||
self._replicape.note_enable_on_shutdown()
|
self._channel, self._start_value, self._shutdown_value)
|
||||||
def build_config(self):
|
def build_config(self):
|
||||||
self._pwm_max = self._mcu.get_constant_float("PCA9685_MAX")
|
self._pwm_max = self._mcu.get_constant_float("PCA9685_MAX")
|
||||||
cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
|
cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
|
||||||
|
@ -281,7 +281,7 @@ class pca9685_pwm:
|
||||||
if self._invert:
|
if self._invert:
|
||||||
value = 1. - value
|
value = 1. - value
|
||||||
value = int(max(0., min(1., value)) * self._pwm_max + 0.5)
|
value = int(max(0., min(1., value)) * self._pwm_max + 0.5)
|
||||||
self._replicape.note_enable(print_time, self._channel, not not value)
|
self._replicape.note_pwm_enable(print_time, self._channel, value)
|
||||||
msg = self._set_cmd.encode(self._oid, clock, value)
|
msg = self._set_cmd.encode(self._oid, clock, value)
|
||||||
self._mcu.send(msg, minclock=self._last_clock, reqclock=clock
|
self._mcu.send(msg, minclock=self._last_clock, reqclock=clock
|
||||||
, cq=self._cmd_queue)
|
, cq=self._cmd_queue)
|
||||||
|
@ -326,10 +326,10 @@ class Replicape:
|
||||||
config.getchoice('revision', revisions)
|
config.getchoice('revision', revisions)
|
||||||
self.host_mcu = mcu.get_printer_mcu(printer, config.get('host_mcu'))
|
self.host_mcu = mcu.get_printer_mcu(printer, config.get('host_mcu'))
|
||||||
# Setup enable pin
|
# Setup enable pin
|
||||||
self.mcu_enable = pins.setup_pin(
|
self.mcu_pwm_enable = pins.setup_pin(
|
||||||
printer, 'digital_out', config.get('enable_pin', '!P9_41'))
|
printer, 'digital_out', config.get('enable_pin', '!P9_41'))
|
||||||
self.mcu_enable.setup_max_duration(0.)
|
self.mcu_pwm_enable.setup_max_duration(0.)
|
||||||
self.enabled_channels = {}
|
self.mcu_pwm_start_value = self.mcu_pwm_shutdown_value = False
|
||||||
# Setup power pins
|
# Setup power pins
|
||||||
self.pins = {
|
self.pins = {
|
||||||
"power_e": (pca9685_pwm, 5), "power_h": (pca9685_pwm, 3),
|
"power_e": (pca9685_pwm, 5), "power_h": (pca9685_pwm, 3),
|
||||||
|
@ -357,22 +357,29 @@ class Replicape:
|
||||||
prefix + 'current', above=0., maxval=REPLICAPE_MAX_CURRENT)
|
prefix + 'current', above=0., maxval=REPLICAPE_MAX_CURRENT)
|
||||||
self.stepper_dacs[channel] = cur / REPLICAPE_MAX_CURRENT
|
self.stepper_dacs[channel] = cur / REPLICAPE_MAX_CURRENT
|
||||||
self.pins[prefix + 'enable'] = (ReplicapeDACEnable, channel)
|
self.pins[prefix + 'enable'] = (ReplicapeDACEnable, channel)
|
||||||
|
self.enabled_channels = {ch: False for cl, ch in self.pins.values()}
|
||||||
shift_registers.reverse()
|
shift_registers.reverse()
|
||||||
self.host_mcu.add_config_cmd("send_spi bus=%d dev=%d msg=%s" % (
|
self.host_mcu.add_config_cmd("send_spi bus=%d dev=%d msg=%s" % (
|
||||||
REPLICAPE_SHIFT_REGISTER_BUS, REPLICAPE_SHIFT_REGISTER_DEVICE,
|
REPLICAPE_SHIFT_REGISTER_BUS, REPLICAPE_SHIFT_REGISTER_DEVICE,
|
||||||
"".join(["%02x" % (x,) for x in shift_registers])))
|
"".join(["%02x" % (x,) for x in shift_registers])))
|
||||||
def note_enable_on_shutdown(self):
|
def note_pwm_start_value(self, channel, start_value, shutdown_value):
|
||||||
self.mcu_enable.setup_start_value(0, 1)
|
self.mcu_pwm_start_value |= not not start_value
|
||||||
def note_enable(self, print_time, channel, is_enable):
|
self.mcu_pwm_shutdown_value |= not not shutdown_value
|
||||||
if is_enable:
|
self.mcu_pwm_enable.setup_start_value(
|
||||||
is_off = not self.enabled_channels
|
self.mcu_pwm_start_value, self.mcu_pwm_shutdown_value)
|
||||||
self.enabled_channels[channel] = 1
|
self.enabled_channels[channel] = not not start_value
|
||||||
if is_off:
|
def note_pwm_enable(self, print_time, channel, value):
|
||||||
self.mcu_enable.set_digital(print_time, 1)
|
is_enable = not not value
|
||||||
elif channel in self.enabled_channels:
|
if self.enabled_channels[channel] == is_enable:
|
||||||
del self.enabled_channels[channel]
|
# Nothing to do
|
||||||
if not self.enabled_channels:
|
return
|
||||||
self.mcu_enable.set_digital(print_time, 0)
|
self.enabled_channels[channel] = is_enable
|
||||||
|
# Check if need to set the pca9685 enable pin
|
||||||
|
on_channels = [1 for c, e in self.enabled_channels.items() if e]
|
||||||
|
if not on_channels:
|
||||||
|
self.mcu_pwm_enable.set_digital(print_time, 0)
|
||||||
|
elif is_enable and len(on_channels) == 1:
|
||||||
|
self.mcu_pwm_enable.set_digital(print_time, 1)
|
||||||
def setup_pin(self, pin_params):
|
def setup_pin(self, pin_params):
|
||||||
pin = pin_params['pin']
|
pin = pin_params['pin']
|
||||||
if pin not in self.pins:
|
if pin not in self.pins:
|
||||||
|
|
Loading…
Reference in New Issue