Mark Hayter | 14336e7 | 2019-12-29 16:21:34 -0800 | [diff] [blame] | 1 | # i2csvg -- Generate svg pictures of I2C commands from text description |
| 2 | |
| 3 | i2csvg is a Python tool to read I2C transactions from a text file and |
| 4 | generate `svg` pictures of them. It also supports SMBus transactions |
| 5 | and the smbus subdirectory contains examples of how to use the tool to |
| 6 | generate all the transactions from section 6.5 of the [SMBus |
| 7 | Specification 3.0](http://smbus.org/specs/SMBus_3_0_20141220.pdf) |
| 8 | |
| 9 | Two source representations are supported. The first is a more |
| 10 | readable format and describes transactions in text. The second is a |
| 11 | hex-dump of values written to the I2C FIFO. In either format a line |
| 12 | starting 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 | |
| 15 | To assist in parsing debug output the tool can be given a prefix. Only |
| 16 | lines with the prefix will be processed (after removal of the prefix). |
| 17 | |
| 18 | ### Textual Source Format |
| 19 | |
| 20 | The textual description includes the flags and value written to the |
| 21 | I2C host interface FIFO to make the transaction. The flags and data |
| 22 | may be separated by whitespace. The flags are letters representing |
| 23 | each 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 | |
| 34 | The flags may occur in any order (but not be repeated) and additional |
| 35 | characters will be ignored. In general other than dot (`.`) other |
| 36 | characters should be avoided since they may be used by future |
| 37 | versions of the tool! |
| 38 | |
| 39 | The value may be an integer (binary, octal, decimal and hex |
| 40 | supported) or one of the special values that change how the output is |
| 41 | drawn: |
| 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 | |
| 51 | Lines of the input may consist of a single flag+value per line or a |
| 52 | comma separated list of flag+value pairs. |
| 53 | |
| 54 | ### Hexdump source format |
| 55 | |
| 56 | In the hexdump source format tool processes the raw 13-bit data that |
| 57 | is written to the I2C FIFO. This is normally in hex (preceded with |
| 58 | 0x) but the tool will accept binary, octal or decimal. Lines of input |
| 59 | may consist of a single hex value, multiple values separated by commas |
| 60 | (and optionally whitespace) or multiple values separated by |
| 61 | whitespace. |
| 62 | |
| 63 | ### Output file format |
| 64 | |
| 65 | The 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 | |
| 73 | The example commands assume `$REPO_TOP` is set to the toplevel |
| 74 | directory of the repo. |
| 75 | |
| 76 | ### Setup |
| 77 | |
| 78 | The i2csvg tool does not depend on any other packages. |
| 79 | |
| 80 | ### Examples using i2csvg.py |
| 81 | |
| 82 | The i2csvg/examples directory contains some example I2C files. For |
| 83 | simple examples text can be piped in to the tool using echo. |
| 84 | |
| 85 | A simple I2C write consists of a Start with Address and direction bit |
| 86 | of zero, and a single data byte (4 in the example) with a Stop. |
| 87 | |
| 88 | The baseline tool will generate an svg file (which can be viewed in a |
| 89 | browser) that includes the diagramatic form of the transaction and a |
| 90 | line 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 | |
| 97 | The text version (which is just the input with more structured |
| 98 | formatting) can be viewed in the terminal by suppressing the svg |
| 99 | output. This output will always have the five flags in order and five |
| 100 | characters in the flags field (including a `.` if the flag is not |
| 101 | set): |
| 102 | |
| 103 | ```console |
| 104 | $ cd $REPO_TOP/util |
| 105 | $ echo "SA0, P4" | ./i2csvg.py --text --nosvg |
| 106 | S.... A0 |
| 107 | .P... 0x4 |
| 108 | ``` |
| 109 | |
| 110 | The debug version is intended for tool development: |
| 111 | |
| 112 | ```console |
| 113 | $ cd $REPO_TOP/util |
| 114 | $ echo "SA0, P4" | ./i2csvg.py --debug --nosvg |
| 115 | I2cOp(read=False, rcont=False, start=True, stop=False, nackok=False, mvalue=False, adr=True, size=10, fbyte=0, tag=None) |
| 116 | I2cOp(read=False, rcont=False, start=False, stop=True, nackok=False, mvalue=False, adr=False, size=10, fbyte=4, tag=None) |
| 117 | ``` |
| 118 | |
| 119 | If svg generation is not suppressed then the text or debug output and |
| 120 | the 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 | |
| 127 | The smbus directory contains files with each of the commands listed in |
| 128 | section 6.5 of the SMBus 3.0 specification. These can be used to |
| 129 | generate 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 | |
| 136 | Alternatively, these can all be converted to individual svg files (for |
| 137 | example for inclusion in documents) with the `--multiout` command. |
| 138 | The output filename matches the input filename with the extension |
| 139 | replaced with `.svg`. Note that if the `--text` or `--debug` flags |
| 140 | are 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 |
| 146 | 01-Quick.txt 04-WriteWord.txt 07-BlockRead.txt 10-Write32.txt |
| 147 | 02-SendByte.txt 05-ReadByte.txt 07-BlockWrite.txt 11-Read32.txt |
| 148 | 03-ReceiveByte.txt 05-ReadWord.txt 08-BlockWrRdPCall.txt 12-Write64.txt |
| 149 | 04-WriteByte.txt 06-ProcessCall.txt 09-HostNotify.txt 13-Read64.txt |
| 150 | $ ./i2csvg.py --multiout i2csvg/smbus/*.txt |
| 151 | $ ls i2csvg/smbus |
| 152 | 01-Quick.svg 04-WriteWord.svg 07-BlockRead.svg 10-Write32.svg |
| 153 | 01-Quick.txt 04-WriteWord.txt 07-BlockRead.txt 10-Write32.txt |
| 154 | 02-SendByte.svg 05-ReadByte.svg 07-BlockWrite.svg 11-Read32.svg |
| 155 | 02-SendByte.txt 05-ReadByte.txt 07-BlockWrite.txt 11-Read32.txt |
| 156 | 03-ReceiveByte.svg 05-ReadWord.svg 08-BlockWrRdPCall.svg 12-Write64.svg |
| 157 | 03-ReceiveByte.txt 05-ReadWord.txt 08-BlockWrRdPCall.txt 12-Write64.txt |
| 158 | 04-WriteByte.svg 06-ProcessCall.svg 09-HostNotify.svg 13-Read64.svg |
| 159 | 04-WriteByte.txt 06-ProcessCall.txt 09-HostNotify.txt 13-Read64.txt |
| 160 | ``` |
| 161 | |
| 162 | ### Example use in Debugging |
| 163 | |
| 164 | The examples directory contains example output from a microcontroller |
| 165 | using the I2C interface. Mixed in to the other debug output are lines |
| 166 | produced when writes are done to the I2C FIFO. These lines are |
| 167 | prefixed 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 |
| 169 | representation: |
| 170 | |
| 171 | ```console |
| 172 | $ cd $REPO_TOP/util |
| 173 | $ ./i2csvg.py --nosvg --text --fifodata --prefix=I2CF: i2csvg/examples/traceout.txt |
| 174 | T read sensor |
| 175 | S.... 0x40 |
| 176 | .PR.. 0x1 |
| 177 | T fix value |
| 178 | S.... 0x41 |
| 179 | ..... 0x22 |
| 180 | .P... 0x33 |
| 181 | ``` |
| 182 | |
| 183 | Or 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 | |