Changeset fcbcaae9 in mainline
- Timestamp:
- 2011-05-23T14:55:46Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fb2de0a
- Parents:
- 563ead9 (diff), c9256c5 (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. - Files:
-
- 1 added
- 4 deleted
- 17 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
.bzrignore
r563ead9 rfcbcaae9 7 7 *.map 8 8 *.disasm 9 *.lo 10 *.la 11 *.so.* 12 *.so0 9 13 _link.ld 10 14 ./*.iso -
uspace/Makefile.common
r563ead9 rfcbcaae9 131 131 endif 132 132 endif 133 # Build static whenever we use libusb because that library uses 134 # thread local variables 135 ifneq ($(findstring usb, $(LIBS)),) 136 STATIC_BUILD = y 137 endif 133 138 134 139 ifeq ($(STATIC_BUILD), y) -
uspace/app/lsusb/main.c
r563ead9 rfcbcaae9 45 45 #include <devmap.h> 46 46 #include <usb/dev/hub.h> 47 #include <usb/h ost.h>47 #include <usb/hc.h> 48 48 49 49 #define NAME "lsusb" -
uspace/app/mkbd/main.c
r563ead9 rfcbcaae9 45 45 #include <devmap.h> 46 46 #include <usb/dev/hub.h> 47 #include <usb/host.h> 48 #include <usb/driver.h> 47 #include <usb/hc.h> 49 48 #include <usb/dev/pipes.h> 50 49 … … 173 172 /* Try to get its address. */ 174 173 if (!addr_found) { 175 addr = usb_ device_get_assigned_address(dev_handle);174 addr = usb_hc_get_address_by_handle(dev_handle); 176 175 if (addr >= 0) { 177 176 addr_found = true; -
uspace/app/usbinfo/main.c
r563ead9 rfcbcaae9 43 43 #include <devman.h> 44 44 #include <devmap.h> 45 #include <usb/ dev/hc.h>45 #include <usb/hc.h> 46 46 #include <usb/dev/pipes.h> 47 #include <usb/host.h>48 #include <usb/driver.h>49 47 #include "usbinfo.h" 50 51 static bool try_parse_class_and_address(const char *path,52 devman_handle_t *out_hc_handle, usb_address_t *out_device_address)53 {54 size_t class_index;55 size_t address;56 int rc;57 char *ptr;58 59 rc = str_size_t(path, &ptr, 10, false, &class_index);60 if (rc != EOK) {61 return false;62 }63 if ((*ptr == ':') || (*ptr == '.')) {64 ptr++;65 } else {66 return false;67 }68 rc = str_size_t(ptr, NULL, 10, true, &address);69 if (rc != EOK) {70 return false;71 }72 rc = usb_ddf_get_hc_handle_by_class(class_index, out_hc_handle);73 if (rc != EOK) {74 return false;75 }76 if (out_device_address != NULL) {77 *out_device_address = (usb_address_t) address;78 }79 return true;80 }81 82 static bool resolve_hc_handle_and_dev_addr(const char *devpath,83 devman_handle_t *out_hc_handle, usb_address_t *out_device_address)84 {85 int rc;86 87 /* Hack for QEMU to save-up on typing ;-). */88 if (str_cmp(devpath, "qemu") == 0) {89 devpath = "/hw/pci0/00:01.2/uhci-rh/usb00_a1";90 }91 92 /* Hack for virtual keyboard. */93 if (str_cmp(devpath, "virt") == 0) {94 devpath = "/virt/usbhc/usb00_a1/usb00_a2";95 }96 97 if (try_parse_class_and_address(devpath,98 out_hc_handle, out_device_address)) {99 return true;100 }101 102 char *path = str_dup(devpath);103 if (path == NULL) {104 return ENOMEM;105 }106 107 devman_handle_t hc = 0;108 bool hc_found = false;109 usb_address_t addr = 0;110 bool addr_found = false;111 112 /* Remove suffixes and hope that we will encounter device node. */113 while (str_length(path) > 0) {114 /* Get device handle first. */115 devman_handle_t dev_handle;116 rc = devman_device_get_handle(path, &dev_handle, 0);117 if (rc != EOK) {118 free(path);119 return false;120 }121 122 /* Try to find its host controller. */123 if (!hc_found) {124 rc = usb_hc_find(dev_handle, &hc);125 if (rc == EOK) {126 hc_found = true;127 }128 }129 /* Try to get its address. */130 if (!addr_found) {131 addr = usb_device_get_assigned_address(dev_handle);132 if (addr >= 0) {133 addr_found = true;134 }135 }136 137 /* Speed-up. */138 if (hc_found && addr_found) {139 break;140 }141 142 /* Remove the last suffix. */143 char *slash_pos = str_rchr(path, '/');144 if (slash_pos != NULL) {145 *slash_pos = 0;146 }147 }148 149 free(path);150 151 if (hc_found && addr_found) {152 if (out_hc_handle != NULL) {153 *out_hc_handle = hc;154 }155 if (out_device_address != NULL) {156 *out_device_address = addr;157 }158 return true;159 } else {160 return false;161 }162 }163 48 164 49 static void print_usage(char *app_name) … … 300 185 devman_handle_t hc_handle = 0; 301 186 usb_address_t dev_addr = 0; 302 bool found = resolve_hc_handle_and_dev_addr(devpath,303 &hc_handle, &dev_addr );304 if ( !found) {187 int rc = usb_resolve_device_handle(devpath, 188 &hc_handle, &dev_addr, NULL); 189 if (rc != EOK) { 305 190 fprintf(stderr, NAME ": device `%s' not found " 306 191 "or not of USB kind, skipping.\n", -
uspace/drv/uhci-rhd/port.h
r563ead9 rfcbcaae9 38 38 #include <fibril.h> 39 39 #include <ddf/driver.h> 40 #include <usb/ dev/hc.h> /* usb_hc_connection_t */40 #include <usb/hc.h> /* usb_hc_connection_t */ 41 41 42 42 typedef uint16_t port_status_t; -
uspace/lib/usb/Makefile
r563ead9 rfcbcaae9 37 37 src/ddfiface.c \ 38 38 src/debug.c \ 39 src/driver.c \40 39 src/dump.c \ 41 src/host.c \ 40 src/hc.c \ 41 src/resolve.c \ 42 42 src/usb.c 43 43 -
uspace/lib/usb/include/usb/hc.h
r563ead9 rfcbcaae9 27 27 */ 28 28 29 /** @addtogroup libusb dev29 /** @addtogroup libusb 30 30 * @{ 31 31 */ 32 32 /** @file 33 * General communication between device drivers andhost controller driver.33 * General communication with host controller driver. 34 34 */ 35 #ifndef LIBUSB DEV_HC_H_36 #define LIBUSB DEV_HC_H_35 #ifndef LIBUSB_HC_H_ 36 #define LIBUSB_HC_H_ 37 37 38 38 #include <sys/types.h> … … 57 57 bool usb_hc_connection_is_opened(const usb_hc_connection_t *); 58 58 int usb_hc_connection_close(usb_hc_connection_t *); 59 int usb_hc_get_handle_by_address(usb_hc_connection_t *, usb_address_t, 60 devman_handle_t *); 59 61 62 int usb_hc_get_address_by_handle(devman_handle_t); 63 64 int usb_hc_find(devman_handle_t, devman_handle_t *); 65 66 int usb_resolve_device_handle(const char *, devman_handle_t *, usb_address_t *, 67 devman_handle_t *); 68 69 int usb_ddf_get_hc_handle_by_class(size_t, devman_handle_t *); 60 70 61 71 -
uspace/lib/usb/src/ddfiface.c
r563ead9 rfcbcaae9 37 37 #include <async.h> 38 38 #include <usb/ddfiface.h> 39 #include <usb/ driver.h>39 #include <usb/hc.h> 40 40 #include <usb/debug.h> 41 41 #include <errno.h> -
uspace/lib/usb/src/hc.c
r563ead9 rfcbcaae9 27 27 */ 28 28 29 /** @addtogroup libusb dev29 /** @addtogroup libusb 30 30 * @{ 31 31 */ 32 32 /** @file 33 * General communication between device drivers and host controller driver.33 * General communication with host controller driver (implementation). 34 34 */ 35 35 #include <devman.h> 36 36 #include <async.h> 37 #include <dev_iface.h> 37 38 #include <usb_iface.h> 38 #include <usb /dev/hc.h>39 #include <usb/ driver.h>39 #include <usbhc_iface.h> 40 #include <usb/hc.h> 40 41 #include <usb/debug.h> 41 42 #include <errno.h> … … 143 144 } 144 145 146 /** Get handle of USB device with given address. 147 * 148 * @param[in] connection Opened connection to host controller. 149 * @param[in] address Address of device in question. 150 * @param[out] handle Where to write the device handle. 151 * @return Error code. 152 */ 153 int usb_hc_get_handle_by_address(usb_hc_connection_t *connection, 154 usb_address_t address, devman_handle_t *handle) 155 { 156 if (!usb_hc_connection_is_opened(connection)) { 157 return ENOENT; 158 } 159 160 sysarg_t tmp; 161 int rc = async_req_2_1(connection->hc_phone, 162 DEV_IFACE_ID(USBHC_DEV_IFACE), 163 IPC_M_USBHC_GET_HANDLE_BY_ADDRESS, 164 address, &tmp); 165 if ((rc == EOK) && (handle != NULL)) { 166 *handle = tmp; 167 } 168 169 return rc; 170 } 171 172 /** Tell USB address assigned to device with given handle. 173 * 174 * @param dev_handle Devman handle of the USB device in question. 175 * @return USB address or negative error code. 176 */ 177 usb_address_t usb_hc_get_address_by_handle(devman_handle_t dev_handle) 178 { 179 int parent_phone = devman_parent_device_connect(dev_handle, 180 IPC_FLAG_BLOCKING); 181 if (parent_phone < 0) { 182 return parent_phone; 183 } 184 185 sysarg_t address; 186 187 int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE), 188 IPC_M_USB_GET_ADDRESS, 189 dev_handle, &address); 190 191 if (rc != EOK) { 192 return rc; 193 } 194 195 async_hangup(parent_phone); 196 197 return (usb_address_t) address; 198 } 199 200 201 /** Get host controller handle by its class index. 202 * 203 * @param class_index Class index for the host controller. 204 * @param hc_handle Where to store the HC handle 205 * (can be NULL for existence test only). 206 * @return Error code. 207 */ 208 int usb_ddf_get_hc_handle_by_class(size_t class_index, 209 devman_handle_t *hc_handle) 210 { 211 char *class_index_str; 212 devman_handle_t hc_handle_tmp; 213 int rc; 214 215 rc = asprintf(&class_index_str, "%zu", class_index); 216 if (rc < 0) { 217 return ENOMEM; 218 } 219 rc = devman_device_get_handle_by_class("usbhc", class_index_str, 220 &hc_handle_tmp, 0); 221 free(class_index_str); 222 if (rc != EOK) { 223 return rc; 224 } 225 226 if (hc_handle != NULL) { 227 *hc_handle = hc_handle_tmp; 228 } 229 230 return EOK; 231 } 232 233 /** Find host controller handle that is ancestor of given device. 234 * 235 * @param[in] device_handle Device devman handle. 236 * @param[out] hc_handle Where to store handle of host controller 237 * controlling device with @p device_handle handle. 238 * @return Error code. 239 */ 240 int usb_hc_find(devman_handle_t device_handle, devman_handle_t *hc_handle) 241 { 242 int parent_phone = devman_parent_device_connect(device_handle, 243 IPC_FLAG_BLOCKING); 244 if (parent_phone < 0) { 245 return parent_phone; 246 } 247 248 devman_handle_t h; 249 int rc = async_req_1_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE), 250 IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &h); 251 252 async_hangup(parent_phone); 253 254 if (rc != EOK) { 255 return rc; 256 } 257 258 if (hc_handle != NULL) { 259 *hc_handle = h; 260 } 261 262 return EOK; 263 } 264 145 265 /** 146 266 * @} -
uspace/lib/usbdev/Makefile
r563ead9 rfcbcaae9 46 46 src/pipesio.c \ 47 47 src/recognise.c \ 48 src/request.c \ 49 src/usbdevice.c 48 src/request.c 50 49 51 50 include $(USPACE_PREFIX)/Makefile.common -
uspace/lib/usbdev/include/usb/dev/hub.h
r563ead9 rfcbcaae9 39 39 40 40 #include <sys/types.h> 41 #include <usb/ dev/hc.h>41 #include <usb/hc.h> 42 42 43 43 int usb_hc_new_device_wrapper(ddf_dev_t *, usb_hc_connection_t *, usb_speed_t, … … 63 63 const usb_hc_attached_device_t *); 64 64 int usb_hc_unregister_device(usb_hc_connection_t *, usb_address_t); 65 int usb_hc_get_handle_by_address(usb_hc_connection_t *, usb_address_t,66 devman_handle_t *);67 65 68 66 #endif -
uspace/lib/usbdev/include/usb/dev/pipes.h
r563ead9 rfcbcaae9 38 38 #include <sys/types.h> 39 39 #include <usb/usb.h> 40 #include <usb/ dev/hc.h>40 #include <usb/hc.h> 41 41 #include <usb/descriptor.h> 42 42 #include <ipc/devman.h> … … 163 163 164 164 int usb_device_get_assigned_interface(ddf_dev_t *); 165 usb_address_t usb_device_get_assigned_address(devman_handle_t);166 165 167 166 int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *, -
uspace/lib/usbdev/src/hub.c
r563ead9 rfcbcaae9 120 120 } 121 121 122 /** Get handle of USB device with given address.123 *124 * @param[in] connection Opened connection to host controller.125 * @param[in] address Address of device in question.126 * @param[out] handle Where to write the device handle.127 * @return Error code.128 */129 int usb_hc_get_handle_by_address(usb_hc_connection_t *connection,130 usb_address_t address, devman_handle_t *handle)131 {132 CHECK_CONNECTION(connection);133 134 sysarg_t tmp;135 int rc = async_req_2_1(connection->hc_phone,136 DEV_IFACE_ID(USBHC_DEV_IFACE),137 IPC_M_USBHC_GET_HANDLE_BY_ADDRESS,138 address, &tmp);139 if ((rc == EOK) && (handle != NULL)) {140 *handle = tmp;141 }142 143 return rc;144 }145 122 146 123 static void unregister_control_endpoint_on_default_address( -
uspace/lib/usbdev/src/pipes.c
r563ead9 rfcbcaae9 36 36 #include <usb/dev/pipes.h> 37 37 #include <usb/debug.h> 38 #include <usb/ driver.h>38 #include <usb/hc.h> 39 39 #include <usbhc_iface.h> 40 40 #include <usb_iface.h> … … 97 97 98 98 return (int) iface_no; 99 }100 101 /** Tell USB address assigned to given device.102 *103 * @param dev_handle Devman handle of the USB device in question.104 * @return USB address or negative error code.105 */106 usb_address_t usb_device_get_assigned_address(devman_handle_t dev_handle)107 {108 int parent_phone = devman_parent_device_connect(dev_handle,109 IPC_FLAG_BLOCKING);110 if (parent_phone < 0) {111 return parent_phone;112 }113 114 sysarg_t address;115 116 int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),117 IPC_M_USB_GET_ADDRESS,118 dev_handle, &address);119 120 if (rc != EOK) {121 return rc;122 }123 124 async_hangup(parent_phone);125 126 return (usb_address_t) address;127 99 } 128 100 -
uspace/lib/usbhid/include/usb/hid/hid_report_items.h
r563ead9 rfcbcaae9 27 27 */ 28 28 29 /** @addtogroup libusb hid29 /** @addtogroup libusb 30 30 * @{ 31 31 */ 32 32 /** @file 33 * @brief USB HID parser.34 */ 35 #ifndef LIBUSB HID_HID_REPORT_ITEMS_H_36 #define LIBUSB HID_HID_REPORT_ITEMS_H_33 * @brief USB HID Report descriptor item tags. 34 */ 35 #ifndef LIBUSB_HID_REPORT_ITEMS_H_ 36 #define LIBUSB_HID_REPORT_ITEMS_H_ 37 37 38 38 #include <stdint.h> 39 39 40 /** 40 /*---------------------------------------------------------------------------*/ 41 /* 41 42 * Item prefix 42 43 */ 44 45 /** Returns size of item data in bytes */ 43 46 #define USB_HID_ITEM_SIZE(data) ((uint8_t)(data & 0x3)) 47 48 /** Returns item tag */ 44 49 #define USB_HID_ITEM_TAG(data) ((uint8_t)((data & 0xF0) >> 4)) 50 51 /** Returns class of item tag */ 45 52 #define USB_HID_ITEM_TAG_CLASS(data) ((uint8_t)((data & 0xC) >> 2)) 53 54 /** Returns if the item is the short item or long item. Long items are not 55 * supported. */ 46 56 #define USB_HID_ITEM_IS_LONG(data) (data == 0xFE) 47 57 48 49 /* *58 /*---------------------------------------------------------------------------*/ 59 /* 50 60 * Extended usage macros 51 61 */ 62 63 /** Recognizes if the given usage is extended (contains also usage page). */ 52 64 #define USB_HID_IS_EXTENDED_USAGE(usage) ((usage & 0xFFFF0000) != 0) 65 66 /** Cuts usage page of the extended usage. */ 53 67 #define USB_HID_EXTENDED_USAGE_PAGE(usage) ((usage & 0xFFFF0000) >> 16) 68 69 /** Cuts usage of the extended usage */ 54 70 #define USB_HID_EXTENDED_USAGE(usage) (usage & 0xFFFF) 55 71 56 /** 72 /*---------------------------------------------------------------------------*/ 73 /* 57 74 * Input/Output/Feature Item flags 58 75 */ 59 /** Constant (1) / Variable (0) */ 76 /** 77 * Indicates whether the item is data (0) or a constant (1) value. Data 78 * indicates the item is defining report fields that contain modifiable device 79 * data. Constant indicates the item is a static read-only field in a report 80 * and cannot be modified (written) by the host. 81 */ 60 82 #define USB_HID_ITEM_FLAG_CONSTANT(flags) ((flags & 0x1) == 0x1) 61 /** Variable (1) / Array (0) */ 83 84 /** 85 * Indicates whether the item creates variable (1) or array (0) data fields in 86 * reports. 87 */ 62 88 #define USB_HID_ITEM_FLAG_VARIABLE(flags) ((flags & 0x2) == 0x2) 63 /** Absolute / Relative*/ 89 90 /** 91 * Indicates whether the data is absolute (0) (based on a fixed origin) or 92 * relative (1) (indicating the change in value from the last report). Mouse 93 * devices usually provide relative data, while tablets usually provide 94 * absolute data. 95 */ 64 96 #define USB_HID_ITEM_FLAG_RELATIVE(flags) ((flags & 0x4) == 0x4) 65 /** Wrap / No Wrap */ 97 98 /** 99 * Indicates whether the data “rolls over” when reaching either the extreme 100 * high or low value. For example, a dial that can spin freely 360 degrees 101 * might output values from 0 to 10. If Wrap is indicated, the next value 102 * reported after passing the 10 position in the increasing direction would be 103 * 0. 104 */ 66 105 #define USB_HID_ITEM_FLAG_WRAP(flags) ((flags & 0x8) == 0x8) 106 107 /** 108 * Indicates whether the raw data from the device has been processed in some 109 * way, and no longer represents a linear relationship between what is 110 * measured and the data that is reported. 111 */ 67 112 #define USB_HID_ITEM_FLAG_LINEAR(flags) ((flags & 0x10) == 0x10) 113 114 /** 115 * Indicates whether the control has a preferred state to which it will return 116 * when the user is not physically interacting with the control. Push buttons 117 * (as opposed to toggle buttons) and self- centering joysticks are examples. 118 */ 68 119 #define USB_HID_ITEM_FLAG_PREFERRED(flags) ((flags & 0x20) == 0x20) 120 121 /** 122 * Indicates whether the control has a state in which it is not sending 123 * meaningful data. One possible use of the null state is for controls that 124 * require the user to physically interact with the control in order for it to 125 * report useful data. 126 */ 69 127 #define USB_HID_ITEM_FLAG_POSITION(flags) ((flags & 0x40) == 0x40) 128 129 /** 130 * Indicates whether the Feature or Output control's value should be changed 131 * by the host or not. Volatile output can change with or without host 132 * interaction. To avoid synchronization problems, volatile controls should be 133 * relative whenever possible. 134 */ 70 135 #define USB_HID_ITEM_FLAG_VOLATILE(flags) ((flags & 0x80) == 0x80) 136 137 /** 138 * Indicates that the control emits a fixed-size stream of bytes. The contents 139 * of the data field are determined by the application. The contents of the 140 * buffer are not interpreted as a single numeric quantity. Report data 141 * defined by a Buffered Bytes item must be aligned on an 8-bit boundary. 142 */ 71 143 #define USB_HID_ITEM_FLAG_BUFFERED(flags) ((flags & 0x100) == 0x100) 72 144 145 /*---------------------------------------------------------------------------*/ 146 73 147 /* MAIN ITEMS */ 74 #define USB_HID_TAG_CLASS_MAIN 0x0 75 #define USB_HID_REPORT_TAG_INPUT 0x8 76 #define USB_HID_REPORT_TAG_OUTPUT 0x9 77 #define USB_HID_REPORT_TAG_FEATURE 0xB 148 149 /** 150 * Main items are used to either define or group certain types of data fields 151 * within a Report descriptor. 152 */ 153 #define USB_HID_TAG_CLASS_MAIN 0x0 154 155 /** 156 * An Input item describes information about the data provided by one or more 157 * physical controls. An application can use this information to interpret the 158 * data provided by the device. All data fields defined in a single item share 159 * an identical data format. 160 */ 161 #define USB_HID_REPORT_TAG_INPUT 0x8 162 163 /** 164 * The Output item is used to define an output data field in a report. This 165 * item is similar to an Input item except it describes data sent to the 166 * device—for example, LED states. 167 */ 168 #define USB_HID_REPORT_TAG_OUTPUT 0x9 169 170 /** 171 * Feature items describe device configuration information that can be sent to 172 * the device. 173 */ 174 #define USB_HID_REPORT_TAG_FEATURE 0xB 175 176 /** 177 * A Collection item identifies a relationship between two or more data 178 * (Input, Output, or Feature.) 179 */ 78 180 #define USB_HID_REPORT_TAG_COLLECTION 0xA 181 182 /** 183 * While the Collection item opens a collection of data, the End Collection 184 * item closes a collection. 185 */ 79 186 #define USB_HID_REPORT_TAG_END_COLLECTION 0xC 80 187 188 /*---------------------------------------------------------------------------*/ 189 81 190 /* GLOBAL ITEMS */ 82 #define USB_HID_TAG_CLASS_GLOBAL 0x1 191 192 /** 193 * Global items describe rather than define data from a control. 194 */ 195 #define USB_HID_TAG_CLASS_GLOBAL 0x1 196 197 /** 198 * Unsigned integer specifying the current Usage Page. Since a usage are 32 199 * bit values, Usage Page items can be used to conserve space in a report 200 * descriptor by setting the high order 16 bits of a subsequent usages. Any 201 * usage that follows which is defines 16 bits or less is interpreted as a 202 * Usage ID and concatenated with the Usage Page to form a 32 bit Usage. 203 */ 83 204 #define USB_HID_REPORT_TAG_USAGE_PAGE 0x0 205 206 /** 207 * Extent value in logical units. This is the minimum value that a variable 208 * or array item will report. For example, a mouse reporting x position values 209 * from 0 to 128 would have a Logical Minimum of 0 and a Logical Maximum of 210 * 128. 211 */ 84 212 #define USB_HID_REPORT_TAG_LOGICAL_MINIMUM 0x1 213 214 /** 215 * Extent value in logical units. This is the maximum value that a variable 216 * or array item will report. 217 */ 85 218 #define USB_HID_REPORT_TAG_LOGICAL_MAXIMUM 0x2 86 #define USB_HID_REPORT_TAG_PHYSICAL_MINIMUM 0x3 87 #define USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM 0x4 219 220 /** 221 * Minimum value for the physical extent of a variable item. This represents 222 * the Logical Minimum with units applied to it. 223 */ 224 #define USB_HID_REPORT_TAG_PHYSICAL_MINIMUM 0x3 225 226 /** 227 * Maximum value for the physical extent of a variable item. 228 */ 229 #define USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM 0x4 230 231 /** 232 * Value of the unit exponent in base 10. See the table later in this section 233 * for more information. 234 */ 88 235 #define USB_HID_REPORT_TAG_UNIT_EXPONENT 0x5 89 #define USB_HID_REPORT_TAG_UNIT 0x6 236 237 /** 238 * Unit values. 239 */ 240 #define USB_HID_REPORT_TAG_UNIT 0x6 241 242 /** 243 * Unsigned integer specifying the size of the report fields in bits. This 244 * allows the parser to build an item map for the report handler to use. 245 */ 90 246 #define USB_HID_REPORT_TAG_REPORT_SIZE 0x7 247 248 /** 249 * Unsigned value that specifies the Report ID. If a Report ID tag is used 250 * anywhere in Report descriptor, all data reports for the device are preceded 251 * by a single byte ID field. All items succeeding the first Report ID tag but 252 * preceding a second Report ID tag are included in a report prefixed by a 253 * 1-byte ID. All items succeeding the second but preceding a third Report ID 254 * tag are included in a second report prefixed by a second ID, and so on. 255 */ 91 256 #define USB_HID_REPORT_TAG_REPORT_ID 0x8 257 258 /** 259 * Unsigned integer specifying the number of data fields for the item; 260 * determines how many fields are included in the report for this particular 261 * item (and consequently how many bits are added to the report). 262 */ 92 263 #define USB_HID_REPORT_TAG_REPORT_COUNT 0x9 93 #define USB_HID_REPORT_TAG_PUSH 0xA 94 #define USB_HID_REPORT_TAG_POP 0xB 95 264 265 /** 266 * Places a copy of the global item state table on the stack. 267 */ 268 #define USB_HID_REPORT_TAG_PUSH 0xA 269 270 /** 271 * Replaces the item state table with the top structure from the stack. 272 */ 273 #define USB_HID_REPORT_TAG_POP 0xB 274 275 /*---------------------------------------------------------------------------*/ 96 276 97 277 /* LOCAL ITEMS */ 98 #define USB_HID_TAG_CLASS_LOCAL 0x2 99 #define USB_HID_REPORT_TAG_USAGE 0x0 100 #define USB_HID_REPORT_TAG_USAGE_MINIMUM 0x1 101 #define USB_HID_REPORT_TAG_USAGE_MAXIMUM 0x2 102 #define USB_HID_REPORT_TAG_DESIGNATOR_INDEX 0x3 278 279 /** 280 * Local item tags define characteristics of controls. These items do not 281 * carry over to the next Main item. If a Main item defines more than one 282 * control, it may be preceded by several similar Local item tags. For 283 * example, an Input item may have several Usage tags associated with it, one 284 * for each control. 285 */ 286 #define USB_HID_TAG_CLASS_LOCAL 0x2 287 288 /** 289 * Usage index for an item usage; represents a suggested usage for the item or 290 * collection. In the case where an item represents multiple controls, a Usage 291 * tag may suggest a usage for every variable or element in an array. 292 */ 293 #define USB_HID_REPORT_TAG_USAGE 0x0 294 295 /** 296 * Defines the starting usage associated with an array or bitmap. 297 */ 298 #define USB_HID_REPORT_TAG_USAGE_MINIMUM 0x1 299 300 /** 301 * Defines the ending usage associated with an array or bitmap. 302 */ 303 #define USB_HID_REPORT_TAG_USAGE_MAXIMUM 0x2 304 305 /** 306 * Determines the body part used for a control. Index points to a designator 307 * in the Physical descriptor. 308 */ 309 #define USB_HID_REPORT_TAG_DESIGNATOR_INDEX 0x3 310 311 /** 312 * Defines the index of the starting designator associated with an array or 313 * bitmap. 314 */ 103 315 #define USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM 0x4 316 317 /** 318 * Defines the index of the ending designator associated with an array or 319 * bitmap. 320 */ 104 321 #define USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM 0x5 105 #define USB_HID_REPORT_TAG_STRING_INDEX 0x7 106 #define USB_HID_REPORT_TAG_STRING_MINIMUM 0x8 107 #define USB_HID_REPORT_TAG_STRING_MAXIMUM 0x9 108 #define USB_HID_REPORT_TAG_DELIMITER 0xA 322 323 /** 324 * String index for a String descriptor; allows a string to be associated with 325 * a particular item or control. 326 */ 327 #define USB_HID_REPORT_TAG_STRING_INDEX 0x7 328 329 /** 330 * Specifies the first string index when assigning a group of sequential 331 * strings to controls in an array or bitmap. 332 */ 333 #define USB_HID_REPORT_TAG_STRING_MINIMUM 0x8 334 335 /** 336 * Specifies the last string index when assigning a group of sequential 337 * strings to controls in an array or bitmap. 338 */ 339 #define USB_HID_REPORT_TAG_STRING_MAXIMUM 0x9 340 341 /** 342 * Defines the beginning or end of a set of local items (1 = open set, 0 = 343 * close set). 344 * 345 * Usages other than the first (most preferred) usage defined are not 346 * accessible by system software. 347 */ 348 #define USB_HID_REPORT_TAG_DELIMITER 0xA 349 350 /*---------------------------------------------------------------------------*/ 109 351 110 352 #endif -
uspace/lib/usbhid/include/usb/hid/hiddescriptor.h
r563ead9 rfcbcaae9 27 27 */ 28 28 29 /** @addtogroup libusb hid29 /** @addtogroup libusb 30 30 * @{ 31 31 */ … … 33 33 * USB HID report descriptor and report data parser 34 34 */ 35 #ifndef LIBUSB HID_HIDDESCRIPTOR_H_36 #define LIBUSB HID_HIDDESCRIPTOR_H_35 #ifndef LIBUSB_HIDDESCRIPTOR_H_ 36 #define LIBUSB_HIDDESCRIPTOR_H_ 37 37 38 38 #include <stdint.h> … … 42 42 #include <usb/hid/hidtypes.h> 43 43 44 45 /*46 * Descriptor parser functions47 */48 49 /** */50 44 int usb_hid_parse_report_descriptor(usb_hid_report_t *report, 51 45 const uint8_t *data, size_t size); 52 46 53 /** */54 47 void usb_hid_free_report(usb_hid_report_t *report); 55 48 56 /** */57 49 void usb_hid_descriptor_print(usb_hid_report_t *report); 58 50 51 int usb_hid_report_init(usb_hid_report_t *report); 59 52 60 int usb_hid_report_init(usb_hid_report_t *report);61 53 int usb_hid_report_append_fields(usb_hid_report_t *report, 62 54 usb_hid_report_item_t *report_item); 63 55 64 56 usb_hid_report_description_t * usb_hid_report_find_description(const usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type); 57 65 58 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size, 66 59 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 60 67 61 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size, 68 62 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 63 69 64 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size, 70 65 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 66 71 67 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, size_t item_size, 72 68 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 73 69 74 70 void usb_hid_descriptor_print_list(link_t *head); 71 75 72 void usb_hid_report_reset_local_items(usb_hid_report_item_t *report_item); 73 76 74 void usb_hid_free_report_list(link_t *head); 75 77 76 usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item); 77 78 78 uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size); 79 79 80 80 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path); 81 82 81 83 #endif 82 84 /** -
uspace/lib/usbhid/include/usb/hid/hidpath.h
r563ead9 rfcbcaae9 27 27 */ 28 28 29 /** @addtogroup libusb hid29 /** @addtogroup libusb 30 30 * @{ 31 31 */ … … 33 33 * USB HID report descriptor and report data parser 34 34 */ 35 #ifndef LIBUSB HID_HIDPATH_H_36 #define LIBUSB HID_HIDPATH_H_35 #ifndef LIBUSB_HIDPATH_H_ 36 #define LIBUSB_HIDPATH_H_ 37 37 38 38 #include <usb/hid/hidparser.h> … … 40 40 #include <adt/list.h> 41 41 42 43 /*---------------------------------------------------------------------------*/ 42 44 /** 43 * Description of path of usage pages and usages in report descriptor 45 * Flags of usage paths comparison modes. 46 * 44 47 */ 45 /** Wanted usage path must be exactly the same as the searched one */ 48 /** Wanted usage path must be exactly the same as the searched one. 49 * This option cannot be combined with the others. 50 */ 46 51 #define USB_HID_PATH_COMPARE_STRICT 0 47 /** Wanted usage path must be the suffix in the searched one */ 52 53 /** 54 * Wanted usage path must be the suffix in the searched one. 55 */ 48 56 #define USB_HID_PATH_COMPARE_END 1 49 /** */ 57 58 /** 59 * Only usage page are compared along the usage path. 60 * This option can be combined with others. 61 */ 50 62 #define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY 2 51 /** Searched usage page must be prefix of the other one */ 63 64 /** 65 * Searched usage page must be prefix of the other one. 66 */ 52 67 #define USB_HID_PATH_COMPARE_BEGIN 4 53 /** Searched couple of usage page and usage can be anywhere in usage path */ 68 69 /** 70 * Searched couple of usage page and usage can be anywhere in usage path. 71 * This option is deprecated. 72 */ 54 73 #define USB_HID_PATH_COMPARE_ANYWHERE 8 55 74 56 57 /** Collection usage path structure */ 75 /*----------------------------------------------------------------------------*/ 76 /** 77 * Item of usage path structure. Last item of linked list describes one item 78 * in report, the others describe superior Collection tags. Usage and Usage 79 * page of report item can be changed due to data in report. 80 */ 58 81 typedef struct { 59 /** */82 /** Usage page of report item. Zero when usage page can be changed. */ 60 83 uint32_t usage_page; 61 /** */84 /** Usage of report item. Zero when usage can be changed. */ 62 85 uint32_t usage; 63 86 87 /** Attribute of Collection tag in report descriptor*/ 64 88 uint8_t flags; 65 /** */ 89 90 /** Linked list structure*/ 66 91 link_t link; 67 92 } usb_hid_report_usage_path_t; 68 93 69 /** */ 94 95 /*---------------------------------------------------------------------------*/ 96 /** 97 * USB HID usage path structure. 98 * */ 70 99 typedef struct { 71 /** */100 /** Length of usage path */ 72 101 int depth; 102 103 /** Report id. Zero is reserved and means that report id is not used. */ 73 104 uint8_t report_id; 74 105 75 /** */106 /** Linked list structure. */ 76 107 link_t link; /* list */ 77 108 78 link_t head; /* head of list of usage paths */ 109 /** Head of the list of usage path items. */ 110 link_t head; 79 111 80 112 } usb_hid_report_path_t; 81 113 82 /* **/114 /*---------------------------------------------------------------------------*/ 83 115 usb_hid_report_path_t *usb_hid_report_path(void); 84 116 85 /** */86 117 void usb_hid_report_path_free(usb_hid_report_path_t *path); 87 118 88 /** */89 119 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path, 90 120 uint8_t report_id); 91 121 92 /** */93 122 int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, 94 123 int32_t usage_page, int32_t usage); 95 124 96 /** */97 125 void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path); 98 126 99 /** */100 127 void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path); 101 128 102 /** */103 129 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, 104 130 int32_t tag, int32_t data); 105 131 106 /** */107 132 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, 108 133 usb_hid_report_path_t *path, int flags); 109 134 110 /** */111 135 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path); 112 136 -
uspace/lib/usbhid/include/usb/hid/hidtypes.h
r563ead9 rfcbcaae9 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 * Report type 75 */ 47 76 typedef enum { 48 77 USB_HID_REPORT_TYPE_INPUT = 1, … … 51 80 } usb_hid_report_type_t; 52 81 53 82 /*---------------------------------------------------------------------------*/ 83 84 /** 85 * Description of all reports described in one report descriptor. 86 */ 54 87 typedef struct { 55 /** */88 /** Count of available reports. */ 56 89 int report_count; 57 link_t reports; /** list of usb_hid_report_description_t */ 58 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. */ 59 95 link_t collection_paths; 96 97 /** Length of list of usage paths. */ 60 98 int collection_paths_count; 61 99 100 /** Flag whether report ids are used. */ 62 101 int use_report_ids; 102 103 /** Report id of last parsed report. */ 63 104 uint8_t last_report_id; 64 105 65 106 } usb_hid_report_t; 66 107 /*---------------------------------------------------------------------------*/ 108 109 /** 110 * Description of one concrete report 111 */ 67 112 typedef struct { 113 /** Report id. Zero when no report id is used. */ 68 114 uint8_t report_id; 115 116 /** Type of report */ 69 117 usb_hid_report_type_t type; 70 118 119 /** Bit length of the report */ 71 120 size_t bit_length; 121 122 /** Number of items in report */ 72 123 size_t item_length; 73 124 74 link_t report_items; /** list of report items (fields) */ 75 125 /** Linked list of report items in report */ 126 link_t report_items; 127 128 /** Linked list of descriptions. */ 76 129 link_t link; 77 130 } usb_hid_report_description_t; 78 131 /*---------------------------------------------------------------------------*/ 132 133 /** 134 * Description of one field/item in report 135 */ 79 136 typedef struct { 80 137 /** Bit offset of the field */ 81 138 int offset; 139 140 /** Bit size of the field */ 82 141 size_t size; 83 142 143 /** Usage page. Zero when usage page can be changed. */ 84 144 uint16_t usage_page; 145 146 /** Usage. Zero when usage can be changed. */ 85 147 uint16_t usage; 86 148 149 /** Item's attributes */ 87 150 uint8_t item_flags; 151 152 /** Usage/Collection path of the field. */ 88 153 usb_hid_report_path_t *collection_path; 89 154 155 /** 156 * The lowest valid logical value (value with the device operates) 157 */ 90 158 int32_t logical_minimum; 159 160 /** 161 * The greatest valid logical value 162 */ 91 163 int32_t logical_maximum; 164 165 /** 166 * The lowest valid physical value (value with the system operates) 167 */ 92 168 int32_t physical_minimum; 169 170 /** The greatest valid physical value */ 93 171 int32_t physical_maximum; 172 173 /** The lowest valid usage index */ 94 174 int32_t usage_minimum; 175 176 /** The greatest valid usage index */ 95 177 int32_t usage_maximum; 178 179 /** Unit of the value */ 96 180 uint32_t unit; 181 182 /** Unit exponent */ 97 183 uint32_t unit_exponent; 98 184 185 /** Array of possible usages */ 99 186 uint32_t *usages; 187 188 /** Size of the array of usages */ 100 189 size_t usages_count; 101 190 191 /** Parsed value */ 102 192 int32_t value; 103 193 194 /** List to another report items */ 104 195 link_t link; 105 196 } usb_hid_report_field_t; 106 197 107 108 109 /** 110 * state table198 /*---------------------------------------------------------------------------*/ 199 200 /** 201 * State table for report descriptor parsing 111 202 */ 112 203 typedef struct { … … 114 205 int32_t id; 115 206 116 /** */207 /** Extended usage page */ 117 208 uint16_t extended_usage_page; 209 210 /** Array of usages specified for this item */ 118 211 uint32_t usages[USB_HID_MAX_USAGES]; 212 213 /** Length of usages array */ 119 214 int usages_count; 120 215 121 /** */216 /** Usage page*/ 122 217 uint32_t usage_page; 123 218 124 /** */219 /** Minimum valid usage index */ 125 220 int32_t usage_minimum; 126 /** */ 221 222 /** Maximum valid usage index */ 127 223 int32_t usage_maximum; 128 /** */ 224 225 /** Minimum valid logical value */ 129 226 int32_t logical_minimum; 130 /** */ 227 228 /** Maximum valid logical value */ 131 229 int32_t logical_maximum; 132 /** */ 230 231 /** Length of the items in bits*/ 133 232 int32_t size; 134 /** */ 233 234 /** COunt of items*/ 135 235 int32_t count; 136 /** */ 236 237 /** Bit offset of the item in report */ 137 238 size_t offset; 138 /** */ 239 240 /** Unit exponent */ 139 241 int32_t unit_exponent; 140 /** */242 /** Unit of the value */ 141 243 int32_t unit; 142 244 143 /** */245 /** String index */ 144 246 uint32_t string_index; 145 /** */ 247 248 /** Minimum valid string index */ 146 249 uint32_t string_minimum; 147 /** */ 250 251 /** Maximum valid string index */ 148 252 uint32_t string_maximum; 149 /** */ 253 254 /** The designator index */ 150 255 uint32_t designator_index; 151 /** */ 256 257 /** Minimum valid designator value*/ 152 258 uint32_t designator_minimum; 153 /** */ 259 260 /** Maximum valid designator value*/ 154 261 uint32_t designator_maximum; 155 /** */ 262 263 /** Minimal valid physical value*/ 156 264 int32_t physical_minimum; 157 /** */ 265 266 /** Maximal valid physical value */ 158 267 int32_t physical_maximum; 159 268 160 /** */269 /** Items attributes*/ 161 270 uint8_t item_flags; 162 271 272 /** Report type */ 163 273 usb_hid_report_type_t type; 164 274 165 275 /** current collection path*/ 166 276 usb_hid_report_path_t *usage_path; 167 /** */ 277 278 /** Unused*/ 168 279 link_t link; 169 280 170 281 int in_delimiter; 171 282 } 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 283 /*---------------------------------------------------------------------------*/ 284 /** 285 * Enum of the keyboard modifiers 286 */ 185 287 typedef enum { 186 288 USB_HID_MOD_LCTRL = 0x01, … … 206 308 USB_HID_MOD_RGUI 207 309 }; 310 /*---------------------------------------------------------------------------*/ 311 208 312 209 313 #endif
Note:
See TracChangeset
for help on using the changeset viewer.