Changes in / [eb393ad:36f737a] in mainline


Ignore:
Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/kbd/kbddev.c

    reb393ad r36f737a  
    299299                return;
    300300        }
    301                
     301       
     302        unsigned i = 0;
     303       
    302304        /* Reset the LED data. */
    303305        memset(kbd_dev->led_data, 0, kbd_dev->led_output_size * sizeof(int32_t));
    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                
    330         int rc = usb_hid_report_output_translate(hid_dev->parser, 0,
     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: ");
     323        for (i = 0; i < kbd_dev->led_output_size; ++i) {
     324                usb_log_debug("%d ", kbd_dev->led_data[i]);
     325        }
     326        usb_log_debug("\n");
     327
     328        usb_hid_report_output_set_data(hid_dev->report, kbd_dev->led_path,
     329            USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     330            kbd_dev->led_data, kbd_dev->led_output_size);
     331        int rc = usb_hid_report_output_translate(hid_dev->report, 0,
    331332            kbd_dev->output_buffer, kbd_dev->output_size);
    332333       
     
    670671        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
    671672        //usb_hid_report_path_set_report_id(path, 0);
    672 
    673         uint8_t report_id;
    674         int rc = usb_hid_parse_report(hid_dev->parser, buffer, actual_size, &report_id);       
    675         usb_hid_report_path_set_report_id (path, report_id);
    676         usb_hid_report_field_t *field = usb_hid_report_get_sibling(hid_dev->parser,
    677                             NULL, path, USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    678                                                 USB_HID_REPORT_TYPE_INPUT);
    679 
    680         usb_hid_report_path_free(path);
     673       
     674        int rc = usb_hid_parse_report(hid_dev->report, buffer, actual_size);
    681675       
    682676        if (rc != EOK) {
  • uspace/drv/usbhid/lgtch-ultrax/lgtch-ultrax.c

    reb393ad r36f737a  
    8181        usb_hid_report_path_t *path = usb_hid_report_path();
    8282        usb_hid_report_path_append_item(path, 0xc, 0);
    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);
     83        usb_hid_report_path_set_report_id(path, 0);
     84       
     85        int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size);
    8786
    8887        usb_hid_report_field_t *field = usb_hid_report_get_sibling(hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END , USB_HID_REPORT_TYPE_INPUT);
  • uspace/drv/usbkbd/kbddev.c

    reb393ad r36f737a  
    618618        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
    619619
    620         uint8_t report_id;
    621         int rc = usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, &report_id);
     620        int rc = usb_hid_parse_report(kbd_dev->parser, buffer, actual_size);
    622621        usb_hid_descriptor_print (kbd_dev->parser);
    623622
  • uspace/lib/usb/include/usb/classes/hidparser.h

    reb393ad r36f737a  
    119119
    120120        int use_report_ids;
    121         uint8_t last_report_id;
    122121       
    123122} usb_hid_report_t;
     
    280279 */
    281280/** */
    282 int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data, size_t size, uint8_t *report_id);
     281int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data, size_t size);
    283282
    284283/** */
     
    319318
    320319usb_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 
    324320
    325321/*
  • uspace/lib/usb/src/hidparser.c

    reb393ad r36f737a  
    8181int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size);
    8282inline 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);
     83int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data, size_t j);
    8484uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int32_t value);
    8585int usb_pow(int a, int b);
     
    151151                list_initialize(&field->link);
    152152
    153                 /* fill the attributes */               
     153                /* fill the attributes */
    154154                field->collection_path = path;
    155155                field->logical_minimum = report_item->logical_minimum;
     
    157157                field->physical_minimum = report_item->physical_minimum;
    158158                field->physical_maximum = report_item->physical_maximum;
    159 
    160159                field->usage_minimum = report_item->usage_minimum;
    161160                field->usage_maximum = report_item->usage_maximum;
     
    166165                        field->usage_page = report_item->usage_page;
    167166                }
    168 
    169                 if(report_item->usages_count > 0 && ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) {
     167               
     168                if(report_item->usages_count > 0 && ((report_item->usage_minimum = 0) && (report_item->usage_maximum = 0))) {
    170169                        if(i < report_item->usages_count){
    171                                 if((report_item->usages[i] & 0xFF00) != 0){
     170                                if((report_item->usages[i] & 0xFF00) > 0){
    172171                                        field->usage_page = (report_item->usages[i] >> 16);                                     
    173172                                        field->usage = (report_item->usages[i] & 0xFF);
     
    180179                                field->usage = report_item->usages[report_item->usages_count - 1];
    181180                        }
    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                 }
     181                }               
    193182               
    194183                field->size = report_item->size;
     
    362351                                        offset_output = 0;
    363352                                        offset_feature = 0;
    364                                         usb_hid_report_path_set_report_id (usage_path, report_item->id);
    365353                                        break;
    366354
     
    800788 */
    801789int usb_hid_parse_report(const usb_hid_report_t *report, 
    802     const uint8_t *data, size_t size, uint8_t *report_id)
     790    const uint8_t *data, size_t size)
    803791{
    804792        link_t *list_item;
    805793        usb_hid_report_field_t *item;
    806794
     795        uint8_t report_id = 0;
    807796        usb_hid_report_description_t *report_des;
    808797        usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT;
     
    813802
    814803        if(report->use_report_ids != 0) {
    815                 *report_id = data[0];
    816         }       
    817         else {
    818                 *report_id = 0;
    819         }
    820 
    821 
    822         report_des = usb_hid_report_find_description(report, *report_id, type);
     804                report_id = data[0];
     805        }
     806
     807        report_des = usb_hid_report_find_description(report, report_id, type);
    823808
    824809        /* read data */
     
    828813                item = list_get_instance(list_item, usb_hid_report_field_t, link);
    829814
    830                 if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) {
     815                if(!USB_HID_ITEM_FLAG_CONSTANT(item->item_flags)) {
    831816                       
    832                         if(USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0) {
    833 
    834                                 // array
    835                                 item->value = usb_hid_translate_data(item, data);
    836                             item->usage = (item->value - item->physical_minimum) + item->usage_minimum;
     817                        if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0) ||
     818                           ((item->usage_minimum == 0) && (item->usage_maximum == 0))) {
     819
     820                                // 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                                }
    837827                        }
    838828                        else {
    839                                 // variable item
    840                                 item->value = usb_hid_translate_data(item, data);                               
    841                         }                               
     829                                // bitmapa
     830                                // TODO: overit jestli vraci hodnoty podle phy min/max
     831                                item->value = usb_hid_translate_data(item, data, 0);
     832                        }                       
    842833                }
    843834                list_item = list_item->next;
     
    856847 * @return Translated data
    857848 */
    858 int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data)
     849int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data, size_t j)
    859850{
    860851        int resolution;
     
    871862        }
    872863
    873         if((item->physical_minimum == 0) && (item->physical_maximum == 0)){
     864        if((item->physical_minimum == 0) && (item->physical_maximum == 0)) {
    874865                item->physical_minimum = item->logical_minimum;
    875                 item->physical_maximum = item->logical_maximum;                 
    876         }
    877        
     866                item->physical_maximum = item->logical_maximum;         
     867        }
    878868
    879869        if(item->physical_maximum == item->physical_minimum){
     
    886876        }
    887877
    888         offset = item->offset;
     878        offset = item->offset + (j * item->size);
    889879        // FIXME
    890880        if((size_t)(offset/8) != (size_t)((offset+item->size-1)/8)) {
     
    924914                value = (uint32_t)value;
    925915        }
     916
    926917
    927918        return (int)(((value - item->logical_minimum) / resolution) + item->physical_minimum);
     
    12511242                return NULL;
    12521243        }
    1253 
    1254         new_usage_path->report_id = usage_path->report_id;
    12551244       
    12561245        if(list_empty(&usage_path->head)){
     
    14041393
    14051394        usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
    1406        
     1395
    14071396        usb_hid_report_description_t *report_des;
    14081397        report_des = usb_hid_report_find_description (report, report_id, USB_HID_REPORT_TYPE_OUTPUT);
     
    14161405                report_item = list_get_instance(item, usb_hid_report_field_t, link);
    14171406
    1418                         if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) {
     1407                        if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) ||
     1408                                ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) {
    14191409                                       
    1420                                 // array
     1410                                // variable item
    14211411                                value = usb_hid_translate_data_reverse(report_item, report_item->value);
    14221412                                offset = report_item->offset;
     
    14241414                        }
    14251415                        else {
    1426                                 // variable item
    1427                                 value  = usb_hid_translate_data_reverse(report_item, report_item->value);
     1416                                //bitmap
     1417                                value += usb_hid_translate_data_reverse(report_item, report_item->value);
    14281418                                offset = report_item->offset;
    14291419                                length = report_item->size;
     
    14721462
    14731463
    1474                 // reset value
    1475                 report_item->value = 0;
    1476                
    14771464                item = item->next;
    14781465        }
    1479        
     1466
    14801467        usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
    14811468
     
    14981485        }
    14991486
    1500         if((item->physical_minimum == 0) && (item->physical_maximum == 0)){
    1501                 item->physical_minimum = item->logical_minimum;
    1502                 item->physical_maximum = item->logical_maximum;                 
    1503         }
    1504        
    1505 
    15061487        if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0)) {
    15071488
    15081489                // 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
    15091495                if(item->physical_maximum == item->physical_minimum){
    15101496                    resolution = 1;
     
    15821568                        if(usb_hid_report_compare_usage_path (field->collection_path, path,
    15831569                                                      flags) == EOK) {
     1570
    15841571                                if(data_idx < data_size) {
    1585                                         if((data[data_idx] >= field->physical_minimum) && (data[data_idx] >= field->physical_minimum)) {
    1586                                                 field->value = data[data_idx];
    1587                                         }
    1588                                         else {
    1589                                                 return ERANGE;
    1590                                         }
    1591 
    1592                                         data_idx++;
     1572                                        field->value = data[data_idx++];
    15931573                                }
    15941574                                else {
     
    16421622        while(field_it != &report_des->report_items) {
    16431623                field = list_get_instance(field_it, usb_hid_report_field_t, link);
    1644 
    1645                 if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) {
    1646                         usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);
    1647                         if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK){
    1648                                 usb_hid_report_remove_last_item (field->collection_path);
    1649                                 return field;
    1650                         }
     1624                       
     1625                usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);
     1626                if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK){
    16511627                        usb_hid_report_remove_last_item (field->collection_path);
    1652                 }
     1628                        usb_log_debug("....OK\n");
     1629                        return field;
     1630                }
     1631                usb_hid_report_remove_last_item (field->collection_path);
     1632
    16531633                field_it = field_it->next;
    16541634        }
     
    16561636        return NULL;
    16571637}
    1658 
    1659 uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type)
    1660 {
    1661         if(report == NULL){
    1662                 return 0;
    1663         }
    1664 
    1665         usb_hid_report_description_t *report_des;
    1666         link_t *report_it;
    1667        
    1668         if(report_id == 0) {
    1669                 report_it = usb_hid_report_find_description (report, report_id, type)->link.next;               
    1670         }
    1671         else {
    1672                 report_it = report->reports.next;
    1673         }
    1674 
    1675         while(report_it != &report->reports) {
    1676                 report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
    1677                 if(report_des->type == type){
    1678                         return report_des->report_id;
    1679                 }
    1680         }
    1681 
    1682         return 0;
    1683 }
    1684 
    1685 
    16861638/**
    16871639 * @}
Note: See TracChangeset for help on using the changeset viewer.