Ignore:
Timestamp:
2011-05-06T13:08:10Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
075c1eb, 3da17644
Parents:
a58dd620 (diff), 310c4df (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:

Development branch changes

File:
1 edited

Legend:

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

    ra58dd620 r3d4aa055  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2011 Matej Klonfar
    33 * All rights reserved.
    44 *
     
    3939#include <adt/list.h>
    4040#include <usb/classes/hid_report_items.h>
    41 
    42 /**
    43  * Item prefix
    44  */
    45 #define USB_HID_ITEM_SIZE(data)         ((uint8_t)(data & 0x3))
    46 #define USB_HID_ITEM_TAG(data)          ((uint8_t)((data & 0xF0) >> 4))
    47 #define USB_HID_ITEM_TAG_CLASS(data)    ((uint8_t)((data & 0xC) >> 2))
    48 #define USB_HID_ITEM_IS_LONG(data)      (data == 0xFE)
    49 
    50 
    51 /**
    52  * Input/Output/Feature Item flags
    53  */
    54 /** Constant (1) / Variable (0) */
    55 #define USB_HID_ITEM_FLAG_CONSTANT(flags)       ((flags & 0x1) == 0x1)
    56 /** Variable (1) / Array (0) */
    57 #define USB_HID_ITEM_FLAG_VARIABLE(flags)       ((flags & 0x2) == 0x2)
    58 /** Absolute / Relative*/
    59 #define USB_HID_ITEM_FLAG_RELATIVE(flags)       ((flags & 0x4) == 0x4)
    60 /** Wrap / No Wrap */
    61 #define USB_HID_ITEM_FLAG_WRAP(flags)           ((flags & 0x8) == 0x8)
    62 #define USB_HID_ITEM_FLAG_LINEAR(flags)         ((flags & 0x10) == 0x10)
    63 #define USB_HID_ITEM_FLAG_PREFERRED(flags)      ((flags & 0x20) == 0x20)
    64 #define USB_HID_ITEM_FLAG_POSITION(flags)       ((flags & 0x40) == 0x40)
    65 #define USB_HID_ITEM_FLAG_VOLATILE(flags)       ((flags & 0x80) == 0x80)
    66 #define USB_HID_ITEM_FLAG_BUFFERED(flags)       ((flags & 0x100) == 0x100)
    67 
    68 
    69 /**
    70  * Description of path of usage pages and usages in report descriptor
    71  */
    72 #define USB_HID_PATH_COMPARE_STRICT                             0
    73 #define USB_HID_PATH_COMPARE_END                                1
    74 #define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY    4
    75 
    76 /** */
    77 typedef struct {
    78         /** */
    79         int32_t usage_page;
    80         /** */ 
    81         int32_t usage;
    82         /** */
    83         link_t link;
    84 } usb_hid_report_usage_path_t;
    85 
    86 /** */
    87 typedef struct {
    88         /** */ 
    89         int depth;     
    90         uint8_t report_id;
    91        
    92         /** */ 
    93         link_t link;
    94 
    95 } usb_hid_report_path_t;
    96 
    97 /**
    98  * Description of report items
    99  */
    100 typedef struct {
    101         /** */ 
    102         int32_t id;
    103         /** */ 
    104         int32_t usage_minimum;
    105         /** */ 
    106         int32_t usage_maximum;
    107         /** */ 
    108         int32_t logical_minimum;
    109         /** */ 
    110         int32_t logical_maximum;
    111         /** */ 
    112         int32_t size;
    113         /** */ 
    114         int32_t count;
    115         /** */ 
    116         size_t offset;
    117         /** */ 
    118         int32_t delimiter;
    119         /** */ 
    120         int32_t unit_exponent;
    121         /** */ 
    122         int32_t unit;
    123 
    124         /** */
    125         int32_t string_index;
    126         /** */ 
    127         int32_t string_minimum;
    128         /** */ 
    129         int32_t string_maximum;
    130         /** */ 
    131         int32_t designator_index;
    132         /** */ 
    133         int32_t designator_minimum;
    134         /** */ 
    135         int32_t designator_maximum;
    136         /** */ 
    137         int32_t physical_minimum;
    138         /** */ 
    139         int32_t physical_maximum;
    140 
    141         /** */ 
    142         uint8_t item_flags;
    143 
    144         /** */ 
    145         usb_hid_report_path_t *usage_path;
    146         /** */ 
    147         link_t link;
    148 } usb_hid_report_item_t;
    149 
    150 
    151 /** HID report parser structure. */
    152 typedef struct {       
    153         /** */ 
    154         link_t input;
    155         /** */ 
    156         link_t output;
    157         /** */ 
    158         link_t feature;
    159        
    160         int use_report_id;
    161 
    162         /** */
    163         link_t stack;
    164 } usb_hid_report_parser_t;     
    165 
    166 
    167 /** HID parser callbacks for IN items. */
    168 typedef struct {
    169         /** Callback for keyboard.
    170          *
    171          * @param key_codes Array of pressed key (including modifiers).
    172          * @param count Length of @p key_codes.
    173          * @param arg Custom argument.
    174          */
    175         void (*keyboard)(const uint8_t *key_codes, size_t count, const uint8_t report_id, void *arg);
    176 } usb_hid_report_in_callbacks_t;
    177 
    178 
    179 typedef enum {
    180         USB_HID_MOD_LCTRL = 0x01,
    181         USB_HID_MOD_LSHIFT = 0x02,
    182         USB_HID_MOD_LALT = 0x04,
    183         USB_HID_MOD_LGUI = 0x08,
    184         USB_HID_MOD_RCTRL = 0x10,
    185         USB_HID_MOD_RSHIFT = 0x20,
    186         USB_HID_MOD_RALT = 0x40,
    187         USB_HID_MOD_RGUI = 0x80,
    188         USB_HID_MOD_COUNT = 8
    189 } usb_hid_modifiers_t;
    190 
    191 //typedef enum {
    192 //      USB_HID_LED_NUM_LOCK = 0x1,
    193 //      USB_HID_LED_CAPS_LOCK = 0x2,
    194 //      USB_HID_LED_SCROLL_LOCK = 0x4,
    195 //      USB_HID_LED_COMPOSE = 0x8,
    196 //      USB_HID_LED_KANA = 0x10,
    197 //      USB_HID_LED_COUNT = 5
    198 //} usb_hid_led_t;
    199 
    200 static const usb_hid_modifiers_t
    201     usb_hid_modifiers_consts[USB_HID_MOD_COUNT] = {
    202         USB_HID_MOD_LCTRL,
    203         USB_HID_MOD_LSHIFT,
    204         USB_HID_MOD_LALT,
    205         USB_HID_MOD_LGUI,
    206         USB_HID_MOD_RCTRL,
    207         USB_HID_MOD_RSHIFT,
    208         USB_HID_MOD_RALT,
    209         USB_HID_MOD_RGUI
    210 };
    211 
    212 //static const usb_hid_led_t usb_hid_led_consts[USB_HID_LED_COUNT] = {
    213 //      USB_HID_LED_NUM_LOCK,
    214 //      USB_HID_LED_CAPS_LOCK,
    215 //      USB_HID_LED_SCROLL_LOCK,
    216 //      USB_HID_LED_COMPOSE,
    217 //      USB_HID_LED_KANA
    218 //};
    219 
    220 //#define USB_HID_BOOT_KEYBOARD_NUM_LOCK                0x01
    221 //#define USB_HID_BOOT_KEYBOARD_CAPS_LOCK               0x02
    222 //#define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK     0x04
    223 //#define USB_HID_BOOT_KEYBOARD_COMPOSE         0x08
    224 //#define USB_HID_BOOT_KEYBOARD_KANA                    0x10
    225 
    226 /*
    227  * Descriptor parser functions
    228  */
    229 /** */
    230 int usb_hid_parser_init(usb_hid_report_parser_t *parser);
    231 
    232 /** */
    233 int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser,
    234     const uint8_t *data, size_t size);
    235 
    236 /** */
    237 void usb_hid_free_report_parser(usb_hid_report_parser_t *parser);
    238 
    239 /** */
    240 void usb_hid_descriptor_print(usb_hid_report_parser_t *parser);
    241 
    242 /*
    243  * Boot protocol functions
    244  */
    245 /** */
    246 int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,
    247         const usb_hid_report_in_callbacks_t *callbacks, void *arg);
    248 
    249 /** */
    250 int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size);
     41#include <usb/classes/hidpath.h>
     42#include <usb/classes/hidtypes.h>
     43#include <usb/classes/hiddescriptor.h>
    25144
    25245
     
    25548 */
    25649/** */
    257 int usb_hid_parse_report(const usb_hid_report_parser_t *parser, 
    258     const uint8_t *data, size_t size,
    259     usb_hid_report_path_t *path, int flags,
    260     const usb_hid_report_in_callbacks_t *callbacks, void *arg);
     50int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data,
     51                         size_t size, uint8_t *report_id);
    26152
    26253/** */
    263 size_t usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
     54size_t usb_hid_report_input_length(const usb_hid_report_t *report,
    26455        usb_hid_report_path_t *path, int flags);
    265 
    266 
    267 
    268 /*
    269  * usage path functions
    270  */
    271 /** */
    272 usb_hid_report_path_t *usb_hid_report_path(void);
    273 
    274 /** */
    275 void usb_hid_report_path_free(usb_hid_report_path_t *path);
    276 
    277 /** */
    278 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path, uint8_t report_id);
    279 
    280 /** */
    281 int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, int32_t usage_page, int32_t usage);
    282 
    283 /** */
    284 void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path);
    285 
    286 /** */
    287 void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path);
    288 
    289 /** */
    290 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data);
    291 
    292 /** */
    293 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, usb_hid_report_path_t *path, int flags);
    294 
    295 /** */
    296 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path);
    297 
    29856
    29957/*
     
    30159 */
    30260/** Allocates output report buffer*/
    303 uint8_t *usb_hid_report_output(usb_hid_report_parser_t *parser, size_t *size);
     61uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size,
     62                               uint8_t report_id);
    30463
    30564/** Frees output report buffer*/
     
    30766
    30867/** Returns size of output for given usage path */
    309 size_t usb_hid_report_output_size(usb_hid_report_parser_t *parser,
     68size_t usb_hid_report_output_size(usb_hid_report_t *report,
    31069                                  usb_hid_report_path_t *path, int flags);
    31170
    312 /** Updates the output report buffer by translated given data */
    313 int usb_hid_report_output_translate(usb_hid_report_parser_t *parser,
    314                                     usb_hid_report_path_t *path, int flags,
    315                                     uint8_t *buffer, size_t size,
    316                                     int32_t *data, size_t data_size);
     71/** Makes the output report buffer by translated given data */
     72int usb_hid_report_output_translate(usb_hid_report_t *report, uint8_t report_id,
     73                                    uint8_t *buffer, size_t size);
     74
     75/** */
     76usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report,
     77                                                   usb_hid_report_field_t *field,
     78                                                   usb_hid_report_path_t *path,
     79                                                   int flags,
     80                                                   usb_hid_report_type_t type);
     81
     82/** */
     83uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report,
     84                                     uint8_t report_id,
     85                                     usb_hid_report_type_t type);
     86
    31787#endif
    31888/**
Note: See TracChangeset for help on using the changeset viewer.