From 02b141ac43317cb5bd9f926c450dbed3b8fcb733 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 8 Jan 2018 20:50:31 -0500 Subject: [PATCH] chipmisc: Fix replicape enable line setup The enable lines are not one per stepper - instead there are 5 distinct enable settings. Handle them properly. Signed-off-by: Kevin O'Connor --- config/generic-replicape.cfg | 4 ++++ klippy/chipmisc.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/config/generic-replicape.cfg b/config/generic-replicape.cfg index 99f3bee4..d9694beb 100644 --- a/config/generic-replicape.cfg +++ b/config/generic-replicape.cfg @@ -98,6 +98,10 @@ host_mcu: host # The name of the mcu config section that communicates with the # Klipper "linux process" mcu instance. This parameter must be # provided. +#standstill_power_down: False +# This parameter controls the CFG6_ENN line on all stepper +# motors. True sets the enable lines to "open". The default is +# False. stepper_x_microstep_mode: spread16 # This parameter controls the CFG1 and CFG2 pins of the given # stepper motor driver. Available options are: disable, 1, 2, diff --git a/klippy/chipmisc.py b/klippy/chipmisc.py index 82ec70d4..cbbb4d75 100644 --- a/klippy/chipmisc.py +++ b/klippy/chipmisc.py @@ -338,13 +338,14 @@ class Replicape: "power_fan2": (pca9685_pwm, 9), "power_fan3": (pca9685_pwm, 10) } # Setup stepper config self.stepper_dacs = {} - shift_registers = [1] * 5 + shift_registers = [1, 0, 0, 1, 1] for port, name in enumerate('xyzeh'): prefix = 'stepper_%s_' % (name,) sc = config.getchoice( prefix + 'microstep_mode', ReplicapeStepConfig, 'disable') if sc is None: continue + sc |= shift_registers[port] if config.getboolean(prefix + 'chopper_off_time_high', False): sc |= 1<<3 if config.getboolean(prefix + 'chopper_hysteresis_high', False): @@ -358,6 +359,14 @@ class Replicape: self.stepper_dacs[channel] = cur / REPLICAPE_MAX_CURRENT self.pins[prefix + 'enable'] = (ReplicapeDACEnable, channel) self.enabled_channels = {ch: False for cl, ch in self.pins.values()} + if [i for i in [0, 1, 2] if 11+i in self.stepper_dacs]: + # Enable xyz steppers + shift_registers[0] &= ~1 + if [i for i in [3, 4] if 11+i in self.stepper_dacs]: + # Enable eh steppers + shift_registers[3] &= ~1 + if config.getboolean('standstill_power_down', False): + shift_registers[4] &= ~1 shift_registers.reverse() self.host_mcu.add_config_cmd("send_spi bus=%d dev=%d msg=%s" % ( REPLICAPE_SHIFT_REGISTER_BUS, REPLICAPE_SHIFT_REGISTER_DEVICE,