Skip to content

Commit

Permalink
Fix 26 pin GPIO handling
Browse files Browse the repository at this point in the history
  • Loading branch information
enesbcs committed Jan 4, 2019
1 parent 2708a14 commit 1c14329
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 50 deletions.
17 changes: 15 additions & 2 deletions gpios.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,15 @@ def disable_i2c(self,channel):

def is_spi_usable(self,channel):
result = False
try:
channel = int(channel)
except:
return False
if channel==0:
if self.pinnum=="26R1" or self.pinnum=="26R2" or self.pinnum=="40":
if str(self.pinnum)=="26R1" or str(self.pinnum)=="26R2" or str(self.pinnum)=="40":
result = True
else:
if self.pinnum=="40":
if str(self.pinnum)=="40":
result = True
return result

Expand All @@ -613,6 +617,11 @@ def is_spi_enabled(self,channel):
return False

def enable_spi(self,channel,cs=3): # cs can 1,2,3 for spi1, 2 for spi0
try:
channel=int(channel)
cs=int(cs)
except:
return False
if self.is_spi_usable(channel):
if (self.is_spi_enabled(channel)==False):
self.spi_channels.append(channel)
Expand All @@ -637,6 +646,10 @@ def enable_spi(self,channel,cs=3): # cs can 1,2,3 for spi1, 2 for spi0
Settings.Pinout[36]["altfunc"] = 1

def disable_spi(self,channel):
try:
channel=int(channel)
except:
return False
if self.is_spi_enabled(channel):
self.spi_channels.remove(channel)
if channel==0:
Expand Down
137 changes: 89 additions & 48 deletions webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,58 +618,90 @@ def handle_pinout(self):

if arg("reread",responsearr) != '':
submit = ''
gpios.HWPorts.readconfig()

try:
gpios.HWPorts.readconfig()
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"Config read error="+str(e))

if (submit=="Submit") or (setbtn!=''):
stat = arg("i2c0",responsearr)
if stat=="on":
gpios.HWPorts.enable_i2c(0)
else:
gpios.HWPorts.disable_i2c(0)
stat = arg("i2c1",responsearr)
if stat=="on":
gpios.HWPorts.enable_i2c(1)
else:
gpios.HWPorts.disable_i2c(1)
try:
stat = arg("i2c0",responsearr)
if stat=="on":
gpios.HWPorts.enable_i2c(0)
else:
gpios.HWPorts.disable_i2c(0)
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"I2C-0 error="+str(e))
try:
stat = arg("i2c1",responsearr)
if stat=="on":
gpios.HWPorts.enable_i2c(1)
else:
gpios.HWPorts.disable_i2c(1)
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"I2C-1 error="+str(e))
try:
stat = arg("spi0",responsearr)
if stat=="on":
gpios.HWPorts.enable_spi(0,2)
else:
gpios.HWPorts.disable_spi(0)
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"SPI-0 error="+str(e))

stat = arg("spi0",responsearr)
if stat=="on":
gpios.HWPorts.enable_spi(0,2)
else:
gpios.HWPorts.disable_spi(0)
try:
stat = int(arg("spi1",responsearr).strip())
except:
stat = 0
try:
if stat == "":
stat = 0
if stat == 0:
gpios.HWPorts.disable_spi(1)
else:
gpios.HWPorts.enable_spi(1,stat)
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"SPI-1 error="+str(e))

stat = int(arg("spi1",responsearr).strip())
if stat == 0:
gpios.HWPorts.disable_spi(1)
else:
gpios.HWPorts.enable_spi(1,stat)
try:
stat = arg("uart",responsearr)
if stat=="on":
gpios.HWPorts.set_serial(1)
else:
gpios.HWPorts.set_serial(0)
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"UART init error="+str(e))

stat = arg("uart",responsearr)
if stat=="on":
gpios.HWPorts.set_serial(1)
else:
gpios.HWPorts.set_serial(0)
stat = arg("audio",responsearr)
if stat=="on":
gpios.HWPorts.set_audio(1)
else:
gpios.HWPorts.set_audio(0)
stat = arg("i2s",responsearr)
if stat=="on":
gpios.HWPorts.set_i2s(1)
else:
gpios.HWPorts.set_i2s(0)
try:
stat = arg("audio",responsearr)
if stat=="on":
gpios.HWPorts.set_audio(1)
else:
gpios.HWPorts.set_audio(0)
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"Audio init error="+str(e))
try:
stat = arg("i2s",responsearr)
if stat=="on":
gpios.HWPorts.set_i2s(1)
else:
gpios.HWPorts.set_i2s(0)
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"I2S init error="+str(e))

try:
stat = int(arg("bluetooth",responsearr).strip())
stat = int(arg("bluetooth",responsearr).strip())
except:
stat=0
gpios.HWPorts.set_internal_bt(stat)
stat = arg("wifi",responsearr)
if stat=="on":
gpios.HWPorts.set_wifi(1)
else:
gpios.HWPorts.set_wifi(0)
try:
gpios.HWPorts.set_internal_bt(stat)
stat = arg("wifi",responsearr)
if stat=="on":
gpios.HWPorts.set_wifi(1)
else:
gpios.HWPorts.set_wifi(0)
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"WLAN init error="+str(e))

try:
stat = int(arg("gpumem",responsearr).strip())
Expand All @@ -679,12 +711,21 @@ def handle_pinout(self):

for p in range(len(Settings.Pinout)):
pins = arg("pinstate"+str(p),responsearr)
if pins:
gpios.HWPorts.setpinstate(p,int(pins))
if pins and pins!="" and p!= "":
try:
gpios.HWPorts.setpinstate(p,int(pins))
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"Pin "+str(p)+" "+str(e))

if OS.check_permission() and setbtn=='':
gpios.HWPorts.saveconfig()
Settings.savepinout()
try:
gpios.HWPorts.saveconfig()
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,str(e))
try:
Settings.savepinout()
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,str(e))

if (len(Settings.Pinout)>1):
TXBuffer += "<form name='frmselect' method='post'><table class='normal'>"
Expand Down

0 comments on commit 1c14329

Please sign in to comment.