You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.2 KiB

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