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