refactor peripheral_gen, split out interface classes
[pinmux.git] / src / bsv / peripheral_gen / twi.py
1 from bsv.peripheral_gen.base import PBase
2
3 class twi(PBase):
4
5 def slowimport(self):
6 return " import I2C_top :: *;"
7
8 def slowifdecl(self):
9 return " interface I2C_out twi{0}_out;\n" + \
10 " method Bit#(1) twi{0}_isint;"
11
12 def num_axi_regs32(self):
13 return 8
14
15 def mkslow_peripheral(self, size=0):
16 return " I2C_IFC twi{0} <- mkI2CController();"
17
18 def _mk_connection(self, name=None, count=0):
19 return "twi{0}.slave_i2c_axi"
20
21 def pinname_out(self, pname):
22 return {'sda': 'out.sda_out',
23 'scl': 'out.scl_out'}.get(pname, '')
24
25 def pinname_in(self, pname):
26 return {'sda': 'out.sda_in',
27 'scl': 'out.scl_in'}.get(pname, '')
28
29 def pinname_outen(self, pname):
30 return {'sda': 'out.sda_out_en',
31 'scl': 'out.scl_out_en'}.get(pname, '')
32
33 def pinname_tweak(self, pname, typ, txt):
34 if typ == 'outen':
35 return "pack({0})".format(txt)
36 return txt
37
38 def num_irqs(self):
39 return 3
40
41 def plic_object(self, pname, idx):
42 return ["{0}.isint()",
43 "{0}.timerint()",
44 "{0}.isber()"
45 ][idx].format(pname)
46
47 def mk_ext_ifacedef(self, iname, inum):
48 name = self.get_iname(inum)
49 return " method {0}_isint = {0}.isint;".format(name)
50
51 def slowifdeclmux(self):
52 return " method Bit#(1) {1}{0}_isint;"
53
54