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

Add Dip Switch as a core feature #6140

Merged
merged 16 commits into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,9 @@ ifeq ($(strip $(SPACE_CADET_ENABLE)), yes)
SRC += $(QUANTUM_DIR)/process_keycode/process_space_cadet.c
OPT_DEFS += -DSPACE_CADET_ENABLE
endif


ifeq ($(strip $(DIP_SWITCH_ENABLE)), yes)
SRC += $(QUANTUM_DIR)/dip_switch.c
OPT_DEFS += -DDIP_SWITCH_ENABLE
endif
1 change: 1 addition & 0 deletions docs/_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
* [Combos](feature_combo.md)
* [Command](feature_command.md)
* [Debounce API](feature_debounce_type.md)
* [DIP Switch](feature_dip_switch.md)
* [Dynamic Macros](feature_dynamic_macros.md)
* [Encoders](feature_encoders.md)
* [Grave Escape](feature_grave_esc.md)
Expand Down
90 changes: 90 additions & 0 deletions docs/feature_dip_switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# DIP Switches

DIP switches are supported by adding this to your `rules.mk`:

DIP_SWITCH_ENABLE = yes

and this to your `config.h`:

```c
#define DIP_SWITCH_PINS { B14, A15, A10, B9 }
```

## Callbacks

The callback functions can be inserted into your `<keyboard>.c`:

```c
void dip_switch_update_kb(uint8_t index, bool active) {
dip_switch_update_user(index, active);
}
```


or `keymap.c`:

```c
void dip_switch_update_user(uint8_t index, bool active) {
switch (index) {
case 0:
if(active) { audio_on(); } else { audio_off(); }
break;
case 1:
if(active) { clicky_on(); } else { clicky_off(); }
break;
case 2:
if(active) { music_on(); } else { music_off(); }
break;
case 3:
if (active) {
#ifdef AUDIO_ENABLE
PLAY_SONG(plover_song);
#endif
layer_on(_PLOVER);
} else {
#ifdef AUDIO_ENABLE
PLAY_SONG(plover_gb_song);
#endif
layer_off(_PLOVER);
}
break;
}
}
```

Additionally, we support bit mask functions which allow for more complex handling.


```c
void dip_switch_update_mask_kb(uint32_t state) {
dip_switch_update_mask_user(state);
}
```


or `keymap.c`:

```c
void dip_switch_update_mask_user(uint32_t state) {
if (state & (1UL<<0) && state & (1UL<<1)) {
layer_on(_ADJUST); // C on esc
} else {
layer_off(_ADJUST);
}
if (state & (1UL<<0)) {
layer_on(_TEST_A); // A on ESC
} else {
layer_off(_TEST_A);
}
if (state & (1UL<<1)) {
layer_on(_TEST_B); // B on esc
} else {
layer_off(_TEST_B);
}
}
```


## Hardware

One side of the DIP switch should be wired directly to the pin on the MCU, and the other side to ground. It should not matter which side is connected to which, as it should be functionally the same.
1 change: 1 addition & 0 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ QMK has a staggering number of features for building your keyboard. It can take
* [Combos](feature_combo.md) - Custom actions for multiple key holds.
* [Command](feature_command.md) - Runtime version of bootmagic (Formerly known as "Magic").
* [Debounce API](feature_debounce_type.md) - Customization of debouncing algorithms, and the ability to add more/custom debouncing.
* [DIP Switch](feature_dip_switch.md) - Toggle switches for customizing board function.
* [Dynamic Macros](feature_dynamic_macros.md) - Record and playback macros from the keyboard itself.
* [Encoders](feature_encoders.md) - Rotary encoders!
* [Grave Escape](feature_grave_esc.md) - Lets you use a single key for Esc and Grave.
Expand Down
1 change: 1 addition & 0 deletions docs/zh-cn/_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
* [热改键](feature_bootmagic.md)
* [组合](feature_combo)
* [命令](feature_command.md)
* [拨动开关](feature_dip_switch.md)
* [动态宏指令](feature_dynamic_macros.md)
* [编码器](feature_encoders.md)
* [重音号Esc复合键](feature_grave_esc.md)
Expand Down
2 changes: 1 addition & 1 deletion keyboards/planck/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void encoder_update(bool clockwise) {
}
}

void dip_update(uint8_t index, bool active) {
void dip_switch_update_user(uint8_t index, bool active) {
switch (index) {
case 0:
if (active) {
Expand Down
15 changes: 10 additions & 5 deletions keyboards/planck/rev6/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,20 @@
* ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
*
*/
/* Note: These are not used for arm boards. They're here purely as documentation.
* #define MATRIX_ROW_PINS { PB0, PB1, PB2, PA15, PA10 }
* #define MATRIX_COL_PINS { PA2, PA3, PA6, PB14, PB15, PA8, PA9, PA7, PB3, PB4, PC14, PC15, PC13, PB5, PB6 }
* #define UNUSED_PINS
*/
/* Note: These are not used for arm boards. They're here purely as documentation. */
#undef MATRIX_ROW_PINS
#undef MATRIX_COL_PINS

#define MATRIX_ROW_PINS { A10, A9, A8, B15, C13, C14, C15, A2 }
#define MATRIX_COL_PINS { B11, B10, B2, B1, A7, B0 }

#define UNUSED_PINS

#define ENCODERS_PAD_A { B12 }
#define ENCODERS_PAD_B { B13 }

#define DIP_SWITCH_PINS { B14, A15, A0, B9 }

#define MUSIC_MAP
#undef AUDIO_VOICES
#undef C6_AUDIO
Expand Down
176 changes: 0 additions & 176 deletions keyboards/planck/rev6/matrix.c

This file was deleted.

10 changes: 10 additions & 0 deletions keyboards/planck/rev6/rev6.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ void matrix_init_kb(void) {
void matrix_scan_kb(void) {
matrix_scan_user();
}

#ifdef DIP_SWITCH_ENABLE
__attribute__((weak))
void dip_update(uint8_t index, bool active) {}

__attribute__((weak))
void dip_switch_update_user(uint8_t index, bool active) {
dip_update(index, active);
}
#endif
3 changes: 1 addition & 2 deletions keyboards/planck/rev6/rules.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# project specific files
SRC = matrix.c
LAYOUTS += ortho_4x12

# Cortex version
Expand Down Expand Up @@ -31,9 +30,9 @@ API_SYSEX_ENABLE = no
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend

CUSTOM_MATRIX = yes # Custom matrix file
# SERIAL_LINK_ENABLE = yes
ENCODER_ENABLE = yes
DIP_SWITCH_ENABLE = yes

LAYOUTS = ortho_4x12 planck_mit
LAYOUTS_HAS_RGB = no
2 changes: 1 addition & 1 deletion keyboards/preonic/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void encoder_update_user(uint8_t index, bool clockwise) {
}
}

void dip_update(uint8_t index, bool active) {
void dip_switch_update_user(uint8_t index, bool active) {
switch (index) {
case 0:
if (active) {
Expand Down
Loading