|
124 | 124 | <span id="readme"></span><h1>i2c README<a class="headerlink" href="#i2c-readme" title="Permalink to this heading"></a></h1> |
125 | 125 | <section id="marble-platform-support-for-i2cbridge-programming"> |
126 | 126 | <h2>Marble Platform Support for I2CBridge Programming<a class="headerlink" href="#marble-platform-support-for-i2cbridge-programming" title="Permalink to this heading"></a></h2> |
127 | | -<section id="one-shot-i2c-transactions"> |
128 | | -<h3>One-shot I2C transactions<a class="headerlink" href="#one-shot-i2c-transactions" title="Permalink to this heading"></a></h3> |
129 | | -<p>The script <code class="docutils literal notranslate"><span class="pre">oneshot.py</span></code> is included here to allow composing and running single-transaction |
130 | | -<code class="docutils literal notranslate"><span class="pre">i2cbridge</span></code> programs to a live target with a (hopefully) user-friendly interface. Without |
131 | | -worrying about the I2C tree on the Marble board or chip addresses, you can simply read from |
132 | | -or write to any register in any chip just referring to the chip by name (refdes on the |
133 | | -schematic).</p> |
134 | | -<p>Example: turn on LD13 via the GPIO expander U39 by writing to register 3 |
135 | | -<strong>WARNING</strong>: The user LEDs are on the same port as <code class="docutils literal notranslate"><span class="pre">/CLKMUX_RST</span></code> which means we can shut down the board on accident |
136 | | -if we aren’t very careful to ensure we always keep bit 7 asserted when writing to this register!</p> |
137 | | -<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nv">PYTHONPATH</span><span class="o">=</span>../../../peripheral_drivers/i2cbridge:<span class="nv">$PYTHONPATH</span><span class="w"> </span>python3<span class="w"> </span>oneshot.py<span class="w"> </span>leep://<span class="nv">$IP</span>:<span class="nv">$PORT</span><span class="w"> </span>U39.3<span class="o">=</span>0x80 |
138 | | -</pre></div> |
139 | | -</div> |
140 | | -<p>Example: turn off LD13</p> |
141 | | -<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nv">PYTHONPATH</span><span class="o">=</span>../../../peripheral_drivers/i2cbridge:<span class="nv">$PYTHONPATH</span><span class="w"> </span>python3<span class="w"> </span>oneshot.py<span class="w"> </span>leep://<span class="nv">$IP</span>:<span class="nv">$PORT</span><span class="w"> </span>U39.3<span class="o">=</span>0x88 |
142 | | -</pre></div> |
143 | | -</div> |
144 | | -<p>Example: read the inputs to port 0 on the GPIO expander U39 by reading from register 0</p> |
145 | | -<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nv">PYTHONPATH</span><span class="o">=</span>../../../peripheral_drivers/i2cbridge:<span class="nv">$PYTHONPATH</span><span class="w"> </span>python3<span class="w"> </span>oneshot.py<span class="w"> </span>leep://192.168.19.40:803<span class="w"> </span>U39.0 |
146 | | -</pre></div> |
147 | | -</div> |
148 | | -<p><em>(The following demos assume you have exported ``PYTHONPATH`` for brevity)</em></p> |
149 | | -<p>We can also read more than 1 byte (very much dependent on the specifics of the IC’s I2C implementation). |
150 | | -Example: read shunt voltage (addr 1, 16 bits) from INA219 U57</p> |
151 | | -<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>python3<span class="w"> </span>oneshot.py<span class="w"> </span>leep://<span class="nv">$IP</span>:<span class="nv">$PORT</span><span class="w"> </span>U57.1:2 |
152 | | -<span class="c1"># Note the ':' instead of a '=' (the latter indicates a write!)</span> |
153 | | -</pre></div> |
154 | | -</div> |
155 | | -<p>Note that you can perform many transactions in one “one shot” program, including adding pauses between |
156 | | -transactions, as in this demo disabling and re-enabling QSFP1 channel 0:</p> |
157 | | -<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>python3<span class="w"> </span>oneshot.py<span class="w"> </span>leep://<span class="nv">$IP</span>:<span class="nv">$PORT</span><span class="w"> </span>J17.86<span class="o">=</span><span class="m">1</span><span class="w"> </span>J17.86<span class="o">=</span><span class="m">0</span> |
158 | | -</pre></div> |
159 | | -</div> |
160 | | -<p>And breaking the “one shot” model, you can tell the program to continue looping after the script exits. |
161 | | -This demo makes LD13 continually blink.</p> |
162 | | -<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>python3<span class="w"> </span>oneshot.py<span class="w"> </span>leep://<span class="nv">$IP</span>:<span class="nv">$PORT</span><span class="w"> </span>U39.3<span class="o">=</span>0x80<span class="w"> </span><span class="nv">pause</span><span class="o">=</span><span class="m">500</span><span class="w"> </span>U39.3<span class="o">=</span>0x88<span class="w"> </span><span class="nv">pause</span><span class="o">=</span><span class="m">500</span><span class="w"> </span>-l |
163 | | -</pre></div> |
164 | | -</div> |
165 | | -</section> |
166 | 127 | <section id="usage"> |
167 | 128 | <h3>Usage:<a class="headerlink" href="#usage" title="Permalink to this heading"></a></h3> |
168 | 129 | <p>These tools assume usage of the i2cbridge modules in <code class="docutils literal notranslate"><span class="pre">bedrock/peripheral_drivers/i2cbridge</span></code>. |
@@ -226,7 +187,7 @@ <h4>Test 2: Decode the program without platform awareness<a class="headerlink" h |
226 | 187 | <h4>Test 3: Test assembler violations<a class="headerlink" href="#test-3-test-assembler-violations" title="Permalink to this heading"></a></h4> |
227 | 188 | <p>This last test is not truly platform-specific but shows various violations of the I2C assembler rules |
228 | 189 | using the Marble platform-aware interface. None of the rules violated are specific to the platform.</p> |
229 | | -<p><code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">violations</span></code></p> |
| 190 | +<p><code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">test</span></code></p> |
230 | 191 | <p>See <code class="docutils literal notranslate"><span class="pre">demo_i2c_baddy.py</span></code> for examples of what to avoid.</p> |
231 | 192 | </section> |
232 | 193 | </section> |
|
0 commit comments