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.

109 lines
2.7 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. ## Callbacks
  17. The callback functions can be inserted into your `<keyboard>.c`:
  18. ```c
  19. bool dip_switch_update_kb(uint8_t index, bool active) {
  20. if (!dip_switch_update_user(index, active)) { return false; }
  21. return true;
  22. }
  23. ```
  24. or `keymap.c`:
  25. ```c
  26. bool dip_switch_update_user(uint8_t index, bool active) {
  27. switch (index) {
  28. case 0:
  29. if(active) { audio_on(); } else { audio_off(); }
  30. break;
  31. case 1:
  32. if(active) { clicky_on(); } else { clicky_off(); }
  33. break;
  34. case 2:
  35. if(active) { music_on(); } else { music_off(); }
  36. break;
  37. case 3:
  38. if (active) {
  39. #ifdef AUDIO_ENABLE
  40. PLAY_SONG(plover_song);
  41. #endif
  42. layer_on(_PLOVER);
  43. } else {
  44. #ifdef AUDIO_ENABLE
  45. PLAY_SONG(plover_gb_song);
  46. #endif
  47. layer_off(_PLOVER);
  48. }
  49. break;
  50. }
  51. return true;
  52. }
  53. ```
  54. Additionally, we support bit mask functions which allow for more complex handling.
  55. ```c
  56. bool dip_switch_update_mask_kb(uint32_t state) {
  57. if (!dip_switch_update_mask_user(state)) { return false; }
  58. return true;
  59. }
  60. ```
  61. or `keymap.c`:
  62. ```c
  63. bool dip_switch_update_mask_user(uint32_t state) {
  64. if (state & (1UL<<0) && state & (1UL<<1)) {
  65. layer_on(_ADJUST); // C on esc
  66. } else {
  67. layer_off(_ADJUST);
  68. }
  69. if (state & (1UL<<0)) {
  70. layer_on(_TEST_A); // A on ESC
  71. } else {
  72. layer_off(_TEST_A);
  73. }
  74. if (state & (1UL<<1)) {
  75. layer_on(_TEST_B); // B on esc
  76. } else {
  77. layer_off(_TEST_B);
  78. }
  79. return true;
  80. }
  81. ```
  82. ## Hardware
  83. ### Connects each switch in the dip switch to the GPIO pin of the MCU
  84. 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.
  85. ### Connect each switch in the DIP switch to an unused intersections in the key matrix.
  86. As with the keyswitch, a diode and DIP switch connect the ROW line to the COL line.