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>
This commit is contained in:
Kevin O'Connor 2019-01-04 22:26:34 -05:00
parent 24fe606d4d
commit c3efcd9c8d
1 changed files with 5 additions and 2 deletions

View File

@ -17,12 +17,14 @@ class MCU_SPI:
shutdown_msg = "".join(["%02x" % (x,) for x in shutdown_seq]) shutdown_msg = "".join(["%02x" % (x,) for x in shutdown_seq])
self.oid = self.mcu.create_oid() self.oid = self.mcu.create_oid()
if pin is None: if pin is None:
self.mcu.add_config_cmd( self.config_msg = (
"config_spi_without_cs oid=%d bus=%d mode=%d rate=%d" "config_spi_without_cs oid=%d bus=%d mode=%d rate=%d"
" shutdown_msg=%s" % ( " shutdown_msg=%s" % (
self.oid, bus, mode, speed, shutdown_msg)) self.oid, bus, mode, speed, shutdown_msg))
else: 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" "config_spi oid=%d bus=%d pin=%s mode=%d rate=%d"
" shutdown_msg=%s" % ( " shutdown_msg=%s" % (
self.oid, bus, pin, mode, speed, shutdown_msg)) self.oid, bus, pin, mode, speed, shutdown_msg))
@ -36,6 +38,7 @@ class MCU_SPI:
def get_command_queue(self): def get_command_queue(self):
return self.cmd_queue return self.cmd_queue
def build_config(self): def build_config(self):
self.mcu.add_config_cmd(self.config_msg)
self.spi_send_cmd = self.mcu.lookup_command( self.spi_send_cmd = self.mcu.lookup_command(
"spi_send oid=%c data=%*s", cq=self.cmd_queue) "spi_send oid=%c data=%*s", cq=self.cmd_queue)
self.spi_transfer_cmd = self.mcu.lookup_command( self.spi_transfer_cmd = self.mcu.lookup_command(