qmk_firmware/assets/understanding_qmk.md.f-Bc_eHQ.js

16 lines
26 KiB
JavaScript
Raw Normal View History

import { _ as _export_sfc, c as createElementBlock, o as openBlock, a8 as createStaticVNode } from "./chunks/framework.DyMmIvSC.js";
const __pageData = JSON.parse(`{"title":"Understanding QMK's Code","description":"","frontmatter":{},"headers":[],"relativePath":"understanding_qmk.md","filePath":"understanding_qmk.md"}`);
const _sfc_main = { name: "understanding_qmk.md" };
const _hoisted_1 = /* @__PURE__ */ createStaticVNode('<h1 id="understanding-qmk-s-code" tabindex="-1">Understanding QMK&#39;s Code <a class="header-anchor" href="#understanding-qmk-s-code" aria-label="Permalink to &quot;Understanding QMK&#39;s Code&quot;"></a></h1><p>This document attempts to explain how the QMK firmware works from a very high level. It assumes you understand basic programming concepts but does not (except where needed to demonstrate) assume familiarity with C. It assumes that you have a basic understanding of the following documents:</p><ul><li><a href="./getting_started_introduction">Introduction</a></li><li><a href="./how_keyboards_work">How Keyboards Work</a></li><li><a href="./faq_general">FAQ</a></li></ul><h2 id="startup" tabindex="-1">Startup <a class="header-anchor" href="#startup" aria-label="Permalink to &quot;Startup&quot;"></a></h2><p>You can think of QMK as no different from any other computer program. It is started and performs its tasks, but this program never finishes. Like other C programs, the entry point is the <code>main()</code> function. For QMK, the <code>main()</code> function is found in <a href="https://github.com/qmk/qmk_firmware/blob/0.15.13/quantum/main.c#L55" target="_blank" rel="noreferrer"><code>quantum/main.c</code></a>.</p><p>If you browse through the <code>main()</code> function you&#39;ll find that it starts by initializing any hardware that has been configured (including USB to the host). The most common platform for QMK is <code>lufa</code>, which runs on AVR processors such as the atmega32u4. When compiled for that platform, it will invoke for example <code>platform_setup()</code> in <a href="https://github.com/qmk/qmk_firmware/blob/0.15.13/platforms/avr/platform.c#L19" target="_blank" rel="noreferrer"><code>platforms/avr/platform.c</code></a> and <code>protocol_setup()</code> in <a href="https://github.com/qmk/qmk_firmware/blob/0.15.13/tmk_core/protocol/lufa/lufa.c#L1066" target="_blank" rel="noreferrer"><code>tmk_core/protocol/lufa/lufa.c</code></a>. It will use other implementations when compiled for other platforms like <code>chibios</code> and <code>vusb</code>. At first glance, it can look like a lot of functionality but most of the time the code will be disabled by <code>#define</code>s.</p><p>The <code>main()</code> function will then start the core part of the program with a <a href="https://github.com/qmk/qmk_firmware/blob/0.15.13/quantum/main.c#L63" target="_blank" rel="noreferrer"><code>while (true)</code></a>. This is <a href="#the-main-loop">The Main Loop</a>.</p><h2 id="the-main-loop" tabindex="-1">The Main Loop <a class="header-anchor" href="#the-main-loop" aria-label="Permalink to &quot;The Main Loop&quot;"></a></h2><p>This section of code is called &quot;The Main Loop&quot; because it&#39;s responsible for looping over the same set of instructions forever, without ever reaching the end. This is where QMK dispatches out to the functions responsible for making the keyboard do everything it is supposed to do.</p><p>The main loop will call <a href="https://github.com/qmk/qmk_firmware/blob/0.15.13/quantum/main.c#L38" target="_blank" rel="noreferrer"><code>protocol_task()</code></a>, which in turn will call <code>keyboard_task()</code> in <a href="https://github.com/qmk/qmk_firmware/blob/0.15.13/quantum/keyboard.c#L377" target="_blank" rel="noreferrer"><code>quantum/keyboard.c</code></a>. This is where all the keyboard specific functionality is dispatched, and it is responsible for detecting changes in the matrix and turning status LEDs on and off.</p><p>Within <code>keyboard_task()</code> you&#39;ll find code to handle:</p><ul><li><a href="#matrix-scanning">Matrix Scanning</a></li><li>Mouse Handling</li><li>Keyboard status LEDs (Caps Lock, Num Lock, Scroll Lock)</li></ul><h4 id="matrix-scanning" tabindex="-1">Matrix Scanning <a class="header-anchor" href="#matrix-scanning" aria-label="Permalink to &quot;Matrix Scanning&quot;"></a></h4><p>Matrix scanning is the core function of a keyboard firmware. It is the process of detecting which keys a
const _hoisted_42 = [
_hoisted_1
];
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock("div", null, _hoisted_42);
}
const understanding_qmk = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export {
__pageData,
understanding_qmk as default
};