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

Allow joysticks to be used without analog pins #10169

Merged
merged 2 commits into from
Aug 27, 2020
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
4 changes: 4 additions & 0 deletions common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -540,5 +540,9 @@ ifeq ($(strip $(JOYSTICK_ENABLE)), yes)
OPT_DEFS += -DJOYSTICK_ENABLE
SRC += $(QUANTUM_DIR)/process_keycode/process_joystick.c
SRC += $(QUANTUM_DIR)/joystick.c
endif

ifeq ($(strip $(ANALOG_JOYSTICK_ENABLE)), yes)
OPT_DEFS += -DANALOG_JOYSTICK_ENABLE
SRC += analog.c
endif
10 changes: 8 additions & 2 deletions docs/feature_joystick.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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
ANALOG_JOYSTICK_ENABLE = yes
```

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).
Expand Down Expand Up @@ -75,7 +81,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 {
Expand All @@ -89,7 +95,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:
Expand Down
1 change: 1 addition & 0 deletions keyboards/handwired/onekey/keymaps/joystick/rules.mk
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
JOYSTICK_ENABLE = yes
ANALOG_JOYSTICK_ENABLE = yes