From 7b51ddcb93b8875f94f34d3de5650adafab75f48 Mon Sep 17 00:00:00 2001 From: Ryan C Date: Tue, 1 Jun 2021 19:28:50 -0500 Subject: [PATCH 1/3] Added right vs left specific pin assignments for dip switch --- docs/feature_dip_switch.md | 16 ++++++++++++++++ docs/ja/feature_dip_switch.md | 2 ++ quantum/dip_switch.c | 26 ++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/docs/feature_dip_switch.md b/docs/feature_dip_switch.md index 15e449c4c465..997721646260 100644 --- a/docs/feature_dip_switch.md +++ b/docs/feature_dip_switch.md @@ -9,6 +9,8 @@ and this to your `config.h`: ```c // Connects each switch in the dip switch to the GPIO pin of the MCU #define DIP_SWITCH_PINS { B14, A15, A10, B9 } +// For split keyboards, you can separately define the right side pins +#define DIP_SWITCH_PINS_RIGHT { ... } ``` or @@ -92,6 +94,20 @@ void dip_switch_update_mask_user(uint32_t state) { } ``` +For DIP switch processing on the slave half of split keyboards, you can add `dip_switch_scan(false);` +to either your base keyboard .c file in `matrix_slave_scan_kb()` or to your user level +`matrix_slave_scan_user()` as needed: + +```c +void matrix_slave_scan_kb() { + dip_switch_read(false); + matrix_slave_scan_user(); +} +// or +void matrix_slave_scan_user() { + dip_switch_read(false); +} +``` ## Hardware diff --git a/docs/ja/feature_dip_switch.md b/docs/ja/feature_dip_switch.md index a0f6aeb0035f..b501cc3fc8d6 100644 --- a/docs/ja/feature_dip_switch.md +++ b/docs/ja/feature_dip_switch.md @@ -14,6 +14,8 @@ DIP スイッチは、以下を `rules.mk` に追加することでサポート ```c // Connects each switch in the dip switch to the GPIO pin of the MCU #define DIP_SWITCH_PINS { B14, A15, A10, B9 } +// For split keyboards, you can separately define the right side pins +#define DIP_SWITCH_PINS_RIGHT { ... } ``` あるいは diff --git a/quantum/dip_switch.c b/quantum/dip_switch.c index cda69bd0ef70..e65be39c3ec3 100644 --- a/quantum/dip_switch.c +++ b/quantum/dip_switch.c @@ -17,6 +17,9 @@ */ #include "dip_switch.h" +#ifdef SPLIT_KEYBOARD +# include "split_common/split_util.h" +#endif // for memcpy #include @@ -32,6 +35,9 @@ #ifdef DIP_SWITCH_PINS # define NUMBER_OF_DIP_SWITCHES (sizeof(dip_switch_pad) / sizeof(pin_t)) static pin_t dip_switch_pad[] = DIP_SWITCH_PINS; +# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) +static pin_t dip_switch_pad_right[] = DIP_SWITCH_PINS_RIGHT; +# endif #endif #ifdef DIP_SWITCH_MATRIX_GRID @@ -60,7 +66,15 @@ __attribute__((weak)) void dip_switch_update_mask_kb(uint32_t state) { dip_switc void dip_switch_init(void) { #ifdef DIP_SWITCH_PINS for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { - setPinInputHigh(dip_switch_pad[i]); +# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) + if ( isLeftHand ) { +# endif + setPinInputHigh(dip_switch_pad[i]); +# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) + } else { + setPinInputHigh(dip_switch_pad_right[i]); + } +# endif } dip_switch_read(true); #endif @@ -89,7 +103,15 @@ void dip_switch_read(bool forced) { for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { #ifdef DIP_SWITCH_PINS - dip_switch_state[i] = !readPin(dip_switch_pad[i]); +# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) + if (isLeftHand) { +# endif + dip_switch_state[i] = !readPin(dip_switch_pad[i]); +# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) + } else { + dip_switch_state[i] = !readPin(dip_switch_pad_right[i]); + } +# endif #endif #ifdef DIP_SWITCH_MATRIX_GRID dip_switch_state[i] = peek_matrix(dip_switch_pad[i].row, dip_switch_pad[i].col, read_raw); From 507a8dd3a2568ecfd4b75fec7ec1e1f465da3966 Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Thu, 17 Jun 2021 21:55:01 -0500 Subject: [PATCH 2/3] Update feature_dip_switch.md --- docs/feature_dip_switch.md | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/docs/feature_dip_switch.md b/docs/feature_dip_switch.md index 997721646260..88e01d4fe081 100644 --- a/docs/feature_dip_switch.md +++ b/docs/feature_dip_switch.md @@ -94,21 +94,6 @@ void dip_switch_update_mask_user(uint32_t state) { } ``` -For DIP switch processing on the slave half of split keyboards, you can add `dip_switch_scan(false);` -to either your base keyboard .c file in `matrix_slave_scan_kb()` or to your user level -`matrix_slave_scan_user()` as needed: - -```c -void matrix_slave_scan_kb() { - dip_switch_read(false); - matrix_slave_scan_user(); -} -// or -void matrix_slave_scan_user() { - dip_switch_read(false); -} -``` - ## Hardware ### Connects each switch in the dip switch to the GPIO pin of the MCU From 166424a1cbf6171d51978891904580b8cfad8fe2 Mon Sep 17 00:00:00 2001 From: Ryan C Date: Fri, 18 Jun 2021 10:53:31 -0500 Subject: [PATCH 3/3] Ran formatting tools --- quantum/dip_switch.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/quantum/dip_switch.c b/quantum/dip_switch.c index e65be39c3ec3..5c2a80a58efc 100644 --- a/quantum/dip_switch.c +++ b/quantum/dip_switch.c @@ -18,7 +18,7 @@ #include "dip_switch.h" #ifdef SPLIT_KEYBOARD -# include "split_common/split_util.h" +# include "split_common/split_util.h" #endif // for memcpy @@ -35,9 +35,9 @@ #ifdef DIP_SWITCH_PINS # define NUMBER_OF_DIP_SWITCHES (sizeof(dip_switch_pad) / sizeof(pin_t)) static pin_t dip_switch_pad[] = DIP_SWITCH_PINS; -# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) +# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) static pin_t dip_switch_pad_right[] = DIP_SWITCH_PINS_RIGHT; -# endif +# endif #endif #ifdef DIP_SWITCH_MATRIX_GRID @@ -66,15 +66,15 @@ __attribute__((weak)) void dip_switch_update_mask_kb(uint32_t state) { dip_switc void dip_switch_init(void) { #ifdef DIP_SWITCH_PINS for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { -# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) - if ( isLeftHand ) { -# endif +# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) + if (isLeftHand) { +# endif setPinInputHigh(dip_switch_pad[i]); -# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) +# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) } else { setPinInputHigh(dip_switch_pad_right[i]); } -# endif +# endif } dip_switch_read(true); #endif @@ -103,15 +103,15 @@ void dip_switch_read(bool forced) { for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { #ifdef DIP_SWITCH_PINS -# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) +# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) if (isLeftHand) { -# endif +# endif dip_switch_state[i] = !readPin(dip_switch_pad[i]); -# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) +# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) } else { dip_switch_state[i] = !readPin(dip_switch_pad_right[i]); } -# endif +# endif #endif #ifdef DIP_SWITCH_MATRIX_GRID dip_switch_state[i] = peek_matrix(dip_switch_pad[i].row, dip_switch_pad[i].col, read_raw);