From 872d52236455cccbcb35bf3b4ef6de2d4b2ac005 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 24 Aug 2015 15:03:29 +1000 Subject: [PATCH] hidpp: move the shared defines into a generic header Signed-off-by: Peter Hutterer --- src/Makefile.am | 2 ++ src/hidpp-generic.c | 50 ++++++++++++++++++++++++++++++++++ src/hidpp-generic.h | 66 +++++++++++++++++++++++++++++++++++++++++++++ src/hidpp10.c | 17 ------------ src/hidpp10.h | 34 ++--------------------- src/hidpp20.h | 6 +++-- 6 files changed, 124 insertions(+), 51 deletions(-) create mode 100644 src/hidpp-generic.c create mode 100644 src/hidpp-generic.h diff --git a/src/Makefile.am b/src/Makefile.am index d8001d91..73cc782f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,6 +7,8 @@ libratbag_la_SOURCES = \ driver-etekcity.c \ driver-hidpp20.c \ driver-hidpp10.c \ + hidpp-generic.h \ + hidpp-generic.c \ hidpp10.c \ hidpp10.h \ hidpp20.c \ diff --git a/src/hidpp-generic.c b/src/hidpp-generic.c new file mode 100644 index 00000000..7daea520 --- /dev/null +++ b/src/hidpp-generic.c @@ -0,0 +1,50 @@ +/* + * HID++ generic definitions + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* + * Based on the HID++ documentation provided by Nestor Lopez Casado at: + * https://drive.google.com/folderview?id=0BxbRzx7vEV7eWmgwazJ3NUFfQ28&usp=sharing + */ + +#include "config.h" + +#include "hidpp-generic.h" + +#include + +const char *hidpp_errors[0xFF] = { + [0x00] = "ERR_SUCCESS", + [0x01] = "ERR_INVALID_SUBID", + [0x02] = "ERR_INVALID_ADDRESS", + [0x03] = "ERR_INVALID_VALUE", + [0x04] = "ERR_CONNECT_FAIL", + [0x05] = "ERR_TOO_MANY_DEVICES", + [0x06] = "ERR_ALREADY_EXISTS", + [0x07] = "ERR_BUSY", + [0x08] = "ERR_UNKNOWN_DEVICE", + [0x09] = "ERR_RESOURCE_ERROR", + [0x0A] = "ERR_REQUEST_UNAVAILABLE", + [0x0B] = "ERR_INVALID_PARAM_VALUE", + [0x0C] = "ERR_WRONG_PIN_CODE", + [0x0D ... 0xFE] = NULL, +}; diff --git a/src/hidpp-generic.h b/src/hidpp-generic.h new file mode 100644 index 00000000..9b01c6fb --- /dev/null +++ b/src/hidpp-generic.h @@ -0,0 +1,66 @@ +/* + * HID++ generic definitions + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* + * Based on the HID++ documentation provided by Nestor Lopez Casado at: + * https://drive.google.com/folderview?id=0BxbRzx7vEV7eWmgwazJ3NUFfQ28&usp=sharing + */ + +#ifndef HIDPP_GENERIC_H +#define HIDPP_GENERIC_H + +#define RECEIVER_IDX 0xFF + +#define REPORT_ID_SHORT 0x10 +#define REPORT_ID_LONG 0x11 + +#define SHORT_MESSAGE_LENGTH 7 +#define LONG_MESSAGE_LENGTH 20 + +#define SET_REGISTER_REQ 0x80 +#define SET_REGISTER_RSP 0x80 +#define GET_REGISTER_REQ 0x81 +#define GET_REGISTER_RSP 0x81 +#define SET_LONG_REGISTER_REQ 0x82 +#define SET_LONG_REGISTER_RSP 0x82 +#define GET_LONG_REGISTER_REQ 0x83 +#define GET_LONG_REGISTER_RSP 0x83 +#define __ERROR_MSG 0x8F + +#define ERR_SUCCESS 0x00 +#define ERR_INVALID_SUBID 0x01 +#define ERR_INVALID_ADDRESS 0x02 +#define ERR_INVALID_VALUE 0x03 +#define ERR_CONNECT_FAIL 0x04 +#define ERR_TOO_MANY_DEVICES 0x05 +#define ERR_ALREADY_EXISTS 0x06 +#define ERR_BUSY 0x07 +#define ERR_UNKNOWN_DEVICE 0x08 +#define ERR_RESOURCE_ERROR 0x09 +#define ERR_REQUEST_UNAVAILABLE 0x0A +#define ERR_INVALID_PARAM_VALUE 0x0B +#define ERR_WRONG_PIN_CODE 0x0C + +extern const char *hidpp_errors[0xFF]; + +#endif /* HIDPP_GENERIC_H */ diff --git a/src/hidpp10.c b/src/hidpp10.c index 42061012..9b1343e4 100644 --- a/src/hidpp10.c +++ b/src/hidpp10.c @@ -43,23 +43,6 @@ #include "libratbag-hidraw.h" #include "libratbag-private.h" -const char *hidpp_errors[0xFF] = { - [0x00] = "ERR_SUCCESS", - [0x01] = "ERR_INVALID_SUBID", - [0x02] = "ERR_INVALID_ADDRESS", - [0x03] = "ERR_INVALID_VALUE", - [0x04] = "ERR_CONNECT_FAIL", - [0x05] = "ERR_TOO_MANY_DEVICES", - [0x06] = "ERR_ALREADY_EXISTS", - [0x07] = "ERR_BUSY", - [0x08] = "ERR_UNKNOWN_DEVICE", - [0x09] = "ERR_RESOURCE_ERROR", - [0x0A] = "ERR_REQUEST_UNAVAILABLE", - [0x0B] = "ERR_INVALID_PARAM_VALUE", - [0x0C] = "ERR_WRONG_PIN_CODE", - [0x0D ... 0xFE] = NULL, -}; - const char *device_types[0xFF] = { [0x00] = "Unknown", [0x01] = "Keyboard", diff --git a/src/hidpp10.h b/src/hidpp10.h index bac3faac..f4d1a24d 100644 --- a/src/hidpp10.h +++ b/src/hidpp10.h @@ -30,26 +30,10 @@ #define HIDPP_10_H #include + +#include "hidpp-generic.h" #include "libratbag.h" -#define RECEIVER_IDX 0xFF - -#define REPORT_ID_SHORT 0x10 -#define REPORT_ID_LONG 0x11 - -#define SHORT_MESSAGE_LENGTH 7 -#define LONG_MESSAGE_LENGTH 20 - -#define SET_REGISTER_REQ 0x80 -#define SET_REGISTER_RSP 0x80 -#define GET_REGISTER_REQ 0x81 -#define GET_REGISTER_RSP 0x81 -#define SET_LONG_REGISTER_REQ 0x82 -#define SET_LONG_REGISTER_RSP 0x82 -#define GET_LONG_REGISTER_REQ 0x83 -#define GET_LONG_REGISTER_RSP 0x83 -#define __ERROR_MSG 0x8F - #define __CMD_HIDPP_NOTIFICATIONS 0x00 #define FEATURE_BIT_R0_CONSUMER_SPECIFIC_CONTROL 0 #define FEATURE_BIT_R0_POWER_KEYS 1 @@ -185,20 +169,6 @@ } \ } -#define ERR_SUCCESS 0x00 -#define ERR_INVALID_SUBID 0x01 -#define ERR_INVALID_ADDRESS 0x02 -#define ERR_INVALID_VALUE 0x03 -#define ERR_CONNECT_FAIL 0x04 -#define ERR_TOO_MANY_DEVICES 0x05 -#define ERR_ALREADY_EXISTS 0x06 -#define ERR_BUSY 0x07 -#define ERR_UNKNOWN_DEVICE 0x08 -#define ERR_RESOURCE_ERROR 0x09 -#define ERR_REQUEST_UNAVAILABLE 0x0A -#define ERR_INVALID_PARAM_VALUE 0x0B -#define ERR_WRONG_PIN_CODE 0x0C - #define ERROR_MSG(__hidpp_msg, idx) { \ .msg = { \ .report_id = REPORT_ID_SHORT, \ diff --git a/src/hidpp20.h b/src/hidpp20.h index bf519a1a..73d52ef8 100644 --- a/src/hidpp20.h +++ b/src/hidpp20.h @@ -29,9 +29,11 @@ #ifndef HIDPP_20_H #define HIDPP_20_H -#include "hidpp10.h" +#include -extern const char *hidpp_errors[0xFF]; +#include "libratbag.h" + +#include "hidpp-generic.h" struct _hidpp20_message { uint8_t report_id;