Skip to content

Commit a42d63b

Browse files
committed
Override SPI and I2c pin functions when they are enabled.
1 parent 0f966c8 commit a42d63b

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

myDevices/devices/digital/gpio.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ def wildcard(self, compact=False):
337337
f = "function"
338338
v = "value"
339339
values = {}
340+
self.system_config = SystemConfig.getConfig()
340341
for i in self.pins + self.overlay_pins:
341342
if compact:
342343
func = self.getFunction(i)
@@ -360,9 +361,11 @@ def getFunctionString(self, channel):
360361
pass
361362
try:
362363
# On Raspberry Pis using the spi_bcm2835 driver SPI chip select is done via software rather than hardware
363-
# so the pin function is OUT instead of ALT0. Here we override that if the SPI MOSI pin is set to ALT0
364-
# so the GPIO map in the UI will display the appropriate SPI pin info.
365-
if channel in self.chip_select_pins and f == 1 and self.getFunction(self.spi_mosi_pin) == 4:
364+
# so the pin function is OUT instead of ALT0. Here we override that (and the I2C to be safe) so the GPIO map
365+
# in the UI will display the appropriate pin info.
366+
if channel in self.spi_pins and self.system_config['SPI'] == 1:
367+
function_string = functions[4]
368+
if channel in self.i2c_pins and self.system_config['I2C'] == 1:
366369
function_string = functions[4]
367370
except:
368371
pass
@@ -626,16 +629,17 @@ def setPinMapping(self):
626629
if isinstance(self.MAPPING, list):
627630
self.pins = []
628631
self.overlay_pins = []
632+
self.spi_pins = []
633+
self.i2c_pins = []
634+
self.system_config = SystemConfig.getConfig()
629635
for header in self.MAPPING:
630636
self.pins.extend([pin['gpio'] for pin in header['map'] if 'gpio' in pin])
631637
try:
632638
if Hardware().isRaspberryPi():
633-
if SystemConfig.getConfig()['OneWire'] == 1:
639+
if self.system_config['OneWire'] == 1:
634640
self.overlay_pins.extend([pin['gpio'] for pin in header['map'] if 'overlay' in pin and pin['overlay']['channel'] == 'sys:1wire'])
635641
self.pins = [pin for pin in self.pins if pin not in self.overlay_pins]
636-
self.chip_select_pins = []
637-
self.spi_mosi_pin = 10
638-
for header in self.MAPPING:
639-
self.chip_select_pins.extend([pin['gpio'] for pin in header['map'] if 'alt0' in pin and pin['alt0']['name'] in ('CE0', 'CE1')])
642+
self.spi_pins.extend([pin['gpio'] for pin in header['map'] if 'alt0' in pin and pin['alt0']['channel'] == 'sys:spi'])
643+
self.i2c_pins.extend([pin['gpio'] for pin in header['map'] if 'alt0' in pin and pin['alt0']['channel'] == 'sys:i2c'])
640644
except:
641645
pass

0 commit comments

Comments
 (0)