From da6d6ce2e1f266892badbd42fb8c6735e61e784f Mon Sep 17 00:00:00 2001 From: kiilerix Date: Sat, 5 Mar 2022 05:58:50 +0100 Subject: [PATCH] Some docs improvements (#15845) * docs: clarify in "Keymap Overview" what LAYOUT is and isn't It is not strictly necessary to use LAYOUT macros in keyboard.c, but it is a convenient abstraction of hardware internals, allowing focus on the physical keyboard layout. From the C source point of view LAYOUT is macro with a parameter list, which expands to a array of rows that each is an array with a keyboard scancode for each column. A macro parameter list is not an array, and even less a single array. Perhaps no big deal, but also no reason to give incorrect hints. * docs: update "Understanding QMK's Code" to current code structure introduced in 96e2b13d1de This part of the documentation was no longer correct. I tried updating it, mainly copy editing and using github links to latest release. This is not trying to fix all problems, but just trying to fix some problems while reusing much of the old phrases and structure. * Update docs to use "qmk format-python" --- docs/cli_development.md | 4 ++-- docs/ja/cli_commands.md | 4 ++-- docs/ja/cli_development.md | 4 ++-- docs/keymap.md | 6 ++++-- docs/understanding_qmk.md | 15 +++++---------- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/docs/cli_development.md b/docs/cli_development.md index 62be3b3d8c..17370a732a 100644 --- a/docs/cli_development.md +++ b/docs/cli_development.md @@ -188,7 +188,7 @@ cli.log.info('Reading from %s and writing to %s', cli.args.filename, cli.args.ou # Testing, and Linting, and Formatting (oh my!) -We use nose2, flake8, and yapf to test, lint, and format code. You can use the `pytest` and `format-py` subcommands to run these tests: +We use nose2, flake8, and yapf to test, lint, and format code. You can use the `pytest` and `format-python` subcommands to run these tests: ### Testing and Linting @@ -196,7 +196,7 @@ We use nose2, flake8, and yapf to test, lint, and format code. You can use the ` ### Formatting - qmk format-py + qmk format-python ## Formatting Details diff --git a/docs/ja/cli_commands.md b/docs/ja/cli_commands.md index 8a661d56ee..b48de077cd 100644 --- a/docs/ja/cli_commands.md +++ b/docs/ja/cli_commands.md @@ -275,14 +275,14 @@ $ qmk kle2json -f kle.txt -f Ψ Wrote out to info.json ``` -## `qmk format-py` +## `qmk format-python` このコマンドは `qmk_firmware` 内の python コードを整形します。 **使用法**: ``` -qmk format-py +qmk format-python ``` ## `qmk pytest` diff --git a/docs/ja/cli_development.md b/docs/ja/cli_development.md index 28cdd91c1e..082bc5dafa 100644 --- a/docs/ja/cli_development.md +++ b/docs/ja/cli_development.md @@ -192,7 +192,7 @@ cli.log.info('Reading from %s and writing to %s', cli.args.filename, cli.args.ou # テスト、リントおよびフォーマット -nose2、flake8 および yapf を使ってコードをテスト、リントおよびフォーマットします。これらのテストを実行するために `pytest` と `format-py` サブコマンドを使うことができます。 +nose2、flake8 および yapf を使ってコードをテスト、リントおよびフォーマットします。これらのテストを実行するために `pytest` と `format-python` サブコマンドを使うことができます。 ### テストとリント @@ -200,7 +200,7 @@ nose2、flake8 および yapf を使ってコードをテスト、リントお ### フォーマット - qmk format-py + qmk format-python ## フォーマットの詳細 diff --git a/docs/keymap.md b/docs/keymap.md index a7c9c50d74..ab8a255bc3 100644 --- a/docs/keymap.md +++ b/docs/keymap.md @@ -132,7 +132,7 @@ The main part of this file is the `keymaps[]` definition. This is where you list const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { -After this you'll find a list of LAYOUT() macros. A LAYOUT() is simply a list of keys to define a single layer. Typically you'll have one or more "base layers" (such as QWERTY, Dvorak, or Colemak) and then you'll layer on top of that one or more "function" layers. Due to the way layers are processed you can't overlay a "lower" layer on top of a "higher" layer. +After this you'll find the layer definitions. Typically you'll have one or more "base layers" (such as QWERTY, Dvorak, or Colemak) and then you'll layer on top of that one or more "function" layers. Due to the way layers are processed you can't overlay a "lower" layer on top of a "higher" layer. `keymaps[][MATRIX_ROWS][MATRIX_COLS]` in QMK holds the 16 bit action code (sometimes referred as the quantum keycode) in it. For the keycode representing typical keys, its high byte is 0 and its low byte is the USB HID usage ID for keyboard. @@ -153,7 +153,9 @@ Here is an example of the Clueboard's base layer: Some interesting things to note about this: -* From a C source point of view it's only a single array, but we have embedded whitespace to more easily visualize where each key is on the physical device. +* The layer is defined using the LAYOUT macro, traditionally defined in the keyboard's `.h` file. +* The LAYOUT macro takes a single list of keycodes, but we have written it in the C source using embedded whitespace and newlines to visualize where each key is on the physical device. +* The LAYOUT macro hides and handles the mapping to the hardware's key scan matrix. * Plain keyboard scancodes are prefixed with KC_, while "special" keys are not. * The upper left key activates custom function 0 (`F(0)`) * The "Fn" key is defined with `MO(_FL)`, which moves to the `_FL` layer while that key is being held down. diff --git a/docs/understanding_qmk.md b/docs/understanding_qmk.md index 582cbf46f2..9b80fb179e 100644 --- a/docs/understanding_qmk.md +++ b/docs/understanding_qmk.md @@ -8,27 +8,22 @@ This document attempts to explain how the QMK firmware works from a very high le ## Startup -You can think of QMK as no different from any other computer program. It is started, performs its tasks, and then ends. The entry point for the program is the `main()` function, just like it is on any other C program. However, for a newcomer to QMK it can be confusing because the `main()` function appears in multiple places, and it can be hard to tell which one to look at. +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 `main()` function. For QMK, the `main()` function is found in [`quantum/main.c`](https://github.com/qmk/qmk_firmware/blob/0.15.13/quantum/main.c#L55). -The reason for this is the different platforms that QMK supports. The most common platform is `lufa`, which runs on AVR processors such at the atmega32u4. We also support `chibios` and `vusb`. +If you browse through the `main()` function you'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 `lufa`, which runs on AVR processors such as the atmega32u4. When compiled for that platform, it will invoke for example `platform_setup()` in [`platforms/avr/platform.c`](https://github.com/qmk/qmk_firmware/blob/0.15.13/platforms/avr/platform.c#L19) and `protocol_setup()` in [`tmk_core/protocol/lufa/lufa.c`](https://github.com/qmk/qmk_firmware/blob/0.15.13/tmk_core/protocol/lufa/lufa.c#L1066). It will use other implementations when compiled for other platforms like `chibios` and `vusb`. At first glance, it can look like a lot of functionality but most of the time the code will be disabled by `#define`s. -We'll focus on AVR processors for the moment, which use the `lufa` platform. You can find the `main()` function in [tmk_core/protocol/lufa/lufa.c](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/tmk_core/protocol/lufa/lufa.c#L1028). If you browse through that function you'll find that it initializes any hardware that has been configured (including USB to the host) and then it starts the core part of the program with a [`while(1)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/tmk_core/protocol/lufa/lufa.c#L1069). This is [The Main Loop](#the-main-loop). +The `main()` function will then start the core part of the program with a [`while (true)`](https://github.com/qmk/qmk_firmware/blob/0.15.13/quantum/main.c#L63). This is [The Main Loop](#the-main-loop). ## The Main Loop -This section of code is called "The Main Loop" because it's responsible for looping over the same set of instructions forever. This is where QMK dispatches out to the functions responsible for making the keyboard do everything it is supposed to do. At first glance it can look like a lot of functionality but most of the time the code will be disabled by `#define`'s. +This section of code is called "The Main Loop" because it'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. -``` - keyboard_task(); -``` - -This is where all the keyboard specific functionality is dispatched. The source code for `keyboard_task()` can be found in [tmk_core/common/keyboard.c](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/tmk_core/common/keyboard.c#L216), and it is responsible for detecting changes in the matrix and turning status LEDs on and off. +The main loop will call [`protocol_task()`](https://github.com/qmk/qmk_firmware/blob/0.15.13/quantum/main.c#L38), which in turn will call `keyboard_task()` in [`quantum/keyboard.c`](https://github.com/qmk/qmk_firmware/blob/0.15.13/quantum/keyboard.c#L377). 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. Within `keyboard_task()` you'll find code to handle: * [Matrix Scanning](#matrix-scanning) * Mouse Handling -* Serial Link(s) * Keyboard status LEDs (Caps Lock, Num Lock, Scroll Lock) #### Matrix Scanning