Changes in uspace/lib/usbhid/src/hidparser.c [5a6cc679:b7fd2a0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhid/src/hidparser.c
r5a6cc679 rb7fd2a0 40 40 #include <usb/debug.h> 41 41 #include <assert.h> 42 #include <bitops.h>43 #include <macros.h>44 42 45 43 … … 201 199 int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data) 202 200 { 201 int resolution; 202 int offset; 203 int part_size; 204 205 int32_t value = 0; 206 int32_t mask = 0; 207 const uint8_t *foo = 0; 208 203 209 /* now only short tags are allowed */ 204 210 if (item->size > 32) { … … 208 214 if ((item->physical_minimum == 0) && (item->physical_maximum == 0)) { 209 215 item->physical_minimum = item->logical_minimum; 210 item->physical_maximum = item->logical_maximum; 211 } 212 213 int resolution; 216 item->physical_maximum = item->logical_maximum; 217 } 218 219 214 220 if (item->physical_maximum == item->physical_minimum) { 215 221 resolution = 1; 216 222 } else { 217 resolution = (item->logical_maximum - item->logical_minimum) / 218 ((item->physical_maximum - item->physical_minimum) * 223 resolution = (item->logical_maximum - item->logical_minimum) / 224 ((item->physical_maximum - item->physical_minimum) * 219 225 (usb_pow(10, (item->unit_exponent)))); 220 226 } 221 227 222 int32_t value = 0; 223 224 /* First, skip all bytes we don't care */ 225 data += item->offset / 8; 226 227 int bits = item->size; 228 int taken = 0; 229 230 /* Than we take the higher bits from the LSB */ 231 const unsigned bit_offset = item->offset % 8; 232 const int lsb_bits = min(bits, 8); 233 234 value |= (*data >> bit_offset) & BIT_RRANGE(uint8_t, lsb_bits); 235 bits -= lsb_bits; 236 taken += lsb_bits; 237 data++; 238 239 /* Then there may be bytes, which we take as a whole. */ 240 while (bits > 8) { 241 value |= *data << taken; 242 taken += 8; 243 bits -= 8; 244 data++; 245 } 246 247 /* And, finally, lower bits from HSB. */ 248 if (bits > 0) { 249 value |= (*data & BIT_RRANGE(uint8_t, bits)) << taken; 228 offset = item->offset; 229 // FIXME 230 if ((size_t) (offset / 8) != (size_t) ((offset+item->size - 1) / 8)) { 231 232 part_size = 0; 233 234 size_t i = 0; 235 for (i = (size_t) (offset / 8); 236 i <= (size_t) (offset + item->size - 1) / 8; i++) { 237 if (i == (size_t) (offset / 8)) { 238 /* the higher one */ 239 part_size = 8 - (offset % 8); 240 foo = data + i; 241 mask = ((1 << (item->size - part_size)) - 1); 242 value = (*foo & mask); 243 } else if (i == ((offset + item->size - 1) / 8)) { 244 /* the lower one */ 245 foo = data + i; 246 mask = ((1 << (item->size - part_size)) - 1) << 247 (8 - (item->size - part_size)); 248 249 value = (((*foo & mask) >> (8 - 250 (item->size - part_size))) << part_size) + 251 value; 252 } else { 253 value = (*(data + 1) << (part_size + 8)) + 254 value; 255 part_size += 8; 256 } 257 } 258 } else { 259 foo = data + (offset / 8); 260 mask = ((1 << item->size) - 1) << 261 (8 - ((offset % 8) + item->size)); 262 value = (*foo & mask) >> (8 - ((offset % 8) + item->size)); 250 263 } 251 264 … … 353 366 length = report_item->size; 354 367 355 usb_log_debug("\ttranslated value: %x ", value);368 usb_log_debug("\ttranslated value: %x\n", value); 356 369 357 370 if ((offset / 8) == ((offset + length - 1) / 8)) { … … 424 437 425 438 if (USB_HID_ITEM_FLAG_CONSTANT(item->item_flags)) { 426 ret urnitem->logical_minimum;439 ret = item->logical_minimum; 427 440 } 428 441
Note:
See TracChangeset
for help on using the changeset viewer.