From 5ae3eabba2c39b02775be614447dd8baf6ae2d5d Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 23 Mar 2014 23:36:47 +0100 Subject: unifying: implement feature FeatureSet, init for M525 --- hw/usb/hid-logitech-hidpp20.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/hw/usb/hid-logitech-hidpp20.c b/hw/usb/hid-logitech-hidpp20.c index 371eaa6bdd..be1e02df53 100644 --- a/hw/usb/hid-logitech-hidpp20.c +++ b/hw/usb/hid-logitech-hidpp20.c @@ -44,8 +44,43 @@ struct HidppFeature { hidpp_feature_cb_t callback; }; +/* define a HID++ 2.0 feature with given name */ +#define HIDPP20_FEATURE(name) \ + int name(LHidDevice *hd, Hidpp20Msg *msg, uint8_t fn, uint8_t *params) + +static HIDPP20_FEATURE(feat_featureset) +{ + const HidppFeature *feat; + + switch (fn) { + case 0: /* GetCount */ + params[0] = hd->info.features_count; + return 1; + case 1: /* featureID, featureType = GetFeatureId(featureIndex) */ + if (params[0] > hd->info.features_count) { + return -HIDPP20_ERR_CODE_OUTOFRANGE; + } + feat = &hd->info.features[params[0]]; + params[0] = feat->id >> 8; + params[1] = (uint8_t) feat->id; + params[2] = feat->type; + return 3; + default: + return -HIDPP20_ERR_CODE_INVALID_FUNCTION_ID; + } +} + +/* root feature not included! */ +static const HidppFeature features_m525[] = { + { 0x0001, 0, feat_featureset }, +}; + void hidpp20_init_features(LHidDevice *hd) { switch (hd->info.wireless_pid) { + case 0x4013: + hd->info.features = features_m525; + hd->info.features_count = ARRAY_SIZE(features_m525); + break; } } -- cgit v1.2.1