1
0
mirror of https://github.com/xtacocorex/CHIP_IO synced 2025-07-20 04:43:21 +00:00

Fixed SPI dtbo and verification. i2c-1 is still off, waiting to hear back from NTC crew on that. Added test case for the OverlayManager. Fof feature #10

This commit is contained in:
Robert Wolterman
2016-07-16 15:23:43 -05:00
parent 00140c2008
commit 44121ed5eb
3 changed files with 63 additions and 6 deletions

View File

@ -10,6 +10,8 @@ CUSTOMOVERLAYFILEPATH = ""
PWMSYSFSPATH = "/sys/class/pwm/pwmchip0"
I2C1SYSFSPATH = "/sys/class/i2c-dev/i2c-1"
# USING THE BASE DIRECTORY FOR SPI AS THE DEVICE NUMBER CHANGES ON LOAD/UNLOAD
SPI2SYSFSPATH = "/sys/class/spi_master/"
# LOADED VARIABLES
# DO NOT MODIFY BY HAND WHEN USING
@ -108,6 +110,15 @@ def _set_overlay_verify(name, overlay_path, config_path):
if DEBUG:
print("ERROR LOADING I2C-1")
return 1
elif name == "SPI2":
if os.listdir(SPI2SYSFSPATH) != "":
if DEBUG:
print("SPI2 IS LOADED!")
return 0
else:
if DEBUG:
print("ERROR LOADING SPI2")
return 0
def load(overlay, path=""):
"""
@ -125,9 +136,7 @@ def load(overlay, path=""):
global DEBUG
global _LOADED
if DEBUG:
print("LOAD OVERLAY")
print("OVERLAY: {0}".format(overlay))
print("PATH: {0}".format(path))
print("LOAD OVERLAY: {0} @ {1}".format(overlay,path))
# SEE IF OUR OVERLAY NAME IS IN THE KEYS
if overlay.upper() in _OVERLAYS.keys():
cpath = OVERLAYCONFIGPATH + "/" + _FOLDERS[overlay.upper()]
@ -168,7 +177,7 @@ def load(overlay, path=""):
# LOAD THE OVERLAY
errc = _set_overlay_verify(overlay.upper(), opath, cpath)
if DEBUG:
print("ERRC: {0}".format(errc))
print("_SET_OVERLAY_VERIFY ERRC: {0}".format(errc))
if errc == 0:
_LOADED[overlay.upper()] = True
@ -179,8 +188,7 @@ def unload(overlay):
global DEBUG
global _LOADED
if DEBUG:
print("UNLOAD OVERLAY")
print(overlay)
print("UNLOAD OVERLAY: {0}".format(overlay))
# SEE IF OUR OVERLAY NAME IS IN THE KEYS
if overlay.upper() in _OVERLAYS.keys():
# BRUTE FORCE REMOVE AS THE DIRECTORY CONTAINS FILES

Binary file not shown.

49
test/omtest.py Executable file
View File

@ -0,0 +1,49 @@
#!/usr/bin/python
import CHIP_IO.OverlayManager as OM
import os
# ENABLE DEBUG
print("ENABLING OVERLAY MANAGER DEBUG")
OM.enable_debug()
# **************** PWM *******************
print("\nIS PWM ENABLED: {0}".format(OM.get_pwm_loaded()))
OM.load("PWM0")
print("IS PWM ENABLED: {0}".format(OM.get_pwm_loaded()))
# VERIFY PWM0 EXISTS
if os.path.exists('/sys/class/pwm/pwmchip0'):
print("PWM DEVICE EXISTS")
else:
print("PWM DEVICE DID NOT LOAD PROPERLY")
print("UNLOADING PWM0")
OM.unload("PWM0")
print("IS PWM ENABLED: {0}".format(OM.get_pwm_loaded()))
# **************** I2C-1 *******************
print("\nIS I2C ENABLED: {0}".format(OM.get_i2c_loaded()))
OM.load("I2C1")
print("IS I2C ENABLED: {0}".format(OM.get_i2c_loaded()))
# VERIFY I2C-1 EXISTS
if os.path.exists('/sys/class/i2c-dev/i2c-1'):
print("I2C1 DEVICE EXISTS")
else:
print("I2C1 DEVICE DID NOT LOAD PROPERLY")
print("UNLOADING I2C1")
OM.unload("I2C1")
print("IS I2C ENABLED: {0}".format(OM.get_i2c_loaded()))
# **************** SPI2 *******************
print("\nIS SPI ENABLED: {0}".format(OM.get_spi_loaded()))
OM.load("SPI2")
print("IS SPI ENABLED: {0}".format(OM.get_spi_loaded()))
# VERIFY SPI2 EXISTS
if os.listdir('/sys/class/spi_master') != "":
print("SPI DEVICE EXISTS")
else:
print("SPI DEVICE DID NOT LOAD PROPERLY")
print("UNLOADING SPI")
OM.unload("SPI2")
print("IS SPI ENABLED: {0}".format(OM.get_spi_loaded()))