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.

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