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.

90 lines
2.0 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. #define DIP_SWITCH_PINS { B14, A15, A10, B9 }
  7. ```
  8. ## Callbacks
  9. The callback functions can be inserted into your `<keyboard>.c`:
  10. ```c
  11. void dip_switch_update_kb(uint8_t index, bool active) {
  12. dip_switch_update_user(index, active);
  13. }
  14. ```
  15. or `keymap.c`:
  16. ```c
  17. void dip_switch_update_user(uint8_t index, bool active) {
  18. switch (index) {
  19. case 0:
  20. if(active) { audio_on(); } else { audio_off(); }
  21. break;
  22. case 1:
  23. if(active) { clicky_on(); } else { clicky_off(); }
  24. break;
  25. case 2:
  26. if(active) { music_on(); } else { music_off(); }
  27. break;
  28. case 3:
  29. if (active) {
  30. #ifdef AUDIO_ENABLE
  31. PLAY_SONG(plover_song);
  32. #endif
  33. layer_on(_PLOVER);
  34. } else {
  35. #ifdef AUDIO_ENABLE
  36. PLAY_SONG(plover_gb_song);
  37. #endif
  38. layer_off(_PLOVER);
  39. }
  40. break;
  41. }
  42. }
  43. ```
  44. Additionally, we support bit mask functions which allow for more complex handling.
  45. ```c
  46. void dip_switch_update_mask_kb(uint32_t state) {
  47. dip_switch_update_mask_user(state);
  48. }
  49. ```
  50. or `keymap.c`:
  51. ```c
  52. void dip_switch_update_mask_user(uint32_t state) {
  53. if (state & (1UL<<0) && state & (1UL<<1)) {
  54. layer_on(_ADJUST); // C on esc
  55. } else {
  56. layer_off(_ADJUST);
  57. }
  58. if (state & (1UL<<0)) {
  59. layer_on(_TEST_A); // A on ESC
  60. } else {
  61. layer_off(_TEST_A);
  62. }
  63. if (state & (1UL<<1)) {
  64. layer_on(_TEST_B); // B on esc
  65. } else {
  66. layer_off(_TEST_B);
  67. }
  68. }
  69. ```
  70. ## Hardware
  71. 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.