Interops with non-BBB platforms
[matches/MCTX3420.git] / notes / pin maps / parseit.py
1 import sys, re, os
2 #lut size of 93 (46 pins/header; 2 headers; padding for 1-indexed)
3
4 def doit(x):
5     '''generate the lut from the csv'''
6     lut = {}
7     reverselut = {}
8     
9     with open(x) as f:
10         for line in f:
11             m = re.search("P(\d)_(\d+),(\d+)", line)
12             header = int(m.group(1))
13             pin = int(m.group(2))
14             gpionum = int(m.group(3))
15
16             if header==8:
17                 header = 0
18             else:
19                 header = 1
20
21             lut[header*46+pin] = gpionum
22             reverselut[gpionum] = header*46+pin
23     lutarr = []
24     reverselutarr =[]
25     
26     for i in range(0, 93):
27         lutarr.append(lut.get(i, 0))
28
29     for i in range(0, 128):
30         reverselutarr.append(reverselut.get(i, 0))
31         
32     return (lutarr, reverselutarr)
33
34 def printlut(lut, name="g_gpio_lut"):
35     '''print the lut for C'''
36     rowsize = 14
37     print("const unsigned char %s[%d] = {" % (name, len(lut)))
38     low = 0
39     high = rowsize
40     for i in range(0, len(lut), rowsize):
41         print("\t", end="")
42         print(*("%3d" % g for g in lut[low:high]), sep=', ', end="")
43         low = high
44         high += rowsize
45         if low < len(lut):
46             print(",")
47         else:
48             print("")
49     print("}")
50
51
52         

UCC git Repository :: git.ucc.asn.au