From 0bde920817ef458f2ad61a66ce76a2535bbc261b Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Thu, 1 Jul 2021 08:22:21 -0700 Subject: Convert Dip Switch callbacks to boolean functions (#13399) --- quantum/dip_switch.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'quantum/dip_switch.c') diff --git a/quantum/dip_switch.c b/quantum/dip_switch.c index cda69bd0ef..72789ca8e8 100644 --- a/quantum/dip_switch.c +++ b/quantum/dip_switch.c @@ -49,13 +49,13 @@ static uint16_t scan_count; static bool dip_switch_state[NUMBER_OF_DIP_SWITCHES] = {0}; static bool last_dip_switch_state[NUMBER_OF_DIP_SWITCHES] = {0}; -__attribute__((weak)) void dip_switch_update_user(uint8_t index, bool active) {} +__attribute__((weak)) bool dip_switch_update_user(uint8_t index, bool active) { return true; } -__attribute__((weak)) void dip_switch_update_kb(uint8_t index, bool active) { dip_switch_update_user(index, active); } +__attribute__((weak)) bool dip_switch_update_kb(uint8_t index, bool active) { return dip_switch_update_user(index, active); } -__attribute__((weak)) void dip_switch_update_mask_user(uint32_t state) {} +__attribute__((weak)) bool dip_switch_update_mask_user(uint32_t state) { return true; } -__attribute__((weak)) void dip_switch_update_mask_kb(uint32_t state) { dip_switch_update_mask_user(state); } +__attribute__((weak)) bool dip_switch_update_mask_kb(uint32_t state) { return dip_switch_update_mask_user(state); } void dip_switch_init(void) { #ifdef DIP_SWITCH_PINS -- cgit v1.2.3 From 9d1c98c891bb8e1e98dc618e0693a7efff23a22e Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Thu, 19 Aug 2021 12:39:15 -0500 Subject: 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 --- quantum/dip_switch.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'quantum/dip_switch.c') diff --git a/quantum/dip_switch.c b/quantum/dip_switch.c index 72789ca8e8..2608cae594 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)) bool dip_switch_update_mask_kb(uint32_t state) { return di 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); -- cgit v1.2.3 From 69c71d4843586fad9c29c4dd945aa170f9990d8e Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Fri, 20 Aug 2021 10:15:11 +0100 Subject: Align DIP_SWITCH_PINS_RIGHT implementation with encoders (#14079) --- quantum/dip_switch.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'quantum/dip_switch.c') diff --git a/quantum/dip_switch.c b/quantum/dip_switch.c index 2608cae594..133ec85027 100644 --- a/quantum/dip_switch.c +++ b/quantum/dip_switch.c @@ -35,9 +35,6 @@ #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 @@ -65,16 +62,16 @@ __attribute__((weak)) bool dip_switch_update_mask_kb(uint32_t state) { return di 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 - setPinInputHigh(dip_switch_pad[i]); -# if defined(SPLIT_KEYBOARD) && defined(DIP_SWITCH_PINS_RIGHT) - } else { - setPinInputHigh(dip_switch_pad_right[i]); + if (!isLeftHand) { + const pin_t dip_switch_pad_right[] = DIP_SWITCH_PINS_RIGHT; + for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { + dip_switch_pad[i] = dip_switch_pad_right[i]; } + } # endif + for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { + setPinInputHigh(dip_switch_pad[i]); } dip_switch_read(true); #endif @@ -103,15 +100,7 @@ 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 (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 + dip_switch_state[i] = !readPin(dip_switch_pad[i]); #endif #ifdef DIP_SWITCH_MATRIX_GRID dip_switch_state[i] = peek_matrix(dip_switch_pad[i].row, dip_switch_pad[i].col, read_raw); -- cgit v1.2.3