1#Diagram demonstrating how to build a command link for an I2C master to send n bytes to a slave
2
3
4blockdiag i2c-command-link-master-write {
5    # global properties
6    span_width = 5;
7    span_height = 5;
8    node_height = 25;
9    default_group_color = lightgrey;
10    class spacer [shape=none, width=10];
11    class cmdlink [colwidth=2, width=180];
12    class cjoint [shape=none, width=40];
13
14    # all the rows
15    0 -- a0 --                         f0 [style=none];
16    1 -- a1 -- b1 -- c1 -- d1 -- e1 -- f1 -- g1 -- h1 [style=none];
17    2 -- a2 -- b2 -- c2 -- d2 -- e2 -- f2 -- g2 [style=none];
18    3 -- a3 --             d3 --       f3 [style=none];
19    4 -- a4 [style=none];
20    5 -- a5 [style=none];
21    6 -- a6 --       c6 [style=none];
22    7 -- a7 --       c7 -- d7 [style=none];
23    8 -- a8 --       c8 --              f8 [style=none];
24    9 -- a9 --       c9 --                         h9 [style=none];
25    10 -- a10 [style=none];
26    11 -- a11 [style=none];
27
28    # separator row
29    3, a3, d3, f3 [shape=none, height=5];
30
31    # tuning node properties and connections
32    0 [class=spacer]; a0 [shape=none, colwidth=5]; f0 [shape=note, colwidth=2];
33    1 [class=spacer]; a1 [shape=none]; b1; c1 [width=40]; e1 [shape=none, width=30]; g1 [shape=none, width=30]; h1 [width=40];
34    2 [class=spacer]; a2 [shape=none]; b2; c2 [class=cjoint]; d2 [shape=none]; e2 [width=30]; f2 [shape=none]; g2 [width=30];
35    3 [class=spacer]; a3 [shape=none, colwidth=3]; d3 [colwidth=2]; f3 [colwidth=2];
36    4 [class=spacer]; a4 [class=cmdlink]
37    5 [class=spacer]; a5 [class=cmdlink];
38    6 [class=spacer]; a6 [class=cmdlink]; c6 [class=cjoint]; a6 -- c6 [style=solid]; c6 -- c2 -> c1 [folded];
39    7 [class=spacer]; a7 [class=cmdlink]; c7 [class=cjoint]; d7 [shape=none, colwidth=2]; a7 -- c7 -- d7 [style=solid]; d7 -> d3 [folded];
40    8 [class=spacer]; a8 [class=cmdlink]; c8 [class=cjoint, colwidth=3]; f8 [shape=none, colwidth=2]; a8 -- c8 -- f8 [style=solid]; f8 -> f3 [folded];
41    9 [class=spacer]; a9 [class=cmdlink]; c9 [class=cjoint, colwidth=5]; h9 [shape=none, width=40]; a9 -- c9 -- h9 [style=solid]; h9 -> h1 [folded];
42    10 [class=spacer]; a10 [class=cmdlink];
43    11 [class=spacer]; a11 [class=cmdlink];
44
45    # labels
46    f0 [label="Data n times", shape=note, color=yellow];
47    b1 [label=Master, shape=note, color=lightyellow]; c1 [label=START]; d1 [label="Slave Address"]; f1 [label=Data]; h1 [label=STOP];
48    b2 [label=Slave, shape=note, color=lightyellow]; e2 [label=ACK]; g2 [label=ACK];
49    a4 [shape=note, label=Commands, color=yellow];
50    a5 [label="cmd = i2c_cmd_link_create()", numbered = 1];
51    a6 [label="i2c_master_start(cmd)", numbered = 2];
52    a7 [label="i2c_master_write_byte(cmd, Address, ACK)", numbered = 3];
53    a8 [label="i2c_master_write(Data, n, ACK)", numbered = 4];
54    a9 [label="i2c_master_stop(cmd)", numbered = 5];
55    a10 [label="i2c_master_cmd_begin(I2c_port, cmd, wait)", numbered = 6];
56    a11 [label="i2c_cmd_link_delete(cmd)", numbered = 7];
57
58    # Slave Address
59    group { d1; e1; }
60    group { d2; e2; d3; }
61
62    # Data x n times
63    group { f1; g1;}
64    group { f2; g2; f3; }
65    }
66