Changeset 9be8669 in mainline
- Timestamp:
- 2011-05-10T22:01:36Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d59d0bb
- Parents:
- 7aaf403e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/hidparser.c
r7aaf403e r9be8669 335 335 usb_log_debug("OUTPUT ITEM usage(%x), value(%x)\n", report_item->usage, report_item->value); 336 336 337 337 if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) { 338 338 339 // array 340 value = usb_hid_translate_data_reverse(report_item, report_item->value); 341 offset = report_item->offset; 342 length = report_item->size; 343 } 344 else { 345 // variable item 346 value = usb_hid_translate_data_reverse(report_item, report_item->value); 347 offset = report_item->offset; 348 length = report_item->size; 349 } 350 351 if((offset/8) == ((offset+length-1)/8)) { 352 // je to v jednom bytu 353 if(((size_t)(offset/8) >= size) || ((size_t)(offset+length-1)/8) >= size) { 354 break; // TODO ErrorCode 339 // array 340 value = usb_hid_translate_data_reverse(report_item, report_item->value); 341 offset = report_item->offset; 342 length = report_item->size; 343 } 344 else { 345 // variable item 346 value = usb_hid_translate_data_reverse(report_item, report_item->value); 347 offset = report_item->offset; 348 length = report_item->size; 349 } 350 351 usb_log_debug("\ttranslated value: %x\n", value); 352 353 if((offset/8) == ((offset+length-1)/8)) { 354 // je to v jednom bytu 355 if(((size_t)(offset/8) >= size) || ((size_t)(offset+length-1)/8) >= size) { 356 break; // TODO ErrorCode 357 } 358 size_t shift = 8 - offset%8 - length; 359 value = value << shift; 360 value = value & (((1 << length)-1) << shift); 361 362 uint8_t mask = 0; 363 mask = 0xff - (((1 << length) - 1) << shift); 364 buffer[offset/8] = (buffer[offset/8] & mask) | value; 365 } 366 else { 367 int i = 0; 368 uint8_t mask = 0; 369 for(i = (offset/8); i <= ((offset+length-1)/8); i++) { 370 if(i == (offset/8)) { 371 tmp_value = value; 372 tmp_value = tmp_value & ((1 << (8-(offset%8)))-1); 373 tmp_value = tmp_value << (offset%8); 374 375 mask = ~(((1 << (8-(offset%8)))-1) << (offset%8)); 376 buffer[i] = (buffer[i] & mask) | tmp_value; 355 377 } 356 357 size_t shift = 8 - offset%8 - length; 358 359 value = value << shift; 360 value = value & (((1 << length)-1) << shift); 378 else if (i == ((offset + length -1)/8)) { 379 380 value = value >> (length - ((offset + length) % 8)); 381 value = value & ((1 << (length - ((offset + length) % 8))) - 1); 361 382 362 uint8_t mask = 0; 363 mask = 0xff - (((1 << length) - 1) << shift); 364 buffer[offset/8] = (buffer[offset/8] & mask) | value; 365 } 366 else { 367 int i = 0; 368 uint8_t mask = 0; 369 for(i = (offset/8); i <= ((offset+length-1)/8); i++) { 370 if(i == (offset/8)) { 371 tmp_value = value; 372 tmp_value = tmp_value & ((1 << (8-(offset%8)))-1); 373 tmp_value = tmp_value << (offset%8); 374 375 mask = ~(((1 << (8-(offset%8)))-1) << (offset%8)); 376 buffer[i] = (buffer[i] & mask) | tmp_value; 377 } 378 else if (i == ((offset + length -1)/8)) { 379 380 value = value >> (length - ((offset + length) % 8)); 381 value = value & ((1 << (length - ((offset + length) % 8))) - 1); 382 383 mask = (1 << (length - ((offset + length) % 8))) - 1; 384 buffer[i] = (buffer[i] & mask) | value; 385 } 386 else { 387 buffer[i] = value & (0xFF << i); 388 } 383 mask = (1 << (length - ((offset + length) % 8))) - 1; 384 buffer[i] = (buffer[i] & mask) | value; 389 385 } 390 } 391 386 else { 387 buffer[i] = value & (0xFF << i); 388 } 389 } 390 } 392 391 393 392 // reset value … … 422 421 } 423 422 424 425 if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0)) { 426 427 // variable item 428 if(item->physical_maximum == item->physical_minimum){ 429 resolution = 1; 430 } 431 else { 432 resolution = (item->logical_maximum - item->logical_minimum) / 433 ((item->physical_maximum - item->physical_minimum) * 434 (usb_pow(10,(item->unit_exponent)))); 435 } 436 437 ret = ((value - item->physical_minimum) * resolution) + item->logical_minimum; 438 } 439 else { 440 // bitmapa 441 if(value == 0) { 442 ret = 0; 443 } 444 else { 445 size_t bitmap_idx = (value - item->usage_minimum); 446 ret = 1 << bitmap_idx; 447 } 448 } 449 423 // variable item 424 if(item->physical_maximum == item->physical_minimum){ 425 resolution = 1; 426 } 427 else { 428 resolution = (item->logical_maximum - item->logical_minimum) / 429 ((item->physical_maximum - item->physical_minimum) * 430 (usb_pow(10,(item->unit_exponent)))); 431 } 432 433 ret = ((value - item->physical_minimum) * resolution) + item->logical_minimum; 434 usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), ret(%x)\n", value, resolution, item->physical_minimum, item->logical_minimum, ret); 435 450 436 if((item->logical_minimum < 0) || (item->logical_maximum < 0)){ 451 437 return USB_HID_INT32_TO_UINT32(ret, item->size); 452 438 } 453 return (int32_t) ret;439 return (int32_t)0 + ret; 454 440 } 455 441
Note:
See TracChangeset
for help on using the changeset viewer.