diff options
author | XScorpion2 <rcalt2vt@gmail.com> | 2021-08-19 12:39:15 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-19 18:39:15 +0100 |
commit | 9d1c98c891bb8e1e98dc618e0693a7efff23a22e (patch) | |
tree | b3ceeb02861a2e94c248c1e538e9b8db456ffa47 | |
parent | af3673a5b6985f4364210c3656f323624c2e1962 (diff) | |
download | qmk_firmware-9d1c98c891bb8e1e98dc618e0693a7efff23a22e.tar.gz qmk_firmware-9d1c98c891bb8e1e98dc618e0693a7efff23a22e.zip |
Added right vs left specific pin assignments for dip switch (#13074)
* Added right vs left specific pin assignments for dip switch
* Update feature_dip_switch.md
* Ran formatting tools
-rw-r--r-- | docs/feature_dip_switch.md | 3 | ||||
-rw-r--r-- | docs/ja/feature_dip_switch.md | 2 | ||||
-rw-r--r-- | quantum/dip_switch.c | 26 |
3 files changed, 28 insertions, 3 deletions
diff --git a/docs/feature_dip_switch.md b/docs/feature_dip_switch.md index 43a6a3faf..6fbe91657 100644 --- a/docs/feature_dip_switch.md +++ b/docs/feature_dip_switch.md | |||
@@ -9,6 +9,8 @@ and this to your `config.h`: | |||
9 | ```c | 9 | ```c |
10 | // Connects each switch in the dip switch to the GPIO pin of the MCU | 10 | // Connects each switch in the dip switch to the GPIO pin of the MCU |
11 | #define DIP_SWITCH_PINS { B14, A15, A10, B9 } | 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 { ... } | ||
12 | ``` | 14 | ``` |
13 | 15 | ||
14 | or | 16 | or |
@@ -96,7 +98,6 @@ bool dip_switch_update_mask_user(uint32_t state) { | |||
96 | } | 98 | } |
97 | ``` | 99 | ``` |
98 | 100 | ||
99 | |||
100 | ## Hardware | 101 | ## Hardware |
101 | 102 | ||
102 | ### Connects each switch in the dip switch to the GPIO pin of the MCU | 103 | ### Connects each switch in the dip switch to the GPIO pin of the MCU |
diff --git a/docs/ja/feature_dip_switch.md b/docs/ja/feature_dip_switch.md index a5436779f..8d0eeafa5 100644 --- a/docs/ja/feature_dip_switch.md +++ b/docs/ja/feature_dip_switch.md | |||
@@ -14,6 +14,8 @@ DIP スイッチは、以下を `rules.mk` に追加することでサポート | |||
14 | ```c | 14 | ```c |
15 | // Connects each switch in the dip switch to the GPIO pin of the MCU | 15 | // Connects each switch in the dip switch to the GPIO pin of the MCU |
16 | #define DIP_SWITCH_PINS { B14, A15, A10, B9 } | 16 | #define DIP_SWITCH_PINS { B14, A15, A10, B9 } |
17 | // For split keyboards, you can separately define the right side pins | ||
18 | #define DIP_SWITCH_PINS_RIGHT { ... } | ||
17 | ``` | 19 | ``` |
18 | 20 | ||
19 | あるいは | 21 | あるいは |
diff --git a/quantum/dip_switch.c b/quantum/dip_switch.c index 72789ca8e..2608cae59 100644 --- a/quantum/dip_switch.c +++ b/quantum/dip_switch.c | |||
@@ -17,6 +17,9 @@ | |||
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include "dip_switch.h" | 19 | #include "dip_switch.h" |
20 | #ifdef SPLIT_KEYBOARD | ||
21 | # include "split_common/split_util.h" | ||
22 | #endif | ||
20 | 23 | ||
21 | // for memcpy | 24 | // for memcpy |
22 | #include <string.h> | 25 | #include <string.h> |
@@ -32,6 +35,9 @@ | |||
32 | #ifdef DIP_SWITCH_PINS | 35 | #ifdef DIP_SWITCH_PINS |
33 | # define NUMBER_OF_DIP_SWITCHES (sizeof(dip_switch_pad) / sizeof(pin_t)) | 36 | # define NUMBER_OF_DIP_SWITCHES (sizeof(dip_switch_pad) / sizeof(pin_t)) |
34 | static pin_t dip_switch_pad[] = DIP_SWITCH_PINS; | 37 | static pin_t dip_switch_pad[] = DIP_SWITCH_PINS; |
38 | # if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) | ||
39 | static pin_t dip_switch_pad_right[] = DIP_SWITCH_PINS_RIGHT; | ||
40 | # endif | ||
35 | #endif | 41 | #endif |
36 | 42 | ||
37 | #ifdef DIP_SWITCH_MATRIX_GRID | 43 | #ifdef DIP_SWITCH_MATRIX_GRID |
@@ -60,7 +66,15 @@ __attribute__((weak)) bool dip_switch_update_mask_kb(uint32_t state) { return di | |||
60 | void dip_switch_init(void) { | 66 | void dip_switch_init(void) { |
61 | #ifdef DIP_SWITCH_PINS | 67 | #ifdef DIP_SWITCH_PINS |
62 | for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { | 68 | for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { |
63 | setPinInputHigh(dip_switch_pad[i]); | 69 | # if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) |
70 | if (isLeftHand) { | ||
71 | # endif | ||
72 | setPinInputHigh(dip_switch_pad[i]); | ||
73 | # if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) | ||
74 | } else { | ||
75 | setPinInputHigh(dip_switch_pad_right[i]); | ||
76 | } | ||
77 | # endif | ||
64 | } | 78 | } |
65 | dip_switch_read(true); | 79 | dip_switch_read(true); |
66 | #endif | 80 | #endif |
@@ -89,7 +103,15 @@ void dip_switch_read(bool forced) { | |||
89 | 103 | ||
90 | for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { | 104 | for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { |
91 | #ifdef DIP_SWITCH_PINS | 105 | #ifdef DIP_SWITCH_PINS |
92 | dip_switch_state[i] = !readPin(dip_switch_pad[i]); | 106 | # if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) |
107 | if (isLeftHand) { | ||
108 | # endif | ||
109 | dip_switch_state[i] = !readPin(dip_switch_pad[i]); | ||
110 | # if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) | ||
111 | } else { | ||
112 | dip_switch_state[i] = !readPin(dip_switch_pad_right[i]); | ||
113 | } | ||
114 | # endif | ||
93 | #endif | 115 | #endif |
94 | #ifdef DIP_SWITCH_MATRIX_GRID | 116 | #ifdef DIP_SWITCH_MATRIX_GRID |
95 | dip_switch_state[i] = peek_matrix(dip_switch_pad[i].row, dip_switch_pad[i].col, read_raw); | 117 | dip_switch_state[i] = peek_matrix(dip_switch_pad[i].row, dip_switch_pad[i].col, read_raw); |