qmk_firmware/assets/drivers_i2c.md.CZ3yUqUc.js

16 lines
24 KiB
JavaScript
Raw Normal View History

import { _ as _export_sfc, c as createElementBlock, o as openBlock, a8 as createStaticVNode } from "./chunks/framework.B9AX-CPi.js";
const __pageData = JSON.parse('{"title":"I2C Master Driver","description":"","frontmatter":{},"headers":[],"relativePath":"drivers/i2c.md","filePath":"drivers/i2c.md"}');
const _sfc_main = { name: "drivers/i2c.md" };
const _hoisted_1 = /* @__PURE__ */ createStaticVNode('<h1 id="i2c-master-driver" tabindex="-1">I2C Master Driver <a class="header-anchor" href="#i2c-master-driver" aria-label="Permalink to &quot;I2C Master Driver {#i2c-master-driver}&quot;"></a></h1><p>The I2C Master drivers used in QMK have a set of common functions to allow portability between MCUs.</p><h2 id="usage" tabindex="-1">Usage <a class="header-anchor" href="#usage" aria-label="Permalink to &quot;Usage {#usage}&quot;"></a></h2><p>In most cases, the I2C Master driver code is automatically included if you are using a feature or driver which requires it, such as <a href="./../features/oled_driver">OLED</a>.</p><p>However, if you need to use the driver standalone, add the following to your <code>rules.mk</code>:</p><div class="language-make vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">make</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">I2C_DRIVER_REQUIRED = yes</span></span></code></pre></div><p>You can then call the I2C API by including <code>i2c_master.h</code> in your code.</p><h2 id="note-on-i2c-addresses" tabindex="-1">I2C Addressing <a class="header-anchor" href="#note-on-i2c-addresses" aria-label="Permalink to &quot;I2C Addressing {#note-on-i2c-addresses}&quot;"></a></h2><p>All of the addresses expected by this driver should be pushed to the upper 7 bits of the address byte. Setting the lower bit (indicating read/write) will be done by the respective functions. Almost all I2C addresses listed on datasheets and the internet will be represented as 7 bits occupying the lower 7 bits and will need to be shifted to the left (more significant) by one bit. This is easy to do via the bitwise shift operator <code>&lt;&lt; 1</code>.</p><p>You can either do this on each call to the functions below, or once in your definition of the address. For example, if your device has an address of <code>0x18</code>:</p><div class="language-c vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> MY_I2C_ADDRESS</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">18</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div><p>See <a href="https://www.robot-electronics.co.uk/i2c-tutorial" target="_blank" rel="noreferrer">https://www.robot-electronics.co.uk/i2c-tutorial</a> for more information about I2C addressing and other technical details.</p><h2 id="avr-configuration" tabindex="-1">AVR Configuration <a class="header-anchor" href="#avr-configuration" aria-label="Permalink to &quot;AVR Configuration {#avr-configuration}&quot;"></a></h2><p>The following defines can be used to configure the I2C master driver:</p><table><thead><tr><th><code>config.h</code> Override</th><th>Description</th><th>Default</th></tr></thead><tbody><tr><td><code>F_SCL</code></td><td>Clock frequency in Hz</td><td><code>400000</code></td></tr></tbody></table><p>No further setup is required - just connect the <code>SDA</code> and <code>SCL</code> pins of your I2C devices to the matching pins on the MCU:</p><table><thead><tr><th>MCU</th><th><code>SCL</code></th><th><code>SDA</code></th></tr></thead><tbody><tr><td>ATmega16/32U4</td><td><code>D0</code></td><td><code>D1</code></td></tr><tr><td>AT90USB64/128</td><td><code>D0</code></td><td><code>D1</code></td></tr><tr><td>ATmega32A</td><td><code>C0</code></td><td><code>C1</code></td></tr><tr><td>ATmega328/P</td><td><code>C5</code></t
const _hoisted_93 = [
_hoisted_1
];
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock("div", null, _hoisted_93);
}
const i2c = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export {
__pageData,
i2c as default
};