forked from timvideos/HDMI2USB-jahanzeb-firmware
/
generate-ucf.py
136 lines (113 loc) · 4.63 KB
/
generate-ucf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vim: set ts=4 sw=4 et sts=4 ai:
import re
import cStringIO as StringIO
def main(argv):
import gdata.spreadsheet.service
client = gdata.spreadsheet.service.SpreadsheetsService()
key = '10vNcsOAxnuiwc5diespjIepMySxhR0iVZfYxouq4p-E'
w = client.GetWorksheetsFeed(key, visibility='public', projection='basic')
for sheet in w.entry:
if sheet.title.text.lower() == "Pins - Firmware".lower():
break
else:
raise Exception("'Pins - Firmware' sheet not found!")
sheet_key = sheet.id.text.split('/')[-1]
data = client.GetListFeed(key, sheet_key, visibility='public', projection='values')
boards = dict(sorted((k, v.text) for k, v in data.entry[0].custom.items() if v.text is not None))
print "Generating UCF files for", boards.values()
names_raw = list(sorted((k, v.text) for k, v in data.entry[1].custom.items()))
names = []
board = ''
while len(names_raw) > 0:
v = names_raw.pop(0)
if v[-1] is None:
continue
if v[0] in boards:
board = boards[v[0]]
if board:
r = (board, v[-1])
else:
r = v[-1]
names.append((v[0], r))
names = dict(names)
rows = list(dict((k, v.text) for k, v in r.custom.items() if v.text is not None) for r in data.entry[2:])
for board in boards.values():
print "Generating UCF file for %s" % board
print "-"*75
f = file('hdmi2usb-%s.ucf' % board.lower(), 'w')
f.write("""\
##############################################################################
# **** DO NOT EDIT THIS FILE! ****
#
# This file is automatically generated using the generate-ucf.py program.
# This program reads from the spreadsheet found at:
# https://docs.google.com/spreadsheets/d/10vNcsOAxnuiwc5diespjIepMySxhR0iVZfYxouq4p-E/edit#gid=1936356070
#
# To make changes to this file, edit the spreadsheet and then re-run
# generate-ucf.py
#
# This file is for %s board.
##############################################################################
CONFIG VCCAUX = 3.3;
""" % board)
module = None
for row in rows:
row4board = {}
for r, v in sorted(row.items()):
if r not in names:
continue
name = names[r]
if isinstance(name, tuple):
if name[0] != board:
continue
name = name[-1]
row4board[name] = v
if 'Description' not in row4board:
row4board['Description'] = '????'
# Skipping modules
if 'Module' not in row4board or row4board['Module'] in ('VHDCI', 'ETH', 'GTP', 'AUD', 'JTAG'):
continue
# This board doesn't have this module, so skip this row.
if row4board['Mod'] == 'No':
continue
if row4board['Mod'] == '???':
print "Warning %(Net Name)s is in unknown module." % row4board
continue
if 'Pin' not in row4board:
print "Warning %(Net Name)s has no pin!" % row4board
continue
if row4board['Pin'] == 'ERR!':
print "Warning %(Net Name)s is ERR! for this board." % row4board
continue
# Output module header, if new module
if module != row4board['Module']:
f.write("""
##############################################################################
# %(Module)s - %(Description)s
##############################################################################
""" % row4board)
module = row4board['Module']
# Output pin information
pin_config = [
(12, 'LOC = "%(Pin)s"' % row4board),
]
if 'IO Standard' in row4board and row4board['IO Standard'] != 'N/A':
pin_config.append((80, 'IOSTANDARD = %s;' % row4board['IO Standard']))
if 'Old Name' in row4board:
row4board['Description'] = "(%s) %s" % (row4board['Net Name'], row4board['Description'])
row4board['Net Name'] = row4board['Old Name']
row4board['Net Name'] = '"%s"' % row4board['Net Name']
row4board['Pin Config'] = " | ".join("%%-%is" % p % v for p, v in pin_config)
f.write("""\
NET %(Net Name) -18s %(Pin Config)s # %(Description)s
""" % row4board)
# Append the footer template
f.write(open('hdmi2usb-extra.ucf', 'r').read())
f.close()
print "Done!"
print "-"*75
if __name__ == "__main__":
import sys
main(sys.argv)