summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach White <skullydazed@gmail.com>2020-08-27 09:38:04 -0700
committerJames Young <18669334+noroadsleft@users.noreply.github.com>2020-08-29 14:30:02 -0700
commitbdd8d2679ba74715b38f958b071fd57eaf092b9d (patch)
tree734407eaf72d2f408a6c0ab7ffb539df0c62bdc3
parent629cfc7f5ebd815231c9e3f969170995db1481c6 (diff)
Allow joysticks to be used without analog pins (#10169)
* Allow joysticks to be used without analog pins * change how analog/digital joysticks are specified
-rw-r--r--common_features.mk11
-rw-r--r--docs/feature_joystick.md16
-rw-r--r--keyboards/handwired/onekey/keymaps/joystick/rules.mk2
3 files changed, 20 insertions, 9 deletions
diff --git a/common_features.mk b/common_features.mk
index 088db89cac..1f110d0819 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -536,9 +536,18 @@ ifeq ($(strip $(AUTO_SHIFT_ENABLE)), yes)
endif
endif
-ifeq ($(strip $(JOYSTICK_ENABLE)), yes)
+JOYSTICK_ENABLE ?= no
+ifneq ($(strip $(JOYSTICK_ENABLE)), no)
OPT_DEFS += -DJOYSTICK_ENABLE
SRC += $(QUANTUM_DIR)/process_keycode/process_joystick.c
SRC += $(QUANTUM_DIR)/joystick.c
+endif
+
+ifeq ($(strip $(JOYSTICK_ENABLE)), analog)
+ OPT_DEFS += -DANALOG_JOYSTICK_ENABLE
SRC += analog.c
endif
+
+ifeq ($(strip $(JOYSTICK_ENABLE)), digital)
+ OPT_DEFS += -DDIGITAL_JOYSTICK_ENABLE
+endif
diff --git a/docs/feature_joystick.md b/docs/feature_joystick.md
index 58dfc7b8df..be3c781f6c 100644
--- a/docs/feature_joystick.md
+++ b/docs/feature_joystick.md
@@ -2,11 +2,7 @@
The keyboard can be made to be recognized as a joystick HID device by the operating system.
-This is enabled by adding the following to `rules.mk`:
-
-```makefile
-JOYSTICK_ENABLE = yes
-```
+This is enabled by adding `JOYSTICK_ENABLE` to `rules.mk`. You can set this value to `analog`, `digital`, or `no`.
!> Joystick support is not currently available on V-USB devices.
@@ -19,6 +15,12 @@ or send gamepad reports based on values computed by the keyboard.
### Analog Input
+To use analog input you must first enable it in `rules.mk`:
+
+```makefile
+JOYSTICK_ENABLE = analog
+```
+
An analog device such as a potentiometer found on a gamepad's analog axes is based on a [voltage divider](https://en.wikipedia.org/wiki/Voltage_divider).
It is composed of three connectors linked to the ground, the power input and power output (usually the middle one). The power output holds the voltage that varies based on the position of the cursor,
which value will be read using your MCU's [ADC](https://en.wikipedia.org/wiki/Analog-to-digital_converter).
@@ -75,7 +77,7 @@ You assign a value by writing to `joystick_status.axes[axis_index]` a signed 8-b
The following example writes two axes based on keypad presses, with `KC_P5` as a precision modifier:
```c
-#ifdef JOYSTICK_ENABLE
+#ifdef ANALOG_JOYSTICK_ENABLE
static uint8_t precision_val = 70;
static uint8_t axesFlags = 0;
enum axes {
@@ -89,7 +91,7 @@ enum axes {
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch(keycode) {
-#ifdef JOYSTICK_ENABLE
+#ifdef ANALOG_JOYSTICK_ENABLE
// virtual joystick
# if JOYSTICK_AXES_COUNT > 1
case KC_P8:
diff --git a/keyboards/handwired/onekey/keymaps/joystick/rules.mk b/keyboards/handwired/onekey/keymaps/joystick/rules.mk
index fbddbc6de1..cf03481737 100644
--- a/keyboards/handwired/onekey/keymaps/joystick/rules.mk
+++ b/keyboards/handwired/onekey/keymaps/joystick/rules.mk
@@ -1 +1 @@
-JOYSTICK_ENABLE = yes
+JOYSTICK_ENABLE = analog