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.
lufa, which runs on AVR processors such at the atmega32u4. We also support
lufaplatform. You can find the
main()function in tmk_core/protocol/lufa/lufa.c. 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). This is The Main Loop.
keyboard_task()can be found in tmk_core/common/keyboard.c, and it is responsible for detecting changes in the matrix and turning status LEDs on and off.
keyboard_task()you'll find code to handle:
LAYOUT()) which maps our keyboard's matrix to physical keys. Sometimes the matrix does not have a switch in every location, and we can use this macro to pre-populate those with KC_NO, making the keymap definition easier to work with. Here's an example
LAYOUT()macro for a numpad:
LAYOUT()macro matches the Matrix Scanning array above? This macro is what will map the matrix scanning array to keycodes. However, if you look at a 17 key numpad you'll notice that it has 3 places where the matrix could have a switch but doesn't, due to larger keys. We have populated those spaces with
KC_NOso that our keymap definition doesn't have to.
LAYOUT()macro above to map keycodes to physical locations to matrix locations. It looks like this:
LAYOUT()macro from the last section? This is how we take a keycode and map it to our Matrix Scan from earlier.
process_recordset of functions.
process_record()function itself is deceptively simple, but hidden within is a gateway to overriding functionality at various levels of QMK. The chain of events is listed below, using cluecard whenever we need to look at the keyboard/keymap level functions. Depending on options set in
rules.mkor elsewhere, only a subset of the functions below will be included in final firmware.
return falseto halt all further processing.
post_process_record()is called, which can be used to handle additional cleanup that needs to be run after the keycode is normally handled.