Ignore:
Timestamp:
2011-05-28T14:30:58Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3fb5a3e
Parents:
e8f826b (diff), 48141f0 (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:

Merge development/ changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhid/include/usb/hid/hidtypes.h

    re8f826b r400735e  
    2727 */
    2828
    29 /** @addtogroup libusbhid
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * USB HID report descriptor and report data parser
    34  */
    35 #ifndef LIBUSBHID_HIDTYPES_H_
    36 #define LIBUSBHID_HIDTYPES_H_
     33 * Basic data structures for USB HID Report descriptor and report parser.
     34 */
     35#ifndef LIBUSB_HIDTYPES_H_
     36#define LIBUSB_HIDTYPES_H_
    3737
    3838#include <stdint.h>
    3939#include <adt/list.h>
    4040
     41/*---------------------------------------------------------------------------*/
     42
     43/**
     44 * Maximum amount of specified usages for one report item
     45 */
    4146#define USB_HID_MAX_USAGES      0xffff
    4247
    43 #define USB_HID_UINT32_TO_INT32(x, size)        ((((x) & (1 << ((size) - 1))) != 0) ? -(~(x - 1) & ((1 << size) - 1)) : (x)) //(-(~((x) - 1)))
    44 #define USB_HID_INT32_TO_UINT32(x, size)        (((x) < 0 ) ? ((1 << (size)) + (x)) : (x))
    45 
    46 
     48/**
     49 * Converts integer from unsigned two's complement format format to signed
     50 * one.
     51 *
     52 * @param x Number to convert
     53 * @param size Length of the unsigned number in bites
     54 * @return signed int
     55 */
     56#define USB_HID_UINT32_TO_INT32(x, size)        \
     57        ((((x) & (1 << ((size) - 1))) != 0) ?   \
     58         -(~((x) - 1) & ((1 << size) - 1)) : (x))
     59
     60/**
     61 * Convert integer from signed format to unsigned. If number is negative the
     62 * two's complement format is used.
     63 *
     64 * @param x Number to convert
     65 * @param size Length of result number in bites
     66 * @return unsigned int
     67 */
     68#define USB_HID_INT32_TO_UINT32(x, size)        \
     69        (((x) < 0 ) ? ((1 << (size)) + (x)) : (x))
     70
     71/*---------------------------------------------------------------------------*/
     72
     73/**
     74 * Enum of report types
     75 */
    4776typedef enum {
     77        /** Input report. Data are sent from device to system */
    4878        USB_HID_REPORT_TYPE_INPUT = 1,
     79
     80        /** Output report. Data are sent from system to device */
    4981        USB_HID_REPORT_TYPE_OUTPUT = 2,
     82
     83        /** Feature report. Describes device configuration information that
     84         * can be sent to the device */
    5085        USB_HID_REPORT_TYPE_FEATURE = 3
    5186} usb_hid_report_type_t;
    5287
    53 
     88/*---------------------------------------------------------------------------*/
     89
     90/**
     91 * Description of all reports described in one report descriptor.
     92 */
    5493typedef struct {
    55         /** */
     94        /** Count of available reports. */
    5695        int report_count;
    57         link_t reports;         /** list of usb_hid_report_description_t */
    58 
     96
     97        /** Head of linked list of description of reports. */
     98        link_t reports;
     99
     100        /** Head of linked list of all used usage/collection paths. */
    59101        link_t collection_paths;
     102
     103        /** Length of list of usage paths. */
    60104        int collection_paths_count;
    61105
     106        /** Flag whether report ids are used. */
    62107        int use_report_ids;
     108
     109        /** Report id of last parsed report. */
    63110        uint8_t last_report_id;
    64111       
    65112} usb_hid_report_t;
    66 
     113/*---------------------------------------------------------------------------*/
     114
     115/**
     116 * Description of one concrete report
     117 */
    67118typedef struct {
     119        /** Report id. Zero when no report id is used. */
    68120        uint8_t report_id;
     121
     122        /** Type of report */
    69123        usb_hid_report_type_t type;
    70124
     125        /** Bit length of the report */
    71126        size_t bit_length;
     127
     128        /** Number of items in report */
    72129        size_t item_length;
    73130       
    74         link_t report_items;    /** list of report items (fields) */
    75 
     131        /** Linked list of report items in report */
     132        link_t report_items;
     133
     134        /** Linked list of descriptions. */
    76135        link_t link;
    77136} usb_hid_report_description_t;
    78 
     137/*---------------------------------------------------------------------------*/
     138
     139/**
     140 * Description of one field/item in report
     141 */
    79142typedef struct {
    80 
     143        /** Bit offset of the field */
    81144        int offset;
     145
     146        /** Bit size of the field */
    82147        size_t size;
    83148
     149        /** Usage page. Zero when usage page can be changed. */
    84150        uint16_t usage_page;
     151
     152        /** Usage. Zero when usage can be changed. */
    85153        uint16_t usage;
    86154
     155        /** Item's attributes */
    87156        uint8_t item_flags;
     157
     158        /** Usage/Collection path of the field. */
    88159        usb_hid_report_path_t *collection_path;
    89160
     161        /**
     162         * The lowest valid logical value (value with the device operates)
     163         */
    90164        int32_t logical_minimum;
     165
     166        /**
     167         * The greatest valid logical value
     168         */
    91169        int32_t logical_maximum;
     170
     171        /**
     172         * The lowest valid physical value (value with the system operates)
     173         */
    92174        int32_t physical_minimum;
     175
     176        /** The greatest valid physical value */
    93177        int32_t physical_maximum;
     178
     179        /** The lowest valid usage index */
    94180        int32_t usage_minimum;
     181
     182        /** The greatest valid usage index */
    95183        int32_t usage_maximum;
     184       
     185        /** Unit of the value */
    96186        uint32_t unit;
     187
     188        /** Unit exponent */
    97189        uint32_t unit_exponent;
    98190
     191        /** Array of possible usages */
    99192        uint32_t *usages;
     193
     194        /** Size of the array of usages */
    100195        size_t usages_count;
    101196
     197        /** Parsed value */
    102198        int32_t value;
    103199
     200        /** List to another report items */
    104201        link_t link;
    105202} usb_hid_report_field_t;
    106203
    107 
    108 
    109 /**
    110  * state table
     204/*---------------------------------------------------------------------------*/
     205
     206/**
     207 * State table for report descriptor parsing
    111208 */
    112209typedef struct {
     
    114211        int32_t id;
    115212       
    116         /** */
     213        /** Extended usage page */
    117214        uint16_t extended_usage_page;
     215
     216        /** Array of usages specified for this item */
    118217        uint32_t usages[USB_HID_MAX_USAGES];
     218       
     219        /** Length of usages array */
    119220        int usages_count;
    120221
    121         /** */
     222        /** Usage page*/
    122223        uint32_t usage_page;
    123224
    124         /** */ 
     225        /** Minimum valid usage index */       
    125226        int32_t usage_minimum;
    126         /** */ 
     227       
     228        /** Maximum valid usage index */       
    127229        int32_t usage_maximum;
    128         /** */ 
     230       
     231        /** Minimum valid logical value */     
    129232        int32_t logical_minimum;
    130         /** */ 
     233       
     234        /** Maximum valid logical value */     
    131235        int32_t logical_maximum;
    132         /** */ 
     236
     237        /** Length of the items in bits*/       
    133238        int32_t size;
    134         /** */ 
     239
     240        /** COunt of items*/   
    135241        int32_t count;
    136         /** */ 
     242
     243        /**  Bit offset of the item in report */       
    137244        size_t offset;
    138         /** */ 
     245
     246        /** Unit exponent */   
    139247        int32_t unit_exponent;
    140         /** */ 
     248        /** Unit of the value */       
    141249        int32_t unit;
    142250
    143         /** */
     251        /** String index */
    144252        uint32_t string_index;
    145         /** */ 
     253
     254        /** Minimum valid string index */       
    146255        uint32_t string_minimum;
    147         /** */ 
     256
     257        /** Maximum valid string index */       
    148258        uint32_t string_maximum;
    149         /** */ 
     259
     260        /** The designator index */     
    150261        uint32_t designator_index;
    151         /** */ 
     262
     263        /** Minimum valid designator value*/   
    152264        uint32_t designator_minimum;
    153         /** */ 
     265
     266        /** Maximum valid designator value*/   
    154267        uint32_t designator_maximum;
    155         /** */ 
     268
     269        /** Minimal valid physical value*/     
    156270        int32_t physical_minimum;
    157         /** */ 
     271
     272        /** Maximal valid physical value */     
    158273        int32_t physical_maximum;
    159274
    160         /** */ 
     275        /** Items attributes*/ 
    161276        uint8_t item_flags;
    162277
     278        /** Report type */
    163279        usb_hid_report_type_t type;
    164280
    165281        /** current collection path*/   
    166282        usb_hid_report_path_t *usage_path;
    167         /** */ 
     283
     284        /** Unused*/   
    168285        link_t link;
    169286
    170287        int in_delimiter;
    171288} usb_hid_report_item_t;
    172 
    173 /** HID parser callbacks for IN items. */
    174 typedef struct {
    175         /** Callback for keyboard.
    176          *
    177          * @param key_codes Array of pressed key (including modifiers).
    178          * @param count Length of @p key_codes.
    179          * @param arg Custom argument.
    180          */
    181         void (*keyboard)(const uint8_t *key_codes, size_t count, const uint8_t report_id, void *arg);
    182 } usb_hid_report_in_callbacks_t;
    183 
    184 
     289/*---------------------------------------------------------------------------*/
     290/**
     291 * Enum of the keyboard modifiers
     292 */
    185293typedef enum {
    186294        USB_HID_MOD_LCTRL = 0x01,
     
    206314        USB_HID_MOD_RGUI
    207315};
     316/*---------------------------------------------------------------------------*/
     317
    208318
    209319#endif
Note: See TracChangeset for help on using the changeset viewer.