Changeset cfbbe1d3 in mainline
- Timestamp:
- 2011-04-21T20:24:14Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c7c0984a
- Parents:
- e50cd7f
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/kbd/kbddev.c
re50cd7f rcfbbe1d3 299 299 return; 300 300 } 301 302 unsigned i = 0; 303 301 304 302 /* Reset the LED data. */ 305 303 memset(kbd_dev->led_data, 0, kbd_dev->led_output_size * sizeof(int32_t)); 306 307 if ((kbd_dev->mods & KM_NUM_LOCK) && (i < kbd_dev->led_output_size)) { 308 kbd_dev->led_data[i++] = USB_HID_LED_NUM_LOCK; 309 } 310 311 if ((kbd_dev->mods & KM_CAPS_LOCK) && (i < kbd_dev->led_output_size)) { 312 kbd_dev->led_data[i++] = USB_HID_LED_CAPS_LOCK; 313 } 314 315 if ((kbd_dev->mods & KM_SCROLL_LOCK) 316 && (i < kbd_dev->led_output_size)) { 317 kbd_dev->led_data[i++] = USB_HID_LED_SCROLL_LOCK; 318 } 319 320 // TODO: COMPOSE and KANA 321 322 usb_log_debug("Creating output report: %s\n", usb_debug_str_buffer ((uint8_t *)kbd_dev->led_data, kbd_dev->led_output_size * 4, 0)); 323 324 usb_hid_report_output_set_data(hid_dev->parser, kbd_dev->led_path, 325 USB_HID_PATH_COMPARE_END , kbd_dev->led_data, 326 kbd_dev->led_output_size); 304 usb_log_debug("Creating output report:\n"); 305 306 usb_hid_report_field_t *field = usb_hid_report_get_sibling (hid_dev->parser, NULL, 307 kbd_dev->led_path, 308 USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY | USB_HID_PATH_COMPARE_END, 309 USB_HID_REPORT_TYPE_OUTPUT); 310 while(field != NULL) { 311 312 if((field->usage == USB_HID_LED_NUM_LOCK) && (kbd_dev->mods & KM_NUM_LOCK)){ 313 field->value = 1; 314 } 315 316 if((field->usage == USB_HID_LED_CAPS_LOCK) && (kbd_dev->mods & KM_CAPS_LOCK)){ 317 field->value = 1; 318 } 319 320 if((field->usage == USB_HID_LED_SCROLL_LOCK) && (kbd_dev->mods & KM_SCROLL_LOCK)){ 321 field->value = 1; 322 } 323 324 field = usb_hid_report_get_sibling (hid_dev->parser, field, 325 kbd_dev->led_path, 326 USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY | USB_HID_PATH_COMPARE_END, 327 USB_HID_REPORT_TYPE_OUTPUT); 328 } 329 327 330 int rc = usb_hid_report_output_translate(hid_dev->parser, 0, 328 331 kbd_dev->output_buffer, kbd_dev->output_size); … … 648 651 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0); 649 652 //usb_hid_report_path_set_report_id(path, 0); 650 651 int rc = usb_hid_parse_report(hid_dev->parser, buffer, actual_size); 653 654 uint8_t report_id; 655 int rc = usb_hid_parse_report(hid_dev->parser, buffer, actual_size, &report_id); 656 usb_hid_report_path_set_report_id (path, report_id); 652 657 usb_hid_report_field_t *field = usb_hid_report_get_sibling(hid_dev->parser, 653 658 NULL, path, USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 654 659 USB_HID_REPORT_TYPE_INPUT); 655 660 661 unsigned i=0; 662 usb_kbd_t *kbd_dev = (usb_kbd_t *)hid_dev->data; 663 664 memset(kbd_dev->keys, 0, kbd_dev->key_count); 656 665 while(field != NULL) { 657 usb_log_debug("FIELD (%X) - VALUE(%X) USAGE(%X)\n", field, field->value, field->usage); 666 if((i < kbd_dev->key_count) && (field->value != 0)){ 667 kbd_dev->keys[i++] = (uint8_t)field->usage; 668 } 658 669 field = usb_hid_report_get_sibling(hid_dev->parser, field, path, 659 670 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 660 671 USB_HID_REPORT_TYPE_INPUT); 661 672 } 662 673 usb_kbd_process_keycodes(kbd_dev->keys, kbd_dev->key_count, report_id, hid_dev); 663 674 664 675 usb_hid_report_path_free(path); -
uspace/drv/usbhid/lgtch-ultrax/lgtch-ultrax.c
re50cd7f rcfbbe1d3 81 81 usb_hid_report_path_t *path = usb_hid_report_path(); 82 82 usb_hid_report_path_append_item(path, 0xc, 0); 83 usb_hid_report_path_set_report_id(path, 0); 84 85 int rc = usb_hid_parse_report(hid_dev->parser, buffer, buffer_size); 83 84 uint8_t report_id; 85 int rc = usb_hid_parse_report(hid_dev->parser, buffer, buffer_size, &report_id); 86 usb_hid_report_path_set_report_id(path, report_id); 86 87 87 88 usb_hid_report_field_t *field = usb_hid_report_get_sibling(hid_dev->parser, NULL, path, USB_HID_PATH_COMPARE_END , USB_HID_REPORT_TYPE_INPUT); -
uspace/drv/usbkbd/kbddev.c
re50cd7f rcfbbe1d3 618 618 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0); 619 619 620 int rc = usb_hid_parse_report(kbd_dev->parser, buffer, actual_size); 620 uint8_t report_id; 621 int rc = usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, &report_id); 621 622 usb_hid_descriptor_print (kbd_dev->parser); 622 623 -
uspace/lib/usb/include/usb/classes/hidparser.h
re50cd7f rcfbbe1d3 119 119 120 120 int use_report_ids; 121 uint8_t last_report_id; 121 122 122 123 } usb_hid_report_t; … … 279 280 */ 280 281 /** */ 281 int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data, size_t size );282 int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data, size_t size, uint8_t *report_id); 282 283 283 284 /** */ … … 318 319 319 320 usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report, usb_hid_report_field_t *field, usb_hid_report_path_t *path, int flags, usb_hid_report_type_t type); 321 322 uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type); 323 320 324 321 325 /* -
uspace/lib/usb/src/hidparser.c
re50cd7f rcfbbe1d3 81 81 int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size); 82 82 inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset); 83 int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data , size_t j);83 int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data); 84 84 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int32_t value); 85 85 int usb_pow(int a, int b); … … 151 151 list_initialize(&field->link); 152 152 153 /* fill the attributes */ 153 /* fill the attributes */ 154 154 field->collection_path = path; 155 155 field->logical_minimum = report_item->logical_minimum; … … 157 157 field->physical_minimum = report_item->physical_minimum; 158 158 field->physical_maximum = report_item->physical_maximum; 159 159 160 field->usage_minimum = report_item->usage_minimum; 160 161 field->usage_maximum = report_item->usage_maximum; … … 165 166 field->usage_page = report_item->usage_page; 166 167 } 167 168 if(report_item->usages_count > 0 && ((report_item->usage_minimum = 0) && (report_item->usage_maximum= 0))) {168 169 if(report_item->usages_count > 0 && ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) { 169 170 if(i < report_item->usages_count){ 170 if((report_item->usages[i] & 0xFF00) >0){171 if((report_item->usages[i] & 0xFF00) != 0){ 171 172 field->usage_page = (report_item->usages[i] >> 16); 172 173 field->usage = (report_item->usages[i] & 0xFF); … … 179 180 field->usage = report_item->usages[report_item->usages_count - 1]; 180 181 } 181 } 182 } 183 184 if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) != 0) && (!((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0)))) { 185 if(report_item->type == USB_HID_REPORT_TYPE_INPUT) { 186 field->usage = report_item->usage_maximum - i; 187 } 188 else { 189 field->usage = report_item->usage_minimum + i; 190 } 191 192 } 182 193 183 194 field->size = report_item->size; … … 788 799 */ 789 800 int usb_hid_parse_report(const usb_hid_report_t *report, 790 const uint8_t *data, size_t size )801 const uint8_t *data, size_t size, uint8_t *report_id) 791 802 { 792 803 link_t *list_item; 793 804 usb_hid_report_field_t *item; 794 805 795 uint8_t report_id = 0;796 806 usb_hid_report_description_t *report_des; 797 807 usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT; … … 802 812 803 813 if(report->use_report_ids != 0) { 804 report_id = data[0]; 805 } 806 807 report_des = usb_hid_report_find_description(report, report_id, type); 814 *report_id = data[0]; 815 } 816 else { 817 *report_id = 0; 818 } 819 820 821 report_des = usb_hid_report_find_description(report, *report_id, type); 808 822 809 823 /* read data */ … … 813 827 item = list_get_instance(list_item, usb_hid_report_field_t, link); 814 828 815 if( !USB_HID_ITEM_FLAG_CONSTANT(item->item_flags)) {829 if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) { 816 830 817 if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0) || 818 ((item->usage_minimum == 0) && (item->usage_maximum == 0))) { 819 831 if(USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0) { 832 833 // array 834 item->value = usb_hid_translate_data(item, data); 835 item->usage = (item->value - item->physical_minimum) + item->usage_minimum; 836 } 837 else { 820 838 // variable item 821 item->value = usb_hid_translate_data(item, data,0); 822 823 // array item ??? 824 if(!((item->usage_minimum == 0) && (item->usage_maximum == 0))) { 825 item->usage = item->value + item->usage_minimum; 826 } 827 } 828 else { 829 // bitmapa 830 // TODO: overit jestli vraci hodnoty podle phy min/max 831 item->value = usb_hid_translate_data(item, data, 0); 832 } 839 item->value = usb_hid_translate_data(item, data); 840 } 833 841 } 834 842 list_item = list_item->next; … … 847 855 * @return Translated data 848 856 */ 849 int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data , size_t j)857 int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data) 850 858 { 851 859 int resolution; … … 862 870 } 863 871 864 if((item->physical_minimum == 0) && (item->physical_maximum == 0)) 872 if((item->physical_minimum == 0) && (item->physical_maximum == 0)){ 865 873 item->physical_minimum = item->logical_minimum; 866 item->physical_maximum = item->logical_maximum; 867 } 874 item->physical_maximum = item->logical_maximum; 875 } 876 868 877 869 878 if(item->physical_maximum == item->physical_minimum){ … … 876 885 } 877 886 878 offset = item->offset + (j * item->size);887 offset = item->offset; 879 888 // FIXME 880 889 if((size_t)(offset/8) != (size_t)((offset+item->size-1)/8)) { … … 914 923 value = (uint32_t)value; 915 924 } 916 917 925 918 926 return (int)(((value - item->logical_minimum) / resolution) + item->physical_minimum); … … 1393 1401 1394 1402 usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0)); 1395 1403 1396 1404 usb_hid_report_description_t *report_des; 1397 1405 report_des = usb_hid_report_find_description (report, report_id, USB_HID_REPORT_TYPE_OUTPUT); … … 1405 1413 report_item = list_get_instance(item, usb_hid_report_field_t, link); 1406 1414 1407 if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) || 1408 ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) { 1415 if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) { 1409 1416 1410 // variable item1417 // array 1411 1418 value = usb_hid_translate_data_reverse(report_item, report_item->value); 1412 1419 offset = report_item->offset; … … 1414 1421 } 1415 1422 else { 1416 // bitmap1417 value += usb_hid_translate_data_reverse(report_item, report_item->value);1423 // variable item 1424 value = usb_hid_translate_data_reverse(report_item, report_item->value); 1418 1425 offset = report_item->offset; 1419 1426 length = report_item->size; … … 1462 1469 1463 1470 1471 // reset value 1472 report_item->value = 0; 1473 1464 1474 item = item->next; 1465 1475 } 1466 1476 1467 1477 usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0)); 1468 1478 … … 1485 1495 } 1486 1496 1497 if((item->physical_minimum == 0) && (item->physical_maximum == 0)){ 1498 item->physical_minimum = item->logical_minimum; 1499 item->physical_maximum = item->logical_maximum; 1500 } 1501 1502 1487 1503 if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0)) { 1488 1504 1489 1505 // variable item 1490 if((item->physical_minimum == 0) && (item->physical_maximum == 0)) {1491 item->physical_minimum = item->logical_minimum;1492 item->physical_maximum = item->logical_maximum;1493 }1494 1495 1506 if(item->physical_maximum == item->physical_minimum){ 1496 1507 resolution = 1; … … 1568 1579 if(usb_hid_report_compare_usage_path (field->collection_path, path, 1569 1580 flags) == EOK) { 1570 1571 1581 if(data_idx < data_size) { 1572 field->value = data[data_idx++]; 1582 if((data[data_idx] >= field->physical_minimum) && (data[data_idx] >= field->physical_minimum)) { 1583 field->value = data[data_idx]; 1584 } 1585 else { 1586 return ERANGE; 1587 } 1588 1589 data_idx++; 1573 1590 } 1574 1591 else { … … 1626 1643 if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK){ 1627 1644 usb_hid_report_remove_last_item (field->collection_path); 1628 usb_log_debug("....OK\n");1629 1645 return field; 1630 1646 } … … 1636 1652 return NULL; 1637 1653 } 1654 1655 uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type) 1656 { 1657 if(report == NULL){ 1658 return 0; 1659 } 1660 1661 usb_hid_report_description_t *report_des; 1662 link_t *report_it; 1663 1664 if(report_id == 0) { 1665 report_it = usb_hid_report_find_description (report, report_id, type)->link.next; 1666 } 1667 else { 1668 report_it = report->reports.next; 1669 } 1670 1671 while(report_it != &report->reports) { 1672 report_des = list_get_instance(report_it, usb_hid_report_description_t, link); 1673 if(report_des->type == type){ 1674 return report_des->report_id; 1675 } 1676 } 1677 1678 return 0; 1679 } 1680 1681 1638 1682 /** 1639 1683 * @}
Note:
See TracChangeset
for help on using the changeset viewer.