blob: 4b2cbc93001d11f155a49e86e9a5c461cb26a9ed [file] [log] [blame] [view]
Mark Hayter14336e72019-12-29 16:21:34 -08001# i2csvg -- Generate svg pictures of I2C commands from text description
2
3i2csvg is a Python tool to read I2C transactions from a text file and
4generate `svg` pictures of them. It also supports SMBus transactions
5and the smbus subdirectory contains examples of how to use the tool to
6generate all the transactions from section 6.5 of the [SMBus
7Specification 3.0](http://smbus.org/specs/SMBus_3_0_20141220.pdf)
8
9Two source representations are supported. The first is a more
10readable format and describes transactions in text. The second is a
11hex-dump of values written to the I2C FIFO. In either format a line
12starting with a `#` is taken as a comment and a line staring with a
13`T` will be used to generate a title in the output.
14
15To assist in parsing debug output the tool can be given a prefix. Only
16lines with the prefix will be processed (after removal of the prefix).
17
18### Textual Source Format
19
20The textual description includes the flags and value written to the
21I2C host interface FIFO to make the transaction. The flags and data
22may be separated by whitespace. The flags are letters representing
23each of the 5 control bits written to the FIFO:
24
25|Flag | Use |
26|-----|-----|
27|S | Send a start signal before the data |
28|P | Send a stop signal after the data |
29|R | Read transaction (data value indicates how many bytes to read) |
30|C | With R, allows read to continue by ACK of the last byte read |
31|N | NACK OK, do not raise an error on a NACK |
32|. | A dot is guarenteed to be ignored in the input, it is included in the text output format to help readability |
33
34The flags may occur in any order (but not be repeated) and additional
35characters will be ignored. In general other than dot (`.`) other
36characters should be avoided since they may be used by future
37versions of the tool!
38
39The value may be an integer (binary, octal, decimal and hex
40supported) or one of the special values that change how the output is
41drawn:
42
43|Value | Use |
44|------|-----|
45|A0 | Address with direction bit set to 0 (write) |
46|A1 | Address with direction bit set to 1 (read) |
47|A2 | Address in SMBus Quick command with direction bit used for data |
48|M | Multi-byte transaction, drawn as D1, D2 ... DN (like SMBus) |
49|'tag'| In single quotes: Tag for the value that is drawn in output |
50
51Lines of the input may consist of a single flag+value per line or a
52comma separated list of flag+value pairs.
53
54### Hexdump source format
55
56In the hexdump source format tool processes the raw 13-bit data that
57is written to the I2C FIFO. This is normally in hex (preceded with
580x) but the tool will accept binary, octal or decimal. Lines of input
59may consist of a single hex value, multiple values separated by commas
60(and optionally whitespace) or multiple values separated by
61whitespace.
62
63### Output file format
64
65The output file generated depends on the options specified.
66
67|Type | Options|
68|-----|--------|
69|`.svg` | If multiple output files are generated or debug/text not selected |
70|`.html` | If debug/text is selected and svg is generated |
71|`.txt` | If debug/test is selected and no svg is generated (`--nosvg`) |
72
73The example commands assume `$REPO_TOP` is set to the toplevel
74directory of the repo.
75
76### Setup
77
78The i2csvg tool does not depend on any other packages.
79
80### Examples using i2csvg.py
81
82The i2csvg/examples directory contains some example I2C files. For
83simple examples text can be piped in to the tool using echo.
84
85A simple I2C write consists of a Start with Address and direction bit
86of zero, and a single data byte (4 in the example) with a Stop.
87
88The baseline tool will generate an svg file (which can be viewed in a
89browser) that includes the diagramatic form of the transaction and a
90line with the comma separated structured text form.
91
92```console
93$ cd $REPO_TOP/util
94$ echo "SA0, P4" | ./i2csvg.py > out.svg
95```
96
97The text version (which is just the input with more structured
98formatting) can be viewed in the terminal by suppressing the svg
99output. This output will always have the five flags in order and five
100characters in the flags field (including a `.` if the flag is not
101set):
102
103```console
104$ cd $REPO_TOP/util
105$ echo "SA0, P4" | ./i2csvg.py --text --nosvg
106S.... A0
107.P... 0x4
108```
109
110The debug version is intended for tool development:
111
112```console
113$ cd $REPO_TOP/util
114$ echo "SA0, P4" | ./i2csvg.py --debug --nosvg
115I2cOp(read=False, rcont=False, start=True, stop=False, nackok=False, mvalue=False, adr=True, size=10, fbyte=0, tag=None)
116I2cOp(read=False, rcont=False, start=False, stop=True, nackok=False, mvalue=False, adr=False, size=10, fbyte=4, tag=None)
117```
118
119If svg generation is not suppressed then the text or debug output and
120the svg are generated in an HTML file.
121
122```console
123$ cd $REPO_TOP/util
124$ echo "SA0, P4" | ./i2csvg.py --text > out.html
125```
126
127The smbus directory contains files with each of the commands listed in
128section 6.5 of the SMBus 3.0 specification. These can be used to
129generate an HTML file with all the transactions expanded.
130
131```console
132$ cd $REPO_TOP/util
133$ ./i2csvg.py i2csvg/smbus/*.txt > out.html
134```
135
136Alternatively, these can all be converted to individual svg files (for
137example for inclusion in documents) with the `--multiout` command.
138The output filename matches the input filename with the extension
139replaced with `.svg`. Note that if the `--text` or `--debug` flags
140are given then the output will be HTML and the extension will be
141`.html`.
142
143```console
144$ cd $REPO_TOP/util
145$ ls i2csvg/smbus
14601-Quick.txt 04-WriteWord.txt 07-BlockRead.txt 10-Write32.txt
14702-SendByte.txt 05-ReadByte.txt 07-BlockWrite.txt 11-Read32.txt
14803-ReceiveByte.txt 05-ReadWord.txt 08-BlockWrRdPCall.txt 12-Write64.txt
14904-WriteByte.txt 06-ProcessCall.txt 09-HostNotify.txt 13-Read64.txt
150$ ./i2csvg.py --multiout i2csvg/smbus/*.txt
151$ ls i2csvg/smbus
15201-Quick.svg 04-WriteWord.svg 07-BlockRead.svg 10-Write32.svg
15301-Quick.txt 04-WriteWord.txt 07-BlockRead.txt 10-Write32.txt
15402-SendByte.svg 05-ReadByte.svg 07-BlockWrite.svg 11-Read32.svg
15502-SendByte.txt 05-ReadByte.txt 07-BlockWrite.txt 11-Read32.txt
15603-ReceiveByte.svg 05-ReadWord.svg 08-BlockWrRdPCall.svg 12-Write64.svg
15703-ReceiveByte.txt 05-ReadWord.txt 08-BlockWrRdPCall.txt 12-Write64.txt
15804-WriteByte.svg 06-ProcessCall.svg 09-HostNotify.svg 13-Read64.svg
15904-WriteByte.txt 06-ProcessCall.txt 09-HostNotify.txt 13-Read64.txt
160```
161
162### Example use in Debugging
163
164The examples directory contains example output from a microcontroller
165using the I2C interface. Mixed in to the other debug output are lines
166produced when writes are done to the I2C FIFO. These lines are
167prefixed by `I2CF:` Prior to a transaction a title line starting with
168`T` is produced. This output can be processed to give a simple text
169representation:
170
171```console
172$ cd $REPO_TOP/util
173$ ./i2csvg.py --nosvg --text --fifodata --prefix=I2CF: i2csvg/examples/traceout.txt
174T read sensor
175S.... 0x40
176.PR.. 0x1
177T fix value
178S.... 0x41
179..... 0x22
180.P... 0x33
181```
182
183Or the output can be converted into pictures for display in a browser:
184
185```console
186$ cd $REPO_TOP/util
187$ ./i2csvg.py --text --fifodata --prefix=I2CF: i2csvg/examples/traceout.txt > out.html
188```
189