diff --git a/klippy/extras/tmc2130.py b/klippy/extras/tmc2130.py index 28ed7ab7..cddc9160 100644 --- a/klippy/extras/tmc2130.py +++ b/klippy/extras/tmc2130.py @@ -175,15 +175,22 @@ class TMCCommandHelper: self.gcode.register_mux_command( "INIT_TMC", "STEPPER", self.name, self.cmd_INIT_TMC, desc=self.cmd_INIT_TMC_help) - def init_registers(self, print_time=0.): + self.printer.register_event_handler("klippy:connect", + self._handle_connect) + def _init_registers(self, print_time): # Send registers for reg_name, val in self.fields.registers.items(): self.mcu_tmc.set_register(reg_name, val, print_time) + def _handle_connect(self): + try: + self._init_registers(0.) + except self.printer.command_error as e: + raise self.printer.config_error(str(e)) cmd_INIT_TMC_help = "Initialize TMC stepper driver registers" def cmd_INIT_TMC(self, params): logging.info("INIT_TMC %s", self.name) print_time = self.printer.lookup_object('toolhead').get_last_move_time() - self.init_registers(print_time) + self._init_registers(print_time) cmd_SET_TMC_FIELD_help = "Set a register field of a TMC driver" def cmd_SET_TMC_FIELD(self, params): if 'FIELD' not in params or 'VALUE' not in params: @@ -353,7 +360,6 @@ class TMC2130: set_config_field(config, "pwm_freq", 1) set_config_field(config, "pwm_autoscale", True) set_config_field(config, "sgt", 0) - cmdhelper.init_registers() def setup_pin(self, pin_type, pin_params): if pin_type != 'endstop' or pin_params['pin'] != 'virtual_endstop': raise pins.error("tmc2130 virtual endstop only useful as endstop") diff --git a/klippy/extras/tmc2208.py b/klippy/extras/tmc2208.py index 6d9e0831..b7cc13ae 100644 --- a/klippy/extras/tmc2208.py +++ b/klippy/extras/tmc2208.py @@ -309,8 +309,6 @@ class TMC2208: def __init__(self, config): self.printer = config.get_printer() self.name = config.get_name().split()[-1] - self.printer.register_event_handler("klippy:connect", - self._handle_connect) # Setup mcu communication self.regs = collections.OrderedDict() self.fields = tmc2130.FieldHelper(Fields, SignedFields, FieldFormatters, @@ -354,15 +352,6 @@ class TMC2208: set_config_field(config, "pwm_autograd", True) set_config_field(config, "PWM_REG", 8) set_config_field(config, "PWM_LIM", 12) - def _init_registers(self): - # Send registers - for reg_name, val in self.regs.items(): - self.set_register(reg_name, val) - def _handle_connect(self): - try: - self._init_registers() - except self.printer.command_error as e: - raise self.printer.config_error(str(e)) def query_registers(self, print_time=0.): out = [] for reg_name in ReadRegisters: diff --git a/klippy/extras/tmc2660.py b/klippy/extras/tmc2660.py index 4d481033..c2ecff8a 100644 --- a/klippy/extras/tmc2660.py +++ b/klippy/extras/tmc2660.py @@ -231,9 +231,6 @@ class TMC2660: self.fields.set_field("RDSEL", 0) # needed for phase calculations self.fields.set_field("SDOFF", 0) # only step/dir mode supported - # Init Registers - cmdhelper.init_registers() - # Register ready/printing handlers self.idle_current_percentage = config.getint( 'idle_current_percent', default=100, minval=0, maxval=100) diff --git a/klippy/extras/tmc5160.py b/klippy/extras/tmc5160.py index ed061ade..37678fa0 100644 --- a/klippy/extras/tmc5160.py +++ b/klippy/extras/tmc5160.py @@ -320,8 +320,6 @@ class TMC5160: self.fields.set_field("TPWMTHRS", thresh) # TPOWERDOWN set_config_field(config, "TPOWERDOWN", 10) - - cmdhelper.init_registers() def setup_pin(self, pin_type, pin_params): if pin_type != 'endstop' or pin_params['pin'] != 'virtual_endstop': raise pins.error("tmc5160 virtual endstop only useful as endstop")