Ignore:
File:
1 edited

Legend:

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

    r2571089 r64dbc83  
    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
     76/** */
     77typedef 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/** */
     87typedef 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 */
     100typedef 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. */
     152typedef 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. */
     168typedef 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
     179typedef 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
     200static 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/** */
     230int usb_hid_parser_init(usb_hid_report_parser_t *parser);
     231
     232/** */
     233int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser,
     234    const uint8_t *data, size_t size);
     235
     236/** */
     237void usb_hid_free_report_parser(usb_hid_report_parser_t *parser);
     238
     239/** */
     240void usb_hid_descriptor_print(usb_hid_report_parser_t *parser);
     241
     242/*
     243 * Boot protocol functions
     244 */
     245/** */
     246int 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/** */
     250int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size);
    44251
    45252
     
    48255 */
    49256/** */
    50 int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data,
    51                          size_t size, uint8_t *report_id);
    52 
    53 /** */
    54 size_t usb_hid_report_input_length(const usb_hid_report_t *report,
     257int 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);
     261
     262/** */
     263size_t usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
    55264        usb_hid_report_path_t *path, int flags);
    56265
     266
     267
     268/*
     269 * usage path functions
     270 */
     271/** */
     272usb_hid_report_path_t *usb_hid_report_path(void);
     273
     274/** */
     275void usb_hid_report_path_free(usb_hid_report_path_t *path);
     276
     277/** */
     278int usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path, uint8_t report_id);
     279
     280/** */
     281int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, int32_t usage_page, int32_t usage);
     282
     283/** */
     284void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path);
     285
     286/** */
     287void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path);
     288
     289/** */
     290void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data);
     291
     292/** */
     293int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, usb_hid_report_path_t *path, int flags);
     294
     295/** */
     296usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path);
     297
     298
    57299/*
    58300 * Output report parser functions
    59301 */
    60302/** Allocates output report buffer*/
    61 uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size,
    62                                uint8_t report_id);
     303uint8_t *usb_hid_report_output(usb_hid_report_parser_t *parser, size_t *size);
    63304
    64305/** Frees output report buffer*/
     
    66307
    67308/** Returns size of output for given usage path */
    68 size_t usb_hid_report_output_size(usb_hid_report_t *report,
     309size_t usb_hid_report_output_size(usb_hid_report_parser_t *parser,
    69310                                  usb_hid_report_path_t *path, int flags);
    70311
    71 /** 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 
     312/** Updates the output report buffer by translated given data */
     313int 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);
    87317#endif
    88318/**
Note: See TracChangeset for help on using the changeset viewer.