-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_doc.py
59 lines (55 loc) · 2.34 KB
/
build_doc.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
import os
import wavedrom
import cairosvg
# Building the timing diagrams
diagrams = [
"""{ "head": { "text": "Combinatory vs Syncronous assignment" },
"signal": [
{ "name": "CK", "wave": "P...", "period": 2 },
{ "name": "a", "wave": "0.1.....", "phase": 0.5 },
{ "name": "b", "wave": "0..1....", "phase": 0.5 },
{ "name": "c_comb", "wave": "0..1....","phase": 0.5 },
{ "name": "d", "wave": "0...1..." },
{ "name": "e", "wave": "0.....1." }
]}""",
"""{ "head": { "text": "Button debouncing" },
"signal": [
{ "name": "CK", "wave": "P......", "period": 2 },
{ "name": "button", "wave": "0.10.1..0.1...", "phase": 0.5 },
{ "name": "timer", "wave": "=.=.=.=...=.=.", "data": ["0", "2", "1", "0", "2", "1"] },
{ "name": "pressed", "wave": "0.1.....0.1..." }
]}""",
"""{ "head": { "text": "Combinatory vs Synchronous assignment" },
"signal": [
{ "name": "CK", "wave": "P........", "period": 2 },
{ "name": "led_col[0]", "wave": "1.0.............1." },
{ "name": "led_col[1]", "wave": "0.1.0............." },
{ "name": "led_col[2]", "wave": "0...1.0..........." },
{ "name": "led_col[3]", "wave": "0.....1.0........." },
{ "name": "..." },
{ "name": "led_col[7]", "wave": "0.............1.0." },
{},
{ "name": "led_row[0:8]", "wave": "=.=.=.=.=.=.=.=.=.", "data": ["row 0", "row 1", "row 2", "row 3", "row 4", "row 5", "row 6", "row 7", "row 0"] }
]}""",
"""{ "head": { "text": "Stream interface" },
"signal": [
{ "name": "CK", "wave": "P........", "period": 2 },
{ "name": "rdy (from sink)", "wave": "0.....1............." },
{ "name": "ack (from source)", "wave": "0.1.0...1.0...1...0." },
{ "name": "data (from source)", "wave": "x.......=.x...=.=.x.", "data": ["#1", "#2", "#3"] }
]}"""
]
def build_diagrams(pdf_mode=False):
for i, diagram in enumerate(diagrams):
svg_path = f"doc/diagram{i+1:02}.svg"
png_path = f"doc/diagram{i+1:02}.png"
print(f"Building {png_path}")
svg = wavedrom.render(diagram)
svg.saveas(svg_path)
if pdf_mode:
cairosvg.svg2pdf(url=svg_path, write_to=png_path, output_width=500)
else:
cairosvg.svg2png(url=svg_path, write_to=png_path, output_width=1000)
build_diagrams(True) # first we make PDF diagrams as they look better with Rinoh
os.system('rinoh README.md')
build_diagrams() # Now we make PNG images so it's viewable online