From ee2bd0475f1395fc4163e2efa4bccc05dde38838 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Fri, 6 Nov 2015 17:53:30 +0100 Subject: [PATCH] hidpp20: move the crc function up Signed-off-by: Benjamin Tissoires --- src/hidpp20.c | 54 +++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/hidpp20.c b/src/hidpp20.c index f26d2c6e..82807e0e 100644 --- a/src/hidpp20.c +++ b/src/hidpp20.c @@ -919,6 +919,33 @@ int hidpp20_adjustable_dpi_set_sensor_dpi(struct hidpp20_device *device, #define HIDPP20_PROFILE_SIZE (16*16) #define HIDPP20_BUTTON_HID 0x80 +/* + * The following crc computation has been provided by Logitech + */ +#define CRC_CCITT_SEED 0xFFFF + +static uint16_t +hidpp20_crc_ccitt(uint8_t *data, unsigned int length) +{ + uint16_t crc, temp, quick; + unsigned int i; + + crc = CRC_CCITT_SEED; + + for (i = 0; i < length; i++) { + temp = (crc >> 8) ^ (*data++); + crc <<= 8; + quick = temp ^ (temp >> 4); + crc ^= quick; + quick <<= 5; + crc ^= quick; + quick <<= 7; + crc ^= quick; + } + + return crc; +} + int hidpp20_onboard_profiles_read_memory(struct hidpp20_device *device, uint8_t read_rom, @@ -1211,33 +1238,6 @@ int hidpp20_onboard_profiles_read(struct hidpp20_device *device, return 0; } -/* - * The following crc computation has been provided by Logitech - */ -#define CRC_CCITT_SEED 0xFFFF - -static uint16_t -hidpp20_crc_ccitt(uint8_t *data, unsigned int length) -{ - uint16_t crc, temp, quick; - unsigned int i; - - crc = CRC_CCITT_SEED; - - for (i = 0; i < length; i++) { - temp = (crc >> 8) ^ (*data++); - crc <<=8; - quick = temp ^ (temp >> 4); - crc ^= quick; - quick <<= 5; - crc ^= quick; - quick <<= 7; - crc ^= quick; - } - - return crc; -} - int hidpp20_onboard_profiles_write(struct hidpp20_device *device, unsigned int index, struct hidpp20_profiles *profiles_list)