keyboard stuff
at master 132 lines 3.3 kB view raw view rendered
1# DIP Switches 2 3DIP switches are supported by adding this to your `rules.mk`: 4 5 DIP_SWITCH_ENABLE = yes 6 7and this to your `config.h`: 8 9```c 10// Connects each switch in the dip switch to the GPIO pin of the MCU 11#define DIP_SWITCH_PINS { B14, A15, A10, B9 } 12// For split keyboards, you can separately define the right side pins 13#define DIP_SWITCH_PINS_RIGHT { ... } 14``` 15 16or 17 18```c 19// Connect each switch in the DIP switch to an unused intersections in the key matrix. 20#define DIP_SWITCH_MATRIX_GRID { {0,6}, {1,6}, {2,6} } // List of row and col pairs 21``` 22 23## DIP Switch map {#dip-switch-map} 24 25DIP Switch mapping may be added to your `keymap.c`, which replicates the normal keyswitch functionality, but with dip switches. Add this to your keymap's `rules.mk`: 26 27```make 28DIP_SWITCH_MAP_ENABLE = yes 29``` 30 31Your `keymap.c` will then need a dip switch mapping defined (for two dip switches): 32 33```c 34#if defined(DIP_SWITCH_MAP_ENABLE) 35const uint16_t PROGMEM dip_switch_map[NUM_DIP_SWITCHES][NUM_DIP_STATES] = { 36 DIP_SWITCH_OFF_ON(DF(0), DF(1)), 37 DIP_SWITCH_OFF_ON(EC_NORM, EC_SWAP) 38}; 39#endif 40``` 41 42::: tip 43This should only be enabled at the keymap level. 44::: 45 46## Callbacks 47 48The callback functions can be inserted into your `<keyboard>.c`: 49 50```c 51bool dip_switch_update_kb(uint8_t index, bool active) { 52 if (!dip_switch_update_user(index, active)) { return false; } 53 return true; 54} 55``` 56 57 58or `keymap.c`: 59 60```c 61bool dip_switch_update_user(uint8_t index, bool active) { 62 switch (index) { 63 case 0: 64 if(active) { audio_on(); } else { audio_off(); } 65 break; 66 case 1: 67 if(active) { clicky_on(); } else { clicky_off(); } 68 break; 69 case 2: 70 if(active) { music_on(); } else { music_off(); } 71 break; 72 case 3: 73 if (active) { 74 #ifdef AUDIO_ENABLE 75 PLAY_SONG(plover_song); 76 #endif 77 layer_on(_PLOVER); 78 } else { 79 #ifdef AUDIO_ENABLE 80 PLAY_SONG(plover_gb_song); 81 #endif 82 layer_off(_PLOVER); 83 } 84 break; 85 } 86 return true; 87} 88``` 89 90Additionally, we support bit mask functions which allow for more complex handling. 91 92 93```c 94bool dip_switch_update_mask_kb(uint32_t state) { 95 if (!dip_switch_update_mask_user(state)) { return false; } 96 return true; 97} 98``` 99 100 101or `keymap.c`: 102 103```c 104bool dip_switch_update_mask_user(uint32_t state) { 105 if (state & (1UL<<0) && state & (1UL<<1)) { 106 layer_on(_ADJUST); // C on esc 107 } else { 108 layer_off(_ADJUST); 109 } 110 if (state & (1UL<<0)) { 111 layer_on(_TEST_A); // A on ESC 112 } else { 113 layer_off(_TEST_A); 114 } 115 if (state & (1UL<<1)) { 116 layer_on(_TEST_B); // B on esc 117 } else { 118 layer_off(_TEST_B); 119 } 120 return true; 121} 122``` 123 124## Hardware 125 126### Connects each switch in the dip switch to the GPIO pin of the MCU 127 128One 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. 129 130### Connect each switch in the DIP switch to an unused intersections in the key matrix. 131 132As with the keyswitch, a diode and DIP switch connect the ROW line to the COL line.