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.

95 lines
2.3 KiB

  1. # DIP スイッチ
  2. <!---
  3. original document: 0.8.94:docs/feature_dip_switch.md
  4. git diff 0.8.94 HEAD -- docs/feature_dip_switch.md | cat
  5. -->
  6. DIP スイッチは、以下を `rules.mk` に追加することでサポートされます:
  7. DIP_SWITCH_ENABLE = yes
  8. さらに、以下を `config.h` に追加します:
  9. ```c
  10. #define DIP_SWITCH_PINS { B14, A15, A10, B9 }
  11. ```
  12. ## コールバック
  13. コールバック関数を `<keyboard>.c` に記述することができます:
  14. ```c
  15. void dip_switch_update_kb(uint8_t index, bool active) {
  16. dip_switch_update_user(index, active);
  17. }
  18. ```
  19. あるいは `keymap.c` に記述することもできます:
  20. ```c
  21. void dip_switch_update_user(uint8_t index, bool active) {
  22. switch (index) {
  23. case 0:
  24. if(active) { audio_on(); } else { audio_off(); }
  25. break;
  26. case 1:
  27. if(active) { clicky_on(); } else { clicky_off(); }
  28. break;
  29. case 2:
  30. if(active) { music_on(); } else { music_off(); }
  31. break;
  32. case 3:
  33. if (active) {
  34. #ifdef AUDIO_ENABLE
  35. PLAY_SONG(plover_song);
  36. #endif
  37. layer_on(_PLOVER);
  38. } else {
  39. #ifdef AUDIO_ENABLE
  40. PLAY_SONG(plover_gb_song);
  41. #endif
  42. layer_off(_PLOVER);
  43. }
  44. break;
  45. }
  46. }
  47. ```
  48. 更に、より複雑な処理ができるビットマスク関数をサポートします。
  49. ```c
  50. void dip_switch_update_mask_kb(uint32_t state) {
  51. dip_switch_update_mask_user(state);
  52. }
  53. ```
  54. あるいは `keymap.c` に記述することもできます:
  55. ```c
  56. void dip_switch_update_mask_user(uint32_t state) {
  57. if (state & (1UL<<0) && state & (1UL<<1)) {
  58. layer_on(_ADJUST); // C on esc
  59. } else {
  60. layer_off(_ADJUST);
  61. }
  62. if (state & (1UL<<0)) {
  63. layer_on(_TEST_A); // A on ESC
  64. } else {
  65. layer_off(_TEST_A);
  66. }
  67. if (state & (1UL<<1)) {
  68. layer_on(_TEST_B); // B on esc
  69. } else {
  70. layer_off(_TEST_B);
  71. }
  72. }
  73. ```
  74. ## ハードウェア
  75. DIP スイッチの片側は MCU のピンへ直接配線し、もう一方の側はグラウンドに配線する必要があります。機能的に同じであるため、どちら側がどちらに接続されているかは問題にはならないはずです。