tmc2660: Define get_register() method
Use a get_register() method instead of get_response(). This makes the tmc2660 class more similar to other TMC drivers. It also enables DUMP_TMC to dump all the readable content. Also, use the tmc2130.get_config_microsteps() helper. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
2b0251ee99
commit
9ce98fd769
|
@ -24,6 +24,8 @@ Registers = {
|
||||||
"CHOPCONF": 0x8, "DRVCTRL": 0x0
|
"CHOPCONF": 0x8, "DRVCTRL": 0x0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReadRegisters = [ "READRSP@RDSEL0", "READRSP@RDSEL1", "READRSP@RDSEL2" ]
|
||||||
|
|
||||||
Fields = {}
|
Fields = {}
|
||||||
|
|
||||||
Fields["DRVCTRL"] = {
|
Fields["DRVCTRL"] = {
|
||||||
|
@ -156,10 +158,8 @@ class TMC2660:
|
||||||
set_config_field = self.fields.set_config_field
|
set_config_field = self.fields.set_config_field
|
||||||
|
|
||||||
# DRVCTRL
|
# DRVCTRL
|
||||||
steps = {'256': 0, '128': 1, '64': 2, '32': 3, '16': 4,
|
mres = tmc2130.get_config_microsteps(config)
|
||||||
'8': 5, '4': 6, '2': 7, '1': 8}
|
self.fields.set_field("MRES", mres)
|
||||||
self.driver_mres = config.getchoice('microsteps', steps)
|
|
||||||
self.fields.set_field("MRES", self.driver_mres)
|
|
||||||
set_config_field(config, "DEDGE", 0)
|
set_config_field(config, "DEDGE", 0)
|
||||||
set_config_field(config, "INTPOL", True, 'interpolate')
|
set_config_field(config, "INTPOL", True, 'interpolate')
|
||||||
# CHOPCONF
|
# CHOPCONF
|
||||||
|
@ -222,13 +222,13 @@ class TMC2660:
|
||||||
self.spi.spi_send([((val >> 16) | reg) & 0xff,
|
self.spi.spi_send([((val >> 16) | reg) & 0xff,
|
||||||
(val >> 8) & 0xff, val & 0xff], min_clock)
|
(val >> 8) & 0xff, val & 0xff], min_clock)
|
||||||
|
|
||||||
def get_response(self):
|
def get_register(self, reg_name):
|
||||||
reg = Registers["DRVCTRL"]
|
reg = Registers["DRVCONF"]
|
||||||
val = self.regs["DRVCTRL"]
|
val = self.fields.set_field("RDSEL", ReadRegisters.index(reg_name))
|
||||||
if self.printer.get_start_args().get('debugoutput') is not None:
|
if self.printer.get_start_args().get('debugoutput') is not None:
|
||||||
return 0
|
return 0
|
||||||
params = self.spi.spi_transfer([((val >> 16) | reg) & 0xff,
|
params = self.spi.spi_transfer([((val >> 16) | reg) & 0xff,
|
||||||
(val >> 8) & 0xff, val & 0xff])
|
(val >> 8) & 0xff, val & 0xff])
|
||||||
pr = bytearray(params['response'])
|
pr = bytearray(params['response'])
|
||||||
return (pr[0] << 16) | (pr[1] << 8) | pr[2]
|
return (pr[0] << 16) | (pr[1] << 8) | pr[2]
|
||||||
|
|
||||||
|
@ -236,8 +236,9 @@ class TMC2660:
|
||||||
return 256 >> self.fields.get_field("MRES")
|
return 256 >> self.fields.get_field("MRES")
|
||||||
|
|
||||||
def get_phase(self):
|
def get_phase(self):
|
||||||
mscnt = self.fields.get_field("MSTEP", self.get_response())
|
reg = self.get_register("READRSP@RDSEL0")
|
||||||
return mscnt >> self.driver_mres
|
mscnt = self.fields.get_field("MSTEP", reg)
|
||||||
|
return mscnt >> self.fields.get_field("MRES")
|
||||||
|
|
||||||
def handle_printing(self, print_time):
|
def handle_printing(self, print_time):
|
||||||
self.set_current(0., self.current) # workaround
|
self.set_current(0., self.current) # workaround
|
||||||
|
@ -278,9 +279,9 @@ class TMC2660:
|
||||||
|
|
||||||
# Send one register to get the return data
|
# Send one register to get the return data
|
||||||
gcode.respond_info("========== Queried registers ==========")
|
gcode.respond_info("========== Queried registers ==========")
|
||||||
return_format = "READRSP@RDSEL" + str(self.fields.get_field("RDSEL"))
|
for reg_name in ReadRegisters:
|
||||||
msg = self.fields.pretty_format(return_format, self.get_response())
|
val = self.get_register(reg_name)
|
||||||
gcode.respond_info(msg)
|
gcode.respond_info(self.fields.pretty_format(reg_name, val))
|
||||||
|
|
||||||
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):
|
||||||
|
|
Loading…
Reference in New Issue