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):
|
||||
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):
|
||||
self.set_current(print_time, (float(self.idle_current_percentage)
|
||||
* self.current / 100))
|
||||
current = self.current * float(self.idle_current_percentage) / 100.
|
||||
self.printer.get_reactor().register_callback(
|
||||
(lambda ev: self.set_current(print_time, current)))
|
||||
|
||||
def set_current(self, print_time, current):
|
||||
vsense, cs = self._calc_current(current)
|
||||
|
@ -204,6 +206,7 @@ class TMC2660CurrentHelper:
|
|||
class MCU_TMC2660_SPI:
|
||||
def __init__(self, config, name_to_reg, fields):
|
||||
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.name_to_reg = name_to_reg
|
||||
self.fields = fields
|
||||
|
@ -215,7 +218,8 @@ class MCU_TMC2660_SPI:
|
|||
if self.printer.get_start_args().get('debugoutput') is not None:
|
||||
return 0
|
||||
msg = [((val >> 16) | reg) & 0xff, (val >> 8) & 0xff, val & 0xff]
|
||||
params = self.spi.spi_transfer(msg)
|
||||
with self.mutex:
|
||||
params = self.spi.spi_transfer(msg)
|
||||
pr = bytearray(params['response'])
|
||||
return (pr[0] << 16) | (pr[1] << 8) | pr[2]
|
||||
def set_register(self, reg_name, val, print_time=None):
|
||||
|
@ -224,7 +228,8 @@ class MCU_TMC2660_SPI:
|
|||
minclock = self.spi.get_mcu().print_time_to_clock(print_time)
|
||||
reg = self.name_to_reg[reg_name]
|
||||
msg = [((val >> 16) | reg) & 0xff, (val >> 8) & 0xff, val & 0xff]
|
||||
self.spi.spi_send(msg, minclock)
|
||||
with self.mutex:
|
||||
self.spi.spi_send(msg, minclock)
|
||||
|
||||
|
||||
######################################################################
|
||||
|
|
Loading…
Reference in New Issue