mirror of https://github.com/Desuuuu/klipper.git
tmc2130: Transmit register initialization during connect callback
Perform the register initialization directly from TMCCommandHelper and perform it during the "connect" phase. This unifies the register setup for the TMC2130, TMC2208, TMC2660, and TMC5160. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
6947548c17
commit
6abe132cf0
|
@ -175,15 +175,22 @@ class TMCCommandHelper:
|
||||||
self.gcode.register_mux_command(
|
self.gcode.register_mux_command(
|
||||||
"INIT_TMC", "STEPPER", self.name,
|
"INIT_TMC", "STEPPER", self.name,
|
||||||
self.cmd_INIT_TMC, desc=self.cmd_INIT_TMC_help)
|
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
|
# Send registers
|
||||||
for reg_name, val in self.fields.registers.items():
|
for reg_name, val in self.fields.registers.items():
|
||||||
self.mcu_tmc.set_register(reg_name, val, print_time)
|
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"
|
cmd_INIT_TMC_help = "Initialize TMC stepper driver registers"
|
||||||
def cmd_INIT_TMC(self, params):
|
def cmd_INIT_TMC(self, params):
|
||||||
logging.info("INIT_TMC %s", self.name)
|
logging.info("INIT_TMC %s", self.name)
|
||||||
print_time = self.printer.lookup_object('toolhead').get_last_move_time()
|
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"
|
cmd_SET_TMC_FIELD_help = "Set a register field of a TMC driver"
|
||||||
def cmd_SET_TMC_FIELD(self, params):
|
def cmd_SET_TMC_FIELD(self, params):
|
||||||
if 'FIELD' not in params or 'VALUE' not in 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_freq", 1)
|
||||||
set_config_field(config, "pwm_autoscale", True)
|
set_config_field(config, "pwm_autoscale", True)
|
||||||
set_config_field(config, "sgt", 0)
|
set_config_field(config, "sgt", 0)
|
||||||
cmdhelper.init_registers()
|
|
||||||
def setup_pin(self, pin_type, pin_params):
|
def setup_pin(self, pin_type, pin_params):
|
||||||
if pin_type != 'endstop' or pin_params['pin'] != 'virtual_endstop':
|
if pin_type != 'endstop' or pin_params['pin'] != 'virtual_endstop':
|
||||||
raise pins.error("tmc2130 virtual endstop only useful as endstop")
|
raise pins.error("tmc2130 virtual endstop only useful as endstop")
|
||||||
|
|
|
@ -309,8 +309,6 @@ class TMC2208:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.printer = config.get_printer()
|
self.printer = config.get_printer()
|
||||||
self.name = config.get_name().split()[-1]
|
self.name = config.get_name().split()[-1]
|
||||||
self.printer.register_event_handler("klippy:connect",
|
|
||||||
self._handle_connect)
|
|
||||||
# Setup mcu communication
|
# Setup mcu communication
|
||||||
self.regs = collections.OrderedDict()
|
self.regs = collections.OrderedDict()
|
||||||
self.fields = tmc2130.FieldHelper(Fields, SignedFields, FieldFormatters,
|
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_autograd", True)
|
||||||
set_config_field(config, "PWM_REG", 8)
|
set_config_field(config, "PWM_REG", 8)
|
||||||
set_config_field(config, "PWM_LIM", 12)
|
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.):
|
def query_registers(self, print_time=0.):
|
||||||
out = []
|
out = []
|
||||||
for reg_name in ReadRegisters:
|
for reg_name in ReadRegisters:
|
||||||
|
|
|
@ -231,9 +231,6 @@ class TMC2660:
|
||||||
self.fields.set_field("RDSEL", 0) # needed for phase calculations
|
self.fields.set_field("RDSEL", 0) # needed for phase calculations
|
||||||
self.fields.set_field("SDOFF", 0) # only step/dir mode supported
|
self.fields.set_field("SDOFF", 0) # only step/dir mode supported
|
||||||
|
|
||||||
# Init Registers
|
|
||||||
cmdhelper.init_registers()
|
|
||||||
|
|
||||||
# Register ready/printing handlers
|
# Register ready/printing handlers
|
||||||
self.idle_current_percentage = config.getint(
|
self.idle_current_percentage = config.getint(
|
||||||
'idle_current_percent', default=100, minval=0, maxval=100)
|
'idle_current_percent', default=100, minval=0, maxval=100)
|
||||||
|
|
|
@ -320,8 +320,6 @@ class TMC5160:
|
||||||
self.fields.set_field("TPWMTHRS", thresh)
|
self.fields.set_field("TPWMTHRS", thresh)
|
||||||
# TPOWERDOWN
|
# TPOWERDOWN
|
||||||
set_config_field(config, "TPOWERDOWN", 10)
|
set_config_field(config, "TPOWERDOWN", 10)
|
||||||
|
|
||||||
cmdhelper.init_registers()
|
|
||||||
def setup_pin(self, pin_type, pin_params):
|
def setup_pin(self, pin_type, pin_params):
|
||||||
if pin_type != 'endstop' or pin_params['pin'] != 'virtual_endstop':
|
if pin_type != 'endstop' or pin_params['pin'] != 'virtual_endstop':
|
||||||
raise pins.error("tmc5160 virtual endstop only useful as endstop")
|
raise pins.error("tmc5160 virtual endstop only useful as endstop")
|
||||||
|
|
Loading…
Reference in New Issue