From: Luke Kenneth Casson Leighton Date: Sat, 31 Mar 2018 07:02:06 +0000 (+0100) Subject: write out to mdwn file instead of stdout X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1ba6e227d3d4d52d1bf6dac221e88d4bd2944924;p=pinmux.git write out to mdwn file instead of stdout --- diff --git a/src/pinmux_generator.py b/src/pinmux_generator.py index 05ebf2d..9512d4d 100644 --- a/src/pinmux_generator.py +++ b/src/pinmux_generator.py @@ -77,8 +77,10 @@ if __name__ == '__main__': printhelp() sys.exit(1) module = modules[pinspec] - pinout, bankspec, pinspec, fixedpins = module.pinspec() - specgen(output_dir, pinout, bankspec, pinspec, fixedpins) + fname = os.path.join(output_dir or '', "%s.mdwn" % pinspec) + with open(fname, "w") as of: + pinout, bankspec, pinspec, fixedpins = module.pinspec(of) + specgen(of, output_dir, pinout, bankspec, pinspec, fixedpins) else: gentypes = {'bsv': bsvgen} if output_type not in gentypes: diff --git a/src/spec/gen.py b/src/spec/gen.py index cb7957f..6c9f563 100644 --- a/src/spec/gen.py +++ b/src/spec/gen.py @@ -3,7 +3,7 @@ import os.path from spec.interfaces import Pinouts -def specgen(pth, pinouts, bankspec, pinbanks, fixedpins): +def specgen(of, pth, pinouts, bankspec, pinbanks, fixedpins): """ generates a specification of pinouts (tsv files) for reading in by pinmux """ @@ -60,8 +60,8 @@ def specgen(pth, pinouts, bankspec, pinbanks, fixedpins): g.write('\t'.join(p) + '\n') # lists bankspec, shows where the pin-numbers *start* - print ("# Pin Bank starting points and lengths\n") + of.write("# Pin Bank starting points and lengths\n\n") with open(os.path.join(pth, 'pinspec.txt'), 'w') as g: for bank, pinstart in bankspec.items(): - print ("* %s %d %d" % (bank, pinstart, pinbanks[bank])) + of.write("* %s %d %d\n" % (bank, pinstart, pinbanks[bank])) g.write("%s\t%d\t%d\n" % (bank, pinstart, pinbanks[bank])) diff --git a/src/spec/ifaceprint.py b/src/spec/ifaceprint.py index 5236a03..c1891f7 100644 --- a/src/spec/ifaceprint.py +++ b/src/spec/ifaceprint.py @@ -3,9 +3,11 @@ from copy import deepcopy -def display(pins): - print "| Pin | Mux0 | Mux1 | Mux2 | Mux3 |" - print "| --- | ----------- | ----------- | ----------- | ----------- |" +def display(of, pins): + of.write("""\ +| Pin | Mux0 | Mux1 | Mux2 | Mux3 | +| --- | ----------- | ----------- | ----------- | ----------- | +""") pinidx = sorted(pins.keys()) for pin in pinidx: pdata = pins.get(pin) @@ -16,7 +18,7 @@ def display(pins): continue name, bank = pdata[mux] res += " %s %-9s |" % (bank, name) - print res + of.write("%s\n" % res) def fnsplit(f): @@ -50,7 +52,7 @@ def find_fn(fname, names): return n -def display_fns(bankspec, pins, function_names): +def display_fns(of, bankspec, pins, function_names): fn_names = function_names.keys() fns = {} for (pin, pdata) in pins.items(): @@ -71,36 +73,30 @@ def display_fns(bankspec, pins, function_names): #print "name", fname, fnbase if fnbase != current_fn: if current_fn is not None: - print - print "## %s" % fnbase - print - print function_names[fnbase] - print + of.write('\n') + of.write("## %s\n\n%s\n\n" % (fnbase, function_names[fnbase])) current_fn = fnbase - print "* %-9s :" % fname, + of.write("* %-9s :" % fname) for (pin, mux, bank) in fns[fname]: - print "%s%d/%d" % (bank, pin, mux), - print + of.write(" %s%d/%d" % (bank, pin, mux)) + of.write('\n') return fns -def check_functions(title, bankspec, fns, pins, required, eint, pwm, +def check_functions(of, title, bankspec, fns, pins, required, eint, pwm, descriptions=None): fns = deepcopy(fns) pins = deepcopy(pins) if descriptions is None: descriptions = {} - print "# Pinmap for %s" % title - print + of.write("# Pinmap for %s\n\n" % title) for name in required: - print "## %s" % name - print + of.write("## %s\n\n" % name) if descriptions and name in descriptions: - print descriptions[name] - print + of.write("%s\n\n" % descriptions[name]) name = name.split(':') if len(name) == 2: @@ -144,9 +140,9 @@ def check_functions(title, bankspec, fns, pins, required, eint, pwm, if len(found) > count: continue del pins[pin_] - print "* %s %d %s%d/%d" % (fname, pin_, bank, pin, mux) + of.write("* %s %d %s%d/%d\n" % (fname, pin_, bank, pin, mux)) - print + of.write('\n') # gpios gpios = [] @@ -159,8 +155,7 @@ def check_functions(title, bankspec, fns, pins, required, eint, pwm, gpios.sort() if gpios: - print "## GPIO" - print + of.write("## GPIO\n\n") for fname in gpios: if fname in found: @@ -175,28 +170,25 @@ def check_functions(title, bankspec, fns, pins, required, eint, pwm, continue del pins[pin_] found.add(fname) - print "* %-8s %d %s%-2d %s" % (fname, pin_, bank, pin, desc) - print + of.write("* %-8s %d %s%-2d %s\n" % (fname, pin_, bank, pin, desc)) + of.write('\n') if eint: - display_group(bankspec, "EINT", eint, fns, pins, descriptions) + display_group(of, bankspec, "EINT", eint, fns, pins, descriptions) if pwm: - display_group(bankspec, "PWM", pwm, fns, pins, descriptions) + display_group(of, bankspec, "PWM", pwm, fns, pins, descriptions) - print "## Unused Pinouts (spare as GPIO) for '%s'" % title - print + of.write("## Unused Pinouts (spare as GPIO) for '%s'\n\n" % title) if descriptions and 'GPIO' in descriptions: - print descriptions['GPIO'] - print - display(pins) - print + of.write("%s\n\n" % descriptions['GPIO']) + display(of, pins) + of.write('\n') return pins # unused -def display_group(bankspec, title, todisplay, fns, pins, descriptions): - print "## %s" % title - print +def display_group(of, bankspec, title, todisplay, fns, pins, descriptions): + of.write("## %s\n\n" % title) found = set() for fname in todisplay: @@ -225,38 +217,38 @@ def display_group(bankspec, title, todisplay, fns, pins, descriptions): continue del pins[pin_] found.add(fname) - print "* %s %d %s%d/%d %s" % (fname, pin_, bank, pin, mux, desc) - print + of.write("* %s %d %s%d/%d %s\n" % + (fname, pin_, bank, pin, mux, desc)) + of.write('\n') -def display_fixed(fixed, offs): +def display_fixed(of, fixed, offs): fkeys = sorted(fixed.keys()) pin_ = offs res = [] for pin, k in enumerate(fkeys): - print "## %s" % k - print + of.write("## %s\n\n" % k) prevname = '' linecount = 0 for name in fixed[k]: if linecount == 4: linecount = 0 - print + of.write('\n') if prevname[:2] == name[:2] and linecount != 0: - print name, + of.write(" %s" % name) linecount += 1 else: if linecount != 0: - print - print "* %d: %d %s" % (pin_, pin, name), + of.write('\n') + of.write("* %d: %d %s" % (pin_, pin, name)) linecount = 1 res.append((pin_, name)) prevname = name pin_ += 1 if linecount != 0: - print - print + of.write('\n') + of.write('\n') return res diff --git a/src/spec/m_class.py b/src/spec/m_class.py index 3f3974b..d0dd7bd 100644 --- a/src/spec/m_class.py +++ b/src/spec/m_class.py @@ -6,7 +6,7 @@ from spec.ifaceprint import display, display_fns, check_functions from spec.ifaceprint import display_fixed -def pinspec(): +def pinspec(of): pinbanks = {'A': 16, 'B': 28, 'C': 24, @@ -142,14 +142,15 @@ def pinspec(): pinouts.sdmmc("1", ('G', 24), "G", 3, limit=2) pinouts.sdmmc("1", ('G', 28), "G", 2, start=2) - print ("""# Pinouts (PinMux) + of.write ("""# Pinouts (PinMux) auto-generated by [[pinouts.py]] [[!toc ]] + """) - display(pinouts) + display(of, pinouts) - print ("\n# Pinouts (Fixed function)\n") + of.write ("\n# Pinouts (Fixed function)\n\n") fixedpins = { 'DDR3': [ @@ -333,11 +334,12 @@ auto-generated by [[pinouts.py]] 'GND_GPIOG', ]} - fixedpins = display_fixed(fixedpins, len(pinouts)) + fixedpins = display_fixed(of, fixedpins, len(pinouts)) - print ("""# Functions (PinMux) + of.write ("""# Functions (PinMux) auto-generated by [[pinouts.py]] + """) function_names = {'EINT': 'External Interrupt', @@ -368,8 +370,8 @@ auto-generated by [[pinouts.py]] 'ULPI2': 'ULPI (USB Low Pin-count) 3', } - fns = display_fns(bankspec, pinouts, function_names) - print + fns = display_fns(of, bankspec, pinouts, function_names) + of.write('\n') # Scenarios below can be spec'd out as either "find first interface" # by name/number e.g. SPI0, or as "find in bank/mux" which must be @@ -401,7 +403,7 @@ auto-generated by [[pinouts.py]] 'ULPI1': 'EOMA68-compliance: dual USB2 Host ULPI PHY' } - unused_pins = check_functions("EOMA68", bankspec, fns, pinouts, + unused_pins = check_functions(of, "EOMA68", bankspec, fns, pinouts, eoma68, eoma68_eint, eoma68_pwm, descriptions) @@ -422,7 +424,7 @@ auto-generated by [[pinouts.py]] industrial_eint = ['EINT_24', 'EINT_25', 'EINT_26', 'EINT_27', 'EINT_20', 'EINT_21', 'EINT_22', 'EINT_23'] - unused_pins = check_functions("Industrial", bankspec, fns, pinouts, + unused_pins = check_functions(of, "Industrial", bankspec, fns, pinouts, industrial, industrial_eint, industrial_pwm) # Industrial scenario, using an SPI-based LCD instead of RGB/TTL @@ -445,7 +447,7 @@ auto-generated by [[pinouts.py]] 'B2:SPI0': 'Used for 320x240 or 640x480 etc. SPI-based LCD.\n' 'Frees up large numbers of GPIO from RGB/TTL bank' } - unused_pins = check_functions("Industrial with SPI-LCD", + unused_pins = check_functions(of, "Industrial with SPI-LCD", bankspec, fns, pinouts, industrial, industrial_eint, industrial_pwm, ind_descriptions) @@ -526,7 +528,7 @@ auto-generated by [[pinouts.py]] 'EINT_30': 'OTG_ID', 'EINT_31': 'Spare?', } - unused_pins = check_functions("Smartphone / Tablet", + unused_pins = check_functions(of, "Smartphone / Tablet", bankspec, fns, pinouts, tablet, tablet_eint, tablet_pwm, descriptions) @@ -582,7 +584,7 @@ auto-generated by [[pinouts.py]] 'EINT_9': 'MCU_INT', 'EINT_31': 'PMIC_INT', } - unused_pins = check_functions("Laptop / Netbook", + unused_pins = check_functions(of, "Laptop / Netbook", bankspec, fns, pinouts, laptop, laptop_eint, laptop_pwm, descriptions) @@ -675,12 +677,12 @@ auto-generated by [[pinouts.py]] 'EINT_30': 'CTP_INT', 'EINT_31': 'SD_DETN', } - unused_pins = check_functions("IoT", + unused_pins = check_functions(of, "IoT", bankspec, fns, pinouts, iot, iot_eint, iot_pwm, descriptions) - print ("""# Reference Datasheets + of.write ("""# Reference Datasheets datasheets and pinout links * @@ -692,6 +694,7 @@ datasheets and pinout links * * ULPI OTG PHY, ST * ULPI OTG PHY, TI TUSB1210 + """) return pinouts, bankspec, pinbanks, fixedpins diff --git a/src/spec/minitest.py b/src/spec/minitest.py index dc91d14..5820d54 100644 --- a/src/spec/minitest.py +++ b/src/spec/minitest.py @@ -6,7 +6,7 @@ from spec.ifaceprint import display, display_fns, check_functions from spec.ifaceprint import display_fixed -def pinspec(): +def pinspec(of): pinbanks = { 'B': 28, } @@ -41,14 +41,15 @@ def pinspec(): pinouts.uart("1", ('B', 2), "B", 2) pinouts.uart("2", ('B', 14), "B", 2) - print ("""# Pinouts (PinMux) + of.write("""# Pinouts (PinMux) auto-generated by [[pinouts.py]] [[!toc ]] + """) - display(pinouts) + display(of, pinouts) - print ("\n# Pinouts (Fixed function)\n") + of.write("\n# Pinouts (Fixed function)\n\n") fixedpins = { 'CTRL_SYS': [ @@ -71,11 +72,12 @@ auto-generated by [[pinouts.py]] 'GND_GPIOB', ]} - fixedpins = display_fixed(fixedpins, len(pinouts)) + fixedpins = display_fixed(of, fixedpins, len(pinouts)) - print ("""# Functions (PinMux) + of.write("""# Functions (PinMux) auto-generated by [[pinouts.py]] + """) function_names = {'EINT': 'External Interrupt', @@ -106,8 +108,8 @@ auto-generated by [[pinouts.py]] 'ULPI2': 'ULPI (USB Low Pin-count) 2', } - fns = display_fns(bankspec, pinouts, function_names) - print + fns = display_fns(of, bankspec, pinouts, function_names) + of.write("\n") # Scenarios below can be spec'd out as either "find first interface" # by name/number e.g. SPI1, or as "find in bank/mux" which must be @@ -133,11 +135,11 @@ auto-generated by [[pinouts.py]] 'ULPI1': 'dual USB2 Host ULPI PHY' } - unused_pins = check_functions("MiniTest", bankspec, fns, pinouts, + unused_pins = check_functions(of, "MiniTest", bankspec, fns, pinouts, minitest, minitest_eint, minitest_pwm, descriptions) - print ("""# Reference Datasheets + of.write("""# Reference Datasheets datasheets and pinout links * @@ -149,6 +151,7 @@ datasheets and pinout links * * ULPI OTG PHY, ST * ULPI OTG PHY, TI TUSB1210 + """) return pinouts, bankspec, pinbanks, fixedpins