X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fifacebase.py;h=cdbfc4d63d23e279bca6a988b0f7df533c2d1cf5;hb=c492bfb3a86f01e770414f52c1f5884c1bc80cea;hp=2fb834cbfff5e3e39f0df2384277b4bbbdc13372;hpb=1b6fa9b183cfa6c14a58c45cd899314a0bc7922b;p=pinmux.git diff --git a/src/ifacebase.py b/src/ifacebase.py index 2fb834c..cdbfc4d 100644 --- a/src/ifacebase.py +++ b/src/ifacebase.py @@ -1,3 +1,4 @@ +import json import os.path try: @@ -5,20 +6,58 @@ try: except ImportError: from collections import UserDict +def _decode_list(data): + rv = [] + for item in data: + if isinstance(item, unicode): + item = item.encode('utf-8') + elif isinstance(item, list): + item = _decode_list(item) + elif isinstance(item, dict): + item = _decode_dict(item) + rv.append(item) + return rv + +def _decode_dict(data): + rv = {} + for key, value in data.iteritems(): + if isinstance(key, unicode): + key = key.encode('utf-8') + if isinstance(value, unicode): + value = value.encode('utf-8') + elif isinstance(value, list): + value = _decode_list(value) + elif isinstance(value, dict): + value = _decode_dict(value) + rv[key] = value + return rv class InterfacesBase(UserDict): """ contains a list of interface definitions """ - def __init__(self, ifacekls, pth=None): + def __init__(self, ifacekls, pth=None, ifaceklsdict=None): self.pth = pth + self.fastbus = [] self.ifacecount = [] + self.fastbus = [] + if ifaceklsdict is None: + ifaceklsdict = {} UserDict.__init__(self, {}) if not pth: return ift = 'interfaces.txt' + cfg = 'configs.txt' if pth: ift = os.path.join(pth, ift) + cfg = os.path.join(pth, cfg) + + with open(cfg, 'r') as ifile: + self.configs = json.loads(ifile.read(), object_hook=_decode_dict) + + print self.configs + + exit(0) with open(ift, 'r') as ifile: for ln in ifile.readlines(): ln = ln.strip() @@ -31,14 +70,29 @@ class InterfacesBase(UserDict): {'name': 'scl', 'outen': True}, ] """ + ikls = ifacekls + for k, v in ifaceklsdict.items(): + if name.startswith(k): + ikls = v + break spec, ganged = self.read_spec(pth, name) - iface = ifacekls(name, spec, ganged, count == 1) - self.ifaceadd(name, count, iface) + # XXX HORRIBLE hack!!! + if name == 'pwm' and count == 1 and len(spec) != 1: + #print "read", name, count, spec, ganged + #print "multi pwm", spec[:1], len(spec) + spec[0]['name'] = 'out' + iface = ikls(name, spec[:1], ganged, False) + self.ifaceadd(name, len(spec), iface) + else: + iface = ikls(name, spec, ganged, count == 1) + self.ifaceadd(name, count, iface) def getifacetype(self, fname): # finds the interface type, e.g sd_d0 returns "inout" for iface in self.values(): typ = iface.getifacetype(fname) + # if fname.startswith('pwm'): + # print fname, iface.ifacename, typ if typ: return typ return None @@ -66,7 +120,8 @@ class InterfacesBase(UserDict): ln = ln.strip() ln = ln.split("\t") name = ln[0] - d = {'name': name} # here we start to make the dictionary + d = {'name': name, # here we start to make the dictionary + 'type': ln[1]} if ln[1] == 'out': d['action'] = True # adding element to the dict elif ln[1] == 'inout': @@ -78,4 +133,3 @@ class InterfacesBase(UserDict): ganged[bus].append(name) spec.append(d) return spec, ganged -