Ignore:
File:
1 edited

Legend:

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

    r2571089 rcfbbe1d3  
    11/*
    2  * Copyright (c) 2011 Matej Klonfar
     2 * Copyright (c) 2010 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    3939#include <adt/list.h>
    4040#include <usb/classes/hid_report_items.h>
    41 #include <usb/classes/hidpath.h>
    42 #include <usb/classes/hidtypes.h>
    43 #include <usb/classes/hiddescriptor.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#define USB_HID_PATH_COMPARE_COLLECTION_ONLY    2 /* porovnava jenom cestu z Kolekci */
     76
     77
     78#define USB_HID_MAX_USAGES      20
     79
     80typedef enum {
     81        USB_HID_REPORT_TYPE_INPUT = 1,
     82        USB_HID_REPORT_TYPE_OUTPUT = 2,
     83        USB_HID_REPORT_TYPE_FEATURE = 3
     84} usb_hid_report_type_t;
     85
     86/** Collection usage path structure */
     87typedef struct {
     88        /** */
     89        uint32_t usage_page;
     90        /** */ 
     91        uint32_t usage;
     92
     93        uint8_t flags;
     94        /** */
     95        link_t link;
     96} usb_hid_report_usage_path_t;
     97
     98/** */
     99typedef struct {
     100        /** */ 
     101        int depth;     
     102        uint8_t report_id;
     103       
     104        /** */ 
     105        link_t link; /* list */
     106
     107        link_t head; /* head of list of usage paths */
     108
     109} usb_hid_report_path_t;
     110
     111
     112typedef struct {
     113        /** */
     114        int report_count;
     115        link_t reports;         /** list of usb_hid_report_description_t */
     116
     117        link_t collection_paths;
     118        int collection_paths_count;
     119
     120        int use_report_ids;
     121        uint8_t last_report_id;
     122       
     123} usb_hid_report_t;
     124
     125typedef struct {
     126        uint8_t report_id;
     127        usb_hid_report_type_t type;
     128
     129        size_t bit_length;
     130        size_t item_length;
     131       
     132        link_t report_items;    /** list of report items (fields) */
     133
     134        link_t link;
     135} usb_hid_report_description_t;
     136
     137typedef struct {
     138
     139        int offset;
     140        size_t size;
     141
     142        uint16_t usage_page;
     143        uint16_t usage;
     144
     145        uint8_t item_flags;
     146        usb_hid_report_path_t *collection_path;
     147
     148        int32_t logical_minimum;
     149        int32_t logical_maximum;
     150        int32_t physical_minimum;
     151        int32_t physical_maximum;
     152        uint32_t usage_minimum;
     153        uint32_t usage_maximum;
     154        uint32_t unit;
     155        uint32_t unit_exponent;
     156       
     157
     158        int32_t value;
     159
     160        link_t link;
     161} usb_hid_report_field_t;
     162
     163
     164
     165/**
     166 * state table
     167 */
     168typedef struct {
     169        /** report id */       
     170        int32_t id;
     171       
     172        /** */
     173        uint16_t extended_usage_page;
     174        uint32_t usages[USB_HID_MAX_USAGES];
     175        int usages_count;
     176
     177        /** */
     178        uint32_t usage_page;
     179
     180        /** */ 
     181        uint32_t usage_minimum;
     182        /** */ 
     183        uint32_t usage_maximum;
     184        /** */ 
     185        int32_t logical_minimum;
     186        /** */ 
     187        int32_t logical_maximum;
     188        /** */ 
     189        int32_t size;
     190        /** */ 
     191        int32_t count;
     192        /** */ 
     193        size_t offset;
     194        /** */ 
     195        int32_t unit_exponent;
     196        /** */ 
     197        int32_t unit;
     198
     199        /** */
     200        uint32_t string_index;
     201        /** */ 
     202        uint32_t string_minimum;
     203        /** */ 
     204        uint32_t string_maximum;
     205        /** */ 
     206        uint32_t designator_index;
     207        /** */ 
     208        uint32_t designator_minimum;
     209        /** */ 
     210        uint32_t designator_maximum;
     211        /** */ 
     212        int32_t physical_minimum;
     213        /** */ 
     214        int32_t physical_maximum;
     215
     216        /** */ 
     217        uint8_t item_flags;
     218
     219        usb_hid_report_type_t type;
     220
     221        /** current collection path*/   
     222        usb_hid_report_path_t *usage_path;
     223        /** */ 
     224        link_t link;
     225} usb_hid_report_item_t;
     226
     227/** HID parser callbacks for IN items. */
     228typedef struct {
     229        /** Callback for keyboard.
     230         *
     231         * @param key_codes Array of pressed key (including modifiers).
     232         * @param count Length of @p key_codes.
     233         * @param arg Custom argument.
     234         */
     235        void (*keyboard)(const uint8_t *key_codes, size_t count, const uint8_t report_id, void *arg);
     236} usb_hid_report_in_callbacks_t;
     237
     238
     239typedef enum {
     240        USB_HID_MOD_LCTRL = 0x01,
     241        USB_HID_MOD_LSHIFT = 0x02,
     242        USB_HID_MOD_LALT = 0x04,
     243        USB_HID_MOD_LGUI = 0x08,
     244        USB_HID_MOD_RCTRL = 0x10,
     245        USB_HID_MOD_RSHIFT = 0x20,
     246        USB_HID_MOD_RALT = 0x40,
     247        USB_HID_MOD_RGUI = 0x80,
     248        USB_HID_MOD_COUNT = 8
     249} usb_hid_modifiers_t;
     250
     251static const usb_hid_modifiers_t
     252    usb_hid_modifiers_consts[USB_HID_MOD_COUNT] = {
     253        USB_HID_MOD_LCTRL,
     254        USB_HID_MOD_LSHIFT,
     255        USB_HID_MOD_LALT,
     256        USB_HID_MOD_LGUI,
     257        USB_HID_MOD_RCTRL,
     258        USB_HID_MOD_RSHIFT,
     259        USB_HID_MOD_RALT,
     260        USB_HID_MOD_RGUI
     261};
     262
     263/*
     264 * Descriptor parser functions
     265 */
     266
     267/** */
     268int usb_hid_parse_report_descriptor(usb_hid_report_t *report,
     269    const uint8_t *data, size_t size);
     270
     271/** */
     272void usb_hid_free_report(usb_hid_report_t *report);
     273
     274/** */
     275void usb_hid_descriptor_print(usb_hid_report_t *report);
    44276
    45277
     
    48280 */
    49281/** */
    50 int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data,
    51                          size_t size, uint8_t *report_id);
     282int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data, size_t size, uint8_t *report_id);
    52283
    53284/** */
     
    55286        usb_hid_report_path_t *path, int flags);
    56287
     288
     289
     290/*
     291 * usage path functions
     292 */
     293/** */
     294usb_hid_report_path_t *usb_hid_report_path(void);
     295
     296/** */
     297void usb_hid_report_path_free(usb_hid_report_path_t *path);
     298
     299/** */
     300int usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path, uint8_t report_id);
     301
     302/** */
     303int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, int32_t usage_page, int32_t usage);
     304
     305/** */
     306void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path);
     307
     308/** */
     309void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path);
     310
     311/** */
     312void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data);
     313
     314/** */
     315int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, usb_hid_report_path_t *path, int flags);
     316
     317/** */
     318usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path);
     319
     320usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report, usb_hid_report_field_t *field, usb_hid_report_path_t *path, int flags, usb_hid_report_type_t type);
     321
     322uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type);
     323
     324
    57325/*
    58326 * Output report parser functions
    59327 */
    60328/** Allocates output report buffer*/
    61 uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size,
    62                                uint8_t report_id);
     329uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, uint8_t report_id);
    63330
    64331/** Frees output report buffer*/
     
    69336                                  usb_hid_report_path_t *path, int flags);
    70337
     338/** Sets data in report structure */
     339int usb_hid_report_output_set_data(usb_hid_report_t *report,
     340                                   usb_hid_report_path_t *path, int flags,
     341                                  int *data, size_t data_size);
     342
    71343/** Makes the output report buffer by translated given data */
    72 int usb_hid_report_output_translate(usb_hid_report_t *report, uint8_t report_id,
    73                                     uint8_t *buffer, size_t size);
    74 
    75 /** */
    76 usb_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 /** */
    83 uint8_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 
     344int usb_hid_report_output_translate(usb_hid_report_t *report, uint8_t report_id, uint8_t *buffer, size_t size);
    87345#endif
    88346/**
Note: See TracChangeset for help on using the changeset viewer.