From a2417c752d628f72b33727721d29c8787a034a10 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 23 Jul 2018 11:53:09 +0100 Subject: [PATCH] pass in Interface factory, to do GPIO differently --- src/bsv/interface_decl.py | 5 ++++- src/ifacebase.py | 13 ++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/bsv/interface_decl.py b/src/bsv/interface_decl.py index 1a728fa..3da0fc0 100644 --- a/src/bsv/interface_decl.py +++ b/src/bsv/interface_decl.py @@ -350,13 +350,16 @@ class IOInterface(Interface): def wirefmt(self, *args): return generic_io.format(*args) +class InterfaceGPIO(Interface): + pass class Interfaces(InterfacesBase, PeripheralInterfaces): """ contains a list of interface definitions """ def __init__(self, pth=None): - InterfacesBase.__init__(self, Interface, pth) + InterfacesBase.__init__(self, Interface, pth, + {'gpio': InterfaceGPIO }) PeripheralInterfaces.__init__(self) def ifacedef(self, f, *args): diff --git a/src/ifacebase.py b/src/ifacebase.py index 0d6d250..e5e7e97 100644 --- a/src/ifacebase.py +++ b/src/ifacebase.py @@ -10,9 +10,11 @@ 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.ifacecount = [] + if ifaceklsdict is None: + ifaceklsdict = {} UserDict.__init__(self, {}) if not pth: return @@ -31,16 +33,21 @@ 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) # 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 = ifacekls(name, spec[:1], ganged, False) + iface = ikls(name, spec[:1], ganged, False) self.ifaceadd(name, len(spec), iface) else: - iface = ifacekls(name, spec, ganged, count == 1) + iface = ikls(name, spec, ganged, count == 1) self.ifaceadd(name, count, iface) def getifacetype(self, fname): -- 2.30.2