Skip to content

Commit

Permalink
Merge pull request #4 from tzarc/joystick-onekey
Browse files Browse the repository at this point in the history
Fix for zero axes or zero buttons
  • Loading branch information
a-chol authored Jan 9, 2020
2 parents a64d68f + 2712619 commit 1b02a41
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 26 deletions.
3 changes: 3 additions & 0 deletions keyboards/handwired/onekey/keymaps/joystick/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once
#define JOYSTICK_AXES_COUNT 0
#define JOYSTICK_BUTTON_COUNT 1
5 changes: 5 additions & 0 deletions keyboards/handwired/onekey/keymaps/joystick/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include QMK_KEYBOARD_H

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
LAYOUT( JS_BUTTON0 )
};
1 change: 1 addition & 0 deletions keyboards/handwired/onekey/keymaps/joystick/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JOYSTICK_ENABLE = yes
1 change: 1 addition & 0 deletions quantum/process_keycode/process_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#endif

#include <string.h>
#include <math.h>

bool process_joystick_buttons(uint16_t keycode, keyrecord_t *record);

Expand Down
59 changes: 33 additions & 26 deletions tmk_core/protocol/usb_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,51 +279,58 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = {
#endif

#ifdef JOYSTICK_ENABLE
#if JOYSTICK_AXES_COUNT == 0 && JOYSTICK_BUTTON_COUNT == 0
#error Need at least one axis or button for joystick
#endif
const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] =
{
HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
HID_RI_USAGE(8, 0x04), /* Joystick */
HID_RI_COLLECTION(8, 0x01), /* Application */
HID_RI_COLLECTION(8, 0x00), /* Physical */
HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
#if JOYSTICK_AXES_COUNT >= 1
HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
#if JOYSTICK_AXES_COUNT >= 1
HID_RI_USAGE(8, 0x30), // USAGE (X)
#endif
#if JOYSTICK_AXES_COUNT >= 2
#if JOYSTICK_AXES_COUNT >= 2
HID_RI_USAGE(8, 0x31), // USAGE (Y)
#endif
#if JOYSTICK_AXES_COUNT >= 3
#if JOYSTICK_AXES_COUNT >= 3
HID_RI_USAGE(8, 0x32), // USAGE (Z)
#endif
#if JOYSTICK_AXES_COUNT >= 4
#if JOYSTICK_AXES_COUNT >= 4
HID_RI_USAGE(8, 0x33), // USAGE (RX)
#endif
#if JOYSTICK_AXES_COUNT >= 5
#if JOYSTICK_AXES_COUNT >= 5
HID_RI_USAGE(8, 0x34), // USAGE (RY)
#endif
#if JOYSTICK_AXES_COUNT >= 6
#if JOYSTICK_AXES_COUNT >= 6
HID_RI_USAGE(8, 0x35), // USAGE (RZ)
#endif
HID_RI_LOGICAL_MINIMUM(8, -127),
HID_RI_LOGICAL_MAXIMUM(8, 127),
HID_RI_REPORT_COUNT(8, JOYSTICK_AXES_COUNT),
HID_RI_REPORT_SIZE(8, 0x08),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),

HID_RI_USAGE_PAGE(8, 0x09), /* Button */
HID_RI_USAGE_MINIMUM(8, 0x01), /* Button 1 */
HID_RI_USAGE_MAXIMUM(8, JOYSTICK_BUTTON_COUNT), /* Button 5 */
HID_RI_LOGICAL_MINIMUM(8, 0x00),
HID_RI_LOGICAL_MAXIMUM(8, 0x01),
HID_RI_REPORT_COUNT(8, JOYSTICK_BUTTON_COUNT),
HID_RI_REPORT_SIZE(8, 0x01),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
#if JOYSTICK_AXES_COUNT >= 1
HID_RI_LOGICAL_MINIMUM(8, -127),
HID_RI_LOGICAL_MAXIMUM(8, 127),
HID_RI_REPORT_COUNT(8, JOYSTICK_AXES_COUNT),
HID_RI_REPORT_SIZE(8, 0x08),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
#endif

#if (JOYSTICK_BUTTON_COUNT % 8) != 0
HID_RI_REPORT_SIZE(8, 0x01),
HID_RI_REPORT_COUNT(8, 8 - (JOYSTICK_BUTTON_COUNT % 8)),
HID_RI_INPUT(8, HID_IOF_CONSTANT),
#endif
#if JOYSTICK_BUTTON_COUNT >= 1
HID_RI_USAGE_PAGE(8, 0x09), /* Button */
HID_RI_USAGE_MINIMUM(8, 0x01), /* Button 1 */
HID_RI_USAGE_MAXIMUM(8, JOYSTICK_BUTTON_COUNT), /* Button max */
HID_RI_LOGICAL_MINIMUM(8, 0x00),
HID_RI_LOGICAL_MAXIMUM(8, 0x01),
HID_RI_REPORT_COUNT(8, JOYSTICK_BUTTON_COUNT),
HID_RI_REPORT_SIZE(8, 0x01),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),

#if (JOYSTICK_BUTTON_COUNT % 8) != 0
HID_RI_REPORT_SIZE(8, 0x01),
HID_RI_REPORT_COUNT(8, 8 - (JOYSTICK_BUTTON_COUNT % 8)),
HID_RI_INPUT(8, HID_IOF_CONSTANT),
#endif
#endif
HID_RI_END_COLLECTION(0),
HID_RI_END_COLLECTION(0),
};
Expand Down

0 comments on commit 1b02a41

Please sign in to comment.