Changeset b7d9606 in mainline


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

report descriptor bug fix

Location:
uspace/lib/usb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/include/usb/classes/hid_report_items.h

    rc7a2e7e rb7d9606  
    4242#define USB_HID_REPORT_TAG_INPUT                        0x8
    4343#define USB_HID_REPORT_TAG_OUTPUT                       0x9
    44 #define USB_HID_REPORT_TAG_FEATURE                      0xA
    45 #define USB_HID_REPORT_TAG_COLLECTION           0xB
     44#define USB_HID_REPORT_TAG_FEATURE                      0xB
     45#define USB_HID_REPORT_TAG_COLLECTION           0xA
    4646#define USB_HID_REPORT_TAG_END_COLLECTION       0xC
    4747
  • uspace/lib/usb/src/hidparser.c

    rc7a2e7e rb7d9606  
    3636#include <errno.h>
    3737#include <stdio.h>
    38 #include <adt/list.h>
    3938#include <malloc.h>
    4039#include <mem.h>
    41 
    42 #define USB_HID_NEW_REPORT_ITEM 0
    43 
    44 
    45 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const const uint8_t *data, size_t item_size,
     40#include <assert.h>
     41#include <usb/debug.h>
     42
     43#define USB_HID_NEW_REPORT_ITEM 1
     44#define USB_HID_NO_ACTION               2
     45#define USB_HID_UNKNOWN_TAG             -99
     46
     47
     48int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size,
    4649                             usb_hid_report_item_t *report_item);
    4750int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size,
     
    5659void usb_hid_free_report_list(link_t *head);
    5760int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size);
    58 size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset);
     61inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset);
    5962/**
    6063 *
     
    8184 */
    8285int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser,
    83     const const uint8_t *data, size_t size)
     86    const uint8_t *data, size_t size)
    8487{
    8588        size_t i=0;
     
    99102        link_initialize(&(report_item->link)); 
    100103       
    101         while(i<size){
    102                
     104        while(i<size){ 
    103105                if(!USB_HID_ITEM_IS_LONG(data[i])){
     106
     107                        if((i+1) >= size){
     108                                return -1; // TODO ERROR CODE
     109                        }
     110                       
    104111                        tag = USB_HID_ITEM_TAG(data[i]);
    105112                        item_size = USB_HID_ITEM_SIZE(data[i]);
    106113                        class = USB_HID_ITEM_TAG_CLASS(data[i]);
    107                                                
    108                         ret = usb_hid_report_parse_tag(tag,class,(data + (i+1)),
     114
     115                        usb_log_debug2(
     116                                "i(%u) data(%X) value(%X): TAG %u, class %u, size %u - ", i,
     117                            data[i], usb_hid_report_tag_data_int32(data+i+1,item_size),
     118                            tag, class, item_size);
     119                       
     120                        ret = usb_hid_report_parse_tag(tag,class,data+i+1,
    109121                                                 item_size,report_item);
     122                        printf("ret: %u\n", ret);
    110123                        switch(ret){
    111124                                case USB_HID_NEW_REPORT_ITEM:
    112125                                        // store report item to report and create the new one
    113                                         printf("\nNEW REPORT ITEM: %X",tag);
    114 
     126                                        usb_log_debug("\nNEW REPORT ITEM: %X",tag);
     127
     128                                        report_item->offset = offset;
    115129                                        offset = usb_hid_count_item_offset(report_item, offset);
    116                                         report_item->offset = offset;
    117130                                        switch(tag) {
    118131                                                case USB_HID_REPORT_TAG_INPUT:
    119                                                         printf(" - INPUT\n");
     132                                                        usb_log_debug(" - INPUT\n");
    120133                                                        list_append(&(report_item->link), &(parser->input));
    121134                                                        break;
    122135                                                case USB_HID_REPORT_TAG_OUTPUT:
    123                                                         printf(" - OUTPUT\n");
     136                                                        usb_log_debug(" - OUTPUT\n");
    124137                                                                list_append(&(report_item->link), &(parser->output));
    125138
    126139                                                        break;
    127140                                                case USB_HID_REPORT_TAG_FEATURE:
    128                                                         printf(" - FEATURE\n");
     141                                                        usb_log_debug(" - FEATURE\n");
    129142                                                                list_append(&(report_item->link), &(parser->feature));
    130143                                                        break;
    131144                                                default:
    132                                                     printf("\tjump over tag: %X\n", tag q);
     145                                                    usb_log_debug("\tjump over - tag %X\n", tag);
    133146                                                    break;
    134147                                        }
     
    153166                                       
    154167                                default:
    155                                         // nothing special to do
     168                                        // nothing special to do                                       
    156169                                        break;
    157170                        }
     
    183196 */
    184197int usb_hid_parse_report(const usb_hid_report_parser_t *parser, 
    185     const const uint8_t *data, size_t size,
     198    const uint8_t *data, size_t size,
    186199    const usb_hid_report_in_callbacks_t *callbacks, void *arg)
    187200{
     
    215228 * @return Error code
    216229 */
    217 int usb_hid_boot_keyboard_input_report(const const uint8_t *data, size_t size,
     230int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,
    218231        const usb_hid_report_in_callbacks_t *callbacks, void *arg)
    219232{
     
    273286 * @return Code of action to be done next
    274287 */
    275 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const const uint8_t *data, size_t item_size,
     288int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size,
    276289                             usb_hid_report_item_t *report_item)
    277290{       
     291        int ret;
     292       
    278293        switch(class){
    279294                case USB_HID_TAG_CLASS_MAIN:
    280295
    281                         if(usb_hid_report_parse_main_tag(tag,data,item_size,report_item) == EOK) {
     296                        if((ret=usb_hid_report_parse_main_tag(tag,data,item_size,report_item)) == EOK) {
    282297                                return USB_HID_NEW_REPORT_ITEM;
    283298                        }
    284299                        else {
    285300                                /*TODO process the error */
    286                                 return -1;
     301                                return ret;
    287302                           }
    288303                        break;
     
    296311                        break;
    297312                default:
    298                         return -1; /* TODO ERROR CODE - UNKNOWN TAG CODE */
     313                        return USB_HID_NO_ACTION;
    299314        }
    300315}
     
    318333                case USB_HID_REPORT_TAG_OUTPUT:
    319334                case USB_HID_REPORT_TAG_FEATURE:
    320                         report_item->item_flags = *data;
    321                         return USB_HID_NEW_REPORT_ITEM;
     335                        report_item->item_flags = *data;                       
     336                        return EOK;                     
    322337                        break;
    323338                       
     
    330345                        break;
    331346                default:
    332                         return -1; //TODO ERROR CODE
    333         }
    334 
    335         return EOK;
     347                        return USB_HID_NO_ACTION;
     348        }
     349
     350        return USB_HID_NO_ACTION;
    336351}
    337352
     
    388403                       
    389404                default:
    390                         return -1; //TODO ERROR CODE INVALID GLOBAL TAG
     405                        return USB_HID_NO_ACTION;
    391406        }
    392407       
     
    441456*/             
    442457                default:
    443                         return -1; //TODO ERROR CODE INVALID LOCAL TAG NOW IS ONLY UNSUPPORTED
     458                        return USB_HID_NO_ACTION;
    444459        }
    445460       
     
    484499            return;
    485500        }
    486 
    487        
    488         printf("\tHEAD %p\n",head);
     501       
    489502        for(item = head->next; item != head; item = item->next) {
    490503               
Note: See TracChangeset for help on using the changeset viewer.