return generic_io.format(*args)
-class InterfaceLCD(Interface):
+class InterfaceBus(object):
- def get_n_iopins(self, pins): # HACK! assume in/out/outen so div by 3
- return len(pins)
+ def __init__(self, namelist, bitspec, filterbus):
+ self.namelist = namelist
+ self.bitspec = bitspec
+ self.fbus = filterbus # filter identifying which are bus pins
+
+ def get_nonbuspins(self):
+ return filter(lambda x: not x.name_.startswith(self.fbus), self.pins)
+
+ def get_buspins(self):
+ return filter(lambda x: x.name_.startswith(self.fbus), self.pins)
def ifacepfmt(self, *args):
- pins = filter(lambda x: not x.name_.startswith('out'), self.pins)
+ pins = self.get_nonbuspins()
res = '\n'.join(map(self.ifacepfmtdecpin, pins)).format(*args)
res = res.format(*args)
- pins = filter(lambda x: x.name_.startswith('out'), self.pins)
+ pins = self.get_buspins()
plen = self.get_n_iopins(pins)
- return "\n" + res + """
- interface Put#(Bit#({0})) data_out;
-""".format(plen)
+ res += '\n'
+ template = " interface {1}#(Bit#({0})) {2};\n"
+ for i, n in enumerate(self.namelist):
+ if not n:
+ continue
+ ftype = 'Get' if i == 2 else "Put"
+ res += template.format(plen, ftype, n)
+
+ return "\n" + res
def ifacedef2(self, *args):
- pins = filter(lambda x: not x.name_.startswith('out'), self.pins)
+ pins = self.get_nonbuspins()
res = '\n'.join(map(self.ifacedef2pin, pins))
res = res.format(*args)
- pins = filter(lambda x: x.name_.startswith('out'), self.pins)
+ pins = self.get_buspins()
plen = self.get_n_iopins(pins)
bitspec = "Bit#({0})".format(plen)
return '\n' + res + self.vectorifacedef2(pins, plen,
- ['data_out', None, None],
- bitspec, *args) + '\n'
+ self.namelist, bitspec, *args) + '\n'
def ifacedef3pin(self, idx, pin):
decfn = self.ifacefmtdecfn2
return pin.ifacedef3(idx, outfn, self.ifacefmtinfn,
decfn)
-class InterfaceNSPI(Interface):
- def get_n_iopins(self, pins): # HACK! assume in/out/outen so div by 3
- return len(pins) / 3
+class InterfaceLCD(InterfaceBus, Interface):
- def ifacepfmt(self, *args):
- pins = filter(lambda x: not x.name_.startswith('io'), self.pins)
- res = '\n'.join(map(self.ifacepfmtdecpin, pins)).format(*args)
- res = res.format(*args)
+ def __init__(self, *args):
+ InterfaceBus.__init__(self, ['data_out', None, None],
+ "Bit#({0})", "out")
+ Interface.__init__(self, *args)
- pins = filter(lambda x: x.name_.startswith('io'), self.pins)
- plen = self.get_n_iopins(pins)
+ def get_n_iopins(self, pins): # HACK! assume in/out/outen so div by 3
+ return len(pins)
- return "\n" + res + """
- interface Put#(Bit#({0})) io_out;
- interface Put#(Bit#({0})) io_out_en;
- interface Get#(Bit#({0})) io_in;
-""".format(plen)
- def ifacedef2(self, *args):
- pins = filter(lambda x: not x.name_.startswith('io'), self.pins)
- res = '\n'.join(map(self.ifacedef2pin, pins))
- res = res.format(*args)
+class InterfaceNSPI(InterfaceBus, Interface):
- pins = filter(lambda x: x.name_.startswith('io'), self.pins)
- plen = self.get_n_iopins(pins)
- bitspec = "Bit#({0})".format(plen)
- return '\n' + res + self.vectorifacedef2(pins, plen,
- ['io_out', 'io_out_en', 'io_in'],
- bitspec, *args) + '\n'
+ def __init__(self, *args):
+ InterfaceBus.__init__(self, ['io_out', 'io_out_en', 'io_in'],
+ "Bit#({0})", "io")
+ Interface.__init__(self, *args)
- def ifacedef3pin(self, idx, pin):
- decfn = self.ifacefmtdecfn2
- outfn = self.ifacefmtoutfn
- # print pin, pin.outenmode
- if pin.outenmode:
- decfn = self.ifacefmtdecfn3
- outfn = self.ifacefmtoutenfn
- return pin.ifacedef3(idx, outfn, self.ifacefmtinfn,
- decfn)
+ def get_n_iopins(self, pins): # HACK! assume in/out/outen so div by 3
+ return len(pins) / 3
class InterfaceEINT(Interface):
""" uses old-style (non-get/put) for now
"""
-
def ifacepfmt(self, *args):
res = '\n'.join(map(self.ifacefmtdecpin, self.pins)).format(*args)
return '\n' + res # pins is a list