From d46251900c32bf4011330bdb316cc68468c0bc49 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 23 Jul 2019 13:28:59 +1000 Subject: [PATCH] hidraw: add a feature report get/set helper functions No real functional changes since they just forward to the existing function. But it reduces the cognitive load a bit when reading the code. Signed-off-by: Peter Hutterer --- src/libratbag-hidraw.c | 17 +++++++++++++++++ src/libratbag-hidraw.h | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/libratbag-hidraw.c b/src/libratbag-hidraw.c index b0ae0b90..62e9596a 100644 --- a/src/libratbag-hidraw.c +++ b/src/libratbag-hidraw.c @@ -1586,6 +1586,23 @@ ratbag_hidraw_raw_request(struct ratbag_device *device, unsigned char reportnum, return -EINVAL; } +int +ratbag_hidraw_get_feature_report(struct ratbag_device *device, unsigned char reportnum, + uint8_t *buf, size_t len) +{ + return ratbag_hidraw_raw_request(device, reportnum, buf, len, + HID_FEATURE_REPORT, HID_REQ_GET_REPORT); +} + +int +ratbag_hidraw_set_feature_report(struct ratbag_device *device, unsigned char reportnum, + uint8_t *buf, size_t len) +{ + return ratbag_hidraw_raw_request(device, reportnum, buf, len, + HID_FEATURE_REPORT, HID_REQ_SET_REPORT); +} + + int ratbag_hidraw_output_report(struct ratbag_device *device, uint8_t *buf, size_t len) { diff --git a/src/libratbag-hidraw.h b/src/libratbag-hidraw.h index 2b80f68c..94931923 100644 --- a/src/libratbag-hidraw.h +++ b/src/libratbag-hidraw.h @@ -101,7 +101,7 @@ void ratbag_close_hidraw_index(struct ratbag_device *device, int idx); * * @param device the ratbag device * @param reportnum report ID - * @param buf in/out data to transfer + * @param buf[in/out] data to transfer * @param len length of buf * @param rtype HID report type * @param reqtype HID_REQ_GET_REPORT or HID_REQ_SET_REPORT @@ -114,6 +114,41 @@ int ratbag_hidraw_raw_request(struct ratbag_device *device, unsigned char report uint8_t *buf, size_t len, unsigned char rtype, int reqtype); +/** + * Get feature report from device. + * + * This call sends a HID_REQ_GET_REPORT to the device for the given feature + * and returns the data in the caller-allocated buffer buf of size len. + * + * @param device the ratbag device + * @param reportnum report ID + * @param buf[out] data returned from device + * @param len length of buf + * + * @return count of data transfered, or a negative errno on error + * + * Convenience wrapper around ratbag_hidraw_raw_request() + */ +int ratbag_hidraw_get_feature_report(struct ratbag_device *device, unsigned char reportnum, + uint8_t *buf, size_t len); + +/** + * Set feature report on device. + * + * This call sends a HID_REQ_SET_REPORT to the device for the given feature + * and the buffer buf of size len. + * + * @param device the ratbag device + * @param reportnum report ID + * @param buf[in] data returned from device + * @param len length of buf + * + * @return count of data transfered, or a negative errno on error + * + * Convenience wrapper around ratbag_hidraw_raw_request() + */ +int ratbag_hidraw_set_feature_report(struct ratbag_device *device, unsigned char reportnum, + uint8_t *buf, size_t len); /** * Send output report to device *