Changeset cfbbe1d3 in mainline for uspace/lib/usb/src/hidparser.c


Ignore:
Timestamp:
2011-04-21T20:24:14Z (13 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c7c0984a
Parents:
e50cd7f
Message:

new hid report structure bug fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/hidparser.c

    re50cd7f rcfbbe1d3  
    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, size_t j);
     83int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data);
    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
    159160                field->usage_minimum = report_item->usage_minimum;
    160161                field->usage_maximum = report_item->usage_maximum;
     
    165166                        field->usage_page = report_item->usage_page;
    166167                }
    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))) {
    169170                        if(i < report_item->usages_count){
    170                                 if((report_item->usages[i] & 0xFF00) > 0){
     171                                if((report_item->usages[i] & 0xFF00) != 0){
    171172                                        field->usage_page = (report_item->usages[i] >> 16);                                     
    172173                                        field->usage = (report_item->usages[i] & 0xFF);
     
    179180                                field->usage = report_item->usages[report_item->usages_count - 1];
    180181                        }
    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                }
    182193               
    183194                field->size = report_item->size;
     
    788799 */
    789800int 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)
    791802{
    792803        link_t *list_item;
    793804        usb_hid_report_field_t *item;
    794805
    795         uint8_t report_id = 0;
    796806        usb_hid_report_description_t *report_des;
    797807        usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT;
     
    802812
    803813        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);
    808822
    809823        /* read data */
     
    813827                item = list_get_instance(list_item, usb_hid_report_field_t, link);
    814828
    815                 if(!USB_HID_ITEM_FLAG_CONSTANT(item->item_flags)) {
     829                if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) {
    816830                       
    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 {
    820838                                // 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                        }                               
    833841                }
    834842                list_item = list_item->next;
     
    847855 * @return Translated data
    848856 */
    849 int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data, size_t j)
     857int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data)
    850858{
    851859        int resolution;
     
    862870        }
    863871
    864         if((item->physical_minimum == 0) && (item->physical_maximum == 0)) {
     872        if((item->physical_minimum == 0) && (item->physical_maximum == 0)){
    865873                item->physical_minimum = item->logical_minimum;
    866                 item->physical_maximum = item->logical_maximum;         
    867         }
     874                item->physical_maximum = item->logical_maximum;                 
     875        }
     876       
    868877
    869878        if(item->physical_maximum == item->physical_minimum){
     
    876885        }
    877886
    878         offset = item->offset + (j * item->size);
     887        offset = item->offset;
    879888        // FIXME
    880889        if((size_t)(offset/8) != (size_t)((offset+item->size-1)/8)) {
     
    914923                value = (uint32_t)value;
    915924        }
    916 
    917925
    918926        return (int)(((value - item->logical_minimum) / resolution) + item->physical_minimum);
     
    13931401
    13941402        usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
    1395 
     1403       
    13961404        usb_hid_report_description_t *report_des;
    13971405        report_des = usb_hid_report_find_description (report, report_id, USB_HID_REPORT_TYPE_OUTPUT);
     
    14051413                report_item = list_get_instance(item, usb_hid_report_field_t, link);
    14061414
    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) {
    14091416                                       
    1410                                 // variable item
     1417                                // array
    14111418                                value = usb_hid_translate_data_reverse(report_item, report_item->value);
    14121419                                offset = report_item->offset;
     
    14141421                        }
    14151422                        else {
    1416                                 //bitmap
    1417                                 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);
    14181425                                offset = report_item->offset;
    14191426                                length = report_item->size;
     
    14621469
    14631470
     1471                // reset value
     1472                report_item->value = 0;
     1473               
    14641474                item = item->next;
    14651475        }
    1466 
     1476       
    14671477        usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
    14681478
     
    14851495        }
    14861496
     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
    14871503        if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0)) {
    14881504
    14891505                // 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 
    14951506                if(item->physical_maximum == item->physical_minimum){
    14961507                    resolution = 1;
     
    15681579                        if(usb_hid_report_compare_usage_path (field->collection_path, path,
    15691580                                                      flags) == EOK) {
    1570 
    15711581                                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++;
    15731590                                }
    15741591                                else {
     
    16261643                if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK){
    16271644                        usb_hid_report_remove_last_item (field->collection_path);
    1628                         usb_log_debug("....OK\n");
    16291645                        return field;
    16301646                }
     
    16361652        return NULL;
    16371653}
     1654
     1655uint8_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
    16381682/**
    16391683 * @}
Note: See TracChangeset for help on using the changeset viewer.