From 1c4168cf0dcda972b4f352eca3dea91878ab51e8 Mon Sep 17 00:00:00 2001 From: Robert Wolterman Date: Fri, 15 Jul 2016 23:32:44 -0500 Subject: [PATCH 1/8] Start of the overlay feature, grabbed the sample dts from CHIP-dt-overlay, modified builder.py from the BeagleBone Black repo --- overlays/__init__.py | 0 overlays/builder.py | 17 ++++++++++ overlays/chip-i2c1.dts | 62 +++++++++++++++++++++++++++++++++++ overlays/chip-pwm0.dts | 61 ++++++++++++++++++++++++++++++++++ overlays/chip-spi2.dts | 74 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 214 insertions(+) create mode 100644 overlays/__init__.py create mode 100644 overlays/builder.py create mode 100644 overlays/chip-i2c1.dts create mode 100644 overlays/chip-pwm0.dts create mode 100644 overlays/chip-spi2.dts diff --git a/overlays/__init__.py b/overlays/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/overlays/builder.py b/overlays/builder.py new file mode 100644 index 0000000..fa01443 --- /dev/null +++ b/overlays/builder.py @@ -0,0 +1,17 @@ +from subprocess import call +import os +import shutil +import glob + +def compile(): + call(["dtc", "-O", "dtb", "-o", "overlays/chip-spi2.dtbo", "-b", "o", "-@", "overlays/chip-spi2.dts"]) + call(["dtc", "-O", "dtb", "-o", "overlays/chip-i2c1.dtbo", "-b", "o", "-@", "overlays/chip-i2c1.dts"]) + call(["dtc", "-O", "dtb", "-o", "overlays/chip-pwm0.dtbo", "-b", "o", "-@", "overlays/chip-pwm0.dts"]) + +def copy(): + for fl in glob.glob("/lib/firmware/chip_io/chip-*-.dtbo"): + os.remove(fl) + shutil.move("overlays/chip-spi2.dtbo", "/lib/firmware/chip_io/chip-spi2.dtbo") + shutil.move("overlays/chip-i2c1.dtbo", "/lib/firmware/chip_io/chip-i2c1.dtbo") + shutil.move("overlays/chip-pwm0.dtbo", "/lib/firmware/chip_io/chip-pwm0.dtbo") + diff --git a/overlays/chip-i2c1.dts b/overlays/chip-i2c1.dts new file mode 100644 index 0000000..648c20d --- /dev/null +++ b/overlays/chip-i2c1.dts @@ -0,0 +1,62 @@ +/* + * Copyright 2016 Free Electrons + * Copyright 2016 NextThing Co + * + * Maxime Ripard + * + * This file is dual-licensed: you can use it either under the terms + * of the GPL or the X11 license, at your option. Note that this dual + * licensing only applies to this file, and not this project as a + * whole. + * + * a) This file is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Or, alternatively, + * + * b) Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +/ { + compatible = "nextthing,chip", "allwinner,sun5i-r8"; + + /* Enable the I2C1 bus and the keyboard */ + fragment@1 { + target = <&i2c1>; + + __overlay__ { + #address-cells = <1>; + #size-cells = <0>; + pinctrl-names = "default"; + pinctrl-0 = <&i2c1_pins_a>; + status = "okay"; + }; + }; +}; + diff --git a/overlays/chip-pwm0.dts b/overlays/chip-pwm0.dts new file mode 100644 index 0000000..a25abb0 --- /dev/null +++ b/overlays/chip-pwm0.dts @@ -0,0 +1,61 @@ +/* + * Copyright 2016 Free Electrons + * Copyright 2016 NextThing Co + * + * Maxime Ripard + * + * This file is dual-licensed: you can use it either under the terms + * of the GPL or the X11 license, at your option. Note that this dual + * licensing only applies to this file, and not this project as a + * whole. + * + * a) This file is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Or, alternatively, + * + * b) Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +/dts-v1/; +/plugin/; + +/ { + compatible = "nextthing,chip", "allwinner,sun5i-r8"; + + /* Enable the PWM */ + fragment@0 { + target = <&pwm>; + + __overlay__ { + pinctrl-names = "default"; + pinctrl-0 = <&pwm0_pins>; + status = "okay"; + }; + }; +}; diff --git a/overlays/chip-spi2.dts b/overlays/chip-spi2.dts new file mode 100644 index 0000000..d0a0ceb --- /dev/null +++ b/overlays/chip-spi2.dts @@ -0,0 +1,74 @@ +/* + * Copyright 2016 Free Electrons + * Copyright 2016 NextThing Co + * + * Maxime Ripard + * + * This file is dual-licensed: you can use it either under the terms + * of the GPL or the X11 license, at your option. Note that this dual + * licensing only applies to this file, and not this project as a + * whole. + * + * a) This file is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Or, alternatively, + * + * b) Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +/dts-v1/; +/plugin/; + +/ { + compatible = "nextthing,chip", "allwinner,sun5i-r8"; + + /* + * Enable our SPI device, with an spidev device connected + * to it + */ + fragment@1 { + target = <&spi2>; + + __overlay__ { + pinctrl-names = "default"; + pinctrl-0 = <&spi2_pins_a>, + <&spi2_cs0_pins_a>; + status = "okay"; + #address-cells = <1>; + #size-cells = <0>; + + spidev@0{ + compatible = "spidev"; + reg = <0>; + spi-max-frequency = <1000000>; + }; + }; + }; +}; From ee8445918e7fdfffef3bfca9864af4356df8395b Mon Sep 17 00:00:00 2001 From: Robert Wolterman Date: Sat, 16 Jul 2016 10:45:13 -0500 Subject: [PATCH 2/8] More work on #10. PWM0 Loading is complete and verified, i2c-1 loading loads to i2c-3, verification fails, spi2 is loaded, but no verification. No work on custom overlay loading. Fixed issues with test_pwm_setup.py; only 2 tests fail now (when PWM0 is loaded --- overlays/builder.py | 8 +++-- overlays/chip-i2c1.dtbo | Bin 0 -> 577 bytes overlays/chip-i2c1.dts | 62 --------------------------------- overlays/chip-pwm0.dtbo | Bin 0 -> 399 bytes overlays/chip-pwm0.dts | 61 --------------------------------- overlays/chip-spi2.dtbo | Bin 0 -> 973 bytes overlays/chip-spi2.dts | 74 ---------------------------------------- setup.py | 2 +- test/test_pwm_setup.py | 38 ++++++++++----------- 9 files changed, 25 insertions(+), 220 deletions(-) create mode 100644 overlays/chip-i2c1.dtbo delete mode 100644 overlays/chip-i2c1.dts create mode 100644 overlays/chip-pwm0.dtbo delete mode 100644 overlays/chip-pwm0.dts create mode 100644 overlays/chip-spi2.dtbo delete mode 100644 overlays/chip-spi2.dts diff --git a/overlays/builder.py b/overlays/builder.py index fa01443..74cd4af 100644 --- a/overlays/builder.py +++ b/overlays/builder.py @@ -9,9 +9,11 @@ def compile(): call(["dtc", "-O", "dtb", "-o", "overlays/chip-pwm0.dtbo", "-b", "o", "-@", "overlays/chip-pwm0.dts"]) def copy(): + if not os.path.exists("/lib/firmware/chip_io/"): + os.makedirs("/lib/firmware/chip_io/") for fl in glob.glob("/lib/firmware/chip_io/chip-*-.dtbo"): os.remove(fl) - shutil.move("overlays/chip-spi2.dtbo", "/lib/firmware/chip_io/chip-spi2.dtbo") - shutil.move("overlays/chip-i2c1.dtbo", "/lib/firmware/chip_io/chip-i2c1.dtbo") - shutil.move("overlays/chip-pwm0.dtbo", "/lib/firmware/chip_io/chip-pwm0.dtbo") + shutil.copy("overlays/chip-spi2.dtbo", "/lib/firmware/chip_io/chip-spi2.dtbo") + shutil.copy("overlays/chip-i2c1.dtbo", "/lib/firmware/chip_io/chip-i2c1.dtbo") + shutil.copy("overlays/chip-pwm0.dtbo", "/lib/firmware/chip_io/chip-pwm0.dtbo") diff --git a/overlays/chip-i2c1.dtbo b/overlays/chip-i2c1.dtbo new file mode 100644 index 0000000000000000000000000000000000000000..45c2402735ce1d98043ce83c40bd94c604d8b33d GIT binary patch literal 577 zcmZuuu};G<5WN!Dmyb9vaYGyTDVSRJJ9kq`~bheH!w2s z2Z%pF+&M`p5+}X*-t)V=*nZpp{sd@W1HdIf>z&qf!Xe>+z@bQg4%y#NtEOADo^o#F z()+nGvwk*L1)$cC${1<;t~3`avNV9BHMKZfNaIII;9TD!?8T@RI_ZK+J|Xf4X*I5d zV2ORlgl_EeY?P!~!V#-MAcHXxwn4kb@0>K~T)#~?`FMH#qV>Q2yx-$JLgOD$&cS?_ za5a%rEVXYmuDPjuvS){Io8RM#4HWDD5n`&AW#Ovhgnmb~-;LK7k`6uEne@ZzB-P9_ z^4x8B;*EP57RqGa>L{s7npvGJUli!oSWBo{Mnva8mzCB6^l&n<(zz&;T07`D^(5=O W>1uF6&(W|1oJU`}&_$5y1i}wLGIp>4 literal 0 HcmV?d00001 diff --git a/overlays/chip-i2c1.dts b/overlays/chip-i2c1.dts deleted file mode 100644 index 648c20d..0000000 --- a/overlays/chip-i2c1.dts +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2016 Free Electrons - * Copyright 2016 NextThing Co - * - * Maxime Ripard - * - * This file is dual-licensed: you can use it either under the terms - * of the GPL or the X11 license, at your option. Note that this dual - * licensing only applies to this file, and not this project as a - * whole. - * - * a) This file is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This file is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Or, alternatively, - * - * b) Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -/ { - compatible = "nextthing,chip", "allwinner,sun5i-r8"; - - /* Enable the I2C1 bus and the keyboard */ - fragment@1 { - target = <&i2c1>; - - __overlay__ { - #address-cells = <1>; - #size-cells = <0>; - pinctrl-names = "default"; - pinctrl-0 = <&i2c1_pins_a>; - status = "okay"; - }; - }; -}; - diff --git a/overlays/chip-pwm0.dtbo b/overlays/chip-pwm0.dtbo new file mode 100644 index 0000000000000000000000000000000000000000..b0e219e0bbb45bac87ce64654a69b79836374d0a GIT binary patch literal 399 zcmY*TT}s115T5u0iWF23`Y7UqNK4~GLGq$U=na-JZqlWjP1v2-_7tAPD|iM^;0?qZ zNN2i<)`4$lXXg99nUBHG7eMj~0Qa0{oNpLsj8lfh1NVpV`|nM@ql_AAV)Z9=r$`d#qsZt{0XM(9gTS-dFjyk^dHhcnr^ sD{G9)$=h)nCH=1BysjD~^JFzdOX!&nD;<8T6apc&+*nqER535W2J>cANdN!< literal 0 HcmV?d00001 diff --git a/overlays/chip-pwm0.dts b/overlays/chip-pwm0.dts deleted file mode 100644 index a25abb0..0000000 --- a/overlays/chip-pwm0.dts +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2016 Free Electrons - * Copyright 2016 NextThing Co - * - * Maxime Ripard - * - * This file is dual-licensed: you can use it either under the terms - * of the GPL or the X11 license, at your option. Note that this dual - * licensing only applies to this file, and not this project as a - * whole. - * - * a) This file is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This file is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Or, alternatively, - * - * b) Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ -/dts-v1/; -/plugin/; - -/ { - compatible = "nextthing,chip", "allwinner,sun5i-r8"; - - /* Enable the PWM */ - fragment@0 { - target = <&pwm>; - - __overlay__ { - pinctrl-names = "default"; - pinctrl-0 = <&pwm0_pins>; - status = "okay"; - }; - }; -}; diff --git a/overlays/chip-spi2.dtbo b/overlays/chip-spi2.dtbo new file mode 100644 index 0000000000000000000000000000000000000000..2f6b18ac6f4fe7086f45ff407b56190ea9ed9b60 GIT binary patch literal 973 zcmah{%}N6?5T05EMFl;G;6HO`;EFCB_1@3Z0mD`$F5(TIy5&JYxBM^zudj z84GVjtoV>IA{0y{8y$UbdS-V^Zb+Cr&y}Z0#oz! zsTb5woBL0fX5i|OF8QSEFga@-qZ97gFK2aH=g9T7FVpNSe-Ulj79E}_OJT~P*e$}< zcYWW7*L;X^TH~G=GsFH>s7y9r;%*}zs*{VUdUsHrnSTknkAHE!d8RXFOoahgtRn|W zlov&f+1bqAyMHdEr*FiaA=jN!B>ooS$?L6YdE6DY5^>vWX3s61*9P*QC%k&jbCmI{ zmV&U4x$;U0@T9!A9Z79Gx0C3=%20!nIvJFs9@p)0E|hq?9SdVBfl$go$;dmA+o%)R gSXDId3j@xpfw9~s2IvkL)nYue@y$9vl3^NyAJ@*lSO5S3 literal 0 HcmV?d00001 diff --git a/overlays/chip-spi2.dts b/overlays/chip-spi2.dts deleted file mode 100644 index d0a0ceb..0000000 --- a/overlays/chip-spi2.dts +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2016 Free Electrons - * Copyright 2016 NextThing Co - * - * Maxime Ripard - * - * This file is dual-licensed: you can use it either under the terms - * of the GPL or the X11 license, at your option. Note that this dual - * licensing only applies to this file, and not this project as a - * whole. - * - * a) This file is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This file is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Or, alternatively, - * - * b) Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -/dts-v1/; -/plugin/; - -/ { - compatible = "nextthing,chip", "allwinner,sun5i-r8"; - - /* - * Enable our SPI device, with an spidev device connected - * to it - */ - fragment@1 { - target = <&spi2>; - - __overlay__ { - pinctrl-names = "default"; - pinctrl-0 = <&spi2_pins_a>, - <&spi2_cs0_pins_a>; - status = "okay"; - #address-cells = <1>; - #size-cells = <0>; - - spidev@0{ - compatible = "spidev"; - reg = <0>; - spi-max-frequency = <1000000>; - }; - }; - }; -}; diff --git a/setup.py b/setup.py index ec17c6b..d3cfdc5 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ try: from overlays import builder - builder.compile() + #builder.compile() builder.copy() except: pass diff --git a/test/test_pwm_setup.py b/test/test_pwm_setup.py index e5944dd..48e0e88 100644 --- a/test/test_pwm_setup.py +++ b/test/test_pwm_setup.py @@ -13,8 +13,8 @@ class TestPwmSetup: pwm_test = '/sys/class/pwm/pwmchip0/pwm0' assert os.path.exists(pwm_test) - duty = open(pwm_test + '/duty_cycle').read() - period = open(pwm_test + '/period').read() + duty = open(pwm_test + '/duty_cycle').readline().strip() + period = open(pwm_test + '/period').readline().strip() assert int(duty) == 0 assert int(period) == 500000 PWM.cleanup() @@ -25,12 +25,12 @@ class TestPwmSetup: pwm_test = '/sys/class/pwm/pwmchip0/pwm0' assert os.path.exists(pwm_test) - duty = open(pwm_test + '/duty_cycle').read() - period = open(pwm_test + '/period').read() - polarity = open(pwm_test + '/polarity').read() + duty = open(pwm_test + '/duty_cycle').readline().strip() + period = open(pwm_test + '/period').readline().strip() + polarity = open(pwm_test + '/polarity').readline().strip() assert int(duty) == 0 assert int(period) == 500000 - assert string(polarity) == "inverted" + assert str(polarity) == "inverted" PWM.cleanup() def test_start_pwm_with_polarity_default(self): @@ -39,12 +39,12 @@ class TestPwmSetup: pwm_test = '/sys/class/pwm/pwmchip0/pwm0' assert os.path.exists(pwm_test) - duty = open(pwm_test + '/duty_cycle').read() - period = open(pwm_test + '/period').read() - polarity = open(pwm_test + '/polarity').read() + duty = open(pwm_test + '/duty_cycle').readline().strip() + period = open(pwm_test + '/period').readline().strip() + polarity = open(pwm_test + '/polarity').readline().strip() assert int(duty) == 0 assert int(period) == 500000 - assert string(polarity) == "normal" + assert str(polarity) == "normal" PWM.cleanup() def test_start_pwm_with_polarity_zero(self): @@ -53,12 +53,12 @@ class TestPwmSetup: pwm_test = '/sys/class/pwm/pwmchip0/pwm0' assert os.path.exists(pwm_test) - duty = open(pwm_test + '/duty_cycle').read() - period = open(pwm_test + '/period').read() - polarity = open(pwm_test + '/polarity').read() + duty = open(pwm_test + '/duty_cycle').readline().strip() + period = open(pwm_test + '/period').readline().strip() + polarity = open(pwm_test + '/polarity').readline().strip() assert int(duty) == 0 assert int(period) == 500000 - assert string(polarity) == "normal" + assert str(polarity) == "normal" PWM.cleanup() def test_pwm_start_invalid_pwm_key(self): @@ -113,14 +113,14 @@ class TestPwmSetup: pwm_test = '/sys/class/pwm/pwmchip0/pwm0' assert os.path.exists(pwm_test) - duty = open(pwm_test + '/duty_cycle').read() - period = open(pwm_test + '/period').read() + duty = open(pwm_test + '/duty_cycle').readline().strip() + period = open(pwm_test + '/period').readline().strip() assert int(duty) == 0 assert int(period) == 500000 PWM.set_duty_cycle("PWM0", 100) - duty = open(pwm_test + '/duty_cycle').read() - period = open(pwm_test + '/period').read() + duty = open(pwm_test + '/duty_cycle').readline().strip() + period = open(pwm_test + '/period').readline().strip() assert int(duty) == 500000 assert int(period) == 500000 PWM.cleanup() @@ -180,6 +180,6 @@ class TestPwmSetup: #PWM.start("PWM0", 1) #PWM.stop("PWM0") #assert os.path.exists('/sys/class/gpio/gpio68') - #direction = open('/sys/class/gpio/gpio68/direction').read() + #direction = open('/sys/class/gpio/gpio68/direction').readline().strip() #assert direction == 'out\n' #PWM.cleanup() From 00140c2008bf4757aa7c4651de26ce33e642c80d Mon Sep 17 00:00:00 2001 From: Robert Wolterman Date: Sat, 16 Jul 2016 13:49:29 -0500 Subject: [PATCH 3/8] Totally forgot to add the OverlayManager code in the last commit. This update is for #10 --- CHIP_IO/OverlayManager.py | 192 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 CHIP_IO/OverlayManager.py diff --git a/CHIP_IO/OverlayManager.py b/CHIP_IO/OverlayManager.py new file mode 100644 index 0000000..7a144a3 --- /dev/null +++ b/CHIP_IO/OverlayManager.py @@ -0,0 +1,192 @@ +import os +import shutil +import time + +DEBUG = False + +OVERLAYINSTALLPATH = "/lib/firmware/chip_io" +OVERLAYCONFIGPATH = "/sys/kernel/config/device-tree/overlays" +CUSTOMOVERLAYFILEPATH = "" + +PWMSYSFSPATH = "/sys/class/pwm/pwmchip0" +I2C1SYSFSPATH = "/sys/class/i2c-dev/i2c-1" + +# LOADED VARIABLES +# DO NOT MODIFY BY HAND WHEN USING +# AS IT COULD BREAK FUNCTIONALITY +_LOADED = { + "I2C1" : False, + "SPI2" : False, + "PWM0" : False, + "CUST" : False +} + +_OVERLAYS = { + "I2C1" : "chip-i2c1.dtbo", + "SPI2" : "chip-spi2.dtbo", + "PWM0" : "chip-pwm0.dtbo", + "CUST" : "" +} + +_FOLDERS = { + "I2C1" : "chip-i2c", + "SPI2" : "chip-spi", + "PWM0" : "chip-pwm", + "CUST" : "chip-cust" +} + +def enable_debug(): + global DEBUG + DEBUG = True + +def get_i2c_loaded(): + """ + get_i2c_loaded - Returns True/False based upon if the i2c-1 Overlay is loaded + """ + global _LOADED + return _LOADED["I2C1"] + +def get_spi_loaded(): + """ + get_spi_loaded - Returns True/False based upon if the spi2 Overlay is loaded + """ + global _LOADED + return _LOADED["SPI2"] + +def get_pwm_loaded(): + """ + get_pwm_loaded - Returns True/False based upon if the pwm0 Overlay is loaded + """ + global _LOADED + return _LOADED["PWM0"] + +def get_custom_loaded(): + """ + get_custom_loaded - Returns True/False based upon if a Custom Overlay is loaded + """ + global _LOADED + return _LOADED["CUST"] + +def _set_overlay_verify(name, overlay_path, config_path): + """ + _set_overlay_verify - Function to load the overlay and verify it was setup properly + """ + global DEBUG + # VERIFY PATH IS NOT THERE + if os.path.exists(config_path): + print("Config path already exists! Not moving forward") + print("config_path: {0}".format(config_path)) + return -1 + + # MAKE THE CONFIGURATION PATH + os.makedirs(config_path) + + # CAT THE OVERLAY INTO THE CONFIG FILESYSTEM + with open(config_path + "/dtbo", 'wb') as outfile: + with open(overlay_path, 'rb') as infile: + shutil.copyfileobj(infile, outfile) + + # SLEEP TO ENABLE THE KERNEL TO DO ITS JOB + time.sleep(0.2) + + # VERIFY + if name == "PWM0": + if os.path.exists(PWMSYSFSPATH): + if DEBUG: + print("PWM IS LOADED!") + return 0 + else: + if DEBUG: + print("ERROR LOAIDNG PWM0") + return 1 + elif name == "I2C1": + if os.path.exists(I2C1SYSFSPATH): + if DEBUG: + print("I2C-1 IS LOADED!") + return 0 + else: + if DEBUG: + print("ERROR LOADING I2C-1") + return 1 + +def load(overlay, path=""): + """ + load - Load a DTB Overlay + + Inputs: + overlay - Overlay Key: I2C1, SPI2, PWM0, CUST + path - Full Path to where the custom overlay is stored + + Returns: + 0 - Successful Load + 1 - Unsuccessful Load + 2 - Overlay was previously set + """ + global DEBUG + global _LOADED + if DEBUG: + print("LOAD OVERLAY") + print("OVERLAY: {0}".format(overlay)) + print("PATH: {0}".format(path)) + # SEE IF OUR OVERLAY NAME IS IN THE KEYS + if overlay.upper() in _OVERLAYS.keys(): + cpath = OVERLAYCONFIGPATH + "/" + _FOLDERS[overlay.upper()] + if DEBUG: + print("VALID OVERLAY") + print("CONFIG PATH: {0}".format(cpath)) + # CHECK TO SEE IF WE HAVE A PATH FOR CUSTOM OVERLAY + if overlay.upper() == "CUST" and path == "": + raise ValueError("Path must be specified for Custom Overlay Choice") + 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") + return 1 + + # SET UP THE OVERLAY PATH FOR OUR USE + if overlay.upper() != "CUST": + opath = OVERLAYINSTALLPATH + "/" + _OVERLAYS[overlay.upper()] + else: + opath = path + if DEBUG: + print("OVERLAY PATH: {0}".format(opath)) + + if overlay.upper() == "PWM0" and _LOADED[overlay.upper()]: + print("PWM0 Overlay already loaded") + return 2 + + if overlay.upper() == "I2C1" and _LOADED[overlay.upper()]: + print("I2C1 Overlay already loaded") + return 2 + + if overlay.upper() == "SPI2" and _LOADED[overlay.upper()]: + print("SPI2 Overlay already loaded") + return 2 + + # LOAD THE OVERLAY + errc = _set_overlay_verify(overlay.upper(), opath, cpath) + if DEBUG: + print("ERRC: {0}".format(errc)) + if errc == 0: + _LOADED[overlay.upper()] = True + + else: + raise ValueError("Invalid Overlay name specified! Choose between: I2C1, SPI2, PWM0, CUST") + +def unload(overlay): + global DEBUG + global _LOADED + if DEBUG: + print("UNLOAD OVERLAY") + print(overlay) + # SEE IF OUR OVERLAY NAME IS IN THE KEYS + if overlay.upper() in _OVERLAYS.keys(): + # BRUTE FORCE REMOVE AS THE DIRECTORY CONTAINS FILES + os.system('rmdir \"{}\"'.format(OVERLAYCONFIGPATH + "/" + _FOLDERS[overlay.upper()])) + _LOADED[overlay.upper()] = False + else: + raise ValueError("Invalid Overlay name specified! Choose between: I2C1, SPI2, PWM0, CUST") + + From 44121ed5eb8782196163db2fbcf5c687fa3c7944 Mon Sep 17 00:00:00 2001 From: Robert Wolterman Date: Sat, 16 Jul 2016 15:23:43 -0500 Subject: [PATCH 4/8] 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 --- CHIP_IO/OverlayManager.py | 20 +++++++++++----- overlays/chip-spi2.dtbo | Bin 973 -> 1063 bytes test/omtest.py | 49 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 6 deletions(-) create mode 100755 test/omtest.py diff --git a/CHIP_IO/OverlayManager.py b/CHIP_IO/OverlayManager.py index 7a144a3..c8cf38f 100644 --- a/CHIP_IO/OverlayManager.py +++ b/CHIP_IO/OverlayManager.py @@ -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 diff --git a/overlays/chip-spi2.dtbo b/overlays/chip-spi2.dtbo index 2f6b18ac6f4fe7086f45ff407b56190ea9ed9b60..1935261465ee7e563f4534213c73408dc130ef39 100644 GIT binary patch delta 173 zcmX@hzMMnj0`I@K3=Ayl3=9kw3=GUEKw1Nc1%X%qh(X{mP+VuD#$iTB#^QoZqj&?b zC^L{`2eE)+DXC>}F%}@J1IzB%WNtwwrnCcmqOqO6)XIwGafqBhjCKgoy2fGtK diff --git a/test/omtest.py b/test/omtest.py new file mode 100755 index 0000000..c680ecb --- /dev/null +++ b/test/omtest.py @@ -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())) + + From e270080af81747c88015d2ed6ea4aad85a8199ba Mon Sep 17 00:00:00 2001 From: Robert Wolterman Date: Sat, 16 Jul 2016 17:33:09 -0500 Subject: [PATCH 5/8] 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 --- CHANGELOG.rst | 7 ++++++ CHIP_IO/OverlayManager.py | 10 +++++--- README.rst | 53 +++++++++++++++++++++++++++++++-------- setup.py | 2 +- source/constants.c | 2 +- 5 files changed, 58 insertions(+), 16 deletions(-) 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); } From 01347416ab532610f3c307da2d31a91c2016ea12 Mon Sep 17 00:00:00 2001 From: Robert Wolterman Date: Sun, 17 Jul 2016 14:23:55 -0500 Subject: [PATCH 6/8] Update to Issue #10 that fixes the errors on SPI loading. Have to not set spidev as compatible for spidev. Such meta, much fail, wow --- overlays/builder.py | 2 + overlays/chip-i2c1.dts | 72 +++++++++++++++++++++++++++++ overlays/chip-pwm0.dts | 63 ++++++++++++++++++++++++++ overlays/chip-spi2.dtbo | Bin 1063 -> 1172 bytes overlays/chip-spi2.dts | 97 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 234 insertions(+) create mode 100644 overlays/chip-i2c1.dts create mode 100644 overlays/chip-pwm0.dts create mode 100644 overlays/chip-spi2.dts diff --git a/overlays/builder.py b/overlays/builder.py index 74cd4af..bc9a4b2 100644 --- a/overlays/builder.py +++ b/overlays/builder.py @@ -4,6 +4,8 @@ import shutil import glob def compile(): + # The compile needs the include for the spi2 stuff, not enabling that at the moment + # as I don't want to pull in the include section from CHIP-dt-overlays call(["dtc", "-O", "dtb", "-o", "overlays/chip-spi2.dtbo", "-b", "o", "-@", "overlays/chip-spi2.dts"]) call(["dtc", "-O", "dtb", "-o", "overlays/chip-i2c1.dtbo", "-b", "o", "-@", "overlays/chip-i2c1.dts"]) call(["dtc", "-O", "dtb", "-o", "overlays/chip-pwm0.dtbo", "-b", "o", "-@", "overlays/chip-pwm0.dts"]) diff --git a/overlays/chip-i2c1.dts b/overlays/chip-i2c1.dts new file mode 100644 index 0000000..c2a2c75 --- /dev/null +++ b/overlays/chip-i2c1.dts @@ -0,0 +1,72 @@ +/* + * Copyright 2016 Free Electrons + * Copyright 2016 NextThing Co + * + * Maxime Ripard + * + * This file is dual-licensed: you can use it either under the terms + * of the GPL or the X11 license, at your option. Note that this dual + * licensing only applies to this file, and not this project as a + * whole. + * + * a) This file is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Or, alternatively, + * + * b) Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +/dts-v1/; +/plugin/; + +/ { + compatible = "nextthing,chip", "allwinner,sun5i-r8"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + i2c1 = "/soc@01c00000/i2c@01c2b000"; + }; + }; + + /* Enable the I2C1 bus and the keyboard */ + fragment@1 { + target = <&i2c1>; + + __overlay__ { + #address-cells = <1>; + #size-cells = <0>; + pinctrl-names = "default"; + pinctrl-0 = <&i2c1_pins_a>; + status = "okay"; + }; + }; +}; + diff --git a/overlays/chip-pwm0.dts b/overlays/chip-pwm0.dts new file mode 100644 index 0000000..1ae213c --- /dev/null +++ b/overlays/chip-pwm0.dts @@ -0,0 +1,63 @@ +/* + * Copyright 2016 Free Electrons + * Copyright 2016 NextThing Co + * + * Maxime Ripard + * + * This file is dual-licensed: you can use it either under the terms + * of the GPL or the X11 license, at your option. Note that this dual + * licensing only applies to this file, and not this project as a + * whole. + * + * a) This file is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Or, alternatively, + * + * b) Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +/dts-v1/; +/plugin/; + +#include + +/ { + compatible = "nextthing,chip", "allwinner,sun5i-r8"; + + /* Enable the PWM */ + fragment@0 { + target = <&pwm>; + + __overlay__ { + pinctrl-names = "default"; + pinctrl-0 = <&pwm0_pins>; + status = "okay"; + }; + }; +}; diff --git a/overlays/chip-spi2.dtbo b/overlays/chip-spi2.dtbo index 1935261465ee7e563f4534213c73408dc130ef39..91828fa29afc2b9910b9d418ed3e36a9624c57b9 100644 GIT binary patch delta 432 zcmZ3^F@;m(0`I@K3=Aw&7#J8V7#Nt>0BH>%76f7eAO?XKK=G1^8v6}F9A+S90b)-O z2MA#N2q2pgi5~~zPyFFdP!kiHCZ@>&jOvVOlPehI>vPcztpV~u0Awi#5O<`crX`l< zlpu>u19CtPftkw+WG~3iPOJne0s_Y3f=nX^127w84j+hBl%J8SlagU%WMq+629^TZ zAqn>BatI&p)76Z5W|P&KG#K|z4q(z|JOdWq&kJ21z} zCFbOmXXfRl7U`rEWtOEfAovBPIXRQ(FsErJXJi({gPas!keOG^fZ!$<8$g5#GV>Wg G3K#%Ge@RII delta 324 zcmbQjxtv4e0`I@K3=Ayl3=9kw3=GUEKw1Nc1%X%qh(X{mP+VuC#(qI2Acq-7RUzykSQEMoSBlEmROoof-F`JB;#_8jSNM z&tTGKTm>X$CO=^EXDpv=z^u=>YjOg!I^({{9n7(lSy)n4!PXRH<`u^$f{ZtcPcAly Mhw=+D^TA>a0OuDptN;K2 diff --git a/overlays/chip-spi2.dts b/overlays/chip-spi2.dts new file mode 100644 index 0000000..789127d --- /dev/null +++ b/overlays/chip-spi2.dts @@ -0,0 +1,97 @@ +/* + * Copyright 2016, Robert Wolterman + * This file is an amalgamation of stuff from Kolja Windeler, Maxime Ripard, and Renzo. + * + * This file is dual-licensed: you can use it either under the terms + * of the GPL or the X11 license, at your option. Note that this dual + * licensing only applies to this file, and not this project as a + * whole. + * + * a) This file is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Or, alternatively, + * + * b) Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +/dts-v1/; + +#include +#include + +/plugin/; + +/ { + compatible = "nextthing,chip", "allwinner,sun5i-r8"; + + /* activate the gpio for interrupt */ + fragment@0 { + target-path = <&pio>; + + __overlay__ { + chip_spi2_pins: spi2@0 { + allwinner,pins = "PE1", "PE2", "PE3"; + allwinner,function = "spi2"; + allwinner,drive = ; + allwinner,pull = ; + }; + + chip_spi2_cs0_pins: spi2_cs0@0 { + allwinner,pins = "PE0"; + allwinner,function = "spi2"; + allwinner,drive = ; + allwinner,pull = ; + }; + }; + }; + + /* + * Enable our SPI device, with an spidev device connected + * to it + */ + fragment@1 { + target = <&spi2>; + + __overlay__ { + #address-cells = <1>; + #size-cells = <0>; + pinctrl-names = "default"; + pinctrl-0 = <&chip_spi2_pins>, <&chip_spi2_cs0_pins>; + status = "okay"; + + spi2@0 { + //compatible = "spidev"; + compatible = "rohm,dh2228fv"; + reg = <0>; + spi-max-frequency = <24000000>; + }; + }; + }; +}; From 4f6acf46765a272de43de53221a618d27a82d65a Mon Sep 17 00:00:00 2001 From: Robert Wolterman Date: Tue, 19 Jul 2016 21:03:40 -0500 Subject: [PATCH 7/8] Pull Request #12 fixes for Issue #10. --- CHANGELOG.rst | 7 ++++ README.rst | 9 ++++- overlays/builder.py | 8 ++--- overlays/chip-i2c1.dtbo | Bin 577 -> 0 bytes overlays/chip-i2c1.dts | 2 +- overlays/chip-pwm0.dtbo | Bin 399 -> 0 bytes overlays/chip-pwm0.dts | 2 -- overlays/chip-spi2.dtbo | Bin 1172 -> 0 bytes overlays/chip-spi2.dts | 78 +++++++++++++++++++--------------------- setup.py | 4 +-- source/constants.c | 2 +- 11 files changed, 59 insertions(+), 53 deletions(-) delete mode 100644 overlays/chip-i2c1.dtbo delete mode 100644 overlays/chip-pwm0.dtbo delete mode 100644 overlays/chip-spi2.dtbo diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f8fcd55..2ff7c94 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,10 @@ +0.2.1 +---- +* Pull request #12 fixes: + - Fixed indent in the i2c-1 dts + - Removed import dependencies in the SPI and PWM overlays + - Re-enabled building of the dtbo on setup.py install + 0.2.0 ---- * Added the ability to load DTB Overlays from within CHIP_IO diff --git a/README.rst b/README.rst index 559f0a6..5e76d9d 100644 --- a/README.rst +++ b/README.rst @@ -2,10 +2,17 @@ CHIP_IO ============================ A CHIP GPIO library +NOTE: Now requires the custom DTC to install the library + Manual:: 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 flex bison -y + git clone https://github.com/atenart/dtc + cd dtc + make + sudo make install PREFIX=/usr + cd .. git clone git://github.com/xtacocorex/CHIP_IO.git cd CHIP_IO sudo python setup.py install diff --git a/overlays/builder.py b/overlays/builder.py index bc9a4b2..e4e625c 100644 --- a/overlays/builder.py +++ b/overlays/builder.py @@ -4,8 +4,6 @@ import shutil import glob def compile(): - # The compile needs the include for the spi2 stuff, not enabling that at the moment - # as I don't want to pull in the include section from CHIP-dt-overlays call(["dtc", "-O", "dtb", "-o", "overlays/chip-spi2.dtbo", "-b", "o", "-@", "overlays/chip-spi2.dts"]) call(["dtc", "-O", "dtb", "-o", "overlays/chip-i2c1.dtbo", "-b", "o", "-@", "overlays/chip-i2c1.dts"]) call(["dtc", "-O", "dtb", "-o", "overlays/chip-pwm0.dtbo", "-b", "o", "-@", "overlays/chip-pwm0.dts"]) @@ -15,7 +13,7 @@ def copy(): os.makedirs("/lib/firmware/chip_io/") for fl in glob.glob("/lib/firmware/chip_io/chip-*-.dtbo"): os.remove(fl) - shutil.copy("overlays/chip-spi2.dtbo", "/lib/firmware/chip_io/chip-spi2.dtbo") - shutil.copy("overlays/chip-i2c1.dtbo", "/lib/firmware/chip_io/chip-i2c1.dtbo") - shutil.copy("overlays/chip-pwm0.dtbo", "/lib/firmware/chip_io/chip-pwm0.dtbo") + shutil.move("overlays/chip-spi2.dtbo", "/lib/firmware/chip_io/chip-spi2.dtbo") + shutil.move("overlays/chip-i2c1.dtbo", "/lib/firmware/chip_io/chip-i2c1.dtbo") + shutil.move("overlays/chip-pwm0.dtbo", "/lib/firmware/chip_io/chip-pwm0.dtbo") diff --git a/overlays/chip-i2c1.dtbo b/overlays/chip-i2c1.dtbo deleted file mode 100644 index 45c2402735ce1d98043ce83c40bd94c604d8b33d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 577 zcmZuuu};G<5WN!Dmyb9vaYGyTDVSRJJ9kq`~bheH!w2s z2Z%pF+&M`p5+}X*-t)V=*nZpp{sd@W1HdIf>z&qf!Xe>+z@bQg4%y#NtEOADo^o#F z()+nGvwk*L1)$cC${1<;t~3`avNV9BHMKZfNaIII;9TD!?8T@RI_ZK+J|Xf4X*I5d zV2ORlgl_EeY?P!~!V#-MAcHXxwn4kb@0>K~T)#~?`FMH#qV>Q2yx-$JLgOD$&cS?_ za5a%rEVXYmuDPjuvS){Io8RM#4HWDD5n`&AW#Ovhgnmb~-;LK7k`6uEne@ZzB-P9_ z^4x8B;*EP57RqGa>L{s7npvGJUli!oSWBo{Mnva8mzCB6^l&n<(zz&;T07`D^(5=O W>1uF6&(W|1oJU`}&_$5y1i}wLGIp>4 diff --git a/overlays/chip-i2c1.dts b/overlays/chip-i2c1.dts index c2a2c75..09aa600 100644 --- a/overlays/chip-i2c1.dts +++ b/overlays/chip-i2c1.dts @@ -47,7 +47,7 @@ /plugin/; / { - compatible = "nextthing,chip", "allwinner,sun5i-r8"; + compatible = "nextthing,chip", "allwinner,sun5i-r8"; fragment@0 { target-path = "/aliases"; diff --git a/overlays/chip-pwm0.dtbo b/overlays/chip-pwm0.dtbo deleted file mode 100644 index b0e219e0bbb45bac87ce64654a69b79836374d0a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 399 zcmY*TT}s115T5u0iWF23`Y7UqNK4~GLGq$U=na-JZqlWjP1v2-_7tAPD|iM^;0?qZ zNN2i<)`4$lXXg99nUBHG7eMj~0Qa0{oNpLsj8lfh1NVpV`|nM@ql_AAV)Z9=r$`d#qsZt{0XM(9gTS-dFjyk^dHhcnr^ sD{G9)$=h)nCH=1BysjD~^JFzdOX!&nD;<8T6apc&+*nqER535W2J>cANdN!< diff --git a/overlays/chip-pwm0.dts b/overlays/chip-pwm0.dts index 1ae213c..a25abb0 100644 --- a/overlays/chip-pwm0.dts +++ b/overlays/chip-pwm0.dts @@ -45,8 +45,6 @@ /dts-v1/; /plugin/; -#include - / { compatible = "nextthing,chip", "allwinner,sun5i-r8"; diff --git a/overlays/chip-spi2.dtbo b/overlays/chip-spi2.dtbo deleted file mode 100644 index 91828fa29afc2b9910b9d418ed3e36a9624c57b9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1172 zcmbtUy^ho{5T4}@3B-?}Ku9!5tb`~w+T9?~aTU!KbXQVg`4VSi;W)u|mfaH%zyly^ zItt(s;0Y*r0w`!`5O08(asIrKpuy6t{Y}34@yvL?T>AYJVE+{W902US$Ndh3>Low0H)jN)6yh%m90j05gP)LlP5TEg*BjB=MabH4Elx^hn_g2cH&H&$has5<^DrOH!W6lm|HTb@M{#ksRGDzaGP$X%HYn-) za7~@ZGZ@wg>3&{E_t^1B{2M6Wg4_-rH!IN@^Rxtk#K>r4Cf7k!um)s#Xe=)b(ao -#include - /plugin/; / { - compatible = "nextthing,chip", "allwinner,sun5i-r8"; + compatible = "nextthing,chip", "allwinner,sun5i-r8"; - /* activate the gpio for interrupt */ - fragment@0 { - target-path = <&pio>; + /* activate the gpio for interrupt */ + fragment@0 { + target-path = <&pio>; - __overlay__ { - chip_spi2_pins: spi2@0 { - allwinner,pins = "PE1", "PE2", "PE3"; - allwinner,function = "spi2"; - allwinner,drive = ; - allwinner,pull = ; - }; + __overlay__ { + chip_spi2_pins: spi2@0 { + allwinner,pins = "PE1", "PE2", "PE3"; + allwinner,function = "spi2"; + allwinner,drive = "0"; //; + allwinner,pull = "0"; //; + }; - chip_spi2_cs0_pins: spi2_cs0@0 { - allwinner,pins = "PE0"; - allwinner,function = "spi2"; - allwinner,drive = ; - allwinner,pull = ; - }; - }; + chip_spi2_cs0_pins: spi2_cs0@0 { + allwinner,pins = "PE0"; + allwinner,function = "spi2"; + allwinner,drive = "0"; //; + allwinner,pull = "0"; //; + }; }; + }; - /* - * Enable our SPI device, with an spidev device connected - * to it - */ - fragment@1 { - target = <&spi2>; + /* + * Enable our SPI device, with an spidev device connected + * to it + */ + fragment@1 { + target = <&spi2>; - __overlay__ { - #address-cells = <1>; - #size-cells = <0>; - pinctrl-names = "default"; - pinctrl-0 = <&chip_spi2_pins>, <&chip_spi2_cs0_pins>; - status = "okay"; + __overlay__ { + #address-cells = <1>; + #size-cells = <0>; + pinctrl-names = "default"; + pinctrl-0 = <&chip_spi2_pins>, <&chip_spi2_cs0_pins>; + status = "okay"; - spi2@0 { - //compatible = "spidev"; - compatible = "rohm,dh2228fv"; - reg = <0>; - spi-max-frequency = <24000000>; - }; - }; + spi2@0 { + compatible = "rohm,dh2228fv"; + reg = <0>; + spi-max-frequency = <24000000>; + }; }; + }; }; + diff --git a/setup.py b/setup.py index c95942a..4cb737a 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ try: from overlays import builder - #builder.compile() + builder.compile() builder.copy() except: pass @@ -20,7 +20,7 @@ classifiers = ['Development Status :: 3 - Alpha', 'Topic :: System :: Hardware'] setup(name = 'CHIP_IO', - version = '0.2.0', + version = '0.2.1', 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 6df746a..e7a481e 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.2.0"); + version = Py_BuildValue("s", "0.2.1"); PyModule_AddObject(module, "VERSION", version); } From 0ed1cfb35263a633b6ab7f5fa6b0acc15d6eddfc Mon Sep 17 00:00:00 2001 From: Robert Wolterman Date: Wed, 20 Jul 2016 08:49:42 -0500 Subject: [PATCH 8/8] Updating the builder script to let the user know what's happening. PR#12, Issue #10 --- overlays/builder.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/overlays/builder.py b/overlays/builder.py index e4e625c..4355f96 100644 --- a/overlays/builder.py +++ b/overlays/builder.py @@ -4,15 +4,20 @@ import shutil import glob def compile(): + print("Compiling DTS Files") call(["dtc", "-O", "dtb", "-o", "overlays/chip-spi2.dtbo", "-b", "o", "-@", "overlays/chip-spi2.dts"]) call(["dtc", "-O", "dtb", "-o", "overlays/chip-i2c1.dtbo", "-b", "o", "-@", "overlays/chip-i2c1.dts"]) call(["dtc", "-O", "dtb", "-o", "overlays/chip-pwm0.dtbo", "-b", "o", "-@", "overlays/chip-pwm0.dts"]) def copy(): + print("Checking for DTBO Install Path") if not os.path.exists("/lib/firmware/chip_io/"): + print("Path not found, creating /lib/firmware/chip_io/") os.makedirs("/lib/firmware/chip_io/") + print("Removing old DTBO files (if applicable)") for fl in glob.glob("/lib/firmware/chip_io/chip-*-.dtbo"): os.remove(fl) + print("Moving DTBO files to /lib/firmware/chip_io/") shutil.move("overlays/chip-spi2.dtbo", "/lib/firmware/chip_io/chip-spi2.dtbo") shutil.move("overlays/chip-i2c1.dtbo", "/lib/firmware/chip_io/chip-i2c1.dtbo") shutil.move("overlays/chip-pwm0.dtbo", "/lib/firmware/chip_io/chip-pwm0.dtbo")