Changeset 57d9c05e in mainline


Ignore:
Timestamp:
2011-03-25T17:15:26Z (13 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
841e6e5
Parents:
9c0f158
Message:

Output report creating API preparation

Location:
uspace/lib/usb
Files:
2 edited

Legend:

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

    r9c0f158 r57d9c05e  
    3131 */
    3232/** @file
    33  * @brief USB HID parser.
     33 * USB HID report descriptor and report data parser
    3434 */
    3535#ifndef LIBUSB_HIDPARSER_H_
     
    7474#define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY    4
    7575
     76/** */
    7677typedef struct {
     78        /** */
    7779        int32_t usage_page;
     80        /** */ 
    7881        int32_t usage;
    79 
     82        /** */
    8083        link_t link;
    8184} usb_hid_report_usage_path_t;
    8285
     86/** */
    8387typedef struct {
     88        /** */ 
    8489        int depth;     
     90       
     91        /** */ 
    8592        link_t link;
    8693} usb_hid_report_path_t;
     
    9097 */
    9198typedef struct {
     99        /** */ 
    92100        int32_t id;
     101        /** */ 
    93102        int32_t usage_minimum;
     103        /** */ 
    94104        int32_t usage_maximum;
     105        /** */ 
    95106        int32_t logical_minimum;
     107        /** */ 
    96108        int32_t logical_maximum;
     109        /** */ 
    97110        int32_t size;
     111        /** */ 
    98112        int32_t count;
     113        /** */ 
    99114        size_t offset;
     115        /** */ 
    100116        int32_t delimiter;
    101 
     117        /** */ 
    102118        int32_t unit_exponent;
     119        /** */ 
    103120        int32_t unit;
    104121
    105         /*
    106          * some not yet used fields
    107          */
     122        /** */
    108123        int32_t string_index;
     124        /** */ 
    109125        int32_t string_minimum;
     126        /** */ 
    110127        int32_t string_maximum;
     128        /** */ 
    111129        int32_t designator_index;
     130        /** */ 
    112131        int32_t designator_minimum;
     132        /** */ 
    113133        int32_t designator_maximum;
     134        /** */ 
    114135        int32_t physical_minimum;
     136        /** */ 
    115137        int32_t physical_maximum;
    116138
     139        /** */ 
    117140        uint8_t item_flags;
    118141
     142        /** */ 
    119143        usb_hid_report_path_t *usage_path;
     144        /** */ 
    120145        link_t link;
    121146} usb_hid_report_item_t;
     
    124149/** HID report parser structure. */
    125150typedef struct {       
     151        /** */ 
    126152        link_t input;
     153        /** */ 
    127154        link_t output;
     155        /** */ 
    128156        link_t feature;
    129157} usb_hid_report_parser_t;     
     
    190218
    191219/*
    192  * modifiers definitions
    193  */
    194 
     220 * Descriptor parser functions
     221 */
     222/** */
     223int usb_hid_parser_init(usb_hid_report_parser_t *parser);
     224
     225/** */
     226int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser,
     227    const uint8_t *data, size_t size);
     228
     229/** */
     230void usb_hid_free_report_parser(usb_hid_report_parser_t *parser);
     231
     232/** */
     233void usb_hid_descriptor_print(usb_hid_report_parser_t *parser);
     234
     235/*
     236 * Boot protocol functions
     237 */
     238/** */
    195239int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,
    196240        const usb_hid_report_in_callbacks_t *callbacks, void *arg);
    197241
     242/** */
    198243int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size);
    199244
    200 int usb_hid_parser_init(usb_hid_report_parser_t *parser);
    201 int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser,
    202     const uint8_t *data, size_t size);
    203 
     245
     246/*
     247 * Input report parser functions
     248 */
     249/** */
    204250int usb_hid_parse_report(const usb_hid_report_parser_t *parser, 
    205251    const uint8_t *data, size_t size,
     
    207253    const usb_hid_report_in_callbacks_t *callbacks, void *arg);
    208254
     255/** */
    209256size_t usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
    210257        usb_hid_report_path_t *path, int flags);
    211258
    212259
    213 void usb_hid_free_report_parser(usb_hid_report_parser_t *parser);
    214 
    215 void usb_hid_descriptor_print(usb_hid_report_parser_t *parser);
    216 
    217 /* usage path functions */
     260
     261/*
     262 * usage path functions
     263 */
     264/** */
    218265usb_hid_report_path_t *usb_hid_report_path(void);
     266
     267/** */
    219268void usb_hid_report_path_free(usb_hid_report_path_t *path);
     269
     270/** */
    220271int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, int32_t usage_page, int32_t usage);
     272
     273/** */
    221274void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path);
     275
     276/** */
    222277void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path);
     278
     279/** */
    223280void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data);
     281
     282/** */
    224283int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, usb_hid_report_path_t *path, int flags);
     284
     285/** */
    225286usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path);
    226287
    227288
    228 // output API
     289/*
     290 * Output report parser functions
     291 */
    229292/** Allocates output report buffer*/
    230293uint8_t *usb_hid_report_output(usb_hid_report_parser_t *parser);
     294
    231295/** Frees output report buffer*/
    232296void usb_hid_report_output_free(uint8_t *output);
     
    235299size_t usb_hid_report_output_size(usb_hid_report_parser_t *parser,
    236300                                  usb_hid_report_path_t *path, int flags);
     301
    237302/** Updates the output report buffer by translated given data */
    238303int usb_hid_report_output_translate(usb_hid_report_parser_t *parser,
  • uspace/lib/usb/src/hidparser.c

    r9c0f158 r57d9c05e  
    3131 */
    3232/** @file
    33  * @brief HID parser implementation.
     33 * HID report descriptor and report data parser implementation.
    3434 */
    3535#include <usb/classes/hidparser.h>
     
    4040#include <usb/debug.h>
    4141
     42/** */
    4243#define USB_HID_NEW_REPORT_ITEM 1
     44
     45/** */
    4346#define USB_HID_NO_ACTION               2
     47
     48/** */
    4449#define USB_HID_UNKNOWN_TAG             -99
    4550
    46 #define BAD_HACK_USAGE_PAGE             0x07
    47 
     51/*
     52 * Private descriptor parser functions
     53 */
    4854int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size,
    4955                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
     
    5864int usb_hid_report_reset_local_items();
    5965void usb_hid_free_report_list(link_t *head);
     66
     67/*
     68 * Data translation private functions
     69 */
    6070int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size);
    6171inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset);
     
    6373int usb_pow(int a, int b);
    6474
    65 
     75// TODO: tohle ma bejt asi jinde
    6676int usb_pow(int a, int b)
    6777{
     
    8090
    8191/**
    82  *
     92 * Initialize the report descriptor parser structure
     93 *
     94 * @param parser Report descriptor parser structure
     95 * @return Error code
    8396 */
    8497int usb_hid_parser_init(usb_hid_report_parser_t *parser)
    8598{
    86    if(parser == NULL) {
    87         return EINVAL;
    88    }
    89 
    90     list_initialize(&(parser->input));
     99        if(parser == NULL) {
     100                return EINVAL;
     101        }
     102
     103        list_initialize(&(parser->input));
    91104    list_initialize(&(parser->output));
    92105    list_initialize(&(parser->feature));
     
    301314
    302315/**
     316 * Parse one tag of the report descriptor
    303317 *
    304318 * @param Tag to parse
     
    517531 * Prints content of given list of report items.
    518532 *
    519  * @param List of report items
     533 * @param List of report items (usb_hid_report_item_t)
    520534 * @return void
    521535 */
     
    549563                        path = path->next;
    550564                }
    551                
    552                
    553 //              usb_log_debug("\tUSAGE: %X\n", report_item->usage);
    554 //              usb_log_debug("\tUSAGE PAGE: %X\n", report_item->usage_page);
     565                               
    555566                usb_log_debug("\tLOGMIN: %X\n", report_item->logical_minimum);
    556567                usb_log_debug("\tLOGMAX: %X\n", report_item->logical_maximum);         
     
    567578}
    568579/**
    569  * Prints content of given descriptor in human readable format.
    570  *
    571  * @param Parsed descriptor to print
     580 * Prints content of given report descriptor in human readable format.
     581 *
     582 * @param parser Parsed descriptor to print
    572583 * @return void
    573584 */
     
    592603 * Releases whole linked list of report items
    593604 *
    594  *
     605 * @param head Head of list of report descriptor items (usb_hid_report_item_t)
     606 * @return void
    595607 */
    596608void usb_hid_free_report_list(link_t *head)
     
    624636}
    625637
    626 /** Free the HID report parser structure
     638/** Frees the HID report descriptor parser structure
    627639 *
    628640 * @param parser Opaque HID report parser structure
    629  * @return Error code
     641 * @return void
    630642 */
    631643void usb_hid_free_report_parser(usb_hid_report_parser_t *parser)
     
    657669    const usb_hid_report_in_callbacks_t *callbacks, void *arg)
    658670{
    659         /*
    660          *
    661          * only key codes (usage page 0x07) will be processed
    662          * other usages will be ignored
    663          */
    664671        link_t *list_item;
    665672        usb_hid_report_item_t *item;
     
    673680                return EINVAL;
    674681        }
    675 
    676        
    677         // get the size of result keycodes array
     682       
     683        /* get the size of result array */
    678684        key_count = usb_hid_report_input_length(parser, path, flags);
    679685
     
    682688        }
    683689
    684         // read data           
     690        /* read data */
    685691        list_item = parser->input.next;   
    686692        while(list_item != &(parser->input)) {
     
    716722}
    717723
    718 
     724/**
     725 * Translate data from the report as specified in report descriptor
     726 *
     727 * @param item Report descriptor item with definition of translation
     728 * @param data Data to translate
     729 * @param j Index of processed field in report descriptor item
     730 * @return Translated data
     731 */
    719732int usb_hid_translate_data(usb_hid_report_item_t *item, const uint8_t *data, size_t j)
    720733{
     
    793806}
    794807
     808/**
     809 *
     810 *
     811 * @param parser
     812 * @param path
     813 * @param flags
     814 * @return
     815 */
    795816size_t usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
    796817        usb_hid_report_path_t *path, int flags)
    797818{       
    798         int ret = 0;
     819        size_t ret = 0;
    799820        link_t *item;
    800821        usb_hid_report_item_t *report_item;
    801822
    802823        if(parser == NULL) {
    803                 return EINVAL;
    804         }
    805        
    806         item = (&parser->input)->next;
     824                return 0;
     825        }
     826       
     827        item = parser->input.next;
    807828        while(&parser->input != item) {
    808829                report_item = list_get_instance(item, usb_hid_report_item_t, link);
     
    821842/**
    822843 *
     844 * @param usage_path
     845 * @param usage_page
     846 * @param usage
     847 * @return
    823848 */
    824849int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path,
     
    842867/**
    843868 *
     869 * @param usage_path
     870 * @return
    844871 */
    845872void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path)
     
    857884/**
    858885 *
     886 * @param usage_path
     887 * @return
    859888 */
    860889void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path)
     
    870899/**
    871900 *
     901 * @param usage_path
     902 * @param tag
     903 * @param data
     904 * @return
    872905 */
    873906void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data)
     
    891924
    892925/**
    893  *
     926 *
     927 *
     928 * @param report_path
     929 * @param path
     930 * @param flags
     931 * @return
    894932 */
    895933int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path,
     
    9891027/**
    9901028 *
     1029 * @return
    9911030 */
    9921031usb_hid_report_path_t *usb_hid_report_path(void)
     
    10061045/**
    10071046 *
     1047 * @param path
     1048 * @return void
    10081049 */
    10091050void usb_hid_report_path_free(usb_hid_report_path_t *path)
     
    10181059 * Clone content of given usage path to the new one
    10191060 *
     1061 * @param usage_path
     1062 * @return
    10201063 */
    10211064usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path)
     
    10451088
    10461089
     1090/*** OUTPUT API **/
     1091
     1092/** Allocates output report buffer
     1093 *
     1094 * @param parser
     1095 * @param size
     1096 * @return
     1097 */
     1098uint8_t *usb_hid_report_output(usb_hid_report_parser_t *parser, size_t *size)
     1099{
     1100        if(parser == NULL) {
     1101                *size = 0;
     1102                return NULL;
     1103        }
     1104       
     1105        // read the last outpu report item
     1106        usb_hid_report_item_t *last;
     1107        link_t *link;
     1108
     1109        link = parser->output.prev;
     1110        if(link != &parser->output) {
     1111                last = list_get_instance(link, usb_hid_report_item_t, link);
     1112                *size = (last->offset + (last->size * last->count)) / 8;
     1113
     1114                uint8_t *buffer = malloc(sizeof(uint8_t) * (*size));
     1115                return buffer;
     1116        }
     1117        else {
     1118                *size = 0;             
     1119                return NULL;
     1120        }
     1121}
     1122
     1123
     1124/** Frees output report buffer
     1125 *
     1126 * @param output Output report buffer
     1127 * @return
     1128 */
     1129void usb_hid_report_output_free(uint8_t *output)
     1130{
     1131        if(output != NULL) {
     1132                free (output);
     1133        }
     1134}
     1135
     1136/** Returns size of output for given usage path
     1137 *
     1138 * @param parser
     1139 * @param path
     1140 * @param flags
     1141 * @return
     1142 */
     1143size_t usb_hid_report_output_size(usb_hid_report_parser_t *parser,
     1144                                  usb_hid_report_path_t *path, int flags)
     1145{
     1146        size_t ret = 0;
     1147        link_t *item;
     1148        usb_hid_report_item_t *report_item;
     1149
     1150        if(parser == NULL) {
     1151                return 0;
     1152        }
     1153       
     1154        item = parser->output.next;
     1155        while(&parser->input != item) {
     1156                report_item = list_get_instance(item, usb_hid_report_item_t, link);
     1157                if(!USB_HID_ITEM_FLAG_CONSTANT(report_item->item_flags) &&
     1158                   (usb_hid_report_compare_usage_path(report_item->usage_path, path, flags) == EOK)) {
     1159                        ret += report_item->count;
     1160                }
     1161
     1162                item = item->next;
     1163        }
     1164
     1165        return ret;
     1166       
     1167}
     1168
     1169/** Updates the output report buffer by translated given data
     1170 *
     1171 * @param parser
     1172 * @param path
     1173 * @param flags
     1174 * @param buffer
     1175 * @param size
     1176 * @param data
     1177 * @param data_size
     1178 * @return
     1179 */
     1180int usb_hid_report_output_translate(usb_hid_report_parser_t *parser,
     1181                                    usb_hid_report_path_t *path, int flags,
     1182                                    uint8_t *buffer, size_t size,
     1183                                    int32_t *data, size_t data_size)
     1184{
     1185        //TODO
     1186        //
     1187        //go throught output descriptor and
     1188        // if path match then take data from the begin, translate them and
     1189        // or to the buffer
     1190        //
     1191        // it should be the reverse process to input translation
     1192       
     1193        usb_hid_report_item_t *report_item;
     1194        link_t *item;   
     1195        size_t idx=0;
     1196        int i=0;
     1197        int32_t field_value=0;
     1198        int32_t value=0;
     1199        int8_t mask;
     1200        int8_t offset;
     1201       
     1202        if(parser == NULL) {
     1203                return EINVAL;
     1204        }
     1205
     1206        item = parser->output.next;     
     1207        while(item != &parser->output) {
     1208                report_item = list_get_instance(item, usb_hid_report_item_t ,link);
     1209
     1210                if(idx > size) {
     1211                        return EINVAL;
     1212                }
     1213
     1214                for(i=0; i<report_item->count; i++, idx++) {
     1215                        // translate data
     1216                        value = usb_hid_translate_data_output(report_item, data[idx]);
     1217
     1218                        // pres kazdy byte v bufferu kteryho se to tyka
     1219                        for(){
     1220                                // vybrat ktera cast value patri do tohodle bytu
     1221                                // shiftnout podle pozice
     1222                               
     1223                                //samotny vlozeni do bufferu
     1224                                buffer[x+j] |= value[j];
     1225                        }                       
     1226                }
     1227        }
     1228
     1229        return EOK;
     1230}
     1231
     1232
    10471233/**
    10481234 * @}
Note: See TracChangeset for help on using the changeset viewer.