Journal of my ideas, thoughts and projects.

Programming your Planck keyboard #2 - Creating a new layer

The Quantum firmware gives you the possibility to create  multiple layers. These may either be different keyboard layouts (e.g.  Dvorak, Colemak etc.) or special layers like the Plover stenography  layer. Today I am showing you how to create such a special layer; a  layer with a numeric keypad in this case. Firstly, open the keymap.c file. If you don't know what I am talking about, be sure to first read part #1 of this series. At the beginning of the file add a #define line below the already existing. Choose a name for your new layer (e.g. _NUMBERS).  

#define _QWERTY 0
#define _COLEMAK 1
#define _DVORAK 2
#define _LOWER 3
#define _RAISE 4
#define _PLOVER 5
#define _ADJUST 16
#define _NUMBERS 17

Add the name you've chosen to the enumeration below (without the leading underscore). Now, scroll down to the layout matrix until you find an entry called [_PLOVER] and copy the matrix (and optionally the comment above which I recommend  for better readability). Then change the name to the name you defined  before and all of the keycode entries to one of these:  

_______ - Set to entry on current keyboard layout at this position  
XXXXXXX - Set to nothing  

I usually use the first. You can now set the layout for your layer. Take a look at the example on Pastebin.
Edit: There is a list of all keycodes included in the repository in the file doc/keycode.txt. ! It is very important to have the macro EXT_NUM assigned to one key to be able to leave the layer. ! You already now how to define a macro so I am just showing you the code the macro is executing:  

case 20: // Change to the number of your macro  
  if (record->event.pressed) {
    #ifdef AUDIO_ENABLE
      PLAY_NOTE_ARRAY(tone_numbers_gb, false, 0); // Change to a melody available on your device (more about melodies in part #3)

There is still one thing left to do: Give the keyboard a way to start  the layer. To do that search for the switch case in a function called process_record_user and add a case with the name of your layer without leading underscore.  

case NUMBERS:  
  if (record->event.pressed) {
    #ifdef AUDIO_ENABLE
      PLAY_NOTE_ARRAY(tone_numbers, false, 0); // Again change the melody or create one with that name
  return false;

If everythings correct you should now be able to compile and flash the new firmware and test it.
If you have any questions contact me on Reddit (/u/lxndio) or via Telegram (@lxndio). The third part of this series is now also available.

Till then,