hidpp20: retrieve and store the list of features once for all

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
Benjamin Tissoires
2015-10-20 16:49:13 -04:00
parent 8ffa2f9b96
commit 6ac92f8479
3 changed files with 35 additions and 31 deletions

View File

@@ -424,25 +424,22 @@ static int
hidpp20drv_20_probe(struct ratbag_device *device)
{
struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
struct hidpp20_feature *feature_list;
int rc, i;
struct hidpp20_device *dev = drv_data->dev;
struct hidpp20_feature *feature_list = dev->feature_list;
unsigned int i;
rc = hidpp20_feature_set_get(drv_data->dev, &feature_list);
if (rc < 0)
return rc;
log_raw(device->ratbag,
"'%s' has %d features\n",
ratbag_device_get_name(device),
dev->feature_count);
if (rc > 0) {
log_raw(device->ratbag, "'%s' has %d features\n", ratbag_device_get_name(device), rc);
for (i = 0; i < rc; i++) {
log_raw(device->ratbag, "Init feature %s (0x%04x) \n",
hidpp20_feature_get_name(feature_list[i].feature),
feature_list[i].feature);
hidpp20drv_init_feature(device, feature_list[i].feature);
}
for (i = 0; i < dev->feature_count; i++) {
log_raw(device->ratbag, "Init feature %s (0x%04x) \n",
hidpp20_feature_get_name(feature_list[i].feature),
feature_list[i].feature);
hidpp20drv_init_feature(device, feature_list[i].feature);
}
free(feature_list);
return 0;
}

View File

@@ -289,8 +289,14 @@ hidpp20_feature_set_get_feature_id(struct hidpp20_device *device,
return 0;
}
int hidpp20_feature_set_get(struct hidpp20_device *device,
struct hidpp20_feature **feature_list)
/**
* allocates a list of features that has to be freed by the caller.
*
* returns the elements in the list or a negative error
*/
static int
hidpp20_feature_set_get(struct hidpp20_device *device,
struct hidpp20_feature **feature_list)
{
uint8_t feature_index, feature_type, feature_version;
struct hidpp20_feature *flist;
@@ -931,6 +937,12 @@ hidpp20_device_new(const struct hidpp_device *base, unsigned int idx)
goto err;
}
rc = hidpp20_feature_set_get(dev, &dev->feature_list);
if (rc <= 0)
goto err;
dev->feature_count = rc;
return dev;
err:
free(dev);
@@ -940,5 +952,6 @@ err:
void
hidpp20_device_destroy(struct hidpp20_device *device)
{
free(device->feature_list);
free(device);
}

View File

@@ -46,11 +46,18 @@ union hidpp20_message {
uint8_t data[LONG_MESSAGE_LENGTH];
};
struct hidpp20_feature {
uint16_t feature;
uint8_t type;
};
struct hidpp20_device {
struct hidpp_device base;
unsigned int index;
unsigned proto_major;
unsigned proto_minor;
unsigned feature_count;
struct hidpp20_feature *feature_list;
};
int hidpp20_request_command(struct hidpp20_device *dev, union hidpp20_message *msg);
@@ -87,21 +94,8 @@ int hidpp20_root_get_protocol_version(struct hidpp20_device *dev,
#define HIDPP_PAGE_FEATURE_SET 0x0001
struct hidpp20_feature {
uint16_t feature;
uint8_t type;
};
/**
* allocates a list of features that has to be freed by the caller.
*
* returns the elements in the list or a negative error
*/
int hidpp20_feature_set_get(struct hidpp20_device *device,
struct hidpp20_feature **feature_list);
/* -------------------------------------------------------------------------- */
/* 0x0001: Device Info */
/* 0x0003: Device Info */
/* -------------------------------------------------------------------------- */
#define HIDPP_PAGE_DEVICE_INFO 0x0003