aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/bus.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-01-04 22:26:34 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-01-04 22:26:34 -0500
commitc3efcd9c8d1177019711c776bc925645a6ea6b0b (patch)
tree28d44abb51d571fabb6c278e09a2b7d500ac386c /klippy/extras/bus.py
parent24fe606d4d7df479e35caf6a3a56d52b746611d0 (diff)
downloadkutter-c3efcd9c8d1177019711c776bc925645a6ea6b0b.tar.gz
kutter-c3efcd9c8d1177019711c776bc925645a6ea6b0b.tar.xz
kutter-c3efcd9c8d1177019711c776bc925645a6ea6b0b.zip
bus: Set all SPI CS pins high before first config_spi message
If an SPI device is shared among many devices, then all the device's CS pins should be set high prior to setting up the clk pin. (Otherwise, there's a chance a device could interpret the clk pin setup as part of a transmission.) Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/bus.py')
-rw-r--r--klippy/extras/bus.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/klippy/extras/bus.py b/klippy/extras/bus.py
index 9721a591..6df95ee5 100644
--- a/klippy/extras/bus.py
+++ b/klippy/extras/bus.py
@@ -17,12 +17,14 @@ class MCU_SPI:
shutdown_msg = "".join(["%02x" % (x,) for x in shutdown_seq])
self.oid = self.mcu.create_oid()
if pin is None:
- self.mcu.add_config_cmd(
+ self.config_msg = (
"config_spi_without_cs oid=%d bus=%d mode=%d rate=%d"
" shutdown_msg=%s" % (
self.oid, bus, mode, speed, shutdown_msg))
else:
- self.mcu.add_config_cmd(
+ # Set all CS pins high before first config_spi
+ self.mcu.add_config_cmd("set_digital_out pin=%s value=1" % (pin,))
+ self.config_msg = (
"config_spi oid=%d bus=%d pin=%s mode=%d rate=%d"
" shutdown_msg=%s" % (
self.oid, bus, pin, mode, speed, shutdown_msg))
@@ -36,6 +38,7 @@ class MCU_SPI:
def get_command_queue(self):
return self.cmd_queue
def build_config(self):
+ self.mcu.add_config_cmd(self.config_msg)
self.spi_send_cmd = self.mcu.lookup_command(
"spi_send oid=%c data=%*s", cq=self.cmd_queue)
self.spi_transfer_cmd = self.mcu.lookup_command(