Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added right vs left specific pin assignments for dip switch #13074

Merged
merged 3 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/feature_dip_switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);`
XScorpion2 marked this conversation as resolved.
Show resolved Hide resolved
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

Expand Down
2 changes: 2 additions & 0 deletions docs/ja/feature_dip_switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 { ... }
```

あるいは
Expand Down
26 changes: 24 additions & 2 deletions quantum/dip_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/

#include "dip_switch.h"
#ifdef SPLIT_KEYBOARD
# include "split_common/split_util.h"
#endif

// for memcpy
#include <string.h>
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down