Skip to content

Commit 00d3912

Browse files
authored
Merge pull request #14 from myDevicesIoT/fix/pi3-gpio
Use filesystem drivers for GPIO info on Pi 3.
2 parents 13f556c + 22a4881 commit 00d3912

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

myDevices/devices/digital/gpio.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ def __init__(self):
6969
self.__checkFilesystemExport__(pin)
7070
if gpio_library:
7171
gpio_library.setmode(gpio_library.ASUS)
72-
else:
72+
elif not Hardware().isRaspberryPi3():
73+
# On the Pi 3 the memory mapped /dev/gpiomem file seems to give strange, inconsistent readings, like duplicated
74+
# 4 byte sequences and "oipg" ASCII values. This might be some issue with the way Python mmap works since it didn't
75+
# seem to happen with the wiringPi C library using uint32_t pointers. For now we just avoid using /dev/gpiomem on Pi 3.
7376
try:
7477
with open('/dev/gpiomem', 'rb') as gpiomem:
7578
self.gpio_map = mmap.mmap(gpiomem.fileno(), BLOCK_SIZE, prot=mmap.PROT_READ)
@@ -350,31 +353,31 @@ def getFunction(self, channel):
350353
return self.__getFunction__(channel)
351354

352355
def getFunctionString(self, channel):
353-
f = self.getFunction(channel)
356+
f = -1
354357
function_string = 'UNKNOWN'
355358
functions = {0:'IN', 1:'OUT', 2:'ALT5', 3:'ALT4', 4:'ALT0', 5:'ALT1', 6:'ALT2', 7:'ALT3', 8:'PWM',
356359
40:'SERIAL', 41:'SPI', 42:'I2C', 43:'PWM', 44:'GPIO', 45:'TS_XXXX', 46:'RESERVED', 47:'I2S'}
357-
if f >= 0:
358-
try:
359-
function_string = functions[f]
360-
except:
361-
pass
362-
try:
363-
# On Raspberry Pis using the spi_bcm2835 driver SPI chip select is done via software rather than hardware
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:
369-
function_string = functions[4]
370-
except:
371-
pass
372-
try:
373-
# If 1-Wire is enabled specify the pin function as a device tree overlay.
374-
if channel in self.overlay_pins:
375-
function_string = 'OVERLAY'
376-
except:
377-
pass
360+
try:
361+
f = self.getFunction(channel)
362+
function_string = functions[f]
363+
except:
364+
pass
365+
try:
366+
# On Raspberry Pis using the spi_bcm2835 driver SPI chip select is done via software rather than hardware
367+
# so the pin function is OUT instead of ALT0. Here we override that (and the I2C to be safe) so the GPIO map
368+
# in the UI will display the appropriate pin info.
369+
if channel in self.spi_pins and self.system_config['SPI'] == 1:
370+
function_string = functions[4]
371+
if channel in self.i2c_pins and self.system_config['I2C'] == 1:
372+
function_string = functions[4]
373+
except:
374+
pass
375+
try:
376+
# If 1-Wire is enabled specify the pin function as a device tree overlay.
377+
if channel in self.overlay_pins:
378+
function_string = 'OVERLAY'
379+
except:
380+
pass
378381
return function_string
379382

380383
def setPinMapping(self):

myDevices/system/hardware.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ def isRaspberryPi(self):
139139
"""Return True if device is a Raspberry Pi"""
140140
return 'Raspberry Pi' in self.model
141141

142+
def isRaspberryPi3(self):
143+
"""Return True if device is a Raspberry Pi 3"""
144+
return 'Raspberry Pi 3' in self.model
145+
142146
def isTinkerBoard(self):
143147
"""Return True if device is a Tinker Board"""
144148
return 'Tinker Board' == self.model

0 commit comments

Comments
 (0)