mirror of https://github.com/Desuuuu/klipper.git
spi_flash: support spi protocol changes
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
7793784640
commit
7db07c46e6
|
@ -104,7 +104,10 @@ GET_CFG_RESPONSES = ( # Supported responses (sorted by newer revisions first).
|
||||||
"config is_config=%c crc=%u move_count=%hu is_shutdown=%c" # Original
|
"config is_config=%c crc=%u move_count=%hu is_shutdown=%c" # Original
|
||||||
)
|
)
|
||||||
ALLOC_OIDS_CMD = "allocate_oids count=%d"
|
ALLOC_OIDS_CMD = "allocate_oids count=%d"
|
||||||
SPI_CFG_CMD = "config_spi oid=%d pin=%s"
|
SPI_CFG_CMDS = (
|
||||||
|
"config_spi oid=%d pin=%s cs_active_high=%d", # 7793784
|
||||||
|
"config_spi oid=%d pin=%s" # Original
|
||||||
|
)
|
||||||
SPI_BUS_CMD = "spi_set_bus oid=%d spi_bus=%s mode=%d rate=%d"
|
SPI_BUS_CMD = "spi_set_bus oid=%d spi_bus=%s mode=%d rate=%d"
|
||||||
SW_SPI_BUS_CMD = "spi_set_software_bus oid=%d " \
|
SW_SPI_BUS_CMD = "spi_set_software_bus oid=%d " \
|
||||||
"miso_pin=%s mosi_pin=%s sclk_pin=%s mode=%d rate=%d"
|
"miso_pin=%s mosi_pin=%s sclk_pin=%s mode=%d rate=%d"
|
||||||
|
@ -794,6 +797,7 @@ class MCUConnection:
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.enumerations = {}
|
self.enumerations = {}
|
||||||
self.raw_dictionary = None
|
self.raw_dictionary = None
|
||||||
|
self.proto_error = None
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
output("Connecting to MCU..")
|
output("Connecting to MCU..")
|
||||||
|
@ -821,6 +825,7 @@ class MCUConnection:
|
||||||
% (build_mcu_type, mcu_type))
|
% (build_mcu_type, mcu_type))
|
||||||
self.enumerations = msgparser.get_enumerations()
|
self.enumerations = msgparser.get_enumerations()
|
||||||
self.raw_dictionary = msgparser.get_raw_data_dictionary()
|
self.raw_dictionary = msgparser.get_raw_data_dictionary()
|
||||||
|
self.proto_error = msgparser.error
|
||||||
|
|
||||||
def _do_serial_connect(self, eventtime):
|
def _do_serial_connect(self, eventtime):
|
||||||
endtime = eventtime + 60.
|
endtime = eventtime + 60.
|
||||||
|
@ -903,15 +908,24 @@ class MCUConnection:
|
||||||
bus_cmd = SPI_BUS_CMD % (SPI_OID, bus, SPI_MODE, SD_SPI_SPEED)
|
bus_cmd = SPI_BUS_CMD % (SPI_OID, bus, SPI_MODE, SD_SPI_SPEED)
|
||||||
if cs_pin not in pin_enums:
|
if cs_pin not in pin_enums:
|
||||||
raise SPIFlashError("Invalid CS Pin: %s" % (cs_pin,))
|
raise SPIFlashError("Invalid CS Pin: %s" % (cs_pin,))
|
||||||
cfg_cmds = [
|
cfg_cmds = [ALLOC_OIDS_CMD % (1,), bus_cmd]
|
||||||
ALLOC_OIDS_CMD % (1),
|
self._serial.send(cfg_cmds[0])
|
||||||
SPI_CFG_CMD % (SPI_OID, cs_pin),
|
spi_cfg_cmds = [
|
||||||
bus_cmd,
|
SPI_CFG_CMDS[0] % (SPI_OID, cs_pin, False),
|
||||||
|
SPI_CFG_CMDS[1] % (SPI_OID, cs_pin),
|
||||||
]
|
]
|
||||||
|
for cmd in spi_cfg_cmds:
|
||||||
|
try:
|
||||||
|
self._serial.send(cmd)
|
||||||
|
except self.proto_error:
|
||||||
|
if cmd == spi_cfg_cmds[-1]:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
cfg_cmds.insert(1, cmd)
|
||||||
|
break
|
||||||
|
self._serial.send(bus_cmd)
|
||||||
config_crc = zlib.crc32('\n'.join(cfg_cmds).encode()) & 0xffffffff
|
config_crc = zlib.crc32('\n'.join(cfg_cmds).encode()) & 0xffffffff
|
||||||
cfg_cmds.append(FINALIZE_CFG_CMD % (config_crc,))
|
self._serial.send(FINALIZE_CFG_CMD % (config_crc,))
|
||||||
for cmd in cfg_cmds:
|
|
||||||
self._serial.send(cmd)
|
|
||||||
self.fatfs = FatFS(self._serial)
|
self.fatfs = FatFS(self._serial)
|
||||||
self.reactor.pause(self.reactor.monotonic() + .5)
|
self.reactor.pause(self.reactor.monotonic() + .5)
|
||||||
printfunc("Initializing SD Card and Mounting file system...")
|
printfunc("Initializing SD Card and Mounting file system...")
|
||||||
|
|
Loading…
Reference in New Issue