plus4的klipper版本

This commit is contained in:
whb0514
2024-09-02 13:37:34 +08:00
parent 653d7a8f6e
commit b90736975b
1006 changed files with 1195894 additions and 11114 deletions

View File

@@ -11,10 +11,12 @@ TMC_FREQUENCY=13200000.
Registers = {
"GCONF": 0x00, "GSTAT": 0x01, "IOIN": 0x04, "IHOLD_IRUN": 0x10,
"TPOWERDOWN": 0x11, "TSTEP": 0x12, "TPWMTHRS": 0x13, "TCOOLTHRS": 0x14,
"THIGH": 0x15, "XDIRECT": 0x2d, "MSLUT0": 0x60, "MSLUTSEL": 0x68,
"MSLUTSTART": 0x69, "MSCNT": 0x6a, "MSCURACT": 0x6b, "CHOPCONF": 0x6c,
"COOLCONF": 0x6d, "DCCTRL": 0x6e, "DRV_STATUS": 0x6f, "PWMCONF": 0x70,
"PWM_SCALE": 0x71, "ENCM_CTRL": 0x72, "LOST_STEPS": 0x73,
"THIGH": 0x15, "XDIRECT": 0x2d, "MSLUT0": 0x60, "MSLUT1": 0x61,
"MSLUT2": 0x62, "MSLUT3": 0x63, "MSLUT4": 0x64, "MSLUT5": 0x65,
"MSLUT6": 0x66, "MSLUT7": 0x67, "MSLUTSEL": 0x68, "MSLUTSTART": 0x69,
"MSCNT": 0x6a, "MSCURACT": 0x6b, "CHOPCONF": 0x6c, "COOLCONF": 0x6d,
"DCCTRL": 0x6e, "DRV_STATUS": 0x6f, "PWMCONF": 0x70, "PWM_SCALE": 0x71,
"ENCM_CTRL": 0x72, "LOST_STEPS": 0x73,
}
ReadRegisters = [
@@ -45,6 +47,27 @@ Fields["TSTEP"] = { "tstep": 0xfffff }
Fields["TPWMTHRS"] = { "tpwmthrs": 0xfffff }
Fields["TCOOLTHRS"] = { "tcoolthrs": 0xfffff }
Fields["THIGH"] = { "thigh": 0xfffff }
Fields["MSLUT0"] = { "mslut0": 0xffffffff }
Fields["MSLUT1"] = { "mslut1": 0xffffffff }
Fields["MSLUT2"] = { "mslut2": 0xffffffff }
Fields["MSLUT3"] = { "mslut3": 0xffffffff }
Fields["MSLUT4"] = { "mslut4": 0xffffffff }
Fields["MSLUT5"] = { "mslut5": 0xffffffff }
Fields["MSLUT6"] = { "mslut6": 0xffffffff }
Fields["MSLUT7"] = { "mslut7": 0xffffffff }
Fields["MSLUTSEL"] = {
"x3": 0xFF << 24,
"x2": 0xFF << 16,
"x1": 0xFF << 8,
"w3": 0x03 << 6,
"w2": 0x03 << 4,
"w1": 0x03 << 2,
"w0": 0x03 << 0,
}
Fields["MSLUTSTART"] = {
"start_sin": 0xFF << 0,
"start_sin90": 0xFF << 16,
}
Fields["MSCNT"] = { "mscnt": 0x3ff }
Fields["MSCURACT"] = { "cur_a": 0x1ff, "cur_b": 0x1ff << 16 }
Fields["CHOPCONF"] = {
@@ -225,13 +248,14 @@ def lookup_tmc_spi_chain(config):
# Helper code for working with TMC devices via SPI
class MCU_TMC_SPI:
def __init__(self, config, name_to_reg, fields):
def __init__(self, config, name_to_reg, fields, tmc_frequency):
self.printer = config.get_printer()
self.name = config.get_name().split()[-1]
self.tmc_spi, self.chain_pos = lookup_tmc_spi_chain(config)
self.mutex = self.tmc_spi.mutex
self.name_to_reg = name_to_reg
self.fields = fields
self.tmc_frequency = tmc_frequency
def get_fields(self):
return self.fields
def get_register(self, reg_name):
@@ -248,6 +272,8 @@ class MCU_TMC_SPI:
return
raise self.printer.command_error(
"Unable to write tmc spi '%s' register %s" % (self.name, reg_name))
def get_tmc_frequency(self):
return self.tmc_frequency
######################################################################
@@ -258,7 +284,8 @@ class TMC2130:
def __init__(self, config):
# Setup mcu communication
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,
TMC_FREQUENCY)
# Allow virtual pins to be created
tmc.TMCVirtualPinHelper(config, self.mcu_tmc)
# Register commands
@@ -268,20 +295,26 @@ class TMC2130:
self.get_phase_offset = cmdhelper.get_phase_offset
self.get_status = cmdhelper.get_status
# Setup basic register values
tmc.TMCWaveTableHelper(config, self.mcu_tmc)
tmc.TMCStealthchopHelper(config, self.mcu_tmc, TMC_FREQUENCY)
# Allow other registers to be set from the config
set_config_field = self.fields.set_config_field
# CHOPCONF
set_config_field(config, "toff", 4)
set_config_field(config, "hstrt", 0)
set_config_field(config, "hend", 7)
set_config_field(config, "tbl", 1)
# COOLCONF
set_config_field(config, "sgt", 0)
# IHOLDIRUN
set_config_field(config, "iholddelay", 8)
set_config_field(config, "tpowerdown", 0)
# PWMCONF
set_config_field(config, "pwm_ampl", 128)
set_config_field(config, "pwm_grad", 4)
set_config_field(config, "pwm_freq", 1)
set_config_field(config, "pwm_autoscale", True)
set_config_field(config, "sgt", 0)
# TPOWERDOWN
set_config_field(config, "tpowerdown", 0)
def load_config_prefix(config):
return TMC2130(config)