DIP Switch
DIP switches are supported by adding this to your rules.mk:
1
DIP_SWITCH_ENABLE = yes
Copied!
and this to your config.h:
1
// Connects each switch in the dip switch to the GPIO pin of the MCU
2
#define DIP_SWITCH_PINS { B14, A15, A10, B9 }
3
// For split keyboards, you can separately define the right side pins
4
#define DIP_SWITCH_PINS_RIGHT { ... }
Copied!
or
1
// Connect each switch in the DIP switch to an unused intersections in the key matrix.
2
#define DIP_SWITCH_MATRIX_GRID { {0,6}, {1,6}, {2,6} } // List of row and col pairs
Copied!

Callbacks

The callback functions can be inserted into your <keyboard>.c:
1
bool dip_switch_update_kb(uint8_t index, bool active) {
2
if (!dip_switch_update_user(index, active)) { return false; }
3
return true;
4
}
Copied!
or keymap.c:
1
bool dip_switch_update_user(uint8_t index, bool active) {
2
switch (index) {
3
case 0:
4
if(active) { audio_on(); } else { audio_off(); }
5
break;
6
case 1:
7
if(active) { clicky_on(); } else { clicky_off(); }
8
break;
9
case 2:
10
if(active) { music_on(); } else { music_off(); }
11
break;
12
case 3:
13
if (active) {
14
#ifdef AUDIO_ENABLE
15
PLAY_SONG(plover_song);
16
#endif
17
layer_on(_PLOVER);
18
} else {
19
#ifdef AUDIO_ENABLE
20
PLAY_SONG(plover_gb_song);
21
#endif
22
layer_off(_PLOVER);
23
}
24
break;
25
}
26
return true;
27
}
Copied!
Additionally, we support bit mask functions which allow for more complex handling.
1
bool dip_switch_update_mask_kb(uint32_t state) {
2
if (!dip_switch_update_mask_user(state)) { return false; }
3
return true;
4
}
Copied!
or keymap.c:
1
bool dip_switch_update_mask_user(uint32_t state) {
2
if (state & (1UL<<0) && state & (1UL<<1)) {
3
layer_on(_ADJUST); // C on esc
4
} else {
5
layer_off(_ADJUST);
6
}
7
if (state & (1UL<<0)) {
8
layer_on(_TEST_A); // A on ESC
9
} else {
10
layer_off(_TEST_A);
11
}
12
if (state & (1UL<<1)) {
13
layer_on(_TEST_B); // B on esc
14
} else {
15
layer_off(_TEST_B);
16
}
17
return true;
18
}
Copied!

Hardware

Connects each switch in the dip switch to the GPIO pin of the MCU

One side of the DIP switch should be wired directly to the pin on the MCU, and the other side to ground. It should not matter which side is connected to which, as it should be functionally the same.

Connect each switch in the DIP switch to an unused intersections in the key matrix.

As with the keyswitch, a diode and DIP switch connect the ROW line to the COL line.
Last modified 3mo ago