]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
Reimplementation of corresponding circuitpython version
authorCefn Hoile <github.com@cefn.com>
Fri, 16 Feb 2018 21:27:32 +0000 (21:27 +0000)
committerCefn Hoile <github.com@cefn.com>
Fri, 16 Feb 2018 21:27:32 +0000 (21:27 +0000)
python/microcontroller/__init__.py [new file with mode: 0644]
python/microcontroller/esp8266.py [new file with mode: 0644]
python/microcontroller/pin.py [new file with mode: 0644]
python/testing/microcontroller.py [new file with mode: 0644]

diff --git a/python/microcontroller/__init__.py b/python/microcontroller/__init__.py
new file mode 100644 (file)
index 0000000..66ce041
--- /dev/null
@@ -0,0 +1,3 @@
+import agnostic
+if agnostic.platform == "esp8266":
+    from microcontroller.esp8266 import *
\ No newline at end of file
diff --git a/python/microcontroller/esp8266.py b/python/microcontroller/esp8266.py
new file mode 100644 (file)
index 0000000..ff0960f
--- /dev/null
@@ -0,0 +1,20 @@
+from mcp import Enum
+class Pin(Enum):
+    def __init__(self, num):
+        self.num = num
+    pass
+Pin.GPIO0=Pin(0)
+Pin.GPIO2=Pin(2)
+Pin.GPIO4=Pin(4)
+Pin.GPIO5=Pin(5)
+Pin.GPIO12=Pin(12)
+Pin.GPIO13=Pin(13)
+Pin.GPIO14=Pin(14)
+Pin.GPIO15=Pin(15)
+Pin.GPIO16=Pin(16)
+
+
+class cpu():
+    def frequency(self):
+        from machine import freq
+        return freq()
diff --git a/python/microcontroller/pin.py b/python/microcontroller/pin.py
new file mode 100644 (file)
index 0000000..73cba87
--- /dev/null
@@ -0,0 +1,3 @@
+from microcontroller import Pin
+for key,val in Pin.iteritems():
+    globals()[key]=val
\ No newline at end of file
diff --git a/python/testing/microcontroller.py b/python/testing/microcontroller.py
new file mode 100644 (file)
index 0000000..23e1347
--- /dev/null
@@ -0,0 +1,15 @@
+import unittest
+import agnostic
+
+
+class TestMicrocontrollerModule(unittest.TestCase):
+
+
+    def test_pins_exist(self):
+        import microcontroller
+        import microcontroller.pin as pin
+        entries = [getattr(pin, key) for key in dir(pin)]
+        # is this filter line needed? any other types valid in pin module?
+        entries = list(filter(lambda val: type(val) is microcontroller.Pin, entries))
+        if agnostic.platform == "esp8266":
+            self.assertTrue(len(entries) == 10)
\ No newline at end of file