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

Last commit for #10 to get the Overlay Manager implemented. i2c-1 still shows up as i2c-3, but everything should work. Will add new bug to investigate. Bumping rev to 0.2.0 as this is a big feature. Custom Overlay should work now

This commit is contained in:
Robert Wolterman
2016-07-16 17:33:09 -05:00
parent 44121ed5eb
commit e270080af8
5 changed files with 58 additions and 16 deletions

View File

@ -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 0.1.1
---- ----
* Some refactoring of the edge detection code, made it function better * Some refactoring of the edge detection code, made it function better

View File

@ -92,7 +92,10 @@ def _set_overlay_verify(name, overlay_path, config_path):
time.sleep(0.2) time.sleep(0.2)
# VERIFY # VERIFY
if name == "PWM0": if name == "CUST":
# BLINDLY ACCEPT THAT IT LOADED
return 0
elif name == "PWM0":
if os.path.exists(PWMSYSFSPATH): if os.path.exists(PWMSYSFSPATH):
if DEBUG: if DEBUG:
print("PWM IS LOADED!") print("PWM IS LOADED!")
@ -149,9 +152,8 @@ def load(overlay, path=""):
elif overlay.upper() == "CUST" and _LOADED[overlay.upper()]: elif overlay.upper() == "CUST" and _LOADED[overlay.upper()]:
print("Custom Overlay already loaded") print("Custom Overlay already loaded")
return 2 return 2
elif overlay.upper() == "CUST": elif overlay.upper() == "CUST" and not os.path.exists(path):
opath = OVERLAYINSTALLPATH + "/" + _OVERLAYS[overlay.upper()] print("Custom Overlay path does not exist")
print("Custom Overlay not implemented yet")
return 1 return 1
# SET UP THE OVERLAY PATH FOR OUR USE # SET UP THE OVERLAY PATH FOR OUR USE

View File

@ -4,7 +4,6 @@ A CHIP GPIO library
Manual:: Manual::
sudo ntpdate pool.ntp.org
sudo apt-get update sudo apt-get update
sudo apt-get install git build-essential python-dev python-pip -y sudo apt-get install git build-essential python-dev python-pip -y
git clone git://github.com/xtacocorex/CHIP_IO.git 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. 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** **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**:: **SOFTPWM**::
import CHIP_IO.SOFTPWM as PWM import CHIP_IO.SOFTPWM as SPWM
#PWM.start(channel, duty, freq=2000, polarity=0) #SPWM.start(channel, duty, freq=2000, polarity=0)
#duty values are valid 0 (off) to 100 (on) #duty values are valid 0 (off) to 100 (on)
#you can choose any pin #you can choose any pin
PWM.start("XIO-P7", 50) SPWM.start("XIO-P7", 50)
PWM.set_duty_cycle("XIO-P7", 25.5) SPWM.set_duty_cycle("XIO-P7", 25.5)
PWM.set_frequency("XIO-P7", 10) SPWM.set_frequency("XIO-P7", 10)
PWM.stop("XIO-P7") SPWM.stop("XIO-P7")
PWM.cleanup() SPWM.cleanup()
#set polarity to 1 on start: #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. 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**:: **ADC**::
Not Implemented yet 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. 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** **Running tests**
Install py.test to run the tests. You'll also need the python compiler package for py.test.:: Install py.test to run the tests. You'll also need the python compiler package for py.test.::

View File

@ -20,7 +20,7 @@ classifiers = ['Development Status :: 3 - Alpha',
'Topic :: System :: Hardware'] 'Topic :: System :: Hardware']
setup(name = 'CHIP_IO', setup(name = 'CHIP_IO',
version = '0.1.1', version = '0.2.0',
author = 'Robert Wolterman', author = 'Robert Wolterman',
author_email = 'robert.wolterman@gmail.com', author_email = 'robert.wolterman@gmail.com',
description = 'A module to control CHIP IO channels', description = 'A module to control CHIP IO channels',

View File

@ -76,6 +76,6 @@ void define_constants(PyObject *module)
both_edge = Py_BuildValue("i", BOTH_EDGE); both_edge = Py_BuildValue("i", BOTH_EDGE);
PyModule_AddObject(module, "BOTH", 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); PyModule_AddObject(module, "VERSION", version);
} }