From 0a8042251297cb7c213c77d9b9c6b5ded635e76c Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 1 Apr 2014 00:08:56 +0200 Subject: unifying: less magic numbers, fix device type for T650 This makes it easier to switch between devices. Signed-off-by: Peter Wu --- hw/usb/hid-logitech-dj.c | 26 ++++++++++++-------------- hw/usb/hid-logitech-dj.h | 3 +++ hw/usb/hid-logitech-hidpp20.c | 4 ++-- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/hw/usb/hid-logitech-dj.c b/hw/usb/hid-logitech-dj.c index 0cfafc293a..7afd3d8194 100644 --- a/hw/usb/hid-logitech-dj.c +++ b/hw/usb/hid-logitech-dj.c @@ -573,7 +573,7 @@ void usb_ltunify_handle_datain_hidpp(USBDevice *dev, USBPacket *p) } } -static void hidpp_init_device(USBLtunifyState *s, int device_index, int devtype) +static void hidpp_init_device(USBLtunifyState *s, int device_index, uint16_t pid) { LHidDevice *hd; @@ -582,26 +582,26 @@ static void hidpp_init_device(USBLtunifyState *s, int device_index, int devtype) memset(hd, 0, sizeof(*hd)); - hd->info.device_type = devtype; hd->info.protocol_type = PROTO_UNIFYING; hd->info.protocol_version = 0x0200; /* HID++ 2.0 */ - switch (devtype) { - case DEVTYPE_KEYBOARD: + hd->info.wireless_pid = pid; + switch (pid) { + case WPID_K800: + hd->info.device_type = DEVTYPE_KEYBOARD; hd->info.version = (struct firmware_version) { 0x22, 0x01, 0x19, 2, 1 }; hd->info.protocol_version = 0x0100; /* override: HID++ 1.0 */ hd->hid = &s->hid[IFACE_KBD]; hd->info.report_types = 0x1a; /* Keyboard, Consumer Control, System Control */ - hd->info.wireless_pid = 0x2010; hd->info.serial = 0x4b657973; memcpy(hd->info.name, "K800", 4); /* hd->info.device_name N/A for HID++ 1.0 */ hd->report_interval = 20; break; - //case DEVTYPE_MOUSE: + case WPID_M525: + hd->info.device_type = DEVTYPE_MOUSE; hd->info.version = (struct firmware_version) { 0x27, 0x02, 0x28, 0, 0 }; hd->hid = &s->hid[IFACE_MSE]; hd->info.report_types = 4; /* HID Collection: Mouse */ - hd->info.wireless_pid = 0x4013; hd->info.serial = 0x52617473; memcpy(hd->info.name, "M525", 4); hd->info.device_name = "WirelessMouse M525"; @@ -610,13 +610,11 @@ static void hidpp_init_device(USBLtunifyState *s, int device_index, int devtype) hd->battery.level = 2; /* Full - 90 % */ hd->battery.critical_perc = 2; break; - case DEVTYPE_MOUSE: - case DEVTYPE_TOUCHPAD: - /* TODO: perhaps "unpair" mouse and use this touchpad instead? */ + case WPID_T650: + hd->info.device_type = DEVTYPE_TOUCHPAD; hd->info.version = (struct firmware_version) { 0x41, 0x01, 0x37, 3, 0 }; hd->hid = &s->hid[IFACE_MSE]; hd->info.report_types = 0x0e; /* Keyboard, Mouse, Consumer Ctrl */ - hd->info.wireless_pid = 0x4101; hd->info.serial = 0x4f4f4f48; memcpy(hd->info.name, "T650", 4); hd->info.device_name = "Rechargeable Touchpad T650"; @@ -641,7 +639,7 @@ void hidpp_reset(USBLtunifyState *s) for (i = 0; i < MAX_DEVICES; i++) { LHidDevice *hd = &s->devices[i]; if (hd->info.device_type) { - hidpp_init_device(s, i + 1, hd->info.device_type); + hidpp_init_device(s, i + 1, hd->info.wireless_pid); } } } @@ -653,7 +651,7 @@ void hidpp_init(USBLtunifyState *s) r->info.version = (struct firmware_version) { 24, 0, 18, 0, 6 }; if (s->enable_kbd) { - hidpp_init_device(s, 1, DEVTYPE_KEYBOARD); + hidpp_init_device(s, 1, WPID_K800); } - hidpp_init_device(s, 2, DEVTYPE_MOUSE); + hidpp_init_device(s, 2, WPID_T650); } diff --git a/hw/usb/hid-logitech-dj.h b/hw/usb/hid-logitech-dj.h index b2190932d4..474ab9ac8c 100644 --- a/hw/usb/hid-logitech-dj.h +++ b/hw/usb/hid-logitech-dj.h @@ -145,6 +145,9 @@ typedef struct { #define HIDPP20_ERR_CODE_BUSY 0x08 #define HIDPP20_ERR_CODE_UNSUPPORTED 0x09 +#define WPID_K800 0x2010U +#define WPID_M525 0x4013U +#define WPID_T650 0x4101U /* device and receiver info */ struct firmware_version { diff --git a/hw/usb/hid-logitech-hidpp20.c b/hw/usb/hid-logitech-hidpp20.c index b616989379..7f679d7828 100644 --- a/hw/usb/hid-logitech-hidpp20.c +++ b/hw/usb/hid-logitech-hidpp20.c @@ -317,11 +317,11 @@ static const HidppFeature features_t650[] = { void hidpp20_init_features(LHidDevice *hd) { switch (hd->info.wireless_pid) { - case 0x4013: + case WPID_M525: hd->info.features = features_m525; hd->info.features_count = ARRAY_SIZE(features_m525); break; - case 0x4101: + case WPID_T650: hd->info.features = features_t650; hd->info.features_count = ARRAY_SIZE(features_t650); break; -- cgit v1.2.1