X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=notes%2Fpin%20maps%2Fparseit.py;fp=notes%2Fpin%20maps%2Fparseit.py;h=0aab5ba1d55ed9a898ddf4964a88fa5fd9346229;hb=1faf2ef76c719ed79e13b359591082854e739fa3;hp=0000000000000000000000000000000000000000;hpb=4d4dd5fe26e40418c9ca04dc31e661be9d22f7d7;p=matches%2FMCTX3420.git diff --git a/notes/pin maps/parseit.py b/notes/pin maps/parseit.py new file mode 100644 index 0000000..0aab5ba --- /dev/null +++ b/notes/pin maps/parseit.py @@ -0,0 +1,48 @@ +import sys, re, os +#lut size of 93 (46 pins/header; 2 headers; padding for 1-indexed) + +def doit(x): + '''generate the lut from the csv''' + lut = {} + reverselut = {} + + with open(x) as f: + for line in f: + m = re.search("P(\d)_(\d+),(\d+)", line) + header = int(m.group(1)) + pin = int(m.group(2)) + gpionum = int(m.group(3)) + + if header==8: + header = 0 + else: + header = 1 + + lut[header*46+pin] = gpionum + reverselut[gpionum] = header*46+pin + lutarr = [] + reverselutarr =[] + + for i in range(0, 93): + lutarr.append(lut.get(i, 0)) + + for i in range(0, 128): + reverselutarr.append(reverselut.get(i, 0)) + + return (lutarr, reverselutarr) + +def printlut(lut, name="g_gpio_lut"): + '''print the lut for C''' + rowsize = 14 + print("const char %s[%d] = {" % (name, len(lut))) + low = 0 + high = rowsize + for i in range(0, len(lut), rowsize): + print("\t", end="") + print(*("%3d" % g for g in lut[low:high]), sep=', ') + low = high + high += rowsize + print("}") + + +