diff options
author | Martin Hierholzer <mhier@tartaros> | 2021-09-25 11:52:31 +0200 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2022-04-22 13:25:03 -0400 |
commit | 77937846402f011c4c49a97027606902acea7a12 (patch) | |
tree | be74983796c6a9a8a3be0cb95301e64e9f900f7d /klippy | |
parent | a02da851011b9eea2ca3083cf286341c550fb208 (diff) | |
download | kutter-77937846402f011c4c49a97027606902acea7a12.tar.gz kutter-77937846402f011c4c49a97027606902acea7a12.tar.xz kutter-77937846402f011c4c49a97027606902acea7a12.zip |
spicmds: Allow inversion of CS pin for SPI busses
Signed-off-by: Martin Hierholzer <martin@hierholzer.info>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy')
-rw-r--r-- | klippy/extras/bus.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/klippy/extras/bus.py b/klippy/extras/bus.py index 9b3e476a..f37897d8 100644 --- a/klippy/extras/bus.py +++ b/klippy/extras/bus.py @@ -39,7 +39,8 @@ def resolve_bus_name(mcu, param, bus): # Helper code for working with devices connected to an MCU via an SPI bus class MCU_SPI: - def __init__(self, mcu, bus, pin, mode, speed, sw_pins=None): + def __init__(self, mcu, bus, pin, mode, speed, sw_pins=None, + cs_active_high=False): self.mcu = mcu self.bus = bus # Config SPI object (set all CS pins high before spi_set_bus commands) @@ -47,7 +48,8 @@ class MCU_SPI: if pin is None: mcu.add_config_cmd("config_spi_without_cs oid=%d" % (self.oid,)) else: - mcu.add_config_cmd("config_spi oid=%d pin=%s" % (self.oid, pin)) + mcu.add_config_cmd("config_spi oid=%d pin=%s cs_active_high=%d" + % (self.oid, pin, cs_active_high)) # Generate SPI bus config message if sw_pins is not None: self.config_fmt = ( @@ -103,7 +105,8 @@ class MCU_SPI: # Helper to setup an spi bus from settings in a config section def MCU_SPI_from_config(config, mode, pin_option="cs_pin", - default_speed=100000, share_type=None): + default_speed=100000, share_type=None, + cs_active_high=False): # Determine pin from config ppins = config.get_printer().lookup_object("pins") cs_pin = config.get(pin_option) @@ -130,7 +133,7 @@ def MCU_SPI_from_config(config, mode, pin_option="cs_pin", bus = config.get('spi_bus', None) sw_pins = None # Create MCU_SPI object - return MCU_SPI(mcu, bus, pin, mode, speed, sw_pins) + return MCU_SPI(mcu, bus, pin, mode, speed, sw_pins, cs_active_high) ###################################################################### |