add litex name map
[pinmux.git] / src / pinmux_generator.py
index e34b4c557f3e53e6b8ad4a1aa47e9e931e7b3a23..3e92bf062353d043b1a5258dc759d54212c0ecaa 100644 (file)
 import getopt
 import os.path
 import sys
+import json
 from spec import modules, specgen, dummytest
 
-from bsv.pinmux_generator import pinmuxgen as bsvgen
-
 
 def printhelp():
     print ('''pinmux_generator.py [-o outputdir] [-v|--validate] [-h|--help]
@@ -83,20 +82,35 @@ if __name__ == '__main__':
         module = modules[pinspec]
 
         fname = os.path.join(output_dir or '', "%s.mdwn" % pinspec)
+        pyname = os.path.join(output_dir or '', "%s_pins.py" % pinspec)
         d = os.path.split(fname)[0]
         if not os.path.exists(d):
             os.makedirs(d)
         with open(fname, "w") as of:
-            ps = module.pinspec()
-            pinout, bankspec, pinspec, fixedpins = ps.write(of)
-            if testing:
-                dummytest(ps, output_dir, output_type)
-            else:
-                specgen(of, output_dir, pinout, bankspec, pinspec, fixedpins)
+            with open(pyname, "w") as pyf:
+                ps = module.pinspec()
+                pm, chip = module.pinparse(ps, pinspec)
+                litexmap = ps.pywrite(pyf, pm)
+                pinout, bankspec, pin_spec, fixedpins = ps.write(of)
+                #chip['litex.map'] = litexmap
+                chip = json.dumps(chip)
+                with open("%s/litex_pinpads.json" % pinspec, "w") as f:
+                    f.write(chip)
+
+                if testing:
+                    dummytest(ps, output_dir, output_type)
+                else:
+                    specgen(of, output_dir, pinout,
+                            bankspec, ps.muxwidths, pin_spec, fixedpins,
+                            ps.fastbus)
     else:
-        gentypes = {'bsv': bsvgen}
-        if output_type not in gentypes:
+        if output_type == 'bsv':
+            from bsv.pinmux_generator import pinmuxgen as gentypes
+        elif output_type == 'myhdl':
+            from myhdlgen.pinmux_generator import pinmuxgen as gentypes
+        else:
             print ("ERROR: output type '%s' does not exist" % output_type)
             printhelp()
             sys.exit(0)
-        gentypes[output_type](output_dir, validate)
+
+        gentypes(output_dir, validate)