mirror of https://github.com/Desuuuu/klipper.git
tmc: Add support for virtual enable pins
Add support for enabling the stepper via the communication channel. This improves support for boards with a shared enable line. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
041831f93a
commit
7702f0a027
|
@ -975,7 +975,10 @@
|
||||||
# Configure a TMC2130 stepper motor driver via SPI bus. To use this
|
# Configure a TMC2130 stepper motor driver via SPI bus. To use this
|
||||||
# feature, define a config section with a "tmc2130" prefix followed by
|
# feature, define a config section with a "tmc2130" prefix followed by
|
||||||
# the name of the corresponding stepper config section (for example,
|
# the name of the corresponding stepper config section (for example,
|
||||||
# "[tmc2130 stepper_x]").
|
# "[tmc2130 stepper_x]"). This also creates a
|
||||||
|
# "tmc2130_stepper_x:virtual_enable" virtual pin which may be used as
|
||||||
|
# the stepper's enable_pin (for enabling the driver via an SPI
|
||||||
|
# message).
|
||||||
#[tmc2130 stepper_x]
|
#[tmc2130 stepper_x]
|
||||||
#cs_pin:
|
#cs_pin:
|
||||||
# The pin corresponding to the TMC2130 chip select line. This pin
|
# The pin corresponding to the TMC2130 chip select line. This pin
|
||||||
|
@ -1038,7 +1041,10 @@
|
||||||
# Configure a TMC2208 (or TMC2224) stepper motor driver via single
|
# Configure a TMC2208 (or TMC2224) stepper motor driver via single
|
||||||
# wire UART. To use this feature, define a config section with a
|
# wire UART. To use this feature, define a config section with a
|
||||||
# "tmc2208" prefix followed by the name of the corresponding stepper
|
# "tmc2208" prefix followed by the name of the corresponding stepper
|
||||||
# config section (for example, "[tmc2208 stepper_x]").
|
# config section (for example, "[tmc2208 stepper_x]"). This also
|
||||||
|
# creates a "tmc2208_stepper_x:virtual_enable" virtual pin which may
|
||||||
|
# be used as the stepper's enable_pin (for enabling the driver via a
|
||||||
|
# UART message).
|
||||||
#[tmc2208 stepper_x]
|
#[tmc2208 stepper_x]
|
||||||
#uart_pin:
|
#uart_pin:
|
||||||
# The pin connected to the TMC2208 PDN_UART line. This parameter
|
# The pin connected to the TMC2208 PDN_UART line. This parameter
|
||||||
|
@ -1096,7 +1102,10 @@
|
||||||
# Configure a TMC2209 stepper motor driver via single wire UART. To
|
# Configure a TMC2209 stepper motor driver via single wire UART. To
|
||||||
# use this feature, define a config section with a "tmc2209" prefix
|
# use this feature, define a config section with a "tmc2209" prefix
|
||||||
# followed by the name of the corresponding stepper config section
|
# followed by the name of the corresponding stepper config section
|
||||||
# (for example, "[tmc2209 stepper_x]").
|
# (for example, "[tmc2209 stepper_x]"). This also creates a
|
||||||
|
# "tmc2209_stepper_x:virtual_enable" virtual pin which may be used as
|
||||||
|
# the stepper's enable_pin (for enabling the driver via a UART
|
||||||
|
# message).
|
||||||
#[tmc2209 stepper_x]
|
#[tmc2209 stepper_x]
|
||||||
#uart_pin:
|
#uart_pin:
|
||||||
#tx_pin:
|
#tx_pin:
|
||||||
|
@ -1132,7 +1141,10 @@
|
||||||
# Configure a TMC2660 stepper motor driver via SPI bus. To use this
|
# Configure a TMC2660 stepper motor driver via SPI bus. To use this
|
||||||
# feature, define a config section with a tmc2660 prefix followed by
|
# feature, define a config section with a tmc2660 prefix followed by
|
||||||
# the name of the corresponding stepper config section (for example,
|
# the name of the corresponding stepper config section (for example,
|
||||||
# "[tmc2660 stepper_x]").
|
# "[tmc2660 stepper_x]"). This also creates a
|
||||||
|
# "tmc2660_stepper_x:virtual_enable" virtual pin which may be used as
|
||||||
|
# the stepper's enable_pin (for enabling the driver via an SPI
|
||||||
|
# message).
|
||||||
#[tmc2660 stepper_x]
|
#[tmc2660 stepper_x]
|
||||||
#cs_pin:
|
#cs_pin:
|
||||||
# The pin corresponding to the TMC2660 chip select line. This pin
|
# The pin corresponding to the TMC2660 chip select line. This pin
|
||||||
|
@ -1204,7 +1216,10 @@
|
||||||
# Configure a TMC5160 stepper motor driver via SPI bus. To use this
|
# Configure a TMC5160 stepper motor driver via SPI bus. To use this
|
||||||
# feature, define a config section with a "tmc5160" prefix followed by
|
# feature, define a config section with a "tmc5160" prefix followed by
|
||||||
# the name of the corresponding stepper config section (for example,
|
# the name of the corresponding stepper config section (for example,
|
||||||
# "[tmc5160 stepper_x]").
|
# "[tmc5160 stepper_x]"). This also creates a
|
||||||
|
# "tmc5160_stepper_x:virtual_enable" virtual pin which may be used as
|
||||||
|
# the stepper's enable_pin (for enabling the driver via an SPI
|
||||||
|
# message).
|
||||||
#[tmc5160 stepper_x]
|
#[tmc5160 stepper_x]
|
||||||
#cs_pin:
|
#cs_pin:
|
||||||
# The pin corresponding to the TMC5160 chip select line. This pin
|
# The pin corresponding to the TMC5160 chip select line. This pin
|
||||||
|
|
|
@ -155,7 +155,7 @@ class TMCCommandHelper:
|
||||||
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# TMC virtual endstops
|
# TMC virtual pins
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
# Endstop wrapper that enables "sensorless homing"
|
# Endstop wrapper that enables "sensorless homing"
|
||||||
|
@ -187,8 +187,30 @@ class TMCVirtualEndstop:
|
||||||
self.mcu_tmc.set_register("TCOOLTHRS", 0)
|
self.mcu_tmc.set_register("TCOOLTHRS", 0)
|
||||||
self.mcu_endstop.home_finalize()
|
self.mcu_endstop.home_finalize()
|
||||||
|
|
||||||
class TMCEndstopHelper:
|
# Digital output wrapper for virtual enable
|
||||||
def __init__(self, config, mcu_tmc, diag_pin):
|
class TMCVirtualEnable:
|
||||||
|
def __init__(self, printer, mcu_tmc):
|
||||||
|
self.reactor = printer.get_reactor()
|
||||||
|
self.mcu_tmc = mcu_tmc
|
||||||
|
self.fields = mcu_tmc.get_fields()
|
||||||
|
self.toff = self.fields.get_field("toff")
|
||||||
|
self.fields.set_field("toff", 0)
|
||||||
|
def setup_max_duration(self, max_duration):
|
||||||
|
pass
|
||||||
|
def _do_set_digital(self, print_time, value):
|
||||||
|
toff_val = 0
|
||||||
|
if value:
|
||||||
|
toff_val = self.toff
|
||||||
|
print_time -= 0.100 # Schedule slightly before deadline
|
||||||
|
val = self.fields.set_field("toff", toff_val)
|
||||||
|
reg_name = self.fields.lookup_register("toff")
|
||||||
|
self.mcu_tmc.set_register(reg_name, val, print_time)
|
||||||
|
def set_digital(self, print_time, value):
|
||||||
|
self.reactor.register_callback(
|
||||||
|
(lambda ev: self._do_set_digital(print_time, value)))
|
||||||
|
|
||||||
|
class TMCVirtualPinHelper:
|
||||||
|
def __init__(self, config, mcu_tmc, diag_pin=None):
|
||||||
self.printer = config.get_printer()
|
self.printer = config.get_printer()
|
||||||
self.mcu_tmc = mcu_tmc
|
self.mcu_tmc = mcu_tmc
|
||||||
self.diag_pin = diag_pin
|
self.diag_pin = diag_pin
|
||||||
|
@ -197,12 +219,18 @@ class TMCEndstopHelper:
|
||||||
ppins.register_chip("%s_%s" % (name_parts[0], name_parts[-1]), self)
|
ppins.register_chip("%s_%s" % (name_parts[0], name_parts[-1]), self)
|
||||||
def setup_pin(self, pin_type, pin_params):
|
def setup_pin(self, pin_type, pin_params):
|
||||||
ppins = self.printer.lookup_object('pins')
|
ppins = self.printer.lookup_object('pins')
|
||||||
|
if pin_params['pin'] not in ('virtual_endstop', 'virtual_enable'):
|
||||||
|
raise ppins.error("Unknown tmc virtual pin")
|
||||||
|
if pin_params['invert'] or pin_params['pullup']:
|
||||||
|
raise ppins.error("Can not pullup/invert tmc virtual pin")
|
||||||
|
if pin_params['pin'] == 'virtual_enable':
|
||||||
|
if pin_type != 'digital_out':
|
||||||
|
raise ppins.error("tmc virtual enable only useful for enable")
|
||||||
|
return TMCVirtualEnable(self.printer, self.mcu_tmc)
|
||||||
if self.diag_pin is None:
|
if self.diag_pin is None:
|
||||||
raise ppins.error("tmc virtual endstop requires diag pin config")
|
raise ppins.error("tmc virtual endstop requires diag pin config")
|
||||||
if pin_type != 'endstop' or pin_params['pin'] != 'virtual_endstop':
|
if pin_type != 'endstop':
|
||||||
raise ppins.error("tmc virtual endstop only useful as endstop")
|
raise ppins.error("tmc virtual endstop only useful as endstop")
|
||||||
if pin_params['invert'] or pin_params['pullup']:
|
|
||||||
raise ppins.error("Can not pullup/invert tmc virtual endstop")
|
|
||||||
mcu_endstop = ppins.setup_pin('endstop', self.diag_pin)
|
mcu_endstop = ppins.setup_pin('endstop', self.diag_pin)
|
||||||
return TMCVirtualEndstop(self.mcu_tmc, mcu_endstop)
|
return TMCVirtualEndstop(self.mcu_tmc, mcu_endstop)
|
||||||
|
|
||||||
|
|
|
@ -208,9 +208,9 @@ class TMC2130:
|
||||||
# Setup mcu communication
|
# Setup mcu communication
|
||||||
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
|
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
|
||||||
self.mcu_tmc = MCU_TMC_SPI(config, Registers, self.fields)
|
self.mcu_tmc = MCU_TMC_SPI(config, Registers, self.fields)
|
||||||
# Allow virtual endstop to be created
|
# Allow virtual pins to be created
|
||||||
diag1_pin = config.get('diag1_pin', None)
|
diag1_pin = config.get('diag1_pin', None)
|
||||||
tmc.TMCEndstopHelper(config, self.mcu_tmc, diag1_pin)
|
tmc.TMCVirtualPinHelper(config, self.mcu_tmc, diag1_pin)
|
||||||
# Register commands
|
# Register commands
|
||||||
cmdhelper = tmc.TMCCommandHelper(config, self.mcu_tmc)
|
cmdhelper = tmc.TMCCommandHelper(config, self.mcu_tmc)
|
||||||
cmdhelper.setup_register_dump(ReadRegisters)
|
cmdhelper.setup_register_dump(ReadRegisters)
|
||||||
|
|
|
@ -187,6 +187,8 @@ class TMC2208:
|
||||||
# Setup mcu communication
|
# Setup mcu communication
|
||||||
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
|
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
|
||||||
self.mcu_tmc = tmc_uart.MCU_TMC_uart(config, Registers, self.fields)
|
self.mcu_tmc = tmc_uart.MCU_TMC_uart(config, Registers, self.fields)
|
||||||
|
# Allow virtual pins to be created
|
||||||
|
tmc.TMCVirtualPinHelper(config, self.mcu_tmc)
|
||||||
# Register commands
|
# Register commands
|
||||||
cmdhelper = tmc.TMCCommandHelper(config, self.mcu_tmc)
|
cmdhelper = tmc.TMCCommandHelper(config, self.mcu_tmc)
|
||||||
cmdhelper.setup_register_dump(ReadRegisters, self.read_translate)
|
cmdhelper.setup_register_dump(ReadRegisters, self.read_translate)
|
||||||
|
|
|
@ -59,6 +59,8 @@ class TMC2209:
|
||||||
self.fields = tmc.FieldHelper(Fields, tmc2208.SignedFields,
|
self.fields = tmc.FieldHelper(Fields, tmc2208.SignedFields,
|
||||||
FieldFormatters)
|
FieldFormatters)
|
||||||
self.mcu_tmc = tmc_uart.MCU_TMC_uart(config, Registers, self.fields)
|
self.mcu_tmc = tmc_uart.MCU_TMC_uart(config, Registers, self.fields)
|
||||||
|
# Allow virtual pins to be created
|
||||||
|
tmc.TMCVirtualPinHelper(config, self.mcu_tmc)
|
||||||
# Register commands
|
# Register commands
|
||||||
cmdhelper = tmc.TMCCommandHelper(config, self.mcu_tmc)
|
cmdhelper = tmc.TMCCommandHelper(config, self.mcu_tmc)
|
||||||
cmdhelper.setup_register_dump(ReadRegisters)
|
cmdhelper.setup_register_dump(ReadRegisters)
|
||||||
|
|
|
@ -23,7 +23,7 @@ Fields["DRVCTRL"] = {
|
||||||
}
|
}
|
||||||
|
|
||||||
Fields["CHOPCONF"] = {
|
Fields["CHOPCONF"] = {
|
||||||
"TOFF": 0x0f,
|
"toff": 0x0f,
|
||||||
"HSTRT": 0x7 << 4,
|
"HSTRT": 0x7 << 4,
|
||||||
"HEND": 0x0f << 7,
|
"HEND": 0x0f << 7,
|
||||||
"HDEC": 0x03 << 11,
|
"HDEC": 0x03 << 11,
|
||||||
|
@ -101,7 +101,7 @@ FieldFormatters = {
|
||||||
"DEDGE": (lambda v:
|
"DEDGE": (lambda v:
|
||||||
"1(Both Edges Active)" if v else "0(Only Rising Edge active)"),
|
"1(Both Edges Active)" if v else "0(Only Rising Edge active)"),
|
||||||
"INTPOL": (lambda v: "1(On)" if v else "0(Off)"),
|
"INTPOL": (lambda v: "1(On)" if v else "0(Off)"),
|
||||||
"TOFF": (lambda v: ("%d" % v) if v else "0(Driver Disabled!)"),
|
"toff": (lambda v: ("%d" % v) if v else "0(Driver Disabled!)"),
|
||||||
"CHM": (lambda v: "1(constant toff)" if v else "0(spreadCycle)"),
|
"CHM": (lambda v: "1(constant toff)" if v else "0(spreadCycle)"),
|
||||||
"SFILT": (lambda v: "1(Filtered mode)" if v else "0(Standard mode)"),
|
"SFILT": (lambda v: "1(Filtered mode)" if v else "0(Standard mode)"),
|
||||||
"VSENSE": (lambda v: "%d(%dmV)" % (v, 165 if v else 305)),
|
"VSENSE": (lambda v: "%d(%dmV)" % (v, 165 if v else 305)),
|
||||||
|
@ -242,6 +242,8 @@ class TMC2660:
|
||||||
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
|
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
|
||||||
self.fields.set_field("SDOFF", 0) # Access DRVCTRL in step/dir mode
|
self.fields.set_field("SDOFF", 0) # Access DRVCTRL in step/dir mode
|
||||||
self.mcu_tmc = MCU_TMC2660_SPI(config, Registers, self.fields)
|
self.mcu_tmc = MCU_TMC2660_SPI(config, Registers, self.fields)
|
||||||
|
# Allow virtual pins to be created
|
||||||
|
tmc.TMCVirtualPinHelper(config, self.mcu_tmc)
|
||||||
# Register commands
|
# Register commands
|
||||||
cmdhelper = tmc.TMCCommandHelper(config, self.mcu_tmc)
|
cmdhelper = tmc.TMCCommandHelper(config, self.mcu_tmc)
|
||||||
cmdhelper.setup_register_dump(ReadRegisters)
|
cmdhelper.setup_register_dump(ReadRegisters)
|
||||||
|
@ -259,7 +261,7 @@ class TMC2660:
|
||||||
set_config_field(config, "CHM", 0)
|
set_config_field(config, "CHM", 0)
|
||||||
set_config_field(config, "HEND", 3)
|
set_config_field(config, "HEND", 3)
|
||||||
set_config_field(config, "HSTRT", 3)
|
set_config_field(config, "HSTRT", 3)
|
||||||
set_config_field(config, "TOFF", 4)
|
set_config_field(config, "toff", 4)
|
||||||
if not self.fields.get_field("CHM"):
|
if not self.fields.get_field("CHM"):
|
||||||
if (self.fields.get_field("HSTRT") +
|
if (self.fields.get_field("HSTRT") +
|
||||||
self.fields.get_field("HEND")) > 15:
|
self.fields.get_field("HEND")) > 15:
|
||||||
|
|
|
@ -291,9 +291,9 @@ class TMC5160:
|
||||||
# Setup mcu communication
|
# Setup mcu communication
|
||||||
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
|
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
|
||||||
self.mcu_tmc = tmc2130.MCU_TMC_SPI(config, Registers, self.fields)
|
self.mcu_tmc = tmc2130.MCU_TMC_SPI(config, Registers, self.fields)
|
||||||
# Allow virtual endstop to be created
|
# Allow virtual pins to be created
|
||||||
diag1_pin = config.get('diag1_pin', None)
|
diag1_pin = config.get('diag1_pin', None)
|
||||||
tmc.TMCEndstopHelper(config, self.mcu_tmc, diag1_pin)
|
tmc.TMCVirtualPinHelper(config, self.mcu_tmc, diag1_pin)
|
||||||
# Register commands
|
# Register commands
|
||||||
cmdhelper = tmc.TMCCommandHelper(config, self.mcu_tmc)
|
cmdhelper = tmc.TMCCommandHelper(config, self.mcu_tmc)
|
||||||
cmdhelper.setup_register_dump(ReadRegisters)
|
cmdhelper.setup_register_dump(ReadRegisters)
|
||||||
|
|
Loading…
Reference in New Issue