This document contains some information on how to define some basic information for your keyboard,
and how to set up a basic matrix and layout setup for your keyboard.
Keyboard Information
The basic trait that every device must implement to use rumcake is the Keyboard trait.
Here, you can define some basic information, including the name of the keyboard, the manufacturer,
version numbers, etc.
Keyboard Matrix
In the templates, you will see that
to implement a keyboard matrix, you need to implement the KeyboardMatrix trait
using one of the build_<matrix_type>_matrix! macros:
If you see an error about Self not implementing KeyboardLayout, don’t worry. This will be fixed once you follow
the next section. Note that this associated type is used to redirect matrix events to the implemented layout.
The identifiers used for the matrix pins must match the identifiers used by the respective
HAL (hardware abstraction library) for your MCU. The linked sites below have a dropdown menu at
the top to allow you to select a chip. Choose your chip to see what pins are available:
After defining your matrix, you can set up your keyboard layout. If you have
a duplex matrix, consider checking that section before setting up your keyboard layout.
Keyboard Layout
To implement a keyboard layout, you must implement the KeyboardLayout trait.
It’s recommended to use rumcake’s build_layout! macro, which is simply a wrapper around keyberon’s layout! macro.
Please follow keyberon’s macro instructions there to set up your keyboard layout.
The following example shows a 3-layer keyboard layout, meant to be used with the matrix we defined previously:
Congratulations! You have implemented a basic keyboard. You can now move onto building
and flashing your firmware, or try implementing additional features in the “Features” sidebar.
Other matrix types
Direct pin matrix (diodeless matrix)
If your MCU pins are connected directly to a switch (as opposed to pins being connected to a row / column of switches),
then you can use the build_direct_pin_matrix! macro instead.
Each pin will map directly to a (row, column) position, which determines the key in the layout it corresponds to.
Each row must have the same number of columns. If there are matrix positions that are unused, you can use No to ignore them.
In this example, the switch connected to PB10 maps to row 0, column 1. Based on the implementation of KeyboardLayout, this
switch will correspond to the Q/F1 key.
Analog matrix
If your switch is powered by an analog-to-digital conversion peripheral (which is usually the case with hall-effect switches, for example),
then you can use the build_analog_matrix! macro. In addition, you will need to specify an ADC sampler configuration, using the setup_adc_sampler!
macro.
Firstly, an ADC sampler definition is provided. In this example, the ADC2 peripheral (controlled by the ADC1_2 interrupt), is connected to two pins.
Pin PA2 is connected to a multiplexer, and pin PA5 is connected directly to the analog source (a switch in this case).
For PA2, the multiplexer output selection is controlled by PA3 and PA4. The second select pin is unused, so that is denoted with No.
Pins are ordered least-significant bit first. So, if PA4 is high and PA2 is low, multiplexer output 4 is selected.
The matrix provided by build_analog_matrix! serves two purposes:
Define a mapping from matrix position (row, col) to analog pin index and multiplexer output (if applicable).
Define the possible ranges of values that the analog source can generate from the ADC process.
When we take a look at row 0, col 0 on the matrix we find:
It corresponds to ADC pin 0 (which is connected to the multiplexer, PA2), and multiplexer output 0 (when the select pins PA3 and PA4 are set low).
It is expected to yield values ranging from 3040 to 4080 from the ADC.
For row 1, col 0 on the matrix, we find:
It corresponds to ADC pin 1 (which is connected directly to the analog source via PA5). The 0 in (1,0) is ignored, since it is not connected to a multiplexer.
It is expected to yield values ranging from 3040 to 4080 from the ADC.
Note that unused matrix positions are denoted by No.
Revisualizing a matrix (e.g. duplex matrix)
Sometimes, your keyboard might have a complicated matrix scheme that could make it
hard to read parts of your configuration.
For example, some keyboards use a “duplex matrix” to save MCU pins. This is usually accomplished
by making an electrical column span two physical columns, and by using two electrical
rows per physical row.
Here’s an example portion of a duplex matrix:
As you can imagine, this would be hard to track in your firmware code.
So, rumcake includes a remap_matrix macro to help “re-visualize” your matrix to look
more readable. It creates a remap macro for you to use in parts of the code that require
you to configure something that would look like your matrix.
This can be useful for your keyboard layout config, or your backlight matrix config: