diff options
Diffstat (limited to 'klippy/extras/tmc2209.py')
-rw-r--r-- | klippy/extras/tmc2209.py | 63 |
1 files changed, 28 insertions, 35 deletions
diff --git a/klippy/extras/tmc2209.py b/klippy/extras/tmc2209.py index 96b7424d..5fc3ae17 100644 --- a/klippy/extras/tmc2209.py +++ b/klippy/extras/tmc2209.py @@ -5,46 +5,37 @@ # This file may be distributed under the terms of the GNU GPLv3 license. from . import tmc2208, tmc2130, tmc, tmc_uart -TMC_FREQUENCY=12000000. +TMC_FREQUENCY = 12000000.0 Registers = dict(tmc2208.Registers) -Registers.update({ - "TCOOLTHRS": 0x14, - "COOLCONF": 0x42, - "SGTHRS": 0x40, - "SG_RESULT": 0x41 -}) +Registers.update( + {"TCOOLTHRS": 0x14, "COOLCONF": 0x42, "SGTHRS": 0x40, "SG_RESULT": 0x41} +) ReadRegisters = tmc2208.ReadRegisters + ["SG_RESULT"] Fields = dict(tmc2208.Fields) Fields["COOLCONF"] = { - "semin": 0x0F << 0, - "seup": 0x03 << 5, - "semax": 0x0F << 8, - "sedn": 0x03 << 13, - "seimin": 0x01 << 15 + "semin": 0x0F << 0, + "seup": 0x03 << 5, + "semax": 0x0F << 8, + "sedn": 0x03 << 13, + "seimin": 0x01 << 15, } Fields["IOIN"] = { - "enn": 0x01 << 0, - "ms1": 0x01 << 2, - "ms2": 0x01 << 3, - "diag": 0x01 << 4, - "pdn_uart": 0x01 << 6, - "step": 0x01 << 7, - "spread_en": 0x01 << 8, - "dir": 0x01 << 9, - "version": 0xff << 24 -} -Fields["SGTHRS"] = { - "sgthrs": 0xFF << 0 -} -Fields["SG_RESULT"] = { - "sg_result": 0x3FF << 0 -} -Fields["TCOOLTHRS"] = { - "tcoolthrs": 0xfffff + "enn": 0x01 << 0, + "ms1": 0x01 << 2, + "ms2": 0x01 << 3, + "diag": 0x01 << 4, + "pdn_uart": 0x01 << 6, + "step": 0x01 << 7, + "spread_en": 0x01 << 8, + "dir": 0x01 << 9, + "version": 0xFF << 24, } +Fields["SGTHRS"] = {"sgthrs": 0xFF << 0} +Fields["SG_RESULT"] = {"sg_result": 0x3FF << 0} +Fields["TCOOLTHRS"] = {"tcoolthrs": 0xFFFFF} FieldFormatters = dict(tmc2208.FieldFormatters) @@ -53,16 +44,17 @@ FieldFormatters = dict(tmc2208.FieldFormatters) # TMC2209 printer object ###################################################################### + class TMC2209: def __init__(self, config): # Setup mcu communication - self.fields = tmc.FieldHelper(Fields, tmc2208.SignedFields, - FieldFormatters) - self.mcu_tmc = tmc_uart.MCU_TMC_uart(config, Registers, self.fields, 3, - TMC_FREQUENCY) + self.fields = tmc.FieldHelper(Fields, tmc2208.SignedFields, FieldFormatters) + self.mcu_tmc = tmc_uart.MCU_TMC_uart( + config, Registers, self.fields, 3, TMC_FREQUENCY + ) # Setup fields for UART self.fields.set_field("pdn_disable", True) - self.fields.set_field("senddelay", 2) # Avoid tx errors on shared uart + self.fields.set_field("senddelay", 2) # Avoid tx errors on shared uart # Allow virtual pins to be created tmc.TMCVirtualPinHelper(config, self.mcu_tmc) # Register commands @@ -106,5 +98,6 @@ class TMC2209: # SGTHRS set_config_field(config, "sgthrs", 0) + def load_config_prefix(config): return TMC2209(config) |