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