Skip to content

Commit 1ffbaae

Browse files
committed
Initial potentiometer support
1 parent e884e42 commit 1ffbaae

File tree

17 files changed

+151
-37
lines changed

17 files changed

+151
-37
lines changed

builddefs/common_features.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,10 @@ ifeq ($(strip $(ENCODER_ENABLE)), yes)
905905
endif
906906
endif
907907

908+
ifeq ($(strip $(POTENTIOMETER_ENABLE)), yes)
909+
ANALOG_DRIVER_REQUIRED = yes
910+
endif
911+
908912
VALID_WS2812_DRIVER_TYPES := bitbang custom i2c pwm spi vendor
909913

910914
WS2812_DRIVER ?= bitbang

builddefs/generic_features.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ GENERIC_FEATURES = \
4040
MOUSEKEY \
4141
MUSIC \
4242
OS_DETECTION \
43+
POTENTIOMETER \
4344
PROGRAMMABLE_BUTTON \
4445
REPEAT_KEY \
4546
SECURE \

data/mappings/info_config.hjson

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
"ONESHOT_TIMEOUT": {"info_key": "oneshot.timeout", "value_type": "int"},
118118
"ONESHOT_TAP_TOGGLE": {"info_key": "oneshot.tap_toggle", "value_type": "int"},
119119

120+
// Potentiometer
121+
"POTENTIOMETER_PINS": {"info_key": "potentiometer.pins", "value_type": "array"},
122+
120123
// PS/2
121124
"PS2_CLOCK_PIN": {"info_key": "ps2.clock_pin"},
122125
"PS2_DATA_PIN": {"info_key": "ps2.data_pin"},

data/mappings/info_rules.hjson

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"NO_USB_STARTUP_CHECK": {"info_key": "usb.no_startup_check", "value_type": "bool"},
3333
"PIN_COMPATIBLE": {"info_key": "pin_compatible"},
3434
"PLATFORM_KEY": {"info_key": "platform_key", "to_json": false},
35+
"POTENTIOMETER_ENABLE": {"info_key": "potentiometer.enabled", "value_type": "bool"},
3536
"PS2_DRIVER": {"info_key": "ps2.driver"},
3637
"PS2_ENABLE": {"info_key": "ps2.enabled", "value_type": "bool"},
3738
"PS2_MOUSE_ENABLE": {"info_key": "ps2.mouse_enabled", "value_type": "bool"},

data/schemas/keyboard.jsonschema

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,13 @@
417417
"timeout": {"$ref": "qmk.definitions.v1#/unsigned_int"}
418418
}
419419
},
420+
"potentiometer": {
421+
"type": "object",
422+
"properties": {
423+
"enabled": {"type": "boolean"},
424+
"pins": {"$ref": "qmk.definitions.v1#/mcu_pin_array"}
425+
}
426+
},
420427
"led_matrix": {
421428
"type": "object",
422429
"properties": {

docs/_summary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
* [LED Indicators](feature_led_indicators.md)
124124
* [MIDI](feature_midi.md)
125125
* [Pointing Device](feature_pointing_device.md)
126+
* [Potentiometer](feature_potentiometers.md)
126127
* [PS/2 Mouse](feature_ps2_mouse.md)
127128
* [Split Keyboard](feature_split_keyboard.md)
128129
* [Stenography](feature_stenography.md)

docs/feature_potentiometers.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Potentiometers
2+
3+
Add this to your `rules.mk`:
4+
5+
```make
6+
POTENTIOMETER_ENABLE = yes
7+
```
8+
9+
and this to your `config.h`:
10+
11+
```c
12+
#define POTENTIOMETER_PINS { B0 }
13+
```
14+
15+
## Callbacks
16+
17+
The callback functions can be inserted into your `<keyboard>.c`:
18+
19+
```c
20+
bool potentiometer_update_kb(uint8_t index, uint16_t value) {
21+
if (!potentiometer_update_user(index, value)) {
22+
midi_send_cc(&midi_device, 2, 0x3E, 0x7F + (value >> 3));
23+
}
24+
return true;
25+
}
26+
```
27+
28+
or `keymap.c`:
29+
30+
```c
31+
bool potentiometer_update_user(uint8_t index, uint16_t value) {
32+
midi_send_cc(&midi_device, 2, 0x3E, 0x7F + (value >> 3));
33+
return false;
34+
}
35+
```

docs/reference_info_json.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,17 @@ Configures [One Shot keys](one_shot_keys.md).
478478
* `timeout`
479479
* The amount of time before the key is released in milliseconds.
480480

481+
## Potentiometer :id=potentiometer
482+
483+
Configures the [Potentiometer](feature_Potentiometers.md) feature.
484+
485+
* `potentiometer`
486+
* `enabled`
487+
* Enable the Potentiometer feature.
488+
* Default: `false`
489+
* `pins` (Required)
490+
* The GPIO pin(s) connected to the Potentiometer(s).
491+
481492
## PS/2 :id=ps2
482493

483494
Configures the [PS/2](feature_ps2_mouse.md) feature.

keyboards/gmmk/numpad/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#pragma once
1919

20-
#define SLIDER_PIN B0
20+
#define POTENTIOMETER_PINS { B0 }
2121
#define MIDI_ADVANCED
2222

2323
#define LOCKING_SUPPORT_ENABLE

keyboards/gmmk/numpad/keymaps/default/keymap.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

1818
#include QMK_KEYBOARD_H
19-
#include "analog.h"
20-
#include "qmk_midi.h"
2119

2220
// clang-format off
2321
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
@@ -43,18 +41,3 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
4341
RGB_TOG, QK_BOOT
4442
)
4543
};
46-
47-
// Potentiometer Slider, MIDI Control
48-
49-
uint8_t divisor = 0;
50-
51-
void slider(void) {
52-
if (divisor++) { /* only run the slider function 1/256 times it's called */
53-
return;
54-
}
55-
midi_send_cc(&midi_device, 2, 0x3E, 0x7F + (analogReadPin(SLIDER_PIN) >> 3));
56-
}
57-
58-
void housekeeping_task_user(void) {
59-
slider();
60-
}

0 commit comments

Comments
 (0)