Add rpi-gpio-periphery, periphery

* Luma requires a RPI.GPIO-compatible GPIO class. Wrap periphery
  in a trival wrapper to map the APIS (for just GPIO).
* Also add periphery as a debian package.

Change-Id: I983995702a476b810913c908eb74d0691da031b9
diff --git a/.gitmodules b/.gitmodules
index 13e7d60..21b6a3a 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -18,3 +18,11 @@
 	path = python/dependencies/smbus2/smbus2
 	url = https://github.com/kplindegaard/smbus2.git
 	branch = master
+[submodule "python/dependencies/spidev/py-spidev"]
+	path = python/dependencies/spidev/py-spidev
+	url = https://github.com/doceme/py-spidev.git
+	branch = master
+[submodule "python/dependencies/periphery/periphery"]
+	path = python/dependencies/periphery/periphery
+	url = https://github.com/vsergeev/python-periphery.git
+	branch = master
diff --git a/python/coral-enviro/coral/enviro/rpi_gpio_periphery.py b/python/coral-enviro/coral/enviro/rpi_gpio_periphery.py
new file mode 100644
index 0000000..28b884b
--- /dev/null
+++ b/python/coral-enviro/coral/enviro/rpi_gpio_periphery.py
@@ -0,0 +1,43 @@
+# Copyright 2019 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Wrapper to enable RPi.GPIO API with periphery."""
+
+from periphery import GPIO
+
+
+class pGPIO(object):
+    # Convert values expected from RPi.GPIO
+    IN = "in"
+    OUT = "out"
+    HIGH = True
+    LOW = False
+    _gpios = dict()
+
+    def setup(self, channels, mode):
+       if isinstance(channels, (list,tuple)):
+           for i in channels:
+               self._gpios[i] = GPIO(i, mode)
+       else:
+           self._gpios[channels] = GPIO(channels, mode)
+
+    def output(self, channels, level):
+       if isinstance(channels, (list, tuple)):
+           for i in channels:
+               self._gpios[i].write(level)
+       else:
+           self._gpios[channels].write(level)
+
+    def input(self, channel):
+       return self._gpios[channel].read()
diff --git a/python/coral-enviro/debian/control b/python/coral-enviro/debian/control
index b71c197..d44119e 100644
--- a/python/coral-enviro/debian/control
+++ b/python/coral-enviro/debian/control
@@ -13,7 +13,8 @@
          python3-coral-cloudiot,
          python3-luma-oled (>= 2.3.2),
          python3-spidev,
-         coral-enviro-drivers-dkms
+         coral-enviro-drivers-dkms,
+         python3-rpi.gpio | python3-periphery
 Description: Coral Environmental Sensor Board Library
  Library and API to enable the Coral Environmental Sensor Board.
 
diff --git a/python/dependencies/periphery/debian/changelog b/python/dependencies/periphery/debian/changelog
new file mode 100644
index 0000000..fc8a3ca
--- /dev/null
+++ b/python/dependencies/periphery/debian/changelog
@@ -0,0 +1,5 @@
+periphery (1.1.1-1) unstable; urgency=low
+
+  * source package automatically created by stdeb 0.8.5
+
+ -- vsergeev <v@sergeev.io>  Wed, 01 May 2019 10:09:01 -0700
diff --git a/python/dependencies/periphery/debian/compat b/python/dependencies/periphery/debian/compat
new file mode 100644
index 0000000..7f8f011
--- /dev/null
+++ b/python/dependencies/periphery/debian/compat
@@ -0,0 +1 @@
+7
diff --git a/python/dependencies/periphery/debian/control b/python/dependencies/periphery/debian/control
new file mode 100644
index 0000000..5eca026
--- /dev/null
+++ b/python/dependencies/periphery/debian/control
@@ -0,0 +1,17 @@
+Source: periphery
+Maintainer: vsergeev <v@sergeev.io>
+Section: python
+Priority: optional
+Build-Depends: python3-setuptools, python3-all, debhelper (>= 7)
+Standards-Version: 3.9.1
+
+
+
+
+
+Package: python3-periphery
+Architecture: all
+Depends: ${misc:Depends}, ${python3:Depends}
+Description: A pure Python 2/3 library for peripheral I/O (GPIO, LED, PWM
+ python-periphery is a pure Python library for GPIO, LED, PWM, SPI, I2C, MMIO, and Serial peripheral I/O interface access in userspace Linux. It is useful in embedded Linux environments (including Raspberry Pi, BeagleBone, etc. platforms) for interfacing with external peripherals. python-periphery is compatible with Python 2 and Python 3, is written in pure Python, and is MIT licensed. See https://github.com/vsergeev/python-periphery for more information.
+
diff --git a/python/dependencies/periphery/debian/rules b/python/dependencies/periphery/debian/rules
new file mode 100755
index 0000000..6a7e0c9
--- /dev/null
+++ b/python/dependencies/periphery/debian/rules
@@ -0,0 +1,14 @@
+#!/usr/bin/make -f
+
+# This file was automatically generated by stdeb 0.8.5 at
+# Wed, 01 May 2019 10:09:01 -0700
+export PYBUILD_NAME=periphery
+
+%:
+	dh $@ --with python3 --buildsystem=pybuild --sourcedirectory=periphery/
+
+
+override_dh_auto_test:
+
+
+
diff --git a/python/dependencies/periphery/debian/source/format b/python/dependencies/periphery/debian/source/format
new file mode 100644
index 0000000..163aaf8
--- /dev/null
+++ b/python/dependencies/periphery/debian/source/format
@@ -0,0 +1 @@
+3.0 (quilt)
diff --git a/python/dependencies/periphery/debian/source/options b/python/dependencies/periphery/debian/source/options
new file mode 100644
index 0000000..bcc4bbb
--- /dev/null
+++ b/python/dependencies/periphery/debian/source/options
@@ -0,0 +1 @@
+extend-diff-ignore="\.egg-info$"
\ No newline at end of file
diff --git a/python/dependencies/periphery/periphery b/python/dependencies/periphery/periphery
new file mode 160000
index 0000000..ff4d535
--- /dev/null
+++ b/python/dependencies/periphery/periphery
@@ -0,0 +1 @@
+Subproject commit ff4d535691a1747a76962a3d077d96d224308611