2018-01-05 02:19:51 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
'''
|
|
|
|
create alternate function tables
|
|
|
|
|
|
|
|
This assumes a csv file extracted from the datasheet using tablula:
|
|
|
|
|
|
|
|
https://github.com/tabulapdf/tabula
|
|
|
|
'''
|
|
|
|
|
|
|
|
import sys, csv, os
|
2020-11-11 14:26:06 -04:00
|
|
|
from functools import cmp_to_key
|
2018-01-05 02:19:51 -04:00
|
|
|
|
|
|
|
def is_pin(str):
|
|
|
|
'''see if a string is a valid pin name'''
|
|
|
|
if len(str) < 3:
|
|
|
|
return False
|
|
|
|
if str[0] != 'P':
|
|
|
|
return False
|
2019-02-06 17:10:40 -04:00
|
|
|
if str[1] not in "ABCDEFGHIJK":
|
2018-01-05 02:19:51 -04:00
|
|
|
return False
|
|
|
|
try:
|
|
|
|
p = int(str[2:])
|
|
|
|
if p < 0 or p > 15:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
except ValueError:
|
|
|
|
return False
|
|
|
|
|
2018-06-04 18:44:32 -03:00
|
|
|
def pin_compare(p1, p2):
|
|
|
|
'''control pin sort order'''
|
|
|
|
(p1,f1) = p1.split(':')
|
|
|
|
(p2,f2) = p2.split(':')
|
|
|
|
port1 = p1[:2]
|
|
|
|
port2 = p2[:2]
|
|
|
|
pin1 = int(p1[2:])
|
|
|
|
pin2 = int(p2[2:])
|
|
|
|
#print(port1, pin1, port2, pin2)
|
|
|
|
if port1 == port2:
|
|
|
|
if pin1 == pin2:
|
|
|
|
if f1 < f2:
|
|
|
|
return -1
|
|
|
|
return 1
|
|
|
|
if pin1 < pin2:
|
|
|
|
return -1
|
|
|
|
return 1
|
|
|
|
if port1 < port2:
|
|
|
|
return -1
|
|
|
|
return 1
|
|
|
|
|
2018-01-05 02:19:51 -04:00
|
|
|
def parse_af_table(fname, table):
|
2019-10-31 07:59:23 -03:00
|
|
|
csvt = csv.reader(open(fname,'r'))
|
2018-01-05 02:19:51 -04:00
|
|
|
i = 0
|
|
|
|
aflist = []
|
|
|
|
for row in csvt:
|
|
|
|
if len(row) > 2 and row[1] == 'AF0':
|
|
|
|
# it is a AF list
|
|
|
|
aflist = []
|
|
|
|
for s in row[1:]:
|
|
|
|
if s:
|
|
|
|
aflist.append(int(s[2:]))
|
|
|
|
if not is_pin(row[0]):
|
2018-06-04 18:44:32 -03:00
|
|
|
if len(row) < 2 or not is_pin(row[1]):
|
|
|
|
continue
|
|
|
|
row = row[1:]
|
2018-01-05 02:19:51 -04:00
|
|
|
pin = row[0]
|
|
|
|
for i in range(len(aflist)):
|
2019-10-31 07:59:23 -03:00
|
|
|
if len(row) <= i+1:
|
|
|
|
break
|
2018-01-05 02:19:51 -04:00
|
|
|
af = aflist[i]
|
|
|
|
s = row[i+1]
|
|
|
|
s = s.replace('_\r', '_')
|
|
|
|
s = s.replace('\r_', '_')
|
|
|
|
s = s.replace('\r', '')
|
|
|
|
s = s.replace(' ', '')
|
|
|
|
if s == '-' or len(s) == 0:
|
|
|
|
continue
|
|
|
|
functions = s.split('/')
|
|
|
|
for f in functions:
|
|
|
|
table[pin+':'+f.upper()] = af
|
|
|
|
|
|
|
|
table = {}
|
|
|
|
|
|
|
|
if len(sys.argv) != 2:
|
|
|
|
print("Error: expected 1 CSV file")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
parse_af_table(sys.argv[1], table)
|
|
|
|
|
|
|
|
sys.stdout.write("AltFunction_map = {\n");
|
|
|
|
sys.stdout.write('\t# format is PIN:FUNCTION : AFNUM\n')
|
|
|
|
sys.stdout.write('\t# extracted from %s\n' % os.path.basename(sys.argv[1]))
|
2020-11-11 14:26:06 -04:00
|
|
|
for k in sorted(table.keys(), key=cmp_to_key(pin_compare)):
|
2018-01-05 02:19:51 -04:00
|
|
|
s = '"' + k + '"'
|
|
|
|
sys.stdout.write('\t%-20s\t:\t%s,\n' % (s, table[k]))
|
|
|
|
sys.stdout.write("}\n");
|