Skip to main content

Custom Devicetree

The SliceMK keymap configurator allows users to define custom Devicetree code to access features that are not yet implemented in the configurator.

warning

This guide is for advanced users only. If you are new to ZMK, we recommend starting with the configurator's included features and revisiting this guide once you are comfortable with basic customization.

Macros

The keymap configurator has support for simple macros including for strings. However if you want to define a macro with arbitrary key sequences, you will need to use custom Devicetree code.

Please refer to ZMK documentation for full details on how to define macros. Some basic examples are provided below for convenience.

Suppose you want to define a macro that presses LCtrl-L, types test, then presses enter. You can define it as follows:

/ {
ZMK_MACRO(
macro_1,
wait-ms = <10>;
tap-ms = <10>;
bindings =
<&macro_tap &kp LC(L)>,
<&macro_tap &kp T>,
<&macro_tap &kp E>,
<&macro_tap &kp S>,
<&macro_tap &kp T>,
<&macro_tap &kp RETURN>;
)
};
tip

LC(L) is the keyboard shortcut for navigating to the browser address bar on Windows and Linux. For macOS, you should use LG(L) instead. You can find the full list of XX() modifier functions and key codes in the ZMK documentation.

Suppose you want to define a macro that holds LShift while typing test. You can define it as follows:

/ {
ZMK_MACRO(
macro_2,
wait-ms = <10>;
tap-ms = <10>;
bindings =
<&macro_press &kp LEFT_SHIFT>,
<&macro_tap &kp T>,
<&macro_tap &kp E>,
<&macro_tap &kp S>,
<&macro_tap &kp T>,
<&macro_release &kp LEFT_SHIFT>;
)
};

After adding the above code to the "Custom Devicetree Code" section of the configurator, you can add a "Custom" key to your keymap with value &macro_1 or &macro_2.

Combos

To define a combo, start by determining the key position for the keys you want to bind. Key position references are available for the following keyboards:

Please refer to ZMK documentation for full details on how to define combos.

As a simple example, suppose you want F and J to trigger Enter when pressed together on your ErgoDox. Using the key position diagram, you can see that F is key 33 and J is key 36. You can define the combo with the following Devicetree code:

/ {
combos {
compatible = "zmk,combos";
combo_return {
timeout-ms = <50>;
key-positions = <33 36>;
bindings = <&kp RETURN>;
};
};
};

RGB Underglow

RGB underglow is experimental on SliceMK keyboards when used with a dongle. In dongleless setups, it may work but SliceMK does not officially support it yet.

To make use of underglow, you must build your firmware with one of the *-rgb releases. You can select the appropriate firmware version when using the configurator, or point your repository at the appropriate branch when using GitHub Actions.

The following &rgb_ug actions are supported:

  • &rgb_ug RGB_HUI to increase the hue
  • &rgb_ug RGB_HUD to decrease the hue
  • &rgb_ug RGB_SAI to increase the saturation
  • &rgb_ug RGB_SAD to decrease the saturation
  • &rgb_ug RGB_BRI to increase the brightness
  • &rgb_ug RGB_BRD to decrease the brightness
  • &rgb_ug RGB_COLOR_HSB(h,s,b) to set the color using hue, saturation, and brightness

As a simple example, suppose you want underglow to be green. You can define a "Custom" key with value:

&rgb_ug RGB_COLOR_HSB(120,100,100)

To turn underglow off, you can define a "Custom" key that sets the brightness to 0%:

&rgb_ug RGB_COLOR_HSB(0,0,0)
tip

When using the SliceMK peripheral firmware, you do not need to manage external power explicitly, unlike with most ZMK keyboards. Setting the brightness to zero is sufficient for turning off underglow and cutting off power at the same time.

As a more complex example, suppose you want underglow to be red while the fn momentary layer is active. You can wrap &mo LAYER_FN with a macro in the following manner:

/ {
ZMK_MACRO(
layer_fn_rgb,
wait-ms = <0>;
tap-ms = <0>;
bindings =
<&macro_press &mo LAYER_FN>,
<&macro_tap &rgb_ug RGB_COLOR_HSB(0,100,100)>,
<&macro_pause_for_release>,
<&macro_release &mo LAYER_FN>,
<&macro_tap &rgb_ug RGB_COLOR_HSB(0,0,0)>;
)
};