diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 32a294f..f8fcd55 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,10 @@ +0.2.0 +---- +* Added the ability to load DTB Overlays from within CHIP_IO + - Support for PWM0, SPI2, and I2C-1 (which comes back as i2c-3 on the 4.4 CHIP + - Support for a custom DTB Overlay +* Fixes to the pwm unit test, all but 2 now pass :) + 0.1.1 ---- * Some refactoring of the edge detection code, made it function better diff --git a/CHIP_IO/OverlayManager.py b/CHIP_IO/OverlayManager.py index c8cf38f..7b8f37c 100644 --- a/CHIP_IO/OverlayManager.py +++ b/CHIP_IO/OverlayManager.py @@ -92,7 +92,10 @@ def _set_overlay_verify(name, overlay_path, config_path): time.sleep(0.2) # VERIFY - if name == "PWM0": + if name == "CUST": + # BLINDLY ACCEPT THAT IT LOADED + return 0 + elif name == "PWM0": if os.path.exists(PWMSYSFSPATH): if DEBUG: print("PWM IS LOADED!") @@ -149,9 +152,8 @@ def load(overlay, path=""): elif overlay.upper() == "CUST" and _LOADED[overlay.upper()]: print("Custom Overlay already loaded") return 2 - elif overlay.upper() == "CUST": - opath = OVERLAYINSTALLPATH + "/" + _OVERLAYS[overlay.upper()] - print("Custom Overlay not implemented yet") + elif overlay.upper() == "CUST" and not os.path.exists(path): + print("Custom Overlay path does not exist") return 1 # SET UP THE OVERLAY PATH FOR OUR USE diff --git a/README.rst b/README.rst index b7a7d54..559f0a6 100644 --- a/README.rst +++ b/README.rst @@ -4,7 +4,6 @@ A CHIP GPIO library Manual:: - sudo ntpdate pool.ntp.org sudo apt-get update sudo apt-get install git build-essential python-dev python-pip -y git clone git://github.com/xtacocorex/CHIP_IO.git @@ -17,7 +16,7 @@ Manual:: Using the library is very similar to the excellent RPi.GPIO library used on the Raspberry Pi. Below are some examples. -All scripts that require GPIO and PWM (HW and/or SW) access need to be run with super user permissions! +All scripts that require GPIO, PWM (HW and/or SW), and Overlay Manager need to be run with super user permissions! **Allowable Pin Names for the Library** @@ -208,22 +207,24 @@ Hardware PWM requires a DTB Overlay loaded on the CHIP to allow the kernel to kn **SOFTPWM**:: - import CHIP_IO.SOFTPWM as PWM - #PWM.start(channel, duty, freq=2000, polarity=0) + import CHIP_IO.SOFTPWM as SPWM + #SPWM.start(channel, duty, freq=2000, polarity=0) #duty values are valid 0 (off) to 100 (on) #you can choose any pin - PWM.start("XIO-P7", 50) - PWM.set_duty_cycle("XIO-P7", 25.5) - PWM.set_frequency("XIO-P7", 10) + SPWM.start("XIO-P7", 50) + SPWM.set_duty_cycle("XIO-P7", 25.5) + SPWM.set_frequency("XIO-P7", 10) - PWM.stop("XIO-P7") - PWM.cleanup() + SPWM.stop("XIO-P7") + SPWM.cleanup() #set polarity to 1 on start: - PWM.start("XIO-P7", 50, 2000, 1) + SPWM.start("XIO-P7", 50, 2000, 1) Use SOFTPWM at low speeds (hundreds of Hz) for the best results. Do not use for anything that needs high precision or reliability. +If using SOFTPWM and PWM at the same time, import CHIP_IO.SOFTPWM as SPWM or something different than PWM as to not confuse the library. + **ADC**:: Not Implemented yet @@ -232,6 +233,38 @@ Use SOFTPWM at low speeds (hundreds of Hz) for the best results. Do not use for SPI requires a DTB Overlay to access. CHIP_IO does not contain any SPI specific code as the Python spidev module works when it can see the SPI bus. +**Overlay Manager**:: + +The Overlay Manager enables you to quickly load simple Device Tree Overlays. The options for loading are: +PWM0, SPI2, I2C1, CUST + +Only one of each type of overlay can be loaded at a time, but all three options can be loaded simultaneously. So you can have SPI2 and I2C1 without PWM0, but you cannot have SPI2 loaded twice. + + import CHIP_IO.OverlayManager as OM + # The enable_debug() function turns on debug printing + #OM.enable_debug() + # To load an overlay, feed in the name to load() + OM.load("PWM0") + # To verify the overlay was properly loaded, the get_ functions return booleans + OM.get_pwm_loaded() + OM.get_i2c_loaded() + OM.get_spi_loaded() + # To unload an overlay, feed in the name to unload() + OM.unload("PWM0") + +To use a custom overlay, you must build and compile it properly per the DIP Docs: http://docs.getchip.com/dip.html#development-by-example +There is no verification that the Custom Overlay is setup properly, it's fire and forget + + import CHIP_IO.OverlayManager as OM + # The full path to the dtbo file needs to be specified + OM.load("CUST","/home/chip/projects/myfunproject/overlays/mycustomoverlay.dtbo") + # You can check for loading like above, but it's really just there for sameness + OM.get_custom_loaded() + # To unload, just call unload() + OM.unload("CUST") + +Note that this requires the 4.4 kernel with the CONFIG_OF_CONFIGFS option enabled in the kernel config. + **Running tests** Install py.test to run the tests. You'll also need the python compiler package for py.test.:: diff --git a/setup.py b/setup.py index d3cfdc5..c95942a 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ classifiers = ['Development Status :: 3 - Alpha', 'Topic :: System :: Hardware'] setup(name = 'CHIP_IO', - version = '0.1.1', + version = '0.2.0', author = 'Robert Wolterman', author_email = 'robert.wolterman@gmail.com', description = 'A module to control CHIP IO channels', diff --git a/source/constants.c b/source/constants.c index 108713b..6df746a 100644 --- a/source/constants.c +++ b/source/constants.c @@ -76,6 +76,6 @@ void define_constants(PyObject *module) both_edge = Py_BuildValue("i", BOTH_EDGE); PyModule_AddObject(module, "BOTH", both_edge); - version = Py_BuildValue("s", "0.1.1"); + version = Py_BuildValue("s", "0.2.0"); PyModule_AddObject(module, "VERSION", version); }