Changeset c156c2d in mainline


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

tested report ids and push&pop

File:
1 edited

Legend:

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

    rb04967a rc156c2d  
    7070int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size);
    7171inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset);
    72 int usb_hid_translate_data(usb_hid_report_item_t *item, const uint8_t *data, size_t j);
     72int usb_hid_translate_data(const usb_hid_report_parser_t *parser, usb_hid_report_item_t *item, const uint8_t *data, size_t j);
    7373int32_t usb_hid_translate_data_reverse(usb_hid_report_item_t *item, int32_t value);
    7474int usb_pow(int a, int b);
     
    103103
    104104        list_initialize(&(parser->input));
    105     list_initialize(&(parser->output));
    106     list_initialize(&(parser->feature));
     105        list_initialize(&(parser->output));
     106        list_initialize(&(parser->feature));
    107107
    108108        list_initialize(&(parser->stack));
     
    246246                                        // push current state to stack
    247247                                        new_report_item = usb_hid_report_item_clone(report_item);
    248                                         list_prepend (&parser->stack, &new_report_item->link);
    249                                        
     248                                        usb_hid_report_path_t *tmp_path = usb_hid_report_path_clone(usage_path);
     249                                        new_report_item->usage_path = tmp_path;
     250
     251                                        list_prepend (&new_report_item->link, &parser->stack);
    250252                                        break;
    251253                                case USB_HID_REPORT_TAG_POP:
     
    254256                                                return EINVAL;
    255257                                        }
     258                                        free(report_item);
     259                                               
     260                                        report_item = list_get_instance(parser->stack.next, usb_hid_report_item_t, link);
    256261                                       
    257                                         report_item = list_get_instance(&parser->stack, usb_hid_report_item_t, link);
     262                                        usb_hid_report_usage_path_t *tmp_usage_path;
     263                                        tmp_usage_path = list_get_instance(report_item->usage_path->link.prev, usb_hid_report_usage_path_t, link);
     264                                       
     265                                        usb_hid_report_set_last_item(usage_path, tmp_usage_path->usage_page, tmp_usage_path->usage);
     266
     267                                        usb_hid_report_path_free(report_item->usage_path);
     268                                        list_initialize(&report_item->usage_path->link);
    258269                                        list_remove (parser->stack.next);
    259270                                       
     
    469480                case USB_HID_REPORT_TAG_PUSH:
    470481                case USB_HID_REPORT_TAG_POP:
     482                        usb_log_debug("PUSH/POP processed\n");
    471483                        return tag;
    472484                        break;
     
    678690        usb_hid_free_report_list(&parser->output);
    679691        usb_hid_free_report_list(&parser->feature);
    680 
     692        usb_hid_free_report_list(&parser->stack);
    681693        return;
    682694}
     
    709721                return EINVAL;
    710722        }
    711        
    712         /* get the size of result array */
    713         key_count = usb_hid_report_input_length(parser, path, flags);
    714 
    715         if(!(keys = malloc(sizeof(uint8_t) * key_count))){
    716                 return ENOMEM;
    717         }
    718723
    719724        if(parser->use_report_id != 0) {
    720725                report_id = data[0];
    721726                usb_hid_report_path_set_report_id(path, report_id);
     727        }
     728
     729
     730        /* get the size of result array */
     731        key_count = usb_hid_report_input_length(parser, path, flags);
     732
     733        if(!(keys = malloc(sizeof(uint8_t) * key_count))){
     734                return ENOMEM;
    722735        }
    723736
     
    734747                                   ((item->usage_minimum == 0) && (item->usage_maximum == 0))) {
    735748                                        // variable item
    736                                         keys[i++] = usb_hid_translate_data(item, data,j);
     749                                        keys[i++] = usb_hid_translate_data(parser, item, data,j);
    737750                                }
    738751                                else {
    739752                                        // bitmapa
    740                                         if((item_value = usb_hid_translate_data(item, data, j)) != 0) {
     753                                        if((item_value = usb_hid_translate_data(parser, item, data, j)) != 0) {
    741754                                                keys[i++] = (item->count - 1 - j) + item->usage_minimum;
    742755                                        }
     
    758771
    759772/**
    760  * Translate data from the report as specified in report descriptor
     773 * Translate data from the report as specified in report descriptor item
    761774 *
    762775 * @param item Report descriptor item with definition of translation
     
    765778 * @return Translated data
    766779 */
    767 int usb_hid_translate_data(usb_hid_report_item_t *item, const uint8_t *data, size_t j)
     780int usb_hid_translate_data(const usb_hid_report_parser_t *parser, usb_hid_report_item_t *item, const uint8_t *data, size_t j)
    768781{
    769782        int resolution;
     
    775788        const uint8_t *foo;
    776789
    777         // now only common numbers llowed
     790        // now only shot tags are allowed
    778791        if(item->size > 32) {
    779792                return 0;
     
    795808
    796809        offset = item->offset + (j * item->size);
    797         if(item->id != 0) {
     810        if(parser->use_report_id != 0) {
    798811                offset += 8;
    799                 usb_log_debug("MOVED OFFSET BY 1Byte, REPORT_ID(%d)\n", item->id);
    800812        }
    801813       
     
    11571169                *size = (last->offset + (last->size * last->count)) / 8;
    11581170
     1171                if(parser->use_report_id != 0) {
     1172                        *size += 1;
     1173                }
     1174
    11591175                uint8_t *buffer = malloc(sizeof(uint8_t) * (*size));
    11601176                memset(buffer, 0, sizeof(uint8_t) * (*size));
     
    12101226
    12111227                item = item->next;
    1212         } 
     1228        }
    12131229
    12141230        return ret;
Note: See TracChangeset for help on using the changeset viewer.