Changes in uspace/lib/usbhid/include/usb/hid/hidtypes.h [74b1e40:160b75e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhid/include/usb/hid/hidtypes.h
r74b1e40 r160b75e 27 27 */ 28 28 29 /** @addtogroup libusb 29 /** @addtogroup libusbhid 30 30 * @{ 31 31 */ 32 32 /** @file 33 * Basic data structures for USB HID Report descriptor and report parser.34 */ 35 #ifndef LIBUSB _HIDTYPES_H_36 #define LIBUSB _HIDTYPES_H_33 * USB HID report descriptor and report data parser 34 */ 35 #ifndef LIBUSBHID_HIDTYPES_H_ 36 #define LIBUSBHID_HIDTYPES_H_ 37 37 38 38 #include <stdint.h> 39 39 #include <adt/list.h> 40 40 41 /*---------------------------------------------------------------------------*/ 42 43 /** 44 * Maximum amount of specified usages for one report item 45 */ 46 #define USB_HID_MAX_USAGES 0xffff 47 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 * Report type 75 */ 41 #define USB_HID_MAX_USAGES 20 42 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 76 47 typedef enum { 77 48 USB_HID_REPORT_TYPE_INPUT = 1, … … 80 51 } usb_hid_report_type_t; 81 52 82 /*---------------------------------------------------------------------------*/ 83 84 /** 85 * Description of all reports described in one report descriptor. 86 */ 87 typedef struct { 88 /** Count of available reports. */ 53 54 typedef struct { 55 /** */ 89 56 int report_count; 90 91 /** Head of linked list of description of reports. */ 92 link_t reports; 93 94 /** Head of linked list of all used usage/collection paths. */ 57 link_t reports; /** list of usb_hid_report_description_t */ 58 95 59 link_t collection_paths; 96 97 /** Length of list of usage paths. */98 60 int collection_paths_count; 99 61 100 /** Flag whether report ids are used. */101 62 int use_report_ids; 102 103 /** Report id of last parsed report. */104 63 uint8_t last_report_id; 105 64 106 65 } usb_hid_report_t; 107 /*---------------------------------------------------------------------------*/ 108 109 /** 110 * Description of one concrete report 111 */ 112 typedef struct { 113 /** Report id. Zero when no report id is used. */ 66 67 typedef struct { 114 68 uint8_t report_id; 115 116 /** Type of report */117 69 usb_hid_report_type_t type; 118 70 119 /** Bit length of the report */120 71 size_t bit_length; 121 122 /** Number of items in report */123 72 size_t item_length; 124 73 125 /** Linked list of report items in report */ 126 link_t report_items; 127 128 /** Linked list of descriptions. */ 74 link_t report_items; /** list of report items (fields) */ 75 129 76 link_t link; 130 77 } usb_hid_report_description_t; 131 /*---------------------------------------------------------------------------*/ 132 133 /** 134 * Description of one field/item in report 135 */ 136 typedef struct { 137 /** Bit offset of the field */ 78 79 typedef struct { 80 138 81 int offset; 139 140 /** Bit size of the field */141 82 size_t size; 142 83 143 /** Usage page. Zero when usage page can be changed. */144 84 uint16_t usage_page; 145 146 /** Usage. Zero when usage can be changed. */147 85 uint16_t usage; 148 86 149 /** Item's attributes */150 87 uint8_t item_flags; 151 152 /** Usage/Collection path of the field. */153 88 usb_hid_report_path_t *collection_path; 154 89 155 /**156 * The lowest valid logical value (value with the device operates)157 */158 90 int32_t logical_minimum; 159 160 /**161 * The greatest valid logical value162 */163 91 int32_t logical_maximum; 164 165 /**166 * The lowest valid physical value (value with the system operates)167 */168 92 int32_t physical_minimum; 169 170 /** The greatest valid physical value */171 93 int32_t physical_maximum; 172 173 /** The lowest valid usage index */ 174 int32_t usage_minimum; 175 176 /** The greatest valid usage index */ 177 int32_t usage_maximum; 178 179 /** Unit of the value */ 94 uint32_t usage_minimum; 95 uint32_t usage_maximum; 180 96 uint32_t unit; 181 182 /** Unit exponent */183 97 uint32_t unit_exponent; 184 185 /** Array of possible usages */ 186 uint32_t *usages; 187 188 /** Size of the array of usages */ 189 size_t usages_count; 190 191 /** Parsed value */ 98 99 192 100 int32_t value; 193 101 194 /** List to another report items */195 102 link_t link; 196 103 } usb_hid_report_field_t; 197 104 198 /*---------------------------------------------------------------------------*/ 105 199 106 200 107 /** 201 * State table for report descriptor parsing108 * state table 202 109 */ 203 110 typedef struct { … … 205 112 int32_t id; 206 113 207 /** Extended usage page*/114 /** */ 208 115 uint16_t extended_usage_page; 209 210 /** Array of usages specified for this item */211 116 uint32_t usages[USB_HID_MAX_USAGES]; 212 213 /** Length of usages array */214 117 int usages_count; 215 118 216 /** Usage page*/119 /** */ 217 120 uint32_t usage_page; 218 121 219 /** Minimum valid usage index */ 220 int32_t usage_minimum; 221 222 /** Maximum valid usage index */ 223 int32_t usage_maximum; 224 225 /** Minimum valid logical value */ 122 /** */ 123 uint32_t usage_minimum; 124 /** */ 125 uint32_t usage_maximum; 126 /** */ 226 127 int32_t logical_minimum; 227 228 /** Maximum valid logical value */ 128 /** */ 229 129 int32_t logical_maximum; 230 231 /** Length of the items in bits*/ 130 /** */ 232 131 int32_t size; 233 234 /** COunt of items*/ 132 /** */ 235 133 int32_t count; 236 237 /** Bit offset of the item in report */ 134 /** */ 238 135 size_t offset; 239 240 /** Unit exponent */ 136 /** */ 241 137 int32_t unit_exponent; 242 /** Unit of the value*/138 /** */ 243 139 int32_t unit; 244 140 245 /** String index*/141 /** */ 246 142 uint32_t string_index; 247 248 /** Minimum valid string index */ 143 /** */ 249 144 uint32_t string_minimum; 250 251 /** Maximum valid string index */ 145 /** */ 252 146 uint32_t string_maximum; 253 254 /** The designator index */ 147 /** */ 255 148 uint32_t designator_index; 256 257 /** Minimum valid designator value*/ 149 /** */ 258 150 uint32_t designator_minimum; 259 260 /** Maximum valid designator value*/ 151 /** */ 261 152 uint32_t designator_maximum; 262 263 /** Minimal valid physical value*/ 153 /** */ 264 154 int32_t physical_minimum; 265 266 /** Maximal valid physical value */ 155 /** */ 267 156 int32_t physical_maximum; 268 157 269 /** Items attributes*/158 /** */ 270 159 uint8_t item_flags; 271 160 272 /** Report type */273 161 usb_hid_report_type_t type; 274 162 275 163 /** current collection path*/ 276 164 usb_hid_report_path_t *usage_path; 277 278 /** Unused*/ 165 /** */ 279 166 link_t link; 280 167 281 168 int in_delimiter; 282 169 } usb_hid_report_item_t; 283 /*---------------------------------------------------------------------------*/ 284 /** 285 * Enum of the keyboard modifiers 286 */ 170 171 /** HID parser callbacks for IN items. */ 172 typedef struct { 173 /** Callback for keyboard. 174 * 175 * @param key_codes Array of pressed key (including modifiers). 176 * @param count Length of @p key_codes. 177 * @param arg Custom argument. 178 */ 179 void (*keyboard)(const uint8_t *key_codes, size_t count, const uint8_t report_id, void *arg); 180 } usb_hid_report_in_callbacks_t; 181 182 287 183 typedef enum { 288 184 USB_HID_MOD_LCTRL = 0x01, … … 308 204 USB_HID_MOD_RGUI 309 205 }; 310 /*---------------------------------------------------------------------------*/311 312 206 313 207 #endif
Note:
See TracChangeset
for help on using the changeset viewer.