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.

115 lines
3.1 KiB

  1. # DIP スイッチ
  2. <!---
  3. original document: 0.9.43:docs/feature_dip_switch.md
  4. git diff 0.9.43 HEAD -- docs/feature_dip_switch.md | cat
  5. -->
  6. DIP スイッチは、以下を `rules.mk` に追加することでサポートされます:
  7. DIP_SWITCH_ENABLE = yes
  8. さらに、以下を `config.h` に追加します:
  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. あるいは
  16. ```c
  17. // Connect each switch in the DIP switch to an unused intersections in the key matrix.
  18. #define DIP_SWITCH_MATRIX_GRID { {0,6}, {1,6}, {2,6} } // List of row and col pairs
  19. ```
  20. ## コールバック
  21. コールバック関数を `<keyboard>.c` に記述することができます:
  22. ```c
  23. bool dip_switch_update_kb(uint8_t index, bool active) {
  24. if !(dip_switch_update_user(index, active)) { return false; }
  25. return true;
  26. }
  27. ```
  28. あるいは `keymap.c` に記述することもできます:
  29. ```c
  30. bool dip_switch_update_user(uint8_t index, bool active) {
  31. switch (index) {
  32. case 0:
  33. if(active) { audio_on(); } else { audio_off(); }
  34. break;
  35. case 1:
  36. if(active) { clicky_on(); } else { clicky_off(); }
  37. break;
  38. case 2:
  39. if(active) { music_on(); } else { music_off(); }
  40. break;
  41. case 3:
  42. if (active) {
  43. #ifdef AUDIO_ENABLE
  44. PLAY_SONG(plover_song);
  45. #endif
  46. layer_on(_PLOVER);
  47. } else {
  48. #ifdef AUDIO_ENABLE
  49. PLAY_SONG(plover_gb_song);
  50. #endif
  51. layer_off(_PLOVER);
  52. }
  53. break;
  54. }
  55. return true;
  56. }
  57. ```
  58. 更に、より複雑な処理ができるビットマスク関数をサポートします。
  59. ```c
  60. bool dip_switch_update_mask_kb(uint32_t state) {
  61. if (!dip_switch_update_mask_user(state)) { return false; }
  62. return true;
  63. }
  64. ```
  65. あるいは `keymap.c` に記述することもできます:
  66. ```c
  67. bool dip_switch_update_mask_user(uint32_t state) {
  68. if (state & (1UL<<0) && state & (1UL<<1)) {
  69. layer_on(_ADJUST); // C on esc
  70. } else {
  71. layer_off(_ADJUST);
  72. }
  73. if (state & (1UL<<0)) {
  74. layer_on(_TEST_A); // A on ESC
  75. } else {
  76. layer_off(_TEST_A);
  77. }
  78. if (state & (1UL<<1)) {
  79. layer_on(_TEST_B); // B on esc
  80. } else {
  81. layer_off(_TEST_B);
  82. }
  83. return true;
  84. }
  85. ```
  86. ## ハードウェア
  87. ### DIP スイッチの各スイッチを MCU の GPIO ピンに接続する
  88. DIP スイッチの片側は MCU のピンへ直接配線し、もう一方の側はグラウンドに配線する必要があります。機能的に同じであるため、どちら側がどちらに接続されているかは問題にはならないはずです。
  89. ### DIP スイッチの各スイッチをキーマトリクスの未使用の交点に接続する
  90. キースイッチと同じように、ダイオードと DIP スイッチが ROW 線と COL 線に接続します。