Changes in / [8d3f198:fa8d346] in mainline
- Files:
-
- 8 added
- 3 deleted
- 36 edited
Legend:
- Unmodified
- Added
- Removed
-
.bzrignore
r8d3f198 rfa8d346 7 7 *.map 8 8 *.disasm 9 *.lo10 *.la11 *.so.*12 *.so013 9 _link.ld 14 10 ./*.iso -
uspace/Makefile.common
r8d3f198 rfa8d346 131 131 endif 132 132 endif 133 # Build static whenever we use libusb because that library uses134 # thread local variables135 ifneq ($(findstring usb, $(LIBS)),)136 STATIC_BUILD = y137 endif138 133 139 134 ifeq ($(STATIC_BUILD), y) -
uspace/app/lsusb/main.c
r8d3f198 rfa8d346 45 45 #include <devmap.h> 46 46 #include <usb/dev/hub.h> 47 #include <usb/h c.h>47 #include <usb/host.h> 48 48 49 49 #define NAME "lsusb" -
uspace/app/usbinfo/main.c
r8d3f198 rfa8d346 43 43 #include <devman.h> 44 44 #include <devmap.h> 45 #include <usb/ hc.h>45 #include <usb/dev/hc.h> 46 46 #include <usb/dev/pipes.h> 47 #include <usb/host.h> 48 #include <usb/driver.h> 47 49 #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 } 48 163 49 164 static void print_usage(char *app_name) … … 185 300 devman_handle_t hc_handle = 0; 186 301 usb_address_t dev_addr = 0; 187 int rc = usb_resolve_device_handle(devpath,188 &hc_handle, &dev_addr , NULL);189 if ( rc != EOK) {302 bool found = resolve_hc_handle_and_dev_addr(devpath, 303 &hc_handle, &dev_addr); 304 if (!found) { 190 305 fprintf(stderr, NAME ": device `%s' not found " 191 306 "or not of USB kind, skipping.\n", -
uspace/drv/ohci/hc.c
r8d3f198 rfa8d346 565 565 bzero(&instance->rh, sizeof(instance->rh)); 566 566 /* Init queues */ 567 const int ret = hc_init_transfer_lists(instance); 568 if (ret != EOK) { 569 return ret; 570 } 567 hc_init_transfer_lists(instance); 571 568 572 569 /*Init HCCA */ -
uspace/drv/uhci-hcd/Makefile
r8d3f198 rfa8d346 48 48 root_hub.c \ 49 49 hw_struct/transfer_descriptor.c \ 50 utils/slab.c \ 50 51 pci.c \ 51 52 batch.c -
uspace/drv/uhci-hcd/batch.h
r8d3f198 rfa8d346 35 35 #define DRV_UHCI_BATCH_H 36 36 37 #include <usbhc_iface.h> 38 #include <usb/usb.h> 39 #include <usb/host/device_keeper.h> 40 #include <usb/host/endpoint.h> 37 41 #include <usb/host/batch.h> 38 42 -
uspace/drv/uhci-hcd/hc.c
r8d3f198 rfa8d346 39 39 #include <usb/debug.h> 40 40 #include <usb/usb.h> 41 #include <usb/ddfiface.h> 42 #include <usb_iface.h> 41 43 42 44 #include "hc.h" … … 83 85 /* allow access to hc control registers */ 84 86 regs_t *io; 85 ret = pio_enable(regs, reg_size, (void 87 ret = pio_enable(regs, reg_size, (void**)&io); 86 88 CHECK_RET_RETURN(ret, 87 89 "Failed(%d) to gain access to registers at %p: %s.\n", … … 141 143 } 142 144 143 constuint16_t status = pio_read_16(®isters->usbcmd);145 uint16_t status = pio_read_16(®isters->usbcmd); 144 146 if (status != 0) 145 147 usb_log_warning("Previous command value: %x.\n", status); … … 210 212 /* Init USB frame list page*/ 211 213 instance->frame_list = get_page(); 212 ret = instance ->frame_list? EOK : ENOMEM;214 ret = instance ? EOK : ENOMEM; 213 215 CHECK_RET_RETURN(ret, "Failed to get frame list page.\n"); 214 216 usb_log_debug("Initialized frame list at %p.\n", instance->frame_list); … … 275 277 &instance->transfers_control_slow); 276 278 277 /*FSBR, This feature is not needed (adds no benefit) and is supposedly 278 * buggy on certain hw, enable at your own risk. */ 279 /*FSBR*/ 279 280 #ifdef FSBR 280 281 transfer_list_set_next(&instance->transfers_bulk_full, … … 427 428 } 428 429 429 constuintptr_t frame_list =430 uintptr_t frame_list = 430 431 pio_read_32(&instance->registers->flbaseadd) & ~0xfff; 431 432 if (frame_list != addr_to_phys(instance->frame_list)) { -
uspace/drv/uhci-hcd/hc.h
r8d3f198 rfa8d346 37 37 38 38 #include <fibril.h> 39 #include <fibril_synch.h> 40 #include <adt/list.h> 39 41 #include <ddi.h> 40 42 43 #include <usbhc_iface.h> 41 44 #include <usb/host/device_keeper.h> 42 45 #include <usb/host/usb_endpoint_manager.h> 43 #include <usb/host/batch.h>44 46 47 #include "batch.h" 45 48 #include "transfer_list.h" 46 49 … … 151 154 */ 152 155 static inline hc_t * fun_to_hc(ddf_fun_t *fun) 153 { 154 assert(fun); 155 return fun->driver_data; 156 } 156 { return (hc_t*)fun->driver_data; } 157 157 #endif 158 158 /** -
uspace/drv/uhci-hcd/iface.c
r8d3f198 rfa8d346 39 39 40 40 #include "iface.h" 41 #include "batch.h"42 41 #include "hc.h" 43 42 … … 123 122 return EOK; 124 123 } 125 /*----------------------------------------------------------------------------*/ 124 126 125 /** Find device handle by address interface function. 127 126 * … … 137 136 hc_t *hc = fun_to_hc(fun); 138 137 assert(hc); 139 constbool found =138 bool found = 140 139 usb_device_keeper_find_by_address(&hc->manager, address, handle); 141 140 return found ? EOK : ENOENT; 142 141 } 142 143 143 /*----------------------------------------------------------------------------*/ 144 144 /** Release address interface function … … 164 164 size_t max_packet_size, unsigned int interval) 165 165 { 166 assert(fun);167 166 hc_t *hc = fun_to_hc(fun); 168 167 assert(hc); … … 184 183 usb_endpoint_t endpoint, usb_direction_t direction) 185 184 { 186 assert(fun);187 185 hc_t *hc = fun_to_hc(fun); 188 186 assert(hc); … … 213 211 if (ret != EOK) 214 212 return ret; 215 assert(batch);216 assert(hc);217 213 batch_interrupt_out(batch); 218 214 ret = hc_schedule(hc, batch); … … 243 239 if (ret != EOK) 244 240 return ret; 245 assert(batch);246 assert(hc);247 241 batch_interrupt_in(batch); 248 242 ret = hc_schedule(hc, batch); … … 273 267 if (ret != EOK) 274 268 return ret; 275 assert(batch);276 assert(hc);277 269 batch_bulk_out(batch); 278 270 ret = hc_schedule(hc, batch); … … 303 295 if (ret != EOK) 304 296 return ret; 305 assert(batch);306 assert(hc);307 297 batch_bulk_in(batch); 308 298 ret = hc_schedule(hc, batch); … … 337 327 if (ret != EOK) 338 328 return ret; 339 assert(batch);340 assert(hc);341 329 usb_endpoint_manager_reset_if_need(&hc->ep_manager, target, setup_data); 342 330 batch_control_write(batch); … … 372 360 if (ret != EOK) 373 361 return ret; 374 assert(batch);375 assert(hc);376 362 batch_control_read(batch); 377 363 ret = hc_schedule(hc, batch); -
uspace/drv/uhci-hcd/pci.c
r8d3f198 rfa8d346 52 52 * @return Error code. 53 53 */ 54 int pci_get_my_registers( constddf_dev_t *dev,54 int pci_get_my_registers(ddf_dev_t *dev, 55 55 uintptr_t *io_reg_address, size_t *io_reg_size, int *irq_no) 56 56 { 57 assert(dev); 58 assert(io_reg_address); 59 assert(io_reg_size); 60 assert(irq_no); 57 assert(dev != NULL); 61 58 62 59 int parent_phone = … … 69 66 int rc = hw_res_get_resource_list(parent_phone, &hw_resources); 70 67 if (rc != EOK) { 71 async_hangup(parent_phone); 72 return rc; 68 goto leave; 73 69 } 74 70 … … 82 78 size_t i; 83 79 for (i = 0; i < hw_resources.count; i++) { 84 consthw_resource_t *res = &hw_resources.resources[i];80 hw_resource_t *res = &hw_resources.resources[i]; 85 81 switch (res->type) 86 82 { … … 103 99 } 104 100 } 105 async_hangup(parent_phone);106 101 107 if (!io_found || !irq_found) 108 return ENOENT; 102 if (!io_found || !irq_found) { 103 rc = ENOENT; 104 goto leave; 105 } 109 106 110 107 *io_reg_address = io_address; … … 112 109 *irq_no = irq; 113 110 114 return EOK; 111 rc = EOK; 112 leave: 113 async_hangup(parent_phone); 114 return rc; 115 115 } 116 116 /*----------------------------------------------------------------------------*/ … … 120 120 * @return Error code. 121 121 */ 122 int pci_enable_interrupts( constddf_dev_t *device)122 int pci_enable_interrupts(ddf_dev_t *device) 123 123 { 124 const int parent_phone = 125 devman_parent_device_connect(device->handle, IPC_FLAG_BLOCKING); 126 if (parent_phone < 0) { 127 return parent_phone; 128 } 129 const bool enabled = hw_res_enable_interrupt(parent_phone); 124 int parent_phone = devman_parent_device_connect(device->handle, 125 IPC_FLAG_BLOCKING); 126 bool enabled = hw_res_enable_interrupt(parent_phone); 130 127 async_hangup(parent_phone); 131 128 return enabled ? EOK : EIO; … … 137 134 * @return Error code. 138 135 */ 139 int pci_disable_legacy( constddf_dev_t *device)136 int pci_disable_legacy(ddf_dev_t *device) 140 137 { 141 138 assert(device); 142 constint parent_phone =139 int parent_phone = 143 140 devman_parent_device_connect(device->handle, IPC_FLAG_BLOCKING); 144 141 if (parent_phone < 0) { … … 148 145 /* See UHCI design guide for these values p.45, 149 146 * write all WC bits in USB legacy register */ 150 constsysarg_t address = 0xc0;151 constsysarg_t value = 0xaf00;147 sysarg_t address = 0xc0; 148 sysarg_t value = 0xaf00; 152 149 153 constint rc = async_req_3_0(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE),150 int rc = async_req_3_0(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE), 154 151 IPC_M_CONFIG_SPACE_WRITE_16, address, value); 155 152 async_hangup(parent_phone); -
uspace/drv/uhci-hcd/pci.h
r8d3f198 rfa8d346 38 38 #include <ddf/driver.h> 39 39 40 int pci_get_my_registers( constddf_dev_t *, uintptr_t *, size_t *, int *);41 int pci_enable_interrupts( constddf_dev_t *);42 int pci_disable_legacy( constddf_dev_t *);40 int pci_get_my_registers(ddf_dev_t *, uintptr_t *, size_t *, int *); 41 int pci_enable_interrupts(ddf_dev_t *); 42 int pci_disable_legacy(ddf_dev_t *); 43 43 44 44 #endif -
uspace/drv/uhci-hcd/root_hub.c
r8d3f198 rfa8d346 60 60 return ret; 61 61 } 62 assert(match_str);63 62 64 63 ret = ddf_fun_add_match_id(fun, match_str, 100); -
uspace/drv/uhci-hcd/root_hub.h
r8d3f198 rfa8d346 43 43 /** List of resources available to the root hub. */ 44 44 hw_resource_list_t resource_list; 45 /** The only resource in the RH resource list */45 /** The only resource in the above list */ 46 46 hw_resource_t io_regs; 47 47 } rh_t; -
uspace/drv/uhci-hcd/transfer_list.c
r8d3f198 rfa8d346 36 36 #include <arch/barrier.h> 37 37 38 39 38 #include "transfer_list.h" 40 #include "batch.h"41 39 42 40 static void transfer_list_remove_batch( … … 60 58 return ENOMEM; 61 59 } 62 constuint32_t queue_head_pa = addr_to_phys(instance->queue_head);60 uint32_t queue_head_pa = addr_to_phys(instance->queue_head); 63 61 usb_log_debug2("Transfer list %s setup with QH: %p (%#" PRIx32" ).\n", 64 62 name, instance->queue_head, queue_head_pa); … … 92 90 { 93 91 assert(instance); 94 assert(instance->queue_head);95 92 assert(next); 93 if (!instance->queue_head) 94 return; 96 95 /* Set queue_head.next to point to the follower */ 97 96 qh_set_next_qh(instance->queue_head, next->queue_head); … … 138 137 write_barrier(); 139 138 140 /* Add to the driver 'slist */139 /* Add to the driver list */ 141 140 list_append(&batch->link, &instance->batch_list); 142 141 … … 161 160 link_t *current = instance->batch_list.next; 162 161 while (current != &instance->batch_list) { 163 link_t * constnext = current->next;162 link_t *next = current->next; 164 163 usb_transfer_batch_t *batch = 165 164 usb_transfer_batch_from_link(current); … … 183 182 fibril_mutex_lock(&instance->guard); 184 183 while (!list_empty(&instance->batch_list)) { 185 link_t * constcurrent = instance->batch_list.next;184 link_t *current = instance->batch_list.next; 186 185 usb_transfer_batch_t *batch = 187 186 usb_transfer_batch_from_link(current); -
uspace/drv/uhci-hcd/transfer_list.h
r8d3f198 rfa8d346 36 36 37 37 #include <fibril_synch.h> 38 #include <usb/host/batch.h>39 38 39 #include "batch.h" 40 40 #include "hw_struct/queue_head.h" 41 41 -
uspace/drv/uhci-hcd/uhci.c
r8d3f198 rfa8d346 77 77 { 78 78 assert(dev); 79 uhci_t *uhci = dev->driver_data; 80 assert(uhci); 81 hc_t *hc = &uhci->hc; 79 hc_t *hc = &((uhci_t*)dev->driver_data)->hc; 82 80 uint16_t status = IPC_GET_ARG1(*call); 83 81 assert(hc); … … 146 144 { 147 145 assert(fun); 148 rh_t *rh = fun->driver_data; 149 assert(rh); 150 return &rh->resource_list; 146 return &((rh_t*)fun->driver_data)->resource_list; 151 147 } 152 148 /*----------------------------------------------------------------------------*/ -
uspace/drv/uhci-hcd/uhci.h
r8d3f198 rfa8d346 35 35 #ifndef DRV_UHCI_UHCI_H 36 36 #define DRV_UHCI_UHCI_H 37 #include <ddi.h> 37 38 #include <ddf/driver.h> 38 39 -
uspace/drv/uhci-hcd/utils/malloc32.h
r8d3f198 rfa8d346 41 41 #include <as.h> 42 42 43 #include "slab.h" 44 43 45 #define UHCI_STRCUTURES_ALIGNMENT 16 44 46 #define UHCI_REQUIRED_PAGE_SIZE 4096 … … 57 59 uintptr_t result; 58 60 const int ret = as_get_physical_mapping(addr, &result); 61 assert(ret == EOK); 62 59 63 if (ret != EOK) 60 64 return 0; … … 68 72 */ 69 73 static inline void * malloc32(size_t size) { 70 /* This works only when the host has less than 4GB of memory as 71 * physical address needs to fit into 32 bits */ 72 73 /* If we need more than one page there is no guarantee that the 74 * memory will be continuous */ 75 if (size > PAGE_SIZE) 76 return NULL; 77 /* Calculate alignment to make sure the block won't cross page 78 * boundary */ 79 size_t alignment = UHCI_STRCUTURES_ALIGNMENT; 80 while (alignment < size) 81 alignment *= 2; 82 return memalign(alignment, size); 74 if (size <= SLAB_ELEMENT_SIZE) 75 return slab_malloc_g(); 76 usb_log_warning("Requested %zu bytes, current allocator can't handle " 77 "that amount, pray that the standard malloc will suffice.", size); 78 return memalign(UHCI_STRCUTURES_ALIGNMENT, size); 83 79 } 84 80 /*----------------------------------------------------------------------------*/ … … 90 86 if (!addr) 91 87 return; 88 if (slab_in_range_g(addr)) 89 return slab_free_g(addr); 92 90 free(addr); 93 91 } … … 100 98 { 101 99 void *free_address = as_get_mappable_page(UHCI_REQUIRED_PAGE_SIZE); 100 assert(free_address); /* TODO: remove this assert */ 102 101 if (free_address == 0) 103 102 return NULL; -
uspace/drv/uhci-rhd/main.c
r8d3f198 rfa8d346 37 37 #include <errno.h> 38 38 #include <str_error.h> 39 40 39 #include <usb_iface.h> 41 40 #include <usb/ddfiface.h> … … 46 45 #define NAME "uhci-rhd" 47 46 48 static int hc_get_my_registers( constddf_dev_t *dev,47 static int hc_get_my_registers(ddf_dev_t *dev, 49 48 uintptr_t *io_reg_address, size_t *io_reg_size); 50 49 /*----------------------------------------------------------------------------*/ … … 131 130 */ 132 131 int hc_get_my_registers( 133 constddf_dev_t *dev, uintptr_t *io_reg_address, size_t *io_reg_size)132 ddf_dev_t *dev, uintptr_t *io_reg_address, size_t *io_reg_size) 134 133 { 135 assert(dev );134 assert(dev != NULL); 136 135 137 constint parent_phone = devman_parent_device_connect(dev->handle,136 int parent_phone = devman_parent_device_connect(dev->handle, 138 137 IPC_FLAG_BLOCKING); 139 138 if (parent_phone < 0) { … … 142 141 143 142 hw_resource_list_t hw_resources; 144 constint ret = hw_res_get_resource_list(parent_phone, &hw_resources);143 int ret = hw_res_get_resource_list(parent_phone, &hw_resources); 145 144 if (ret != EOK) { 146 145 async_hangup(parent_phone); -
uspace/drv/uhci-rhd/port.c
r8d3f198 rfa8d346 36 36 #include <errno.h> 37 37 #include <str_error.h> 38 #include <time.h> 38 39 #include <async.h> 39 40 … … 81 82 * @param[in] number Port number. 82 83 * @param[in] usec Polling interval. 83 * @param[in] rh Pointer to ddf instance ofthe root hub driver.84 * @param[in] rh Pointer to ddf instance fo the root hub driver. 84 85 * @return Error code. 85 86 * … … 90 91 { 91 92 assert(port); 92 char *id_string; 93 asprintf(&id_string, "Port (%p - %u)", port, number); 94 if (id_string == NULL) { 93 asprintf(&port->id_string, "Port (%p - %u)", port, number); 94 if (port->id_string == NULL) { 95 95 return ENOMEM; 96 96 } 97 97 98 port->id_string = id_string;99 98 port->address = address; 100 99 port->number = number; … … 106 105 usb_hc_connection_initialize_from_device(&port->hc_connection, rh); 107 106 if (ret != EOK) { 108 usb_log_error("%s: failed to initialize connection to HC.", 109 port->id_string); 110 free(id_string); 107 usb_log_error("Failed to initialize connection to HC."); 111 108 return ret; 112 109 } … … 116 113 usb_log_error("%s: failed to create polling fibril.", 117 114 port->id_string); 118 free(id_string);119 115 return ENOMEM; 120 116 } … … 136 132 assert(port); 137 133 free(port->id_string); 138 / / TODO: Kill fibril here134 /* TODO: Kill fibril here */ 139 135 return; 140 136 } … … 154 150 155 151 /* Read register value */ 156 const port_status_t port_status = 157 uhci_port_read_status(instance); 152 port_status_t port_status = uhci_port_read_status(instance); 158 153 159 154 /* Print the value if it's interesting */ … … 166 161 usb_log_debug("%s: Connected change detected: %x.\n", 167 162 instance->id_string, port_status); 163 164 int rc = 165 usb_hc_connection_open(&instance->hc_connection); 166 if (rc != EOK) { 167 usb_log_error("%s: Failed to connect to HC.", 168 instance->id_string); 169 continue; 170 } 168 171 169 172 /* Remove any old device */ … … 172 175 instance->id_string); 173 176 uhci_port_remove_device(instance); 174 }175 176 int ret =177 usb_hc_connection_open(&instance->hc_connection);178 if (ret != EOK) {179 usb_log_error("%s: Failed to connect to HC.",180 instance->id_string);181 continue;182 177 } 183 178 … … 195 190 } 196 191 197 r et= usb_hc_connection_close(&instance->hc_connection);198 if (r et!= EOK) {192 rc = usb_hc_connection_close(&instance->hc_connection); 193 if (rc != EOK) { 199 194 usb_log_error("%s: Failed to disconnect.", 200 195 instance->id_string); … … 214 209 int uhci_port_reset_enable(int portno, void *arg) 215 210 { 216 uhci_port_t *port = arg; 217 assert(port); 211 uhci_port_t *port = (uhci_port_t *) arg; 218 212 219 213 usb_log_debug2("%s: new_device_enable_port.\n", port->id_string); … … 289 283 usb_log_error("%s: Don't know how to remove device %" PRIun ".\n", 290 284 port->id_string, port->attached_device); 291 port->attached_device = 0;292 285 return ENOTSUP; 293 286 } -
uspace/drv/uhci-rhd/port.h
r8d3f198 rfa8d346 38 38 #include <fibril.h> 39 39 #include <ddf/driver.h> 40 #include <usb/ hc.h> /* usb_hc_connection_t */40 #include <usb/dev/hc.h> /* usb_hc_connection_t */ 41 41 42 42 typedef uint16_t port_status_t; … … 57 57 typedef struct uhci_port 58 58 { 59 c onst char *id_string;59 char *id_string; 60 60 port_status_t *address; 61 61 unsigned number; -
uspace/lib/usb/Makefile
r8d3f198 rfa8d346 37 37 src/ddfiface.c \ 38 38 src/debug.c \ 39 src/driver.c \ 39 40 src/dump.c \ 40 src/hc.c \ 41 src/resolve.c \ 41 src/host.c \ 42 42 src/usb.c 43 43 -
uspace/lib/usb/src/ddfiface.c
r8d3f198 rfa8d346 37 37 #include <async.h> 38 38 #include <usb/ddfiface.h> 39 #include <usb/ hc.h>39 #include <usb/driver.h> 40 40 #include <usb/debug.h> 41 41 #include <errno.h> -
uspace/lib/usbdev/Makefile
r8d3f198 rfa8d346 46 46 src/pipesio.c \ 47 47 src/recognise.c \ 48 src/request.c 48 src/request.c \ 49 src/usbdevice.c 49 50 50 51 include $(USPACE_PREFIX)/Makefile.common -
uspace/lib/usbdev/include/usb/dev/hub.h
r8d3f198 rfa8d346 39 39 40 40 #include <sys/types.h> 41 #include <usb/ hc.h>41 #include <usb/dev/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 *); 65 67 66 68 #endif -
uspace/lib/usbdev/include/usb/dev/pipes.h
r8d3f198 rfa8d346 38 38 #include <sys/types.h> 39 39 #include <usb/usb.h> 40 #include <usb/ hc.h>40 #include <usb/dev/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); 165 166 166 167 int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *, -
uspace/lib/usbdev/src/hub.c
r8d3f198 rfa8d346 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 } 122 145 123 146 static void unregister_control_endpoint_on_default_address( -
uspace/lib/usbdev/src/pipes.c
r8d3f198 rfa8d346 36 36 #include <usb/dev/pipes.h> 37 37 #include <usb/debug.h> 38 #include <usb/ hc.h>38 #include <usb/driver.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; 99 127 } 100 128 -
uspace/lib/usbhid/include/usb/hid/hid_report_items.h
r8d3f198 rfa8d346 27 27 */ 28 28 29 /** @addtogroup libusb 29 /** @addtogroup libusbhid 30 30 * @{ 31 31 */ 32 32 /** @file 33 * @brief USB HID Report descriptor item tags.33 * @brief USB HID parser. 34 34 */ 35 #ifndef LIBUSB _HID_REPORT_ITEMS_H_36 #define LIBUSB _HID_REPORT_ITEMS_H_35 #ifndef LIBUSBHID_HID_REPORT_ITEMS_H_ 36 #define LIBUSBHID_HID_REPORT_ITEMS_H_ 37 37 38 38 #include <stdint.h> 39 39 40 /*---------------------------------------------------------------------------*/ 41 /* 40 /** 42 41 * Item prefix 43 42 */ 44 45 /** Returns size of item data in bytes */46 43 #define USB_HID_ITEM_SIZE(data) ((uint8_t)(data & 0x3)) 47 48 /** Returns item tag */49 44 #define USB_HID_ITEM_TAG(data) ((uint8_t)((data & 0xF0) >> 4)) 50 51 /** Returns class of item tag */52 45 #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 not55 * supported. */56 46 #define USB_HID_ITEM_IS_LONG(data) (data == 0xFE) 57 47 58 /*---------------------------------------------------------------------------*/ 59 /* 48 49 /** 60 50 * Extended usage macros 61 51 */ 62 63 /** Recognizes if the given usage is extended (contains also usage page). */64 52 #define USB_HID_IS_EXTENDED_USAGE(usage) ((usage & 0xFFFF0000) != 0) 65 66 /** Cuts usage page of the extended usage. */67 53 #define USB_HID_EXTENDED_USAGE_PAGE(usage) ((usage & 0xFFFF0000) >> 16) 68 69 /** Cuts usage of the extended usage */70 54 #define USB_HID_EXTENDED_USAGE(usage) (usage & 0xFFFF) 71 55 72 /*---------------------------------------------------------------------------*/ 73 /* 56 /** 74 57 * Input/Output/Feature Item flags 75 58 */ 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 */ 59 /** Constant (1) / Variable (0) */ 82 60 #define USB_HID_ITEM_FLAG_CONSTANT(flags) ((flags & 0x1) == 0x1) 83 84 /** 85 * Indicates whether the item creates variable (1) or array (0) data fields in 86 * reports. 87 */ 61 /** Variable (1) / Array (0) */ 88 62 #define USB_HID_ITEM_FLAG_VARIABLE(flags) ((flags & 0x2) == 0x2) 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 */ 63 /** Absolute / Relative*/ 96 64 #define USB_HID_ITEM_FLAG_RELATIVE(flags) ((flags & 0x4) == 0x4) 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 */ 65 /** Wrap / No Wrap */ 105 66 #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 some109 * way, and no longer represents a linear relationship between what is110 * measured and the data that is reported.111 */112 67 #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 return116 * when the user is not physically interacting with the control. Push buttons117 * (as opposed to toggle buttons) and self- centering joysticks are examples.118 */119 68 #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 sending123 * meaningful data. One possible use of the null state is for controls that124 * require the user to physically interact with the control in order for it to125 * report useful data.126 */127 69 #define USB_HID_ITEM_FLAG_POSITION(flags) ((flags & 0x40) == 0x40) 128 129 /**130 * Indicates whether the Feature or Output control's value should be changed131 * by the host or not. Volatile output can change with or without host132 * interaction. To avoid synchronization problems, volatile controls should be133 * relative whenever possible.134 */135 70 #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 contents139 * of the data field are determined by the application. The contents of the140 * buffer are not interpreted as a single numeric quantity. Report data141 * defined by a Buffered Bytes item must be aligned on an 8-bit boundary.142 */143 71 #define USB_HID_ITEM_FLAG_BUFFERED(flags) ((flags & 0x100) == 0x100) 144 72 145 /*---------------------------------------------------------------------------*/146 147 73 /* MAIN ITEMS */ 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 */ 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 180 78 #define USB_HID_REPORT_TAG_COLLECTION 0xA 181 182 /**183 * While the Collection item opens a collection of data, the End Collection184 * item closes a collection.185 */186 79 #define USB_HID_REPORT_TAG_END_COLLECTION 0xC 187 80 188 /*---------------------------------------------------------------------------*/ 81 /* GLOBAL ITEMS */ 82 #define USB_HID_TAG_CLASS_GLOBAL 0x1 83 #define USB_HID_REPORT_TAG_USAGE_PAGE 0x0 84 #define USB_HID_REPORT_TAG_LOGICAL_MINIMUM 0x1 85 #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 88 #define USB_HID_REPORT_TAG_UNIT_EXPONENT 0x5 89 #define USB_HID_REPORT_TAG_UNIT 0x6 90 #define USB_HID_REPORT_TAG_REPORT_SIZE 0x7 91 #define USB_HID_REPORT_TAG_REPORT_ID 0x8 92 #define USB_HID_REPORT_TAG_REPORT_COUNT 0x9 93 #define USB_HID_REPORT_TAG_PUSH 0xA 94 #define USB_HID_REPORT_TAG_POP 0xB 189 95 190 /* GLOBAL ITEMS */191 192 /**193 * Global items describe rather than define data from a control.194 */195 #define USB_HID_TAG_CLASS_GLOBAL 0x1196 197 /**198 * Unsigned integer specifying the current Usage Page. Since a usage are 32199 * bit values, Usage Page items can be used to conserve space in a report200 * descriptor by setting the high order 16 bits of a subsequent usages. Any201 * usage that follows which is defines 16 bits or less is interpreted as a202 * Usage ID and concatenated with the Usage Page to form a 32 bit Usage.203 */204 #define USB_HID_REPORT_TAG_USAGE_PAGE 0x0205 206 /**207 * Extent value in logical units. This is the minimum value that a variable208 * or array item will report. For example, a mouse reporting x position values209 * from 0 to 128 would have a Logical Minimum of 0 and a Logical Maximum of210 * 128.211 */212 #define USB_HID_REPORT_TAG_LOGICAL_MINIMUM 0x1213 214 /**215 * Extent value in logical units. This is the maximum value that a variable216 * or array item will report.217 */218 #define USB_HID_REPORT_TAG_LOGICAL_MAXIMUM 0x2219 220 /**221 * Minimum value for the physical extent of a variable item. This represents222 * the Logical Minimum with units applied to it.223 */224 #define USB_HID_REPORT_TAG_PHYSICAL_MINIMUM 0x3225 226 /**227 * Maximum value for the physical extent of a variable item.228 */229 #define USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM 0x4230 231 /**232 * Value of the unit exponent in base 10. See the table later in this section233 * for more information.234 */235 #define USB_HID_REPORT_TAG_UNIT_EXPONENT 0x5236 237 /**238 * Unit values.239 */240 #define USB_HID_REPORT_TAG_UNIT 0x6241 242 /**243 * Unsigned integer specifying the size of the report fields in bits. This244 * allows the parser to build an item map for the report handler to use.245 */246 #define USB_HID_REPORT_TAG_REPORT_SIZE 0x7247 248 /**249 * Unsigned value that specifies the Report ID. If a Report ID tag is used250 * anywhere in Report descriptor, all data reports for the device are preceded251 * by a single byte ID field. All items succeeding the first Report ID tag but252 * preceding a second Report ID tag are included in a report prefixed by a253 * 1-byte ID. All items succeeding the second but preceding a third Report ID254 * tag are included in a second report prefixed by a second ID, and so on.255 */256 #define USB_HID_REPORT_TAG_REPORT_ID 0x8257 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 particular261 * item (and consequently how many bits are added to the report).262 */263 #define USB_HID_REPORT_TAG_REPORT_COUNT 0x9264 265 /**266 * Places a copy of the global item state table on the stack.267 */268 #define USB_HID_REPORT_TAG_PUSH 0xA269 270 /**271 * Replaces the item state table with the top structure from the stack.272 */273 #define USB_HID_REPORT_TAG_POP 0xB274 275 /*---------------------------------------------------------------------------*/276 96 277 97 /* LOCAL ITEMS */ 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 */ 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 315 103 #define USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM 0x4 316 317 /**318 * Defines the index of the ending designator associated with an array or319 * bitmap.320 */321 104 #define USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM 0x5 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 /*---------------------------------------------------------------------------*/ 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 351 109 352 110 #endif -
uspace/lib/usbhid/include/usb/hid/hiddescriptor.h
r8d3f198 rfa8d346 27 27 */ 28 28 29 /** @addtogroup libusb 29 /** @addtogroup libusbhid 30 30 * @{ 31 31 */ … … 33 33 * USB HID report descriptor and report data parser 34 34 */ 35 #ifndef LIBUSB _HIDDESCRIPTOR_H_36 #define LIBUSB _HIDDESCRIPTOR_H_35 #ifndef LIBUSBHID_HIDDESCRIPTOR_H_ 36 #define LIBUSBHID_HIDDESCRIPTOR_H_ 37 37 38 38 #include <stdint.h> … … 42 42 #include <usb/hid/hidtypes.h> 43 43 44 45 /* 46 * Descriptor parser functions 47 */ 48 49 /** */ 44 50 int usb_hid_parse_report_descriptor(usb_hid_report_t *report, 45 51 const uint8_t *data, size_t size); 46 52 53 /** */ 47 54 void usb_hid_free_report(usb_hid_report_t *report); 48 55 56 /** */ 49 57 void usb_hid_descriptor_print(usb_hid_report_t *report); 50 58 59 51 60 int usb_hid_report_init(usb_hid_report_t *report); 52 53 61 int usb_hid_report_append_fields(usb_hid_report_t *report, 54 62 usb_hid_report_item_t *report_item); 55 63 56 64 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 58 65 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size, 59 66 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 60 61 67 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size, 62 68 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 63 64 69 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size, 65 70 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 66 67 71 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, size_t item_size, 68 72 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 69 73 70 74 void usb_hid_descriptor_print_list(link_t *head); 71 72 75 void usb_hid_report_reset_local_items(usb_hid_report_item_t *report_item); 73 74 76 void usb_hid_free_report_list(link_t *head); 75 76 77 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 83 81 #endif 84 82 /** -
uspace/lib/usbhid/include/usb/hid/hidparser.h
r8d3f198 rfa8d346 65 65 usb_hid_report_type_t type); 66 66 67 size_t usb_hid_report_byte_size(usb_hid_report_t *report, uint8_t report_id,68 usb_hid_report_type_t type);69 70 71 67 /** Makes the output report buffer by translated given data */ 72 68 int usb_hid_report_output_translate(usb_hid_report_t *report, uint8_t report_id, 73 69 uint8_t *buffer, size_t size); 74 75 70 76 71 /** */ … … 82 77 83 78 /** */ 84 uint8_t usb_hid_ get_next_report_id(usb_hid_report_t *report,79 uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report, 85 80 uint8_t report_id, 86 81 usb_hid_report_type_t type); -
uspace/lib/usbhid/include/usb/hid/hidpath.h
r8d3f198 rfa8d346 27 27 */ 28 28 29 /** @addtogroup libusb 29 /** @addtogroup libusbhid 30 30 * @{ 31 31 */ … … 33 33 * USB HID report descriptor and report data parser 34 34 */ 35 #ifndef LIBUSB _HIDPATH_H_36 #define LIBUSB _HIDPATH_H_35 #ifndef LIBUSBHID_HIDPATH_H_ 36 #define LIBUSBHID_HIDPATH_H_ 37 37 38 38 #include <usb/hid/hidparser.h> … … 40 40 #include <adt/list.h> 41 41 42 43 /*---------------------------------------------------------------------------*/44 42 /** 45 * Flags of usage paths comparison modes. 46 * 43 * Description of path of usage pages and usages in report descriptor 47 44 */ 48 /** Wanted usage path must be exactly the same as the searched one. 49 * This option cannot be combined with the others. 50 */ 45 /** Wanted usage path must be exactly the same as the searched one */ 51 46 #define USB_HID_PATH_COMPARE_STRICT 0 52 53 /** 54 * Wanted usage path must be the suffix in the searched one. 55 */ 47 /** Wanted usage path must be the suffix in the searched one */ 56 48 #define USB_HID_PATH_COMPARE_END 1 57 58 /** 59 * Only usage page are compared along the usage path. 60 * This option can be combined with others. 61 */ 49 /** */ 62 50 #define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY 2 63 64 /** 65 * Searched usage page must be prefix of the other one. 66 */ 51 /** Searched usage page must be prefix of the other one */ 67 52 #define USB_HID_PATH_COMPARE_BEGIN 4 68 69 /** 70 * Searched couple of usage page and usage can be anywhere in usage path. 71 * This option is deprecated. 72 */ 53 /** Searched couple of usage page and usage can be anywhere in usage path */ 73 54 #define USB_HID_PATH_COMPARE_ANYWHERE 8 74 55 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 */ 56 57 /** Collection usage path structure */ 81 58 typedef struct { 82 /** Usage page of report item. Zero when usage page can be changed.*/59 /** */ 83 60 uint32_t usage_page; 84 /** Usage of report item. Zero when usage can be changed.*/61 /** */ 85 62 uint32_t usage; 86 63 87 /** Attribute of Collection tag in report descriptor*/88 64 uint8_t flags; 89 90 /** Linked list structure*/ 65 /** */ 91 66 link_t link; 92 67 } usb_hid_report_usage_path_t; 93 68 94 95 /*---------------------------------------------------------------------------*/ 96 /** 97 * USB HID usage path structure. 98 * */ 69 /** */ 99 70 typedef struct { 100 /** Length of usage path*/71 /** */ 101 72 int depth; 102 103 /** Report id. Zero is reserved and means that report id is not used. */104 73 uint8_t report_id; 105 74 106 /** Linked list structure.*/75 /** */ 107 76 link_t link; /* list */ 108 77 109 /** Head of the list of usage path items. */ 110 link_t head; 78 link_t head; /* head of list of usage paths */ 111 79 112 80 } usb_hid_report_path_t; 113 81 114 /* ---------------------------------------------------------------------------*/82 /** */ 115 83 usb_hid_report_path_t *usb_hid_report_path(void); 116 84 85 /** */ 117 86 void usb_hid_report_path_free(usb_hid_report_path_t *path); 118 87 88 /** */ 119 89 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path, 120 90 uint8_t report_id); 121 91 92 /** */ 122 93 int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, 123 94 int32_t usage_page, int32_t usage); 124 95 96 /** */ 125 97 void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path); 126 98 99 /** */ 127 100 void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path); 128 101 102 /** */ 129 103 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, 130 104 int32_t tag, int32_t data); 131 105 106 /** */ 132 107 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, 133 108 usb_hid_report_path_t *path, int flags); 134 109 110 /** */ 135 111 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path); 136 112 -
uspace/lib/usbhid/include/usb/hid/hidtypes.h
r8d3f198 rfa8d346 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 item45 */46 41 #define USB_HID_MAX_USAGES 0xffff 47 42 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 */ 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 94 int32_t usage_minimum; 175 176 /** The greatest valid usage index */177 95 int32_t usage_maximum; 178 179 /** Unit of the value */180 96 uint32_t unit; 181 182 /** Unit exponent */183 97 uint32_t unit_exponent; 184 98 185 /** Array of possible usages */186 99 uint32_t *usages; 187 188 /** Size of the array of usages */189 100 size_t usages_count; 190 101 191 /** Parsed value */192 102 int32_t value; 193 103 194 /** List to another report items */195 104 link_t link; 196 105 } usb_hid_report_field_t; 197 106 198 /*---------------------------------------------------------------------------*/ 107 199 108 200 109 /** 201 * State table for report descriptor parsing110 * state table 202 111 */ 203 112 typedef struct { … … 205 114 int32_t id; 206 115 207 /** Extended usage page*/116 /** */ 208 117 uint16_t extended_usage_page; 209 210 /** Array of usages specified for this item */211 118 uint32_t usages[USB_HID_MAX_USAGES]; 212 213 /** Length of usages array */214 119 int usages_count; 215 120 216 /** Usage page*/121 /** */ 217 122 uint32_t usage_page; 218 123 219 /** Minimum valid usage index*/124 /** */ 220 125 int32_t usage_minimum; 221 222 /** Maximum valid usage index */ 126 /** */ 223 127 int32_t usage_maximum; 224 225 /** Minimum valid logical value */ 128 /** */ 226 129 int32_t logical_minimum; 227 228 /** Maximum valid logical value */ 130 /** */ 229 131 int32_t logical_maximum; 230 231 /** Length of the items in bits*/ 132 /** */ 232 133 int32_t size; 233 234 /** COunt of items*/ 134 /** */ 235 135 int32_t count; 236 237 /** Bit offset of the item in report */ 136 /** */ 238 137 size_t offset; 239 240 /** Unit exponent */ 138 /** */ 241 139 int32_t unit_exponent; 242 /** Unit of the value*/140 /** */ 243 141 int32_t unit; 244 142 245 /** String index*/143 /** */ 246 144 uint32_t string_index; 247 248 /** Minimum valid string index */ 145 /** */ 249 146 uint32_t string_minimum; 250 251 /** Maximum valid string index */ 147 /** */ 252 148 uint32_t string_maximum; 253 254 /** The designator index */ 149 /** */ 255 150 uint32_t designator_index; 256 257 /** Minimum valid designator value*/ 151 /** */ 258 152 uint32_t designator_minimum; 259 260 /** Maximum valid designator value*/ 153 /** */ 261 154 uint32_t designator_maximum; 262 263 /** Minimal valid physical value*/ 155 /** */ 264 156 int32_t physical_minimum; 265 266 /** Maximal valid physical value */ 157 /** */ 267 158 int32_t physical_maximum; 268 159 269 /** Items attributes*/160 /** */ 270 161 uint8_t item_flags; 271 162 272 /** Report type */273 163 usb_hid_report_type_t type; 274 164 275 165 /** current collection path*/ 276 166 usb_hid_report_path_t *usage_path; 277 278 /** Unused*/ 167 /** */ 279 168 link_t link; 280 169 281 170 int in_delimiter; 282 171 } usb_hid_report_item_t; 283 /*---------------------------------------------------------------------------*/ 284 /** 285 * Enum of the keyboard modifiers 286 */ 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 287 185 typedef enum { 288 186 USB_HID_MOD_LCTRL = 0x01, … … 308 206 USB_HID_MOD_RGUI 309 207 }; 310 /*---------------------------------------------------------------------------*/311 312 208 313 209 #endif -
uspace/lib/usbhid/src/hidparser.c
r8d3f198 rfa8d346 31 31 */ 32 32 /** @file 33 * USB HIDreport data parser implementation.33 * HID report descriptor and report data parser implementation. 34 34 */ 35 35 #include <usb/hid/hidparser.h> … … 41 41 #include <assert.h> 42 42 43 /*---------------------------------------------------------------------------*/ 43 44 44 /* 45 45 * Data translation private functions 46 46 */ 47 47 uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size); 48 48 //inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset); 49 49 int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data); 50 51 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, 52 int32_t value); 53 50 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int32_t value); 54 51 int usb_pow(int a, int b); 55 52 56 /*---------------------------------------------------------------------------*/57 53 58 54 // TODO: tohle ma bejt asi jinde … … 60 56 { 61 57 switch(b) { 62 case 0:63 return 1;64 break;65 case 1:66 return a;67 break;68 default:69 return a * usb_pow(a, b-1);70 break;71 } 72 } 73 /*---------------------------------------------------------------------------*/ 58 case 0: 59 return 1; 60 break; 61 case 1: 62 return a; 63 break; 64 default: 65 return a * usb_pow(a, b-1); 66 break; 67 } 68 } 69 74 70 75 71 /** Returns size of report of specified report id and type in items … … 98 94 } 99 95 100 /** Returns size of report of specified report id and type in bytes101 *102 * @param parser Opaque report parser structure103 * @param report_id104 * @param type105 * @return Number of items in specified report106 */107 size_t usb_hid_report_byte_size(usb_hid_report_t *report, uint8_t report_id,108 usb_hid_report_type_t type)109 {110 usb_hid_report_description_t *report_des;111 112 if(report == NULL) {113 return 0;114 }115 116 report_des = usb_hid_report_find_description (report, report_id, type);117 if(report_des == NULL){118 return 0;119 }120 else {121 return (report_des->bit_length + 7) / 8;122 }123 }124 /*---------------------------------------------------------------------------*/125 96 126 97 /** Parse and act upon a HID report. … … 132 103 * @return Error code. 133 104 */ 134 int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data,135 105 int usb_hid_parse_report(const usb_hid_report_t *report, 106 const uint8_t *data, size_t size, uint8_t *report_id) 136 107 { 137 108 link_t *list_item; … … 168 139 item->value = usb_hid_translate_data(item, data); 169 140 170 item->usage = USB_HID_EXTENDED_USAGE( 171 item->usages[item->value - item->physical_minimum]); 172 item->usage_page = USB_HID_EXTENDED_USAGE_PAGE( 173 item->usages[item->value - item->physical_minimum]); 141 item->usage = USB_HID_EXTENDED_USAGE(item->usages[item->value - item->physical_minimum]); 142 item->usage_page = USB_HID_EXTENDED_USAGE_PAGE(item->usages[item->value - item->physical_minimum]); 174 143 175 144 usb_hid_report_set_last_item (item->collection_path, 176 USB_HID_TAG_CLASS_GLOBAL, item->usage_page); 145 USB_HID_TAG_CLASS_GLOBAL, 146 item->usage_page); 177 147 usb_hid_report_set_last_item (item->collection_path, 178 USB_HID_TAG_CLASS_LOCAL, item->usage); 148 USB_HID_TAG_CLASS_LOCAL, 149 item->usage); 179 150 180 151 } … … 191 162 } 192 163 193 /*---------------------------------------------------------------------------*/194 164 /** 195 165 * Translate data from the report as specified in report descriptor item … … 197 167 * @param item Report descriptor item with definition of translation 198 168 * @param data Data to translate 169 * @param j Index of processed field in report descriptor item 199 170 * @return Translated data 200 171 */ … … 269 240 } 270 241 271 /*---------------------------------------------------------------------------*/ 272 /* OUTPUT API */ 242 /*** OUTPUT API **/ 273 243 274 244 /** … … 280 250 * @return Returns allocated output buffer for specified output 281 251 */ 282 uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, 283 uint8_t report_id) 252 uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, uint8_t report_id) 284 253 { 285 254 if(report == NULL) { … … 291 260 usb_hid_report_description_t *report_des = NULL; 292 261 while(report_it != &report->reports) { 293 report_des = list_get_instance(report_it, 294 usb_hid_report_description_t, link); 295 296 if((report_des->report_id == report_id) && 297 (report_des->type == USB_HID_REPORT_TYPE_OUTPUT)){ 262 report_des = list_get_instance(report_it, usb_hid_report_description_t, link); 263 if((report_des->report_id == report_id) && (report_des->type == USB_HID_REPORT_TYPE_OUTPUT)){ 298 264 break; 299 265 } … … 337 303 * @return Error code 338 304 */ 339 int usb_hid_report_output_translate(usb_hid_report_t *report, 340 uint8_t report_id,uint8_t *buffer, size_t size)305 int usb_hid_report_output_translate(usb_hid_report_t *report, uint8_t report_id, 306 uint8_t *buffer, size_t size) 341 307 { 342 308 link_t *item; … … 354 320 } 355 321 322 usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0)); 323 356 324 usb_hid_report_description_t *report_des; 357 report_des = usb_hid_report_find_description (report, report_id, 358 USB_HID_REPORT_TYPE_OUTPUT); 359 325 report_des = usb_hid_report_find_description (report, report_id, USB_HID_REPORT_TYPE_OUTPUT); 360 326 if(report_des == NULL){ 361 327 return EINVAL; … … 367 333 report_item = list_get_instance(item, usb_hid_report_field_t, link); 368 334 335 usb_log_debug("OUTPUT ITEM usage(%x), value(%x)\n", report_item->usage, report_item->value); 336 369 337 if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) { 370 338 371 339 // array 372 value = usb_hid_translate_data_reverse(report_item, 373 report_item->value); 374 340 value = usb_hid_translate_data_reverse(report_item, report_item->value); 375 341 offset = report_item->offset; 376 342 length = report_item->size; … … 378 344 else { 379 345 // variable item 380 value = usb_hid_translate_data_reverse(report_item, 381 report_item->value); 382 346 value = usb_hid_translate_data_reverse(report_item, report_item->value); 383 347 offset = report_item->offset; 384 348 length = report_item->size; … … 389 353 if((offset/8) == ((offset+length-1)/8)) { 390 354 // je to v jednom bytu 391 if(((size_t)(offset/8) >= size) || 392 ((size_t)(offset+length-1)/8) >= size) { 355 if(((size_t)(offset/8) >= size) || ((size_t)(offset+length-1)/8) >= size) { 393 356 break; // TODO ErrorCode 394 357 } … … 416 379 417 380 value = value >> (length - ((offset + length) % 8)); 418 value = value & 419 ((1 << (length - ((offset + length) % 8))) - 1); 381 value = value & ((1 << (length - ((offset + length) % 8))) - 1); 420 382 421 383 mask = (1 << (length - ((offset + length) % 8))) - 1; … … 434 396 } 435 397 398 usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0)); 399 436 400 return EOK; 437 401 } 438 402 439 /*---------------------------------------------------------------------------*/440 403 /** 441 404 * Translate given data for putting them into the outoput report … … 444 407 * @return ranslated value 445 408 */ 446 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, 447 int value) 409 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int value) 448 410 { 449 411 int ret=0; … … 469 431 } 470 432 471 ret = ((value - item->physical_minimum) * resolution) + 472 item->logical_minimum; 473 474 usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), \ 475 ret(%x)\n", value, resolution, item->physical_minimum, 476 item->logical_minimum, ret); 433 ret = ((value - item->physical_minimum) * resolution) + item->logical_minimum; 434 usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), ret(%x)\n", value, resolution, item->physical_minimum, item->logical_minimum, ret); 477 435 478 436 if((item->logical_minimum < 0) || (item->logical_maximum < 0)){ … … 482 440 } 483 441 484 /*---------------------------------------------------------------------------*/ 485 /** 486 * Clones given state table 487 * 488 * @param item State table to clone 489 * @return Pointer to the cloned item 490 */ 491 usb_hid_report_item_t *usb_hid_report_item_clone( 492 const usb_hid_report_item_t *item) 442 usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item) 493 443 { 494 444 usb_hid_report_item_t *new_report_item; … … 503 453 } 504 454 505 /*---------------------------------------------------------------------------*/ 506 /** 507 * Function for sequence walking through the report. Returns next field in the 508 * report or the first one when no field is given. 509 * 510 * @param report Searched report structure 511 * @param field Current field. If NULL is given, the first one in the report 512 * is returned. Otherwise the next one i nthe list is returned. 513 * @param path Usage path specifying which fields wa are interested in. 514 * @param flags Flags defining mode of usage paths comparison 515 * @param type Type of report we search. 516 * @retval NULL if no field is founded 517 * @retval Pointer to the founded report structure when founded 518 */ 455 519 456 usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report, 520 usb_hid_report_field_t *field, usb_hid_report_path_t *path, int flags, 521 usb_hid_report_type_t type) 522 { 523 usb_hid_report_description_t *report_des = usb_hid_report_find_description( 524 report, path->report_id, type); 525 457 usb_hid_report_field_t *field, 458 usb_hid_report_path_t *path, int flags, 459 usb_hid_report_type_t type) 460 { 461 usb_hid_report_description_t *report_des = usb_hid_report_find_description (report, path->report_id, type); 526 462 link_t *field_it; 527 463 … … 531 467 532 468 if(field == NULL){ 469 // vezmu prvni co mathuje podle path!! 533 470 field_it = report_des->report_items.next; 534 471 } … … 541 478 542 479 if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) { 543 usb_hid_report_path_append_item (field->collection_path, 544 field->usage_page, field->usage); 545 546 if(usb_hid_report_compare_usage_path(field->collection_path, path, 547 flags) == EOK){ 548 549 usb_hid_report_remove_last_item(field->collection_path); 480 usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage); 481 if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK){ 482 usb_hid_report_remove_last_item (field->collection_path); 550 483 return field; 551 484 } … … 558 491 } 559 492 560 /*---------------------------------------------------------------------------*/ 561 /** 562 * Returns next report_id of report of specified type. If zero is given than 563 * first report_id of specified type is returned (0 is not legal value for 564 * repotr_id) 565 * 566 * @param report_id Current report_id, 0 if there is no current report_id 567 * @param type Type of searched report 568 * @param report Report structure inwhich we search 569 * @retval 0 if report structure is null or there is no specified report 570 * @retval report_id otherwise 571 */ 572 uint8_t usb_hid_get_next_report_id(usb_hid_report_t *report, 573 uint8_t report_id, usb_hid_report_type_t type) 493 uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type) 574 494 { 575 495 if(report == NULL){ … … 580 500 link_t *report_it; 581 501 582 if(report_id > 0) { 583 report_it = usb_hid_report_find_description(report, report_id, 584 type)->link.next; 502 if(report_id == 0) { 503 report_it = usb_hid_report_find_description (report, report_id, type)->link.next; 585 504 } 586 505 else { … … 589 508 590 509 while(report_it != &report->reports) { 591 report_des = list_get_instance(report_it, 592 usb_hid_report_description_t, link); 593 510 report_des = list_get_instance(report_it, usb_hid_report_description_t, link); 594 511 if(report_des->type == type){ 595 512 return report_des->report_id; … … 600 517 } 601 518 602 /*---------------------------------------------------------------------------*/603 /**604 * Reset all local items in given state table605 *606 * @param report_item State table containing current state of report607 * descriptor parsing608 *609 * @return void610 */611 519 void usb_hid_report_reset_local_items(usb_hid_report_item_t *report_item) 612 520 { -
uspace/lib/usbhid/src/hidpath.c
r8d3f198 rfa8d346 41 41 #include <assert.h> 42 42 43 /*---------------------------------------------------------------------------*/ 44 /** 45 * Compares two usages if they are same or not or one of the usages is not 46 * set. 47 * 48 * @param usage1 49 * @param usage2 50 * @return boolean 51 */ 52 #define USB_HID_SAME_USAGE(usage1, usage2) \ 53 ((usage1 == usage2) || (usage1 == 0) || (usage2 == 0)) 54 55 /** 56 * Compares two usage pages if they are same or not or one of them is not set. 57 * 58 * @param page1 59 * @param page2 60 * @return boolean 61 */ 62 #define USB_HID_SAME_USAGE_PAGE(page1, page2) \ 63 ((page1 == page2) || (page1 == 0) || (page2 == 0)) 64 65 /*---------------------------------------------------------------------------*/ 43 44 #define USB_HID_SAME_USAGE(usage1, usage2) ((usage1 == usage2) || (usage1 == 0) || (usage2 == 0)) 45 #define USB_HID_SAME_USAGE_PAGE(page1, page2) ((page1 == page2) || (page1 == 0) || (page2 == 0)) 46 66 47 /** 67 48 * Appends one item (couple of usage_path and usage) into the usage path … … 92 73 } 93 74 94 /*---------------------------------------------------------------------------*/95 75 /** 96 76 * Removes last item from the usage path structure … … 111 91 } 112 92 113 /*---------------------------------------------------------------------------*/114 93 /** 115 94 * Nulls last item of the usage path structure. … … 123 102 124 103 if(!list_empty(&usage_path->head)){ 125 item = list_get_instance(usage_path->head.prev, 126 usb_hid_report_usage_path_t, link); 127 104 item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link); 128 105 memset(item, 0, sizeof(usb_hid_report_usage_path_t)); 129 106 } 130 107 } 131 108 132 /*---------------------------------------------------------------------------*/133 109 /** 134 110 * Modifies last item of usage path structure by given usage page or usage … … 161 137 } 162 138 163 /*---------------------------------------------------------------------------*/ 164 /** 165 * 166 * 167 * 168 * 169 */ 139 170 140 void usb_hid_print_usage_path(usb_hid_report_path_t *path) 171 141 { … … 177 147 while(item != &path->head) { 178 148 179 path_item = list_get_instance(item, usb_hid_report_usage_path_t, 180 link); 181 149 path_item = list_get_instance(item, usb_hid_report_usage_path_t, link); 182 150 usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page); 183 151 usb_log_debug("\tUSAGE: %X\n", path_item->usage); 184 152 usb_log_debug("\tFLAGS: %d\n", path_item->flags); 185 153 186 item = item->next; 187 } 188 } 189 190 /*---------------------------------------------------------------------------*/ 154 item = item->next; 155 } 156 } 157 191 158 /** 192 159 * Compares two usage paths structures … … 231 198 } 232 199 200 // projit skrz cestu a kdyz nekde sedi tak vratim EOK 201 // dojduli az za konec tak nnesedi 233 202 report_link = report_path->head.next; 234 203 path_link = path->head.next; 235 path_item = list_get_instance(path_link, 236 usb_hid_report_usage_path_t, link); 204 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link); 237 205 238 206 while(report_link != &report_path->head) { 239 report_item = list_get_instance(report_link, 240 usb_hid_report_usage_path_t, link); 241 242 if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 243 path_item->usage_page)){ 244 207 report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link); 208 if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page)){ 245 209 if(only_page == 0){ 246 if(USB_HID_SAME_USAGE(report_item->usage, 247 path_item->usage)) { 248 210 if(USB_HID_SAME_USAGE(report_item->usage, path_item->usage)) { 249 211 return EOK; 250 212 } … … 276 238 277 239 report_item = list_get_instance(report_link, 278 usb_hid_report_usage_path_t, link); 240 usb_hid_report_usage_path_t, 241 link); 279 242 280 243 path_item = list_get_instance(path_link, 281 usb_hid_report_usage_path_t, link); 282 283 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 284 path_item->usage_page) || ((only_page == 0) &&285 !USB_HID_SAME_USAGE(report_item->usage,286 244 usb_hid_report_usage_path_t, 245 link); 246 247 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) || 248 ((only_page == 0) && 249 !USB_HID_SAME_USAGE(report_item->usage, path_item->usage))) { 287 250 288 251 return 1; … … 294 257 } 295 258 296 if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && 297 (path_link == &path->head)) || 298 ((report_link == &report_path->head) && 299 (path_link == &path->head))) { 300 259 if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && (path_link == &path->head)) || 260 ((report_link == &report_path->head) && (path_link == &path->head))) { 301 261 return EOK; 302 262 } … … 320 280 321 281 report_item = list_get_instance(report_link, 322 usb_hid_report_usage_path_t, link);323 282 usb_hid_report_usage_path_t, 283 link); 324 284 path_item = list_get_instance(path_link, 325 usb_hid_report_usage_path_t, link); 285 usb_hid_report_usage_path_t, 286 link); 326 287 327 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 328 path_item->usage_page) || ((only_page == 0) && 329 !USB_HID_SAME_USAGE(report_item->usage, 330 path_item->usage))) { 331 288 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) || 289 ((only_page == 0) && 290 !USB_HID_SAME_USAGE(report_item->usage, path_item->usage))) { 332 291 return 1; 333 292 } else { … … 352 311 } 353 312 354 /*---------------------------------------------------------------------------*/355 313 /** 356 314 * Allocates and initializes new usage path structure. … … 374 332 } 375 333 376 /*---------------------------------------------------------------------------*/377 334 /** 378 335 * Releases given usage path structure. … … 391 348 } 392 349 393 /*---------------------------------------------------------------------------*/ 350 394 351 /** 395 352 * Clone content of given usage path to the new one … … 398 355 * @return New copy of given usage path structure 399 356 */ 400 usb_hid_report_path_t *usb_hid_report_path_clone( 401 usb_hid_report_path_t *usage_path) 357 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path) 402 358 { 403 359 link_t *path_link; … … 418 374 path_link = usage_path->head.next; 419 375 while(path_link != &usage_path->head) { 420 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, 376 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, 421 377 link); 422 378 new_path_item = malloc(sizeof(usb_hid_report_usage_path_t)); … … 439 395 } 440 396 441 /*---------------------------------------------------------------------------*/ 397 442 398 /** 443 399 * Sets report id in usage path structure … … 447 403 * @return Error code 448 404 */ 449 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, 450 uint8_t report_id) 405 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, uint8_t report_id) 451 406 { 452 407 if(path == NULL){
Note:
See TracChangeset
for help on using the changeset viewer.