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


Ignore:
Timestamp:
2011-04-21T20:57:21Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6513110
Parents:
36f737a (diff), c7c0984a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged fixes from maklf

File:
1 edited

Legend:

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

    r36f737a reb393ad  
    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;
     
    351362                                        offset_output = 0;
    352363                                        offset_feature = 0;
     364                                        usb_hid_report_path_set_report_id (usage_path, report_item->id);
    353365                                        break;
    354366
     
    788800 */
    789801int usb_hid_parse_report(const usb_hid_report_t *report, 
    790     const uint8_t *data, size_t size)
     802    const uint8_t *data, size_t size, uint8_t *report_id)
    791803{
    792804        link_t *list_item;
    793805        usb_hid_report_field_t *item;
    794806
    795         uint8_t report_id = 0;
    796807        usb_hid_report_description_t *report_des;
    797808        usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT;
     
    802813
    803814        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);
     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);
    808823
    809824        /* read data */
     
    813828                item = list_get_instance(list_item, usb_hid_report_field_t, link);
    814829
    815                 if(!USB_HID_ITEM_FLAG_CONSTANT(item->item_flags)) {
     830                if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) {
    816831                       
    817                         if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0) ||
    818                            ((item->usage_minimum == 0) && (item->usage_maximum == 0))) {
    819 
     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;
     837                        }
     838                        else {
    820839                                // 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                         }                       
     840                                item->value = usb_hid_translate_data(item, data);                               
     841                        }                               
    833842                }
    834843                list_item = list_item->next;
     
    847856 * @return Translated data
    848857 */
    849 int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data, size_t j)
     858int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data)
    850859{
    851860        int resolution;
     
    862871        }
    863872
    864         if((item->physical_minimum == 0) && (item->physical_maximum == 0)) {
     873        if((item->physical_minimum == 0) && (item->physical_maximum == 0)){
    865874                item->physical_minimum = item->logical_minimum;
    866                 item->physical_maximum = item->logical_maximum;         
    867         }
     875                item->physical_maximum = item->logical_maximum;                 
     876        }
     877       
    868878
    869879        if(item->physical_maximum == item->physical_minimum){
     
    876886        }
    877887
    878         offset = item->offset + (j * item->size);
     888        offset = item->offset;
    879889        // FIXME
    880890        if((size_t)(offset/8) != (size_t)((offset+item->size-1)/8)) {
     
    914924                value = (uint32_t)value;
    915925        }
    916 
    917926
    918927        return (int)(((value - item->logical_minimum) / resolution) + item->physical_minimum);
     
    12421251                return NULL;
    12431252        }
     1253
     1254        new_usage_path->report_id = usage_path->report_id;
    12441255       
    12451256        if(list_empty(&usage_path->head)){
     
    13931404
    13941405        usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
    1395 
     1406       
    13961407        usb_hid_report_description_t *report_des;
    13971408        report_des = usb_hid_report_find_description (report, report_id, USB_HID_REPORT_TYPE_OUTPUT);
     
    14051416                report_item = list_get_instance(item, usb_hid_report_field_t, link);
    14061417
    1407                         if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) ||
    1408                                 ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) {
     1418                        if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) {
    14091419                                       
    1410                                 // variable item
     1420                                // array
    14111421                                value = usb_hid_translate_data_reverse(report_item, report_item->value);
    14121422                                offset = report_item->offset;
     
    14141424                        }
    14151425                        else {
    1416                                 //bitmap
    1417                                 value += usb_hid_translate_data_reverse(report_item, report_item->value);
     1426                                // variable item
     1427                                value  = usb_hid_translate_data_reverse(report_item, report_item->value);
    14181428                                offset = report_item->offset;
    14191429                                length = report_item->size;
     
    14621472
    14631473
     1474                // reset value
     1475                report_item->value = 0;
     1476               
    14641477                item = item->next;
    14651478        }
    1466 
     1479       
    14671480        usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
    14681481
     
    14851498        }
    14861499
     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
    14871506        if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0)) {
    14881507
    14891508                // 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 
    14951509                if(item->physical_maximum == item->physical_minimum){
    14961510                    resolution = 1;
     
    15681582                        if(usb_hid_report_compare_usage_path (field->collection_path, path,
    15691583                                                      flags) == EOK) {
    1570 
    15711584                                if(data_idx < data_size) {
    1572                                         field->value = data[data_idx++];
     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++;
    15731593                                }
    15741594                                else {
     
    16221642        while(field_it != &report_des->report_items) {
    16231643                field = list_get_instance(field_it, usb_hid_report_field_t, link);
    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){
     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                        }
    16271651                        usb_hid_report_remove_last_item (field->collection_path);
    1628                         usb_log_debug("....OK\n");
    1629                         return field;
    1630                 }
    1631                 usb_hid_report_remove_last_item (field->collection_path);
    1632 
     1652                }
    16331653                field_it = field_it->next;
    16341654        }
     
    16361656        return NULL;
    16371657}
     1658
     1659uint8_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
    16381686/**
    16391687 * @}
Note: See TracChangeset for help on using the changeset viewer.