mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-02-27 01:56:43 +00:00
16 lines
28 KiB
JavaScript
16 lines
28 KiB
JavaScript
|
import { _ as _export_sfc, c as createElementBlock, o as openBlock, a8 as createStaticVNode } from "./chunks/framework.DyMmIvSC.js";
|
|||
|
const __pageData = JSON.parse('{"title":"Persistent Configuration (EEPROM)","description":"","frontmatter":{},"headers":[],"relativePath":"feature_eeprom.md","filePath":"feature_eeprom.md"}');
|
|||
|
const _sfc_main = { name: "feature_eeprom.md" };
|
|||
|
const _hoisted_1 = /* @__PURE__ */ createStaticVNode('<h1 id="persistent-configuration-eeprom" tabindex="-1">Persistent Configuration (EEPROM) <a class="header-anchor" href="#persistent-configuration-eeprom" aria-label="Permalink to "Persistent Configuration (EEPROM)""></a></h1><p>This allows you to configure persistent settings for your keyboard. These settings are stored in the EEPROM of your controller, and are retained even after power loss. The settings can be read with <code>eeconfig_read_kb</code> and <code>eeconfig_read_user</code>, and can be written to using <code>eeconfig_update_kb</code> and <code>eeconfig_update_user</code>. This is useful for features that you want to be able to toggle (like toggling rgb layer indication). Additionally, you can use <code>eeconfig_init_kb</code> and <code>eeconfig_init_user</code> to set the default values for the EEPROM.</p><p>The complicated part here, is that there are a bunch of ways that you can store and access data via EEPROM, and there is no "correct" way to do this. However, you only have a DWORD (4 bytes) for each function.</p><p>Keep in mind that EEPROM has a limited number of writes. While this is very high, it's not the only thing writing to the EEPROM, and if you write too often, you can potentially drastically shorten the life of your MCU.</p><ul><li>If you don't understand the example, then you may want to avoid using this feature, as it is rather complicated.</li></ul><h2 id="example-implementation" tabindex="-1">Example Implementation <a class="header-anchor" href="#example-implementation" aria-label="Permalink to "Example Implementation""></a></h2><p>This is an example of how to add settings, and read and write it. We're using the user keymap for the example here. This is a complex function, and has a lot going on. In fact, it uses a lot of the above functions to work!</p><p>In your keymap.c file, add this to the top:</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;">typedef</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> union</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> uint32_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> raw;</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> struct</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> bool</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> rgb_layer_change :</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> };</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">} </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">user_config_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>\n<span class="line"></span>\n<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">user_config_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> user_config;</span></span></code></pre></div><p>This sets up a 32 bit structure that we can store settings with in memory, and write to the EEPROM. Using this removes the need to define variables, since they're defined in this structure. Remember that <code>bool</code> (boolean) values use 1 bit, <code>uint8_t</code> uses 8 bits, <code>uint16_t</code> uses up 16 bits. You can mix and match, but changing the order can cause issues, as it will change the values that are read and written.</p><p>We're using <co
|
|||
|
const _hoisted_24 = [
|
|||
|
_hoisted_1
|
|||
|
];
|
|||
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|||
|
return openBlock(), createElementBlock("div", null, _hoisted_24);
|
|||
|
}
|
|||
|
const feature_eeprom = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|||
|
export {
|
|||
|
__pageData,
|
|||
|
feature_eeprom as default
|
|||
|
};
|