Changeset 5499a8b in mainline for uspace/lib/usbhid/src/hidparser.c


Ignore:
Timestamp:
2011-05-20T13:43:09Z (13 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
14e7959
Parents:
74b1e40
Message:

usb hid parser doxygen

File:
1 edited

Legend:

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

    r74b1e40 r5499a8b  
    3131 */
    3232/** @file
    33  * HID report descriptor and report data parser implementation.
     33 * USB HID report data parser implementation.
    3434 */
    3535#include <usb/hid/hidparser.h>
     
    4141#include <assert.h>
    4242
    43 
     43/*---------------------------------------------------------------------------*/
    4444/*
    4545 * Data translation private functions
    4646 */
    4747uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size);
    48 //inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset);
     48
    4949int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data);
    50 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int32_t value);
     50
     51uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item,
     52        int32_t value);
     53
    5154int usb_pow(int a, int b);
    5255
     56/*---------------------------------------------------------------------------*/
    5357
    5458// TODO: tohle ma bejt asi jinde
     
    5660{
    5761        switch(b) {
    58                 case 0:
    59                         return 1;
    60                         break;
    61                 case 1:
    62                         return a;
    63                         break;
    64                 default:
    65                         return a * usb_pow(a, b-1);
    66                         break;
    67         }
    68 }
    69 
     62        case 0:
     63                return 1;
     64                break;
     65        case 1:
     66                return a;
     67                break;
     68        default:
     69                return a * usb_pow(a, b-1);
     70                break;
     71        }
     72}
     73/*---------------------------------------------------------------------------*/
    7074
    7175/** Returns size of report of specified report id and type in items
     
    9397        }
    9498}
    95 
     99/*---------------------------------------------------------------------------*/
    96100
    97101/** Parse and act upon a HID report.
     
    103107 * @return Error code.
    104108 */
    105 int usb_hid_parse_report(const usb_hid_report_t *report,
    106     const uint8_t *data, size_t size, uint8_t *report_id)
     109int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data,
     110        size_t size, uint8_t *report_id)
    107111{
    108112        link_t *list_item;
     
    139143                                item->value = usb_hid_translate_data(item, data);
    140144               
    141                                 item->usage = USB_HID_EXTENDED_USAGE(item->usages[item->value - item->physical_minimum]);
    142                                 item->usage_page = USB_HID_EXTENDED_USAGE_PAGE(item->usages[item->value - item->physical_minimum]);                             
     145                                item->usage = USB_HID_EXTENDED_USAGE(
     146                                        item->usages[item->value - item->physical_minimum]);
     147                                item->usage_page = USB_HID_EXTENDED_USAGE_PAGE(
     148                                        item->usages[item->value - item->physical_minimum]);                           
    143149
    144150                                usb_hid_report_set_last_item (item->collection_path,
    145                                                               USB_HID_TAG_CLASS_GLOBAL,
    146                                                               item->usage_page);
     151                                        USB_HID_TAG_CLASS_GLOBAL, item->usage_page);
    147152                                usb_hid_report_set_last_item (item->collection_path,
    148                                                               USB_HID_TAG_CLASS_LOCAL,
    149                                                               item->usage);
     153                                    USB_HID_TAG_CLASS_LOCAL, item->usage);
    150154                               
    151155                        }
     
    162166}
    163167
     168/*---------------------------------------------------------------------------*/
    164169/**
    165170 * Translate data from the report as specified in report descriptor item
     
    167172 * @param item Report descriptor item with definition of translation
    168173 * @param data Data to translate
    169  * @param j Index of processed field in report descriptor item
    170174 * @return Translated data
    171175 */
     
    240244}
    241245
    242 /*** OUTPUT API **/
     246/*---------------------------------------------------------------------------*/
     247/* OUTPUT API */
    243248
    244249/**
     
    250255 * @return Returns allocated output buffer for specified output
    251256 */
    252 uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, uint8_t report_id)
     257uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size,
     258        uint8_t report_id)
    253259{
    254260        if(report == NULL) {
     
    260266        usb_hid_report_description_t *report_des = NULL;
    261267        while(report_it != &report->reports) {
    262                 report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
    263                 if((report_des->report_id == report_id) && (report_des->type == USB_HID_REPORT_TYPE_OUTPUT)){
     268                report_des = list_get_instance(report_it,
     269                        usb_hid_report_description_t, link);
     270               
     271                if((report_des->report_id == report_id) &&
     272                        (report_des->type == USB_HID_REPORT_TYPE_OUTPUT)){
    264273                        break;
    265274                }
     
    303312 * @return Error code
    304313 */
    305 int usb_hid_report_output_translate(usb_hid_report_t *report, uint8_t report_id,
    306                                     uint8_t *buffer, size_t size)
     314int usb_hid_report_output_translate(usb_hid_report_t *report,
     315        uint8_t report_id, uint8_t *buffer, size_t size)
    307316{
    308317        link_t *item;   
     
    320329        }
    321330
    322         usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
    323        
    324331        usb_hid_report_description_t *report_des;
    325         report_des = usb_hid_report_find_description (report, report_id, USB_HID_REPORT_TYPE_OUTPUT);
     332        report_des = usb_hid_report_find_description (report, report_id,
     333                USB_HID_REPORT_TYPE_OUTPUT);
     334       
    326335        if(report_des == NULL){
    327336                return EINVAL;
     
    333342                report_item = list_get_instance(item, usb_hid_report_field_t, link);
    334343
    335                 usb_log_debug("OUTPUT ITEM usage(%x), value(%x)\n", report_item->usage, report_item->value);
    336                
    337344                if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) {
    338345                                       
    339346                        // array
    340                         value = usb_hid_translate_data_reverse(report_item, report_item->value);
     347                        value = usb_hid_translate_data_reverse(report_item,
     348                                report_item->value);
     349
    341350                        offset = report_item->offset;
    342351                        length = report_item->size;
     
    344353                else {
    345354                        // variable item
    346                         value  = usb_hid_translate_data_reverse(report_item, report_item->value);
     355                        value  = usb_hid_translate_data_reverse(report_item,
     356                                report_item->value);
     357
    347358                        offset = report_item->offset;
    348359                        length = report_item->size;
     
    353364                if((offset/8) == ((offset+length-1)/8)) {
    354365                        // je to v jednom bytu
    355                         if(((size_t)(offset/8) >= size) || ((size_t)(offset+length-1)/8) >= size) {
     366                        if(((size_t)(offset/8) >= size) ||
     367                                ((size_t)(offset+length-1)/8) >= size) {
    356368                                break; // TODO ErrorCode
    357369                        }
     
    379391                                       
    380392                                        value = value >> (length - ((offset + length) % 8));
    381                                         value = value & ((1 << (length - ((offset + length) % 8))) - 1);
     393                                        value = value &
     394                                                ((1 << (length - ((offset + length) % 8))) - 1);
    382395                               
    383396                                        mask = (1 << (length - ((offset + length) % 8))) - 1;
     
    396409        }
    397410       
    398         usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
    399 
    400411        return EOK;
    401412}
    402413
     414/*---------------------------------------------------------------------------*/
    403415/**
    404416 * Translate given data for putting them into the outoput report
     
    407419 * @return ranslated value
    408420 */
    409 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int value)
     421uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item,
     422        int value)
    410423{
    411424        int ret=0;
     
    431444        }
    432445
    433         ret = ((value - item->physical_minimum) * resolution) + item->logical_minimum;
    434         usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), ret(%x)\n", value, resolution, item->physical_minimum, item->logical_minimum, ret);
     446        ret = ((value - item->physical_minimum) * resolution) +
     447                item->logical_minimum;
     448
     449        usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), \
     450                ret(%x)\n", value, resolution, item->physical_minimum,
     451                item->logical_minimum, ret);
    435452       
    436453        if((item->logical_minimum < 0) || (item->logical_maximum < 0)){
     
    440457}
    441458
    442 usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item)
     459/*---------------------------------------------------------------------------*/
     460/**
     461 * Clones given state table
     462 *
     463 * @param item State table to clone
     464 * @return Pointer to the cloned item
     465 */
     466usb_hid_report_item_t *usb_hid_report_item_clone(
     467        const usb_hid_report_item_t *item)
    443468{
    444469        usb_hid_report_item_t *new_report_item;
     
    453478}
    454479
    455 
     480/*---------------------------------------------------------------------------*/
     481/**
     482 * Function for sequence walking through the report. Returns next field in the
     483 * report or the first one when no field is given.
     484 *
     485 * @param report Searched report structure
     486 * @param field Current field. If NULL is given, the first one in the report
     487 * is returned. Otherwise the next one i nthe list is returned.
     488 * @param path Usage path specifying which fields wa are interested in.
     489 * @param flags Flags defining mode of usage paths comparison
     490 * @param type Type of report we search.
     491 * @retval NULL if no field is founded
     492 * @retval Pointer to the founded report structure when founded
     493 */
    456494usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report,
    457                                                         usb_hid_report_field_t *field,
    458                             usb_hid_report_path_t *path, int flags,
    459                             usb_hid_report_type_t type)
    460 {
    461         usb_hid_report_description_t *report_des = usb_hid_report_find_description (report, path->report_id, type);
     495        usb_hid_report_field_t *field, usb_hid_report_path_t *path, int flags,
     496        usb_hid_report_type_t type)
     497{
     498        usb_hid_report_description_t *report_des = usb_hid_report_find_description(
     499                report, path->report_id, type);
     500
    462501        link_t *field_it;
    463502       
     
    467506
    468507        if(field == NULL){
    469                 // vezmu prvni co mathuje podle path!!
    470508                field_it = report_des->report_items.next;
    471509        }
     
    478516
    479517                if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) {
    480                         usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);
    481                         if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK){
    482                                 usb_hid_report_remove_last_item (field->collection_path);
     518                        usb_hid_report_path_append_item (field->collection_path,
     519                                field->usage_page, field->usage);
     520
     521                        if(usb_hid_report_compare_usage_path(field->collection_path, path,
     522                                flags) == EOK){
     523
     524                                usb_hid_report_remove_last_item(field->collection_path);
    483525                                return field;
    484526                        }
     
    491533}
    492534
    493 uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type)
     535/*---------------------------------------------------------------------------*/
     536/**
     537 * Returns nonzero (report_id) number if there is report of given type and
     538 * have the specified report_id in report structure
     539 *
     540 * @param report_id Searched report id
     541 * @param type Type of searched report
     542 * @param report Report structure inwhich we search
     543 * @retval 0 if report structure is null or there is no specified report
     544 * @retval report_id otherwise
     545 */
     546uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report,
     547        uint8_t report_id, usb_hid_report_type_t type)
    494548{
    495549        if(report == NULL){
     
    501555       
    502556        if(report_id == 0) {
    503                 report_it = usb_hid_report_find_description (report, report_id, type)->link.next;               
     557                report_it = usb_hid_report_find_description(report, report_id,
     558                        type)->link.next;               
    504559        }
    505560        else {
     
    508563
    509564        while(report_it != &report->reports) {
    510                 report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
     565                report_des = list_get_instance(report_it, usb_hid_report_description_t,
     566                        link);
     567
    511568                if(report_des->type == type){
    512569                        return report_des->report_id;
     
    517574}
    518575
     576/*---------------------------------------------------------------------------*/
     577/**
     578 * Reset all local items in given state table
     579 *
     580 * @param report_item State table containing current state of report
     581 * descriptor parsing
     582 *
     583 * @return void
     584 */
    519585void usb_hid_report_reset_local_items(usb_hid_report_item_t *report_item)
    520586{
Note: See TracChangeset for help on using the changeset viewer.