submodule update
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 4 Oct 2020 16:44:18 +0000 (17:44 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 4 Oct 2020 16:44:18 +0000 (17:44 +0100)
libreriscv
pinmux
src/soc/config/pinouts.py [new file with mode: 0644]

index cdd0f8a50f3c15703d8b507333b5df526b86210c..29c78ebd8ac03fd811a41ea772fe20813bdb1927 160000 (submodule)
@@ -1 +1 @@
-Subproject commit cdd0f8a50f3c15703d8b507333b5df526b86210c
+Subproject commit 29c78ebd8ac03fd811a41ea772fe20813bdb1927
diff --git a/pinmux b/pinmux
index f1e4b3a8bc48bcdfca867a0322096556e8317984..6e6f3a7e47ee08773d9ec0d8f129906ab28d140c 160000 (submodule)
--- a/pinmux
+++ b/pinmux
@@ -1 +1 @@
-Subproject commit f1e4b3a8bc48bcdfca867a0322096556e8317984
+Subproject commit 6e6f3a7e47ee08773d9ec0d8f129906ab28d140c
diff --git a/src/soc/config/pinouts.py b/src/soc/config/pinouts.py
new file mode 100644 (file)
index 0000000..95713e0
--- /dev/null
@@ -0,0 +1,59 @@
+import os
+import sys
+import json
+from pprint import pprint
+
+def _byteify(data, ignore_dicts = False):
+    # if this is a unicode string, return its string representation
+    try:
+        if isinstance(data, unicode):
+            return data.encode('utf-8')
+    except NameError:
+        return data
+    # if this is a list of values, return list of byteified values
+    if isinstance(data, list):
+        return [ _byteify(item, ignore_dicts=True) for item in data ]
+    # if this is a dictionary, return dictionary of byteified keys and values
+    # but only if we haven't already byteified it
+    if isinstance(data, dict) and not ignore_dicts:
+        return dict((_byteify(key, ignore_dicts=True),
+                    _byteify(value, ignore_dicts=True))
+                        for key, value in data.iteritems())
+    # if it's anything else, return it in its original form
+    return data
+
+def load_pinouts(chipname=None):
+    """load_pinouts - loads the JSON-formatted dictionary of a chip spec
+
+    note: this works only when pinmux is a correctly-initialised git submodule
+    and when the spec has been actually generated.  see Makefile "make mkpinmux"
+    """
+
+    # default pinouts for now: ls180
+    if chipname is None:
+        chipname = 'ls180'
+
+    # load JSON-formatted pad info from pinmux
+    pth = os.path.abspath(__file__)
+    pth = os.path.split(pth)[0]
+
+    # path is relative to this filename, in the pinmux submodule
+    fname = "%s/../../../pinmux/%s/litex_pinpads.json" % (pth, chipname)
+    with open(fname) as f:
+        txt = f.read()
+
+    # decode the json, strip unicode formatting (has to be recursive)
+    chip = json.loads(txt, object_hook=_byteify)
+    chip = _byteify(chip, ignore_dicts=True)
+
+    return chip
+
+if __name__ == '__main__':
+    if sys.argv == 2:
+        chipname = sys.argv[1]
+    else:
+        chipname = None
+    chip = load_pinouts(chipname)
+    for k, v in chip.items():
+        print ("\n****", k, "****")
+        pprint(v)