Ignore:
Timestamp:
2011-03-01T22:03:37Z (13 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
19a1800
Parents:
2f60e57d
Message:

Basic version of usb hid report descriptor parser

File:
1 edited

Legend:

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

    r2f60e57d r976f546  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3737
    3838#include <stdint.h>
     39#include <adt/list.h>
     40
     41#include <hid_report_items.h>
     42
     43/**
     44 * Items prefix
     45 */
     46#define USB_HID_ITEM_SIZE(data)         ((uint8_t)(data & 0x3))
     47#define USB_HID_ITEM_TAG(data)          ((uint8_t)((data & 0xF0) >> 4))
     48#define USB_HID_ITEM_TAG_CLASS(data)    ((uint8_t)((data & 0xC) >> 2))
     49#define USB_HID_ITEM_IS_LONG(data)      (data == 0xFE)
     50
     51
     52/**
     53 * Input/Output/Feature Item flags
     54 */
     55#define USB_HID_ITEM_FLAG_CONSTANT(flags)       (flags & 0x1)
     56#define USB_HID_ITEM_FLAG_VARIABLE(flags)       (flags & 0x2)
     57#define USB_HID_ITEM_FLAG_RELATIVE(flags)       (flags & 0x4)
     58#define USB_HID_ITEM_FLAG_WRAP(flags)           (flags & 0x8)
     59#define USB_HID_ITEM_FLAG_LINEAR(flags)         (flags & 0x10)
     60#define USB_HID_ITEM_FLAG_PREFERRED(flags)      (flags & 0x20)
     61#define USB_HID_ITEM_FLAG_POSITION(flags)       (flags & 0x40)
     62#define USB_HID_ITEM_FLAG_VOLATILE(flags)       (flags & 0x80)
     63#define USB_HID_ITEM_FLAG_BUFFERED(flags)       (flags & 0x100)
     64
     65
     66/**
     67 * Collection Item Types
     68 */
     69#define USB_HID_COLLECTION_TYPE_PHYSICAL                0x00
     70#define USB_HID_COLLECTION_TYPE_APPLICATION             0x01
     71#define USB_HID_COLLECTION_TYPE_LOGICAL                 0x02
     72#define USB_HID_COLLECTION_TYPE_REPORT                  0x03
     73#define USB_HID_COLLECTION_TYPE_NAMED_ARRAY             0x04
     74#define USB_HID_COLLECTION_TYPE_USAGE_SWITCH    0x05
     75
     76/*
     77 * modifiers definitions
     78 */
     79#define USB_HID_BOOT_KEYBOARD_NUM_LOCK          0x01
     80#define USB_HID_BOOT_KEYBOARD_CAPS_LOCK         0x02
     81#define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK       0x04
     82#define USB_HID_BOOT_KEYBOARD_COMPOSE           0x08
     83#define USB_HID_BOOT_KEYBOARD_KANA                      0x10
     84
    3985
    4086/**
     
    4288 */
    4389typedef struct {
     90        int32_t id;
     91        int32_t usage_page;
     92        int32_t usage; 
     93        int32_t usage_minimum;
     94        int32_t usage_maximum;
     95        int32_t logical_minimum;
     96        int32_t logical_maximum;
     97        int32_t size;
     98        int32_t count;
     99        int32_t offset;
    44100
    45         uint8_t usage_min;
    46         uint8_t usage_max;
    47         uint8_t logical_min;
    48         uint8_t logical_max;
    49         uint8_t size;
    50         uint8_t count;
    51         uint8_t offset;
     101        int32_t unit_exponent;
     102        int32_t unit;
    52103
     104        /*
     105         * some not yet used fields
     106         */
     107        int32_t string_index;
     108        int32_t string_minimum;
     109        int32_t string_maximum;
     110        int32_t designator_index;
     111        int32_t designator_minimum;
     112        int32_t designator_maximum;
     113        int32_t physical_minimum;
     114        int32_t physical_maximum;
     115
     116        uint8_t item_flags;
     117
     118        link_t link;
    53119} usb_hid_report_item_t;
    54120
    55121
    56122/** HID report parser structure. */
    57 typedef struct {
    58 } usb_hid_report_parser_t;
     123typedef struct {       
     124        link_t input;
     125        link_t output;
     126        link_t feature;
     127} usb_hid_report_parser_t;     
    59128
    60129
     
    70139} usb_hid_report_in_callbacks_t;
    71140
    72 #define USB_HID_BOOT_KEYBOARD_NUM_LOCK          0x01
    73 #define USB_HID_BOOT_KEYBOARD_CAPS_LOCK         0x02
    74 #define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK       0x04
    75 #define USB_HID_BOOT_KEYBOARD_COMPOSE           0x08
    76 #define USB_HID_BOOT_KEYBOARD_KANA                      0x10
    77 
    78 /*
    79  * modifiers definitions
    80  */
    81 
    82141int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,
    83142        const usb_hid_report_in_callbacks_t *callbacks, void *arg);
     
    85144int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size);
    86145
     146
     147int usb_hid_parser_init(usb_hid_report_parser_t *parser);
    87148int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser,
    88149    const uint8_t *data, size_t size);
     
    93154
    94155
    95 int usb_hid_free_report_parser(usb_hid_report_parser_t *parser);
     156void usb_hid_free_report_parser(usb_hid_report_parser_t *parser);
    96157
     158void usb_hid_descriptor_print(usb_hid_report_parser_t *parser);
    97159#endif
    98160/**
Note: See TracChangeset for help on using the changeset viewer.