Skip to content

Commit

Permalink
HID: asus: add ROG Ally xpad settings
Browse files Browse the repository at this point in the history
- move ROG specific stuff to new .c
- add a header for common parts
- add xpad mode
- add deadzones
- add anti-deadzones
- add gamepad button remapping
- add gamepad mapping reset for xpad and wasd modes
- add turbo mode for individual buttons
- add joystick response curves
- add vibration intensity settings
- add calibration setting
  • Loading branch information
flukejones authored and Samsagax committed Jul 28, 2024
1 parent 1fdf826 commit 1534c38
Show file tree
Hide file tree
Showing 6 changed files with 2,125 additions and 41 deletions.
85 changes: 85 additions & 0 deletions Documentation/ABI/testing/sysfs-driver-hid-asus
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
What: /sys/bus/usb/devices/1-3:1.0/0003:0B05:1ABE.0001/gamepad_mode
Date: December 2023
Contact: [email protected]
Description: Set the mode the ROG Ally xpad operates in:
- 1 = Game mode
- 2 = WASD mode
- 3 = Mouse mode
This setting applies instantly and applies settings that were previously changed
under that mode which are:
- deadzones
- anti-deadzones
- button mapping
- button turbo settings
- response curves

What: /sys/bus/usb/devices/1-3:1.0/0003:0B05:1ABE.0001/apply
Date: December 2023
Contact: [email protected]
Description: Apply the settings that have been stored in attributes so far. Because there are
many individual settings across a dozen packets this separation is required to
prevent spamming the MCU when userspace applications apply many changes at once.

What: /sys/bus/usb/devices/1-3:1.0/0003:0B05:1ABE.0001/reset_btn_mapping
Date: December 2023
Contact: [email protected]
Description: Reset a gamepad mode to its default button mapping.

What: /sys/bus/usb/devices/1-3:1.0/0003:0B05:1ABE.0001/axis_<x/y/z>_<left/right>/deadzone
Date: December 2023
Contact: [email protected]
Description: Set the inner and outer deadzones of joysticks and triggers. These settings are not
written to the MCU until `apply` is set.
- range 0-64 (corresponds to 0-100%)

What: /sys/bus/usb/devices/1-3:1.0/0003:0B05:1ABE.0001/axis_<x/y/z>_<left/right>/deadzone_index
Date: December 2023
Contact: [email protected]
Description: Descriptive labels for joystick deadzone array.

What: /sys/bus/usb/devices/1-3:1.0/0003:0B05:1ABE.0001/axis_<x/y>_<left/right>/anti-deadzone
Date: December 2023
Contact: [email protected]
Description: Set the joystick anti-deadzone feature:
- range 0-32 (corresponds to 0-50%)

What: /sys/bus/usb/devices/1-3:1.0/0003:0B05:1ABE.0001/axis_<x/y/z>_<left/right>/calibration
Date: December 2023
Contact: [email protected]
Description: Calibration values for the joysticks and trigger analogues. There are no default
values as the calibration is determined in userspace.

What: /sys/bus/usb/devices/1-3:1.0/0003:0B05:1ABE.0001/axis_<x/y/z>_<left/right>/calibration_index
Date: December 2023
Contact: [email protected]
Description: Descriptive labels for joystick and triggers calibration array.

What: /sys/bus/usb/devices/1-3:1.0/0003:0B05:1ABE.0001/axis_<x/y>_<left/right>/rc_point<n>
Date: December 2023
Contact: [email protected]
Description: Set the joystick response curve. There are 4 points available with 1 being the lowest
point and 4 being the highest point.
- range 0-64 (corresponds to 0-100%)

What: /sys/bus/usb/devices/1-3:1.0/0003:0B05:1ABE.0001/axis_<x/y>_<left/right>/rc_point_index
Date: December 2023
Contact: [email protected]
Description: Descriptive labels for joystick response curve points.

What: /sys/bus/usb/devices/1-3:1.0/0003:0B05:1ABE.0001/btn_<label>/turbo
Date: December 2023
Contact: [email protected]
Description: Set the turbo mode of the button:
- 0 = no turbo, a separate press and release is registered on press and release
- 1-16 = interval between presses if button held down in steps of 1000ms/16
These settings are not written to the MCU until `apply` is set.

What: /sys/bus/usb/devices/1-3:1.0/0003:0B05:1ABE.0001/vibration_intensity
Date: December 2023
Contact: [email protected]
Description: Set the vibration intensity for left and right haptics. Applies instantly.

What: /sys/bus/usb/devices/1-3:1.0/0003:0B05:1ABE.0001/vibration_intensity_index
Date: December 2023
Contact: [email protected]
Description: Descriptive labels for index points of vibration_intensity.
2 changes: 2 additions & 0 deletions drivers/hid/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ hid-logitech-$(CONFIG_LOGIWHEELS_FF) += hid-lg4ff.o
hid-wiimote-y := hid-wiimote-core.o hid-wiimote-modules.o
hid-wiimote-$(CONFIG_DEBUG_FS) += hid-wiimote-debug.o

hid-asus-y := hid-asus-core.o hid-asus-rog.o

obj-$(CONFIG_HID_A4TECH) += hid-a4tech.o
obj-$(CONFIG_HID_ACCUTOUCH) += hid-accutouch.o
obj-$(CONFIG_HID_ALPS) += hid-alps.o
Expand Down
71 changes: 30 additions & 41 deletions drivers/hid/hid-asus.c → drivers/hid/hid-asus-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
* Copyright (c) 2016 Frederik Wenigwieser <[email protected]>
*/

/*
*/

#include <asm-generic/errno-base.h>
#include <asm-generic/errno.h>
#include <linux/dmi.h>
#include <linux/hid.h>
#include <linux/module.h>
Expand All @@ -32,6 +31,7 @@
#include <linux/power_supply.h>
#include <linux/leds.h>

#include "hid-asus.h"
#include "hid-ids.h"

MODULE_AUTHOR("Yusuke Fujimaki <[email protected]>");
Expand All @@ -47,10 +47,6 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
#define T100CHI_MOUSE_REPORT_ID 0x06
#define FEATURE_REPORT_ID 0x0d
#define INPUT_REPORT_ID 0x5d
#define FEATURE_KBD_REPORT_ID 0x5a
#define FEATURE_KBD_REPORT_SIZE 16
#define FEATURE_KBD_LED_REPORT_ID1 0x5d
#define FEATURE_KBD_LED_REPORT_ID2 0x5e

#define SUPPORT_KBD_BACKLIGHT BIT(0)

Expand All @@ -71,20 +67,6 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
#define BATTERY_STAT_CHARGING (1)
#define BATTERY_STAT_FULL (2)

#define QUIRK_FIX_NOTEBOOK_REPORT BIT(0)
#define QUIRK_NO_INIT_REPORTS BIT(1)
#define QUIRK_SKIP_INPUT_MAPPING BIT(2)
#define QUIRK_IS_MULTITOUCH BIT(3)
#define QUIRK_NO_CONSUMER_USAGES BIT(4)
#define QUIRK_USE_KBD_BACKLIGHT BIT(5)
#define QUIRK_T100_KEYBOARD BIT(6)
#define QUIRK_T100CHI BIT(7)
#define QUIRK_G752_KEYBOARD BIT(8)
#define QUIRK_T90CHI BIT(9)
#define QUIRK_MEDION_E1239T BIT(10)
#define QUIRK_ROG_NKEY_KEYBOARD BIT(11)
#define QUIRK_ROG_CLAYMORE_II_KEYBOARD BIT(12)

#define I2C_KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \
QUIRK_NO_INIT_REPORTS | \
QUIRK_NO_CONSUMER_USAGES)
Expand Down Expand Up @@ -113,22 +95,6 @@ struct asus_touchpad_info {
int report_size;
};

struct asus_drvdata {
unsigned long quirks;
struct hid_device *hdev;
struct input_dev *input;
struct input_dev *tp_kbd_input;
struct asus_kbd_leds *kbd_backlight;
const struct asus_touchpad_info *tp;
bool enable_backlight;
struct power_supply *battery;
struct power_supply_desc battery_desc;
int battery_capacity;
int battery_stat;
bool battery_in_query;
unsigned long battery_next_query;
};

static int asus_report_battery(struct asus_drvdata *, u8 *, int);

static const struct asus_touchpad_info asus_i2c_tp = {
Expand Down Expand Up @@ -329,6 +295,16 @@ static int asus_raw_event(struct hid_device *hdev,
if (drvdata->battery && data[0] == BATTERY_REPORT_ID)
return asus_report_battery(drvdata, data, size);

// TODO: remove after debugging
// if (data[0] == 0x5a || data[0] == 0x5d || data[0] == 0x5e){
// for (int i = 0; i < size; i++) {
// if (i == 0)
// printk(KERN_INFO "GOT: %02x,", data[i]);
// else
// printk(KERN_CONT "%02x,", data[i]);
// }
// }

if (drvdata->tp && data[0] == INPUT_REPORT_ID)
return asus_report_input(drvdata, data, size);

Expand Down Expand Up @@ -365,7 +341,7 @@ static int asus_raw_event(struct hid_device *hdev,
return 0;
}

static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t buf_size)
int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t buf_size)
{
unsigned char *dmabuf;
int ret;
Expand All @@ -386,6 +362,13 @@ static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t bu
return ret;
}

int asus_kbd_get_report(struct hid_device *hdev, u8 *out_buf, size_t out_buf_size)
{
return hid_hw_raw_request(hdev, FEATURE_KBD_REPORT_ID, out_buf,
out_buf_size, HID_FEATURE_REPORT,
HID_REQ_GET_REPORT);
}

static int asus_kbd_init(struct hid_device *hdev, u8 report_id)
{
const u8 buf[] = { report_id, 0x41, 0x53, 0x55, 0x53, 0x20, 0x54,
Expand Down Expand Up @@ -846,8 +829,8 @@ static int asus_input_mapping(struct hid_device *hdev,
case 0xb2: asus_map_key_clear(KEY_PROG2); break; /* Fn+Left previous aura */
case 0xb3: asus_map_key_clear(KEY_PROG3); break; /* Fn+Left next aura */
case 0x6a: asus_map_key_clear(KEY_F13); break; /* Screenpad toggle */
case 0x4b: asus_map_key_clear(KEY_F14); break; /* Arrows/Pg-Up/Dn toggle */
case 0xa5: asus_map_key_clear(KEY_F15); break; /* ROG Ally left back */
case 0x4b: asus_map_key_clear(KEY_F14); break; /* Arrows/Pg-Up/Dn toggle, Ally M1 */
case 0xa5: asus_map_key_clear(KEY_F15); break; /* ROG Ally M2 */
case 0xa6: asus_map_key_clear(KEY_F16); break; /* ROG Ally QAM button */
case 0xa7: asus_map_key_clear(KEY_F17); break; /* ROG Ally ROG long-press */
case 0xa8: asus_map_key_clear(KEY_F18); break; /* ROG Ally ROG long-press-release */
Expand Down Expand Up @@ -1063,6 +1046,10 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)
}
}

/* all ROG devices have this HID interface but we will focus on Ally for now */
if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD && hid_is_usb(hdev))
rog_ally.probe(hdev, &rog_ally);

ret = hid_parse(hdev);
if (ret) {
hid_err(hdev, "Asus hid parse failed: %d\n", ret);
Expand Down Expand Up @@ -1112,6 +1099,8 @@ static void asus_remove(struct hid_device *hdev)
cancel_work_sync(&drvdata->kbd_backlight->work);
}

rog_ally.remove(hdev, &rog_ally);

hid_hw_stop(hdev);
}

Expand Down Expand Up @@ -1245,7 +1234,7 @@ static const struct hid_device_id asus_devices[] = {
QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD },
{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,
USB_DEVICE_ID_ASUSTEK_ROG_NKEY_ALLY),
QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD },
QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_ROG_ALLY_XPAD },
{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,
USB_DEVICE_ID_ASUSTEK_ROG_CLAYMORE_II_KEYBOARD),
QUIRK_ROG_CLAYMORE_II_KEYBOARD },
Expand Down
Loading

0 comments on commit 1534c38

Please sign in to comment.