Hint
Refer to QMK’s documentation for details on how to use community modules
Warning
This is currently broken and WIP, dont use it because it will crash your board.
micropython¶
Embeds microypthon’s interpreter into your board
Since that’s not very useful by itself, a module is provided to hook into QMK APIs. Namely, you use: import qmk
To execute some code, store it as a string and feed it into the mp_embed_exec_str
function
Tip
Writing a C-string directly is not convenient (eg: no IntelliSense for suggestions/typo detection)
To circumvent that, you can write a regular .py
file, and then use euc py2c <file.py>
to generate
the equivalent string in a standalone file, which you can later #include
You could also point your editor at the qmk
folder, and get auto-completion thanks to the .pyi
files in it
Important
In the future, I plan to integrate import ...
with QMK filesystem API (not a thing yet)
When (if) this happens, you would be able to run dynamic code, opposed to the current state, where you can only execute something defined as a const char*
at compile time
Available APIs are:
"""Utilities to interact with QMK from MicroPython."""
# ruff: noqa: F401
# the modules being imported dont really exist on the VM
# these imports are the result of having multiple `.c` files
# to organize the code (each one gets its own `.pyi` generated)
#
# this is: you can't `import qmk.keycode` nor `import _keycode`
# instead, you `import qmk` and use it as `qmk.keycode.foo()`
from . import _keycode as keycode
from . import _rgb as rgb
version: str
"""Version of QMK on which this firmware was built, as a raw string."""
version_info: tuple[int, int, int]
"""Version of QMK on which this firmware was built, as a (major, minor, patch) tuple."""
def get_highest_active_layer() -> int:
"""Get what the highest (currently active) layer is."""
def send_string(text: str, /) -> None:
"""Send a string over HID."""
def tap_code(kc: int, /) -> None:
"""Send a basic keycode over HID."""
"""Registry of QMK keycodes."""
KC_A: int
KC_B: int
KC_C: int
KC_D: int
KC_E: int
KC_F: int
KC_G: int
KC_H: int
KC_I: int
KC_J: int
KC_K: int
KC_L: int
KC_M: int
KC_N: int
KC_O: int
KC_P: int
KC_Q: int
KC_R: int
KC_S: int
KC_T: int
KC_U: int
KC_V: int
KC_W: int
KC_X: int
KC_Y: int
KC_Z: int
def C(kc: int, /) -> int: # noqa: N802 # name mimics QMK's
"""Return control + `kc` combination."""
def S(kc: int, /) -> int: # noqa: N802 # name mimics QMK's
"""Return shift + `kc` combination."""
def G(kc: int, /) -> int: # noqa: N802 # name mimics QMK's
"""Return gui + `kc` combination."""
def A(kc: int, /) -> int: # noqa: N802 # name mimics QMK's
"""Return alt + `kc` combination."""
"""Interact with RGB LEDs."""
RED: RGB
GREEN: RGB
BLUE: RGB
class RGB:
"""Represent a color."""
r: int
g: int
b: int
def __init__(self, r: int, g: int, b: int) -> None:
"""Create instance from the given color channels."""
def set_color(index: int, rgb: RGB, /) -> None:
"""Configure a LED's color."""