From d4d971231678ed7ca5730256a84d0e3ce36f98e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Mon, 9 Sep 2019 10:59:44 +0100 Subject: [PATCH] hidpp20: add suport for the G602 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe LaĆ­ns --- data/devices/logitech-g602.device | 1 + src/driver-hidpp20.c | 8 +++++++- src/hidpp20.c | 15 +++++++++++++++ src/hidpp20.h | 1 + src/libratbag-data.c | 2 ++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/data/devices/logitech-g602.device b/data/devices/logitech-g602.device index 10adb703..2748ef13 100644 --- a/data/devices/logitech-g602.device +++ b/data/devices/logitech-g602.device @@ -6,3 +6,4 @@ Driver=hidpp20 [Driver/hidpp20] DeviceIndex=1 +Quirk=G602 diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index 5a8addf8..8c9bf2a7 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -859,7 +859,8 @@ hidpp20drv_read_resolution_dpi(struct ratbag_profile *profile) unsigned int default_rate = 500; int rc; - if (drv_data->capabilities & HIDPP_CAP_RESOLUTION_2200) { + if ((drv_data->capabilities & HIDPP_CAP_RESOLUTION_2200) && + (drv_data->capabilities & HIDPP_CAP_SWITCHABLE_RESOLUTION_2201) == 0) { uint16_t resolution; uint8_t flags; @@ -1305,6 +1306,11 @@ hidpp20drv_init_feature(struct ratbag_device *device, uint16_t feature) break; } case HIDPP_PAGE_COLOR_LED_EFFECTS: { + /* The 8070 feauture implemented in the G602 doesn't follow the spec, + * so we ignore it */ + if (ratbag_device_data_hidpp20_get_quirk(device->data) == HIDPP20_QUIRK_G602) + break; + log_debug(ratbag, "device has color effects\n"); drv_data->capabilities |= HIDPP_CAP_COLOR_LED_EFFECTS_8070; diff --git a/src/hidpp20.c b/src/hidpp20.c index 37ea2799..0811e4c5 100644 --- a/src/hidpp20.c +++ b/src/hidpp20.c @@ -108,6 +108,7 @@ hidpp20_get_quirk_string(enum hidpp20_quirk quirk) switch (quirk) { CASE_RETURN_STRING(HIDPP20_QUIRK_NONE); CASE_RETURN_STRING(HIDPP20_QUIRK_G305); + CASE_RETURN_STRING(HIDPP20_QUIRK_G602); } abort(); @@ -1441,6 +1442,11 @@ hidpp20_adjustable_dpi_get_dpi_list(struct hidpp20_device *device, .msg.parameters[0] = sensor->index, }; + if (device->quirk == HIDPP20_QUIRK_G602) { + msg.msg.parameters[0] = 1; + i = 0; + } + rc = hidpp20_request_command(device, &msg); if (rc) return rc; @@ -1452,6 +1458,9 @@ hidpp20_adjustable_dpi_get_dpi_list(struct hidpp20_device *device, get_unaligned_be_u16(&msg.msg.parameters[i]) != 0) { uint16_t value = get_unaligned_be_u16(&msg.msg.parameters[i]); + if (device->quirk == HIDPP20_QUIRK_G602 && i == 2) + value += 0xe000; + if (value > 0xe000) { sensor->dpi_steps = value - 0xe000; } else { @@ -1481,6 +1490,9 @@ hidpp20_adjustable_dpi_get_dpi(struct hidpp20_device *device, .msg.parameters[0] = sensor->index, }; + if (device->quirk == HIDPP20_QUIRK_G602) + msg.msg.parameters[0] = 1; + rc = hidpp20_request_command(device, &msg); if (rc) return rc; @@ -1560,6 +1572,9 @@ int hidpp20_adjustable_dpi_set_sensor_dpi(struct hidpp20_device *device, .msg.parameters[0] = sensor->index, }; + if (device->quirk == HIDPP20_QUIRK_G602) + msg.msg.parameters[0] = 1; + set_unaligned_be_u16(&msg.msg.parameters[1], dpi); feature_index = hidpp_root_get_feature_idx(device, diff --git a/src/hidpp20.h b/src/hidpp20.h index aeea99a8..bb1d3b0c 100644 --- a/src/hidpp20.h +++ b/src/hidpp20.h @@ -54,6 +54,7 @@ struct hidpp20_feature { enum hidpp20_quirk { HIDPP20_QUIRK_NONE, HIDPP20_QUIRK_G305, + HIDPP20_QUIRK_G602, }; struct hidpp20_device { diff --git a/src/libratbag-data.c b/src/libratbag-data.c index c9589a95..9a9db884 100644 --- a/src/libratbag-data.c +++ b/src/libratbag-data.c @@ -169,6 +169,8 @@ init_data_hidpp20(struct ratbag *ratbag, if (str) { if (streq(str, "G305")) data->hidpp20.quirk = HIDPP20_QUIRK_G305; + else if(streq(str, "G602")) + data->hidpp20.quirk = HIDPP20_QUIRK_G602; } }