use class iterator for mk_connection (all of them)
[pinmux.git] / src / ifacebase.py
index cdbfc4d63d23e279bca6a988b0f7df533c2d1cf5..fb5cd7a651735cedea96bf937e1c6a02c2c55344 100644 (file)
@@ -6,6 +6,7 @@ try:
 except ImportError:
     from collections import UserDict
 
+
 def _decode_list(data):
     rv = []
     for item in data:
@@ -18,6 +19,7 @@ def _decode_list(data):
         rv.append(item)
     return rv
 
+
 def _decode_dict(data):
     rv = {}
     for key, value in data.iteritems():
@@ -32,13 +34,13 @@ def _decode_dict(data):
         rv[key] = value
     return rv
 
+
 class InterfacesBase(UserDict):
     """ contains a list of interface definitions
     """
 
     def __init__(self, ifacekls, pth=None, ifaceklsdict=None):
         self.pth = pth
-        self.fastbus = []
         self.ifacecount = []
         self.fastbus = []
         if ifaceklsdict is None:
@@ -52,18 +54,25 @@ class InterfacesBase(UserDict):
             ift = os.path.join(pth, ift)
             cfg = os.path.join(pth, cfg)
 
+        # read in configs in JSON format, but strip out unicode
         with open(cfg, 'r') as ifile:
             self.configs = json.loads(ifile.read(), object_hook=_decode_dict)
 
-        print self.configs
+        # process the configs, look for "bus" type... XXX TODO; make this
+        # a bit more sophisticated
+        self.fastbus = []
+        for (ifacename, v) in self.configs.items():
+            if v.get('bus', "") == "fastbus":
+                self.fastbus.append(ifacename)
 
-        exit(0)
+        # reads the interfaces, name and quantity of each
         with open(ift, 'r') as ifile:
             for ln in ifile.readlines():
                 ln = ln.strip()
                 ln = ln.split("\t")
                 name = ln[0]  # will have uart
                 count = int(ln[1])  # will have count of uart
+
                 # spec looks like this:
                 """
                 [{'name': 'sda', 'outen': True},
@@ -86,6 +95,19 @@ class InterfacesBase(UserDict):
                 else:
                     iface = ikls(name, spec, ganged, count == 1)
                     self.ifaceadd(name, count, iface)
+                cfgs = self.getconfigs(name, count)
+                iface.configs = cfgs
+                print name, count, cfgs
+
+    def getconfigs(self, fname, count):
+        cfgs = []
+        for i in range(count):
+            if count == 1:
+                name = fname
+            else:
+                name = "%s%d" % (fname, i)
+            cfgs.append(self.configs.get(name, {}))
+        return cfgs
 
     def getifacetype(self, fname):
         # finds the interface type, e.g sd_d0 returns "inout"