pass in Interface factory, to do GPIO differently
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 23 Jul 2018 10:53:09 +0000 (11:53 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 23 Jul 2018 10:53:09 +0000 (11:53 +0100)
src/bsv/interface_decl.py
src/ifacebase.py

index 1a728fad8db9f6ee4674b19520da729865931651..3da0fc02610fe73652c3735216320950ee43aed2 100644 (file)
@@ -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):
index 0d6d25039ecb38be3c7afbacbd6a4f2b81ee036b..e5e7e974d17335c925b020367e39e565c9e60687 100644 (file)
@@ -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):