tmc2660: Hold a mutex during MCU_TMC2660_SPI get/set_register()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
1f3b74d2f7
commit
844dca9c6e
|
@ -170,11 +170,13 @@ class TMC2660CurrentHelper:
|
||||||
|
|
||||||
def handle_printing(self, print_time):
|
def handle_printing(self, print_time):
|
||||||
print_time -= 0.100 # Schedule slightly before deadline
|
print_time -= 0.100 # Schedule slightly before deadline
|
||||||
self.set_current(print_time, self.current)
|
self.printer.get_reactor().register_callback(
|
||||||
|
(lambda ev: self.set_current(print_time, self.current)))
|
||||||
|
|
||||||
def handle_ready(self, print_time):
|
def handle_ready(self, print_time):
|
||||||
self.set_current(print_time, (float(self.idle_current_percentage)
|
current = self.current * float(self.idle_current_percentage) / 100.
|
||||||
* self.current / 100))
|
self.printer.get_reactor().register_callback(
|
||||||
|
(lambda ev: self.set_current(print_time, current)))
|
||||||
|
|
||||||
def set_current(self, print_time, current):
|
def set_current(self, print_time, current):
|
||||||
vsense, cs = self._calc_current(current)
|
vsense, cs = self._calc_current(current)
|
||||||
|
@ -204,6 +206,7 @@ class TMC2660CurrentHelper:
|
||||||
class MCU_TMC2660_SPI:
|
class MCU_TMC2660_SPI:
|
||||||
def __init__(self, config, name_to_reg, fields):
|
def __init__(self, config, name_to_reg, fields):
|
||||||
self.printer = config.get_printer()
|
self.printer = config.get_printer()
|
||||||
|
self.mutex = self.printer.get_reactor().mutex()
|
||||||
self.spi = bus.MCU_SPI_from_config(config, 0, default_speed=4000000)
|
self.spi = bus.MCU_SPI_from_config(config, 0, default_speed=4000000)
|
||||||
self.name_to_reg = name_to_reg
|
self.name_to_reg = name_to_reg
|
||||||
self.fields = fields
|
self.fields = fields
|
||||||
|
@ -215,6 +218,7 @@ class MCU_TMC2660_SPI:
|
||||||
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
|
||||||
msg = [((val >> 16) | reg) & 0xff, (val >> 8) & 0xff, val & 0xff]
|
msg = [((val >> 16) | reg) & 0xff, (val >> 8) & 0xff, val & 0xff]
|
||||||
|
with self.mutex:
|
||||||
params = self.spi.spi_transfer(msg)
|
params = self.spi.spi_transfer(msg)
|
||||||
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]
|
||||||
|
@ -224,6 +228,7 @@ class MCU_TMC2660_SPI:
|
||||||
minclock = self.spi.get_mcu().print_time_to_clock(print_time)
|
minclock = self.spi.get_mcu().print_time_to_clock(print_time)
|
||||||
reg = self.name_to_reg[reg_name]
|
reg = self.name_to_reg[reg_name]
|
||||||
msg = [((val >> 16) | reg) & 0xff, (val >> 8) & 0xff, val & 0xff]
|
msg = [((val >> 16) | reg) & 0xff, (val >> 8) & 0xff, val & 0xff]
|
||||||
|
with self.mutex:
|
||||||
self.spi.spi_send(msg, minclock)
|
self.spi.spi_send(msg, minclock)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue