Changes in / [74341ed:9ca8539] in mainline
- Location:
- uspace
- Files:
-
- 2 deleted
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mkbd/Makefile
r74341ed r9ca8539 31 31 32 32 LIBS = \ 33 $(LIBUSBHID_PREFIX)/libusbhid.a \34 33 $(LIBUSBDEV_PREFIX)/libusbdev.a \ 35 34 $(LIBUSB_PREFIX)/libusb.a \ 36 $(LIBDRV_PREFIX)/libdrv.a 35 $(LIBDRV_PREFIX)/libdrv.a 37 36 EXTRA_CFLAGS = \ 38 37 -I$(LIBUSB_PREFIX)/include \ 39 38 -I$(LIBUSBDEV_PREFIX)/include \ 40 -I$(LIBDRV_PREFIX)/include \ 41 -I$(LIBUSBHID_PREFIX)/include 39 -I$(LIBDRV_PREFIX)/include 42 40 43 41 SOURCES = \ -
uspace/app/mkbd/main.c
r74341ed r9ca8539 45 45 #include <devmap.h> 46 46 #include <usb/dev/hub.h> 47 //#include <usb/host.h> 48 //#include <usb/driver.h> 49 #include <usb/hid/iface.h> 47 #include <usb/hc.h> 50 48 #include <usb/dev/pipes.h> 51 #include <async.h>52 #include <usb/hid/usages/core.h>53 #include <usb/hid/hidparser.h>54 #include <usb/hid/hiddescriptor.h>55 #include <usb/hid/usages/consumer.h>56 #include <assert.h>57 49 58 50 #define NAME "mkbd" … … 60 52 static int dev_phone = -1; 61 53 62 static int initialize_report_parser(int dev_phone, usb_hid_report_t **report) 63 { 64 *report = (usb_hid_report_t *)malloc(sizeof(usb_hid_report_t)); 65 if (*report == NULL) { 54 //static void print_found_hc(size_t class_index, const char *path) 55 //{ 56 // // printf(NAME ": host controller %zu is `%s'.\n", class_index, path); 57 // printf("Bus %02zu: %s\n", class_index, path); 58 //} 59 //static void print_found_dev(usb_address_t addr, const char *path) 60 //{ 61 // // printf(NAME ": device with address %d is `%s'.\n", addr, path); 62 // printf(" Device %02d: %s\n", addr, path); 63 //} 64 65 //static void print_hc_devices(devman_handle_t hc_handle) 66 //{ 67 // int rc; 68 // usb_hc_connection_t conn; 69 70 // usb_hc_connection_initialize(&conn, hc_handle); 71 // rc = usb_hc_connection_open(&conn); 72 // if (rc != EOK) { 73 // printf(NAME ": failed to connect to HC: %s.\n", 74 // str_error(rc)); 75 // return; 76 // } 77 // usb_address_t addr; 78 // for (addr = 1; addr < 5; addr++) { 79 // devman_handle_t dev_handle; 80 // rc = usb_hc_get_handle_by_address(&conn, addr, &dev_handle); 81 // if (rc != EOK) { 82 // continue; 83 // } 84 // char path[MAX_PATH_LENGTH]; 85 // rc = devman_get_device_path(dev_handle, path, MAX_PATH_LENGTH); 86 // if (rc != EOK) { 87 // continue; 88 // } 89 // print_found_dev(addr, path); 90 // } 91 // usb_hc_connection_close(&conn); 92 //} 93 94 static bool try_parse_class_and_address(const char *path, 95 devman_handle_t *out_hc_handle, usb_address_t *out_device_address) 96 { 97 size_t class_index; 98 size_t address; 99 int rc; 100 char *ptr; 101 102 rc = str_size_t(path, &ptr, 10, false, &class_index); 103 if (rc != EOK) { 104 return false; 105 } 106 if ((*ptr == ':') || (*ptr == '.')) { 107 ptr++; 108 } else { 109 return false; 110 } 111 rc = str_size_t(ptr, NULL, 10, true, &address); 112 if (rc != EOK) { 113 return false; 114 } 115 rc = usb_ddf_get_hc_handle_by_class(class_index, out_hc_handle); 116 if (rc != EOK) { 117 return false; 118 } 119 if (out_device_address != NULL) { 120 *out_device_address = (usb_address_t) address; 121 } 122 return true; 123 } 124 125 static bool resolve_hc_handle_and_dev_addr(const char *devpath, 126 devman_handle_t *out_hc_handle, usb_address_t *out_device_address) 127 { 128 int rc; 129 130 /* Hack for QEMU to save-up on typing ;-). */ 131 if (str_cmp(devpath, "qemu") == 0) { 132 devpath = "/hw/pci0/00:01.2/uhci-rh/usb00_a1"; 133 } 134 135 /* Hack for virtual keyboard. */ 136 if (str_cmp(devpath, "virt") == 0) { 137 devpath = "/virt/usbhc/usb00_a1/usb00_a2"; 138 } 139 140 if (try_parse_class_and_address(devpath, 141 out_hc_handle, out_device_address)) { 142 return true; 143 } 144 145 char *path = str_dup(devpath); 146 if (path == NULL) { 66 147 return ENOMEM; 67 148 } 68 69 int rc = usb_hid_report_init(*report); 70 if (rc != EOK) { 71 usb_hid_free_report(*report); 72 *report = NULL; 73 printf("usb_hid_report_init() failed.\n"); 74 return rc; 75 } 76 77 // get the report descriptor length from the device 78 size_t report_desc_size; 79 rc = usbhid_dev_get_report_descriptor_length( 80 dev_phone, &report_desc_size); 81 if (rc != EOK) { 82 usb_hid_free_report(*report); 83 *report = NULL; 84 printf("usbhid_dev_get_report_descriptor_length() failed.\n"); 85 return rc; 86 } 87 88 if (report_desc_size == 0) { 89 usb_hid_free_report(*report); 90 *report = NULL; 91 printf("usbhid_dev_get_report_descriptor_length() returned 0.\n"); 92 return EINVAL; // TODO: other error code? 93 } 94 95 uint8_t *desc = (uint8_t *)malloc(report_desc_size); 96 if (desc == NULL) { 97 usb_hid_free_report(*report); 98 *report = NULL; 99 return ENOMEM; 100 } 101 102 // get the report descriptor from the device 103 size_t actual_size; 104 rc = usbhid_dev_get_report_descriptor(dev_phone, desc, report_desc_size, 105 &actual_size); 106 if (rc != EOK) { 107 usb_hid_free_report(*report); 108 *report = NULL; 109 free(desc); 110 printf("usbhid_dev_get_report_descriptor() failed.\n"); 111 return rc; 112 } 113 114 if (actual_size != report_desc_size) { 115 usb_hid_free_report(*report); 116 *report = NULL; 117 free(desc); 118 printf("usbhid_dev_get_report_descriptor() returned wrong size:" 119 " %zu, expected: %zu.\n", actual_size, report_desc_size); 120 return EINVAL; // TODO: other error code? 121 } 122 123 // initialize the report parser 124 125 rc = usb_hid_parse_report_descriptor(*report, desc, report_desc_size); 126 free(desc); 127 128 if (rc != EOK) { 129 free(desc); 130 printf("usb_hid_parse_report_descriptor() failed.\n"); 131 return rc; 132 } 133 134 return EOK; 135 } 136 137 static void print_key(uint8_t *buffer, size_t size, usb_hid_report_t *report) 138 { 139 assert(buffer != NULL); 140 assert(report != NULL); 141 142 // printf("Calling usb_hid_parse_report() with size %zu and " 143 // "buffer: \n", size); 144 // for (size_t i = 0; i < size; ++i) { 145 // printf(" %X ", buffer[i]); 146 // } 147 // printf("\n"); 148 149 uint8_t report_id; 150 int rc = usb_hid_parse_report(report, buffer, size, &report_id); 151 if (rc != EOK) { 152 // printf("Error parsing report: %s\n", str_error(rc)); 153 return; 154 } 155 156 usb_hid_report_path_t *path = usb_hid_report_path(); 157 if (path == NULL) { 158 return; 159 } 160 161 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0); 162 163 usb_hid_report_path_set_report_id(path, report_id); 164 165 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 166 report, NULL, path, USB_HID_PATH_COMPARE_END 167 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 168 USB_HID_REPORT_TYPE_INPUT); 169 170 // printf("Field: %p\n", field); 171 172 while (field != NULL) { 173 // printf("Field usage: %u, field value: %d\n", field->usage, 174 // field->value); 175 if (field->value != 0) { 176 const char *key_str = 177 usbhid_multimedia_usage_to_str(field->usage); 178 printf("Pressed key: %s\n", key_str); 179 } 180 181 field = usb_hid_report_get_sibling( 182 report, field, path, USB_HID_PATH_COMPARE_END 183 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 184 USB_HID_REPORT_TYPE_INPUT); 185 // printf("Next field: %p\n", field); 186 } 187 188 usb_hid_report_path_free(path); 189 } 190 191 #define MAX_PATH_LENGTH 1024 149 150 devman_handle_t hc = 0; 151 bool hc_found = false; 152 usb_address_t addr = 0; 153 bool addr_found = false; 154 155 /* Remove suffixes and hope that we will encounter device node. */ 156 while (str_length(path) > 0) { 157 /* Get device handle first. */ 158 devman_handle_t dev_handle; 159 rc = devman_device_get_handle(path, &dev_handle, 0); 160 if (rc != EOK) { 161 free(path); 162 return false; 163 } 164 165 /* Try to find its host controller. */ 166 if (!hc_found) { 167 rc = usb_hc_find(dev_handle, &hc); 168 if (rc == EOK) { 169 hc_found = true; 170 } 171 } 172 /* Try to get its address. */ 173 if (!addr_found) { 174 addr = usb_hc_get_address_by_handle(dev_handle); 175 if (addr >= 0) { 176 addr_found = true; 177 } 178 } 179 180 /* Speed-up. */ 181 if (hc_found && addr_found) { 182 break; 183 } 184 185 /* Remove the last suffix. */ 186 char *slash_pos = str_rchr(path, '/'); 187 if (slash_pos != NULL) { 188 *slash_pos = 0; 189 } 190 } 191 192 free(path); 193 194 if (hc_found && addr_found) { 195 if (out_hc_handle != NULL) { 196 *out_hc_handle = hc; 197 } 198 if (out_device_address != NULL) { 199 *out_device_address = addr; 200 } 201 return true; 202 } else { 203 return false; 204 } 205 } 192 206 193 207 static void print_usage(char *app_name) … … 195 209 #define _INDENT " " 196 210 197 198 199 211 printf(NAME ": Print out what multimedia keys were pressed.\n\n"); 212 printf("Usage: %s device\n", app_name); 213 printf(_INDENT "The device is a devman path to the device.\n"); 200 214 201 215 #undef _OPTION … … 205 219 int main(int argc, char *argv[]) 206 220 { 207 int act_event = -1;208 221 209 222 if (argc <= 1) { … … 212 225 } 213 226 214 //char *devpath = argv[1]; 215 const char *devpath = "/hw/pci0/00:06.0/ohci-rh/usb00_a2/HID1/hid"; 227 char *devpath = argv[1]; 228 229 /* The initialization is here only to make compiler happy. */ 230 devman_handle_t hc_handle = 0; 231 usb_address_t dev_addr = 0; 232 bool found = resolve_hc_handle_and_dev_addr(devpath, 233 &hc_handle, &dev_addr); 234 if (!found) { 235 fprintf(stderr, NAME ": device `%s' not found " 236 "or not of USB kind. Exiting.\n", devpath); 237 return -1; 238 } 216 239 217 240 int rc; 218 219 devman_handle_t dev_handle = 0; 220 rc = devman_device_get_handle(devpath, &dev_handle, 0); 221 if (rc != EOK) { 222 printf("Failed to get handle from devman: %s.\n", 241 usb_hc_connection_t conn; 242 243 usb_hc_connection_initialize(&conn, hc_handle); 244 rc = usb_hc_connection_open(&conn); 245 if (rc != EOK) { 246 printf(NAME ": failed to connect to HC: %s.\n", 223 247 str_error(rc)); 224 return rc; 225 } 248 return -1; 249 } 250 usb_address_t addr = 0; 251 252 devman_handle_t dev_handle; 253 rc = usb_hc_get_handle_by_address(&conn, addr, &dev_handle); 254 if (rc != EOK) { 255 printf(NAME ": failed getting handle to the device: %s.\n", 256 str_error(rc)); 257 return -1; 258 } 259 260 usb_hc_connection_close(&conn); 226 261 227 262 rc = devman_device_connect(dev_handle, 0); 228 263 if (rc < 0) { 229 printf(NAME ": failed to connect to the device (handle %"230 PRIun "): %s.\n", dev_handle,str_error(rc));231 return rc;264 printf(NAME ": failed to connect to the device: %s.\n", 265 str_error(rc)); 266 return -1; 232 267 } 233 268 234 269 dev_phone = rc; 235 // printf("Got phone to the device: %d\n", dev_phone); 236 237 char path[MAX_PATH_LENGTH]; 238 rc = devman_get_device_path(dev_handle, path, MAX_PATH_LENGTH); 239 if (rc != EOK) { 240 return ENOMEM; 241 } 242 243 printf("Device path: %s\n", path); 244 245 246 usb_hid_report_t *report = NULL; 247 rc = initialize_report_parser(dev_phone, &report); 248 if (rc != EOK) { 249 printf("Failed to initialize report parser: %s\n", 250 str_error(rc)); 251 return rc; 252 } 253 254 assert(report != NULL); 255 256 size_t size; 257 rc = usbhid_dev_get_event_length(dev_phone, &size); 258 if (rc != EOK) { 259 printf("Failed to get event length: %s.\n", str_error(rc)); 260 return rc; 261 } 262 263 // printf("Event length: %zu\n", size); 264 uint8_t *event = (uint8_t *)malloc(size); 265 if (event == NULL) { 266 // hangup phone? 267 return ENOMEM; 268 } 269 270 // printf("Event length: %zu\n", size); 271 272 size_t actual_size; 273 int event_nr; 274 275 while (1) { 276 // get event from the driver 277 // printf("Getting event from the driver.\n"); 278 279 /** @todo Try blocking call. */ 280 rc = usbhid_dev_get_event(dev_phone, event, size, &actual_size, 281 &event_nr, 0); 282 if (rc != EOK) { 283 // hangup phone? 284 printf("Error in getting event from the HID driver:" 285 "%s.\n", str_error(rc)); 286 break; 287 } 288 289 // printf("Got buffer: %p, size: %zu, max size: %zu\n", event, 290 // actual_size, size); 291 292 // printf("Event number: %d, my actual event: %d\n", event_nr, 293 // act_event); 294 if (event_nr > act_event) { 295 print_key(event, size, report); 296 act_event = event_nr; 297 } 298 299 async_usleep(100000); 300 } 270 printf("Got phone to the device: %d\n", dev_phone); 271 272 273 // size_t class_index = 0; 274 // size_t failed_attempts = 0; 275 276 // while (failed_attempts < MAX_FAILED_ATTEMPTS) { 277 // class_index++; 278 // devman_handle_t hc_handle = 0; 279 // int rc = usb_ddf_get_hc_handle_by_class(class_index, &hc_handle); 280 // if (rc != EOK) { 281 // failed_attempts++; 282 // continue; 283 // } 284 // char path[MAX_PATH_LENGTH]; 285 // rc = devman_get_device_path(hc_handle, path, MAX_PATH_LENGTH); 286 // if (rc != EOK) { 287 // continue; 288 // } 289 // print_found_hc(class_index, path); 290 // print_hc_devices(hc_handle); 291 // } 301 292 302 293 return 0; -
uspace/drv/usbhid/generic/hiddev.c
r74341ed r9ca8539 62 62 static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun); 63 63 64 static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer,65 size_t size, size_t *act_size, int *event_nr,unsigned int flags);64 static int usb_generic_hid_get_event(ddf_fun_t *fun, int32_t *buffer, 65 size_t size, size_t *act_size, unsigned int flags); 66 66 67 67 static int usb_generic_hid_client_connected(ddf_fun_t *fun); 68 69 static size_t usb_generic_get_report_descriptor_length(ddf_fun_t *fun);70 71 static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc,72 size_t size, size_t *actual_size);73 68 74 69 /*----------------------------------------------------------------------------*/ … … 76 71 static usbhid_iface_t usb_generic_iface = { 77 72 .get_event = usb_generic_hid_get_event, 78 .get_event_length = usb_generic_hid_get_event_length, 79 .get_report_descriptor_length = usb_generic_get_report_descriptor_length, 80 .get_report_descriptor = usb_generic_get_report_descriptor 73 .get_event_length = usb_generic_hid_get_event_length 81 74 }; 82 75 … … 90 83 static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun) 91 84 { 92 usb_log_debug2("Generic HID: Get event length (fun: %p, " 93 "fun->driver_data: %p.\n", fun, fun->driver_data); 94 95 if (fun == NULL || fun->driver_data == NULL) { 85 if (fun == NULL || fun->driver_data) { 96 86 return 0; 97 87 } … … 99 89 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 100 90 101 usb_log_debug2("hid_dev: %p, Max input report size (%d).\n", 102 hid_dev, hid_dev->max_input_report_size); 103 104 return hid_dev->max_input_report_size; 91 return hid_dev->input_report_size; 105 92 } 106 93 107 94 /*----------------------------------------------------------------------------*/ 108 95 109 static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer,110 size_t size, size_t *act_size, int *event_nr,unsigned int flags)96 static int usb_generic_hid_get_event(ddf_fun_t *fun, int32_t *buffer, 97 size_t size, size_t *act_size, unsigned int flags) 111 98 { 112 usb_log_debug2("Generic HID: Get event.\n"); 113 114 if (fun == NULL || fun->driver_data == NULL || buffer == NULL 115 || act_size == NULL || event_nr == NULL) { 116 usb_log_debug("No function"); 99 if (fun == NULL || fun->driver_data) { 117 100 return EINVAL; 118 101 } … … 121 104 122 105 if (hid_dev->input_report_size > size) { 123 usb_log_debug("input_report_size > size (%zu, %zu)\n",124 hid_dev->input_report_size, size);125 106 return EINVAL; // TODO: other error code 126 107 } 127 108 128 109 /*! @todo This should probably be atomic. */ 129 // if (usb_hid_report_ready()) { 130 // usb_log_debug2("Report ready, size: %zu\n", 131 // hid_dev->input_report_size); 132 133 // usb_hid_report_received(); 134 // } else { 135 // memset(buffer, 0, hid_dev->input_report_size); 136 // } 137 memcpy(buffer, hid_dev->input_report, 138 hid_dev->input_report_size); 139 *act_size = hid_dev->input_report_size; 140 *event_nr = usb_hid_report_number(hid_dev); 110 if (usb_hid_report_ready()) { 111 memcpy(buffer, hid_dev->input_report, 112 hid_dev->input_report_size); 113 *act_size = hid_dev->input_report_size; 114 usb_hid_report_received(); 115 } 141 116 142 117 // clear the buffer so that it will not be received twice … … 145 120 // note that we already received this report 146 121 // report_received = true; 147 usb_log_debug2("OK\n");148 149 return EOK;150 }151 152 /*----------------------------------------------------------------------------*/153 154 static size_t usb_generic_get_report_descriptor_length(ddf_fun_t *fun)155 {156 usb_log_debug("Generic HID: Get report descriptor length.\n");157 158 if (fun == NULL || fun->driver_data == NULL) {159 usb_log_debug("No function");160 return EINVAL;161 }162 163 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;164 165 usb_log_debug2("hid_dev->report_desc_size = %zu\n",166 hid_dev->report_desc_size);167 168 return hid_dev->report_desc_size;169 }170 171 /*----------------------------------------------------------------------------*/172 173 static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc,174 size_t size, size_t *actual_size)175 {176 usb_log_debug2("Generic HID: Get report descriptor.\n");177 178 if (fun == NULL || fun->driver_data == NULL) {179 usb_log_debug("No function");180 return EINVAL;181 }182 183 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;184 185 if (hid_dev->report_desc_size > size) {186 return EINVAL; // TODO: other error code187 }188 189 memcpy(desc, hid_dev->report_desc, hid_dev->report_desc_size);190 *actual_size = hid_dev->report_desc_size;191 122 192 123 return EOK; … … 197 128 static int usb_generic_hid_client_connected(ddf_fun_t *fun) 198 129 { 199 usb_ log_debug("Generic HID: Client connected.\n");130 usb_hid_report_received(); 200 131 return EOK; 201 132 } … … 214 145 return ENOMEM; 215 146 } 216 217 fun->ops = &usb_generic_hid_ops;218 fun->driver_data = hid_dev;219 147 220 148 int rc = ddf_fun_bind(fun); … … 226 154 } 227 155 228 usb_log_debug("HID function created. Handle: %d\n", fun->handle); 156 fun->ops = &usb_generic_hid_ops; 157 fun->driver_data = hid_dev; 229 158 230 159 return EOK; … … 247 176 uint8_t *buffer, size_t buffer_size) 248 177 { 249 usb_log_debug 2("usb_hid_polling_callback(%p, %p, %zu)\n",178 usb_log_debug("usb_hid_polling_callback(%p, %p, %zu)\n", 250 179 hid_dev, buffer, buffer_size); 251 180 usb_debug_str_buffer(buffer, buffer_size, 0); -
uspace/drv/usbhid/kbd/kbddev.c
r74341ed r9ca8539 798 798 } 799 799 800 usb_log_debug("%s function created. Handle: %d\n", HID_KBD_FUN_NAME,801 fun->handle);802 803 800 usb_log_debug("Adding DDF function to class %s...\n", 804 801 HID_KBD_CLASS_NAME); -
uspace/drv/usbhid/multimedia/keymap.c
r74341ed r9ca8539 48 48 */ 49 49 static int usb_hid_keymap_consumer[0x29c] = { 50 [0xf] = KC_F1, /* Just for testing purposes */ 51 [0x5] = KC_F2, /* Just for testing purposes */ 52 [0x8] = KC_F3, /* Just for testing purposes */ 53 [0x6] = KC_F4, /* Just for testing purposes */ 54 [0x7] = KC_F5, /* Just for testing purposes */ 55 [0xc] = KC_F6, /* Just for testing purposes */ 56 50 57 [0xb5] = 0, /* Scan Next Track */ 51 58 [0xb6] = 0, /* Scan Previous Track */ 52 59 [0xb7] = 0, /* Stop */ 53 60 [0xb8] = 0, /* Eject */ 54 [0xcd] = 0/*KC_F2*/, /* Play/Pause */55 [0xe2] = 0/*KC_F3*/, /* Mute */56 [0xe9] = 0/*KC_F5*/, /* Volume Increment */57 [0xea] = 0/*KC_F4*/, /* Volume Decrement */58 [0x183] = 0 /*KC_F1*/, /* AL Consumer Control Configuration */61 [0xcd] = KC_F2, /* Play/Pause */ 62 [0xe2] = KC_F3, /* Mute */ 63 [0xe9] = KC_F5, /* Volume Increment */ 64 [0xea] = KC_F4, /* Volume Decrement */ 65 [0x183] = 0, /* AL Consumer Control Configuration */ 59 66 [0x18a] = 0, /* AL Email Reader */ 60 67 [0x192] = 0, /* AL Calculator */ 61 68 [0x221] = 0, /* AC Search */ 62 [0x223] = 0 /*KC_F6*/, /* AC Home */69 [0x223] = 0, /* AC Home */ 63 70 [0x224] = 0, /* AC Back */ 64 71 [0x225] = 0, /* AC Forward */ 65 72 [0x226] = 0, /* AC Stop */ 66 [0x227] = 0, /* AC Refresh */ 67 [0x22a] = 0 /* AC Bookmarks */ 73 [0x227] = KC_F1, /* AC Refresh */ 74 [0x22a] = KC_F6 /* AC Bookmarks */ 75 }; 76 77 static const char *usb_hid_consumer_usage_str[0x29d] = { 78 [0x01] = "Consumer Control", 79 [0x02] = "Numeric Key Pad", 80 [0x03] = "Programmable Buttons", 81 [0x04] = "Microphone", 82 [0x05] = "Headphone", 83 [0x06] = "Graphic Equalizer", 84 [0x07] = "Reserved", 85 [0x08] = "Reserved", 86 [0x09] = "Reserved", 87 [0x0a] = "Reserved", 88 [0x0b] = "Reserved", 89 [0x0c] = "Reserved", 90 [0x0d] = "Reserved", 91 [0x0e] = "Reserved", 92 [0x0f] = "Reserved", 93 [0x10] = "Reserved", 94 [0x11] = "Reserved", 95 [0x12] = "Reserved", 96 [0x13] = "Reserved", 97 [0x14] = "Reserved", 98 [0x15] = "Reserved", 99 [0x16] = "Reserved", 100 [0x17] = "Reserved", 101 [0x18] = "Reserved", 102 [0x19] = "Reserved", 103 [0x1a] = "Reserved", 104 [0x1b] = "Reserved", 105 [0x1c] = "Reserved", 106 [0x1d] = "Reserved", 107 [0x1e] = "Reserved", 108 [0x1f] = "Reserved", 109 [0x20] = "+10", 110 [0x21] = "+100", 111 [0x22] = "AM/PM", 112 [0x23] = "Reserved", 113 [0x24] = "Reserved", 114 [0x25] = "Reserved", 115 [0x26] = "Reserved", 116 [0x27] = "Reserved", 117 [0x28] = "Reserved", 118 [0x29] = "Reserved", 119 [0x2a] = "Reserved", 120 [0x2b] = "Reserved", 121 [0x2c] = "Reserved", 122 [0x2d] = "Reserved", 123 [0x2e] = "Reserved", 124 [0x2f] = "Reserved", 125 [0x30] = "Reserved", 126 [0x31] = "Reserved", 127 [0x32] = "Reserved", 128 [0x33] = "Reserved", 129 [0x34] = "Reserved", 130 [0x35] = "Reserved", 131 [0x36] = "Reserved", 132 [0x37] = "Reserved", 133 [0x38] = "Reserved", 134 [0x39] = "Reserved", 135 [0x3a] = "Reserved", 136 [0x3b] = "Reserved", 137 [0x3c] = "Reserved", 138 [0x3d] = "Reserved", 139 [0x3e] = "Reserved", 140 [0x3f] = "Reserved", 141 [0x40] = "Menu", 142 [0x41] = "Menu Pick", 143 [0x42] = "Menu Up", 144 [0x43] = "Menu Down", 145 [0x44] = "Menu Left", 146 [0x45] = "Menu Right", 147 [0x46] = "Menu Escape", 148 [0x47] = "Menu Value Increase", 149 [0x48] = "Menu Value Decrease", 150 [0x49] = "Reserved", 151 [0x4a] = "Reserved", 152 [0x4b] = "Reserved", 153 [0x4c] = "Reserved", 154 [0x4d] = "Reserved", 155 [0x4e] = "Reserved", 156 [0x4f] = "Reserved", 157 [0x50] = "Reserved", 158 [0x51] = "Reserved", 159 [0x52] = "Reserved", 160 [0x53] = "Reserved", 161 [0x54] = "Reserved", 162 [0x55] = "Reserved", 163 [0x56] = "Reserved", 164 [0x57] = "Reserved", 165 [0x58] = "Reserved", 166 [0x59] = "Reserved", 167 [0x5a] = "Reserved", 168 [0x5b] = "Reserved", 169 [0x5c] = "Reserved", 170 [0x5d] = "Reserved", 171 [0x5e] = "Reserved", 172 [0x5f] = "Reserved", 173 [0x60] = "Data On Screen", 174 [0x61] = "Closed Caption", 175 [0x62] = "Closed Caption Select", 176 [0x63] = "VCR/TV", 177 [0x64] = "Broadcast Mode", 178 [0x65] = "Snapshot", 179 [0x66] = "Still", 180 [0x67] = "Reserved", 181 [0x68] = "Reserved", 182 [0x69] = "Reserved", 183 [0x6a] = "Reserved", 184 [0x6b] = "Reserved", 185 [0x6c] = "Reserved", 186 [0x6d] = "Reserved", 187 [0x6e] = "Reserved", 188 [0x6f] = "Reserved", 189 [0x70] = "Reserved", 190 [0x71] = "Reserved", 191 [0x72] = "Reserved", 192 [0x73] = "Reserved", 193 [0x74] = "Reserved", 194 [0x75] = "Reserved", 195 [0x76] = "Reserved", 196 [0x77] = "Reserved", 197 [0x78] = "Reserved", 198 [0x79] = "Reserved", 199 [0x7a] = "Reserved", 200 [0x7b] = "Reserved", 201 [0x7c] = "Reserved", 202 [0x7d] = "Reserved", 203 [0x7e] = "Reserved", 204 [0x7f] = "Reserved", 205 [0x80] = "Selection", 206 [0x81] = "Assign Selection", 207 [0x82] = "Mode Step", 208 [0x83] = "Recall Last", 209 [0x84] = "Enter Channel", 210 [0x85] = "Order Movie", 211 [0x86] = "Channel", 212 [0x87] = "Media Selection", 213 [0x88] = "Media Select Computer", 214 [0x89] = "Media Select TV", 215 [0x8a] = "Media Select WWW", 216 [0x8b] = "Media Select DVD", 217 [0x8c] = "Media Select Telephone", 218 [0x8d] = "Media Select Program Guide", 219 [0x8e] = "Media Select Video Phone", 220 [0x8f] = "Media Select Games", 221 [0x90] = "Media Select Messages", 222 [0x91] = "Media Select CD", 223 [0x92] = "Media Select VCR", 224 [0x93] = "Media Select Tuner", 225 [0x94] = "Quit", 226 [0x95] = "Help", 227 [0x96] = "Media Select Tape", 228 [0x97] = "Media Select Cable", 229 [0x98] = "Media Select Satellite", 230 [0x99] = "Media Select Security", 231 [0x9a] = "Media Select Home", 232 [0x9b] = "Media Select Call", 233 [0x9c] = "Channel Increment", 234 [0x9d] = "Channel Decrement", 235 [0x9e] = "Media Select SAP", 236 [0x9f] = "Reserved", 237 [0xa0] = "VCR Plus", 238 [0xa1] = "Once", 239 [0xa2] = "Daily", 240 [0xa3] = "Weekly", 241 [0xa4] = "Monthly", 242 [0xa5] = "Reserved", 243 [0xa6] = "Reserved", 244 [0xa7] = "Reserved", 245 [0xa8] = "Reserved", 246 [0xa9] = "Reserved", 247 [0xaa] = "Reserved", 248 [0xab] = "Reserved", 249 [0xac] = "Reserved", 250 [0xad] = "Reserved", 251 [0xae] = "Reserved", 252 [0xaf] = "Reserved", 253 [0xb0] = "Play", 254 [0xb1] = "Pause", 255 [0xb2] = "Record", 256 [0xb3] = "Fast Forward", 257 [0xb4] = "Rewind", 258 [0xb5] = "Scan Next Track", 259 [0xb6] = "Scan Previous Trac", 260 [0xb7] = "Stop", 261 [0xb8] = "Eject", 262 [0xb9] = "Random Play", 263 [0xba] = "Select Disc", 264 [0xbb] = "Enter Disc", 265 [0xbc] = "Repeat", 266 [0xbd] = "Tracking", 267 [0xbe] = "Track Normal", 268 [0xbf] = "Slow Tracking", 269 [0xc0] = "Frame Forward", 270 [0xc1] = "Frame Back", 271 [0xc2] = "Mark", 272 [0xc3] = "Clear Mark", 273 [0xc4] = "Repeat From Mark", 274 [0xc5] = "Return to Mark", 275 [0xc6] = "Search Mark Forward", 276 [0xc7] = "Search Mark Backwards", 277 [0xc8] = "Counter Reset", 278 [0xc9] = "Show Counter", 279 [0xca] = "Tracking Increment", 280 [0xcb] = "Tracking Decrement", 281 [0xcc] = "Stop/Eject", 282 [0xcd] = "Play/Pause", 283 [0xce] = "Play/Skip", 284 [0xcf] = "Reserved", 285 [0xd0] = "Reserved", 286 [0xd1] = "Reserved", 287 [0xd2] = "Reserved", 288 [0xd3] = "Reserved", 289 [0xd4] = "Reserved", 290 [0xd5] = "Reserved", 291 [0xd6] = "Reserved", 292 [0xd7] = "Reserved", 293 [0xd8] = "Reserved", 294 [0xd9] = "Reserved", 295 [0xda] = "Reserved", 296 [0xdb] = "Reserved", 297 [0xdc] = "Reserved", 298 [0xdd] = "Reserved", 299 [0xde] = "Reserved", 300 [0xdf] = "Reserved", 301 [0xe0] = "Volume", 302 [0xe1] = "Balance", 303 [0xe2] = "Mute", 304 [0xe3] = "Bass", 305 [0xe4] = "Treble", 306 [0xe5] = "Bass Boost", 307 [0xe6] = "Surround Mode", 308 [0xe7] = "Loudness", 309 [0xe8] = "MPX", 310 [0xe9] = "Volume Increment", 311 [0xea] = "Volume Decrement", 312 [0xeb] = "Reserved", 313 [0xec] = "Reserved", 314 [0xed] = "Reserved", 315 [0xee] = "Reserved", 316 [0xef] = "Reserved", 317 [0xf0] = "Speed Select", 318 [0xf1] = "Playback Speed", 319 [0xf2] = "Standard Play", 320 [0xf3] = "Long Play", 321 [0xf4] = "Extended Play", 322 [0xf5] = "Slow", 323 [0xf6] = "Reserved", 324 [0xf7] = "Reserved", 325 [0xf8] = "Reserved", 326 [0xf9] = "Reserved", 327 [0xfa] = "Reserved", 328 [0xfb] = "Reserved", 329 [0xfc] = "Reserved", 330 [0xfd] = "Reserved", 331 [0xfe] = "Reserved", 332 [0xff] = "Reserved", 333 [0x100] = "Fan Enable", 334 [0x101] = "Fan Speed", 335 [0x102] = "Light Enable", 336 [0x103] = "Light Illumination Level", 337 [0x104] = "Climate Control Enable", 338 [0x105] = "Room Temperature", 339 [0x106] = "Security Enable", 340 [0x107] = "Fire Alarm", 341 [0x108] = "Police Alarm", 342 [0x109] = "Proximity", 343 [0x10a] = "Motion", 344 [0x10b] = "Duress Alarm", 345 [0x10c] = "Holdup Alarm", 346 [0x10d] = "Medical Alarm", 347 [0x10e] = "Reserved", 348 [0x10f] = "Reserved", 349 [0x110] = "Reserved", 350 [0x111] = "Reserved", 351 [0x112] = "Reserved", 352 [0x113] = "Reserved", 353 [0x114] = "Reserved", 354 [0x115] = "Reserved", 355 [0x116] = "Reserved", 356 [0x117] = "Reserved", 357 [0x118] = "Reserved", 358 [0x119] = "Reserved", 359 [0x11a] = "Reserved", 360 [0x11b] = "Reserved", 361 [0x11c] = "Reserved", 362 [0x11d] = "Reserved", 363 [0x11e] = "Reserved", 364 [0x11f] = "Reserved", 365 [0x120] = "Reserved", 366 [0x121] = "Reserved", 367 [0x122] = "Reserved", 368 [0x123] = "Reserved", 369 [0x124] = "Reserved", 370 [0x125] = "Reserved", 371 [0x126] = "Reserved", 372 [0x127] = "Reserved", 373 [0x128] = "Reserved", 374 [0x129] = "Reserved", 375 [0x12a] = "Reserved", 376 [0x12b] = "Reserved", 377 [0x12c] = "Reserved", 378 [0x12d] = "Reserved", 379 [0x12e] = "Reserved", 380 [0x12f] = "Reserved", 381 [0x130] = "Reserved", 382 [0x131] = "Reserved", 383 [0x132] = "Reserved", 384 [0x133] = "Reserved", 385 [0x134] = "Reserved", 386 [0x135] = "Reserved", 387 [0x136] = "Reserved", 388 [0x137] = "Reserved", 389 [0x138] = "Reserved", 390 [0x139] = "Reserved", 391 [0x13a] = "Reserved", 392 [0x13b] = "Reserved", 393 [0x13c] = "Reserved", 394 [0x13d] = "Reserved", 395 [0x13e] = "Reserved", 396 [0x13f] = "Reserved", 397 [0x140] = "Reserved", 398 [0x141] = "Reserved", 399 [0x142] = "Reserved", 400 [0x143] = "Reserved", 401 [0x144] = "Reserved", 402 [0x145] = "Reserved", 403 [0x146] = "Reserved", 404 [0x147] = "Reserved", 405 [0x148] = "Reserved", 406 [0x149] = "Reserved", 407 [0x14a] = "Reserved", 408 [0x14b] = "Reserved", 409 [0x14c] = "Reserved", 410 [0x14d] = "Reserved", 411 [0x14e] = "Reserved", 412 [0x14f] = "Reserved", 413 [0x150] = "Balance Right", 414 [0x151] = "Balance Left", 415 [0x152] = "Bass Increment", 416 [0x153] = "Bass Decrement", 417 [0x154] = "Treble Increment", 418 [0x155] = "Treble Decrement", 419 [0x156] = "Reserved", 420 [0x157] = "Reserved", 421 [0x158] = "Reserved", 422 [0x159] = "Reserved", 423 [0x15a] = "Reserved", 424 [0x15b] = "Reserved", 425 [0x15c] = "Reserved", 426 [0x15d] = "Reserved", 427 [0x15e] = "Reserved", 428 [0x15f] = "Reserved", 429 [0x160] = "Speaker System", 430 [0x161] = "Channel Left", 431 [0x162] = "Channel Right", 432 [0x163] = "Channel Center", 433 [0x164] = "Channel Front", 434 [0x165] = "Channel Center Front", 435 [0x166] = "Channel Side", 436 [0x167] = "Channel Surround", 437 [0x168] = "Channel Low Frequency Enhancement", 438 [0x169] = "Channel Top", 439 [0x16a] = "Channel Unknown", 440 [0x16b] = "Reserved", 441 [0x16c] = "Reserved", 442 [0x16d] = "Reserved", 443 [0x16e] = "Reserved", 444 [0x16f] = "Reserved", 445 [0x170] = "Sub-channel", 446 [0x171] = "Sub-channel Increment", 447 [0x172] = "Sub-channel Decrement", 448 [0x173] = "Alternate Audio Increment", 449 [0x174] = "Alternate Audio Decrement", 450 [0x175] = "Reserved", 451 [0x176] = "Reserved", 452 [0x177] = "Reserved", 453 [0x178] = "Reserved", 454 [0x179] = "Reserved", 455 [0x17a] = "Reserved", 456 [0x17b] = "Reserved", 457 [0x17c] = "Reserved", 458 [0x17d] = "Reserved", 459 [0x17e] = "Reserved", 460 [0x17f] = "Reserved", 461 [0x180] = "Application Launch Buttons", 462 [0x181] = "AL Launch Buttion Configuration Tool", 463 [0x182] = "AL Programmable Button Configuration", 464 [0x183] = "AL Consumer Control Configuration", 465 [0x184] = "AL Word Processor", 466 [0x185] = "AL Text Editor", 467 [0x186] = "AL Spreadsheet", 468 [0x187] = "AL Graphics Editor", 469 [0x188] = "AL Presentation App", 470 [0x189] = "AL Database App", 471 [0x18a] = "AL Email Reader", 472 [0x18b] = "AL Newsreader", 473 [0x18c] = "AL Voicemail", 474 [0x18d] = "AL Contacts/Address Book", 475 [0x18e] = "AL Calendar/Schedule", 476 [0x18f] = "AL Task/Project Manager", 477 [0x190] = "AL Log/Journal/Timecard", 478 [0x191] = "AL Checkbook/Finance", 479 [0x192] = "AL Calculator", 480 [0x193] = "AL A/V Capture/Playback", 481 [0x194] = "AL Local Machine Browser", 482 [0x195] = "AL LAN/WAN Browser", 483 [0x196] = "AL Internet Browser", 484 [0x197] = "AL Remote Networking/ISP Connect", 485 [0x198] = "AL Network Conference", 486 [0x199] = "AL Network Chat", 487 [0x19a] = "AL Telephony/Dialer", 488 [0x19b] = "AL Logon", 489 [0x19c] = "AL Logoff", 490 [0x19d] = "AL Logon/Logoff", 491 [0x19e] = "AL Terminal Lock/Screensaver", 492 [0x19f] = "AL Control Panel", 493 [0x1a0] = "AL Command Line Processor/Run", 494 [0x1a1] = "AL Process/Task Manager", 495 [0x1a2] = "AL Select Task/Application", 496 [0x1a3] = "AL Next Task/Application", 497 [0x1a4] = "AL Previous Task/Application", 498 [0x1a5] = "AL Preemptive Halt Task/Application", 499 [0x1a6] = "AL Integrated Help Center", 500 [0x1a7] = "AL Documents", 501 [0x1a8] = "AL Thesaurus", 502 [0x1a9] = "AL Dictionary", 503 [0x1aa] = "AL Desktop", 504 [0x1ab] = "AL Spell Check", 505 [0x1ac] = "AL Grammar Check", 506 [0x1ad] = "AL Wireless Status", 507 [0x1ae] = "AL Keyboard Layout", 508 [0x1af] = "AL Virus Protection", 509 [0x1b0] = "AL Encryption", 510 [0x1b1] = "AL Screen Saver", 511 [0x1b2] = "AL Alarms", 512 [0x1b3] = "AL Clock", 513 [0x1b4] = "AL File Browser", 514 [0x1b5] = "AL Power Status", 515 [0x1b6] = "AL Image Browser", 516 [0x1b7] = "AL Audio Browser", 517 [0x1b8] = "AL Movie Browser", 518 [0x1b9] = "AL Digital Rights Manager", 519 [0x1ba] = "AL Digital Wallet", 520 [0x1bb] = "Reserved", 521 [0x1bc] = "AL Instant Messaging", 522 [0x1bd] = "AL OEM Features Tips/Tutorial Browser", 523 [0x1be] = "AL OEM Help", 524 [0x1bf] = "AL Online Community", 525 [0x1c0] = "AL Entertainment Content Browser", 526 [0x1c1] = "AL Online Shopping Browser", 527 [0x1c2] = "AL SmartCard Information/Help", 528 [0x1c3] = "AL Market Monitor/Finance Browser", 529 [0x1c4] = "AL Customized Corporate News Browser", 530 [0x1c5] = "AL Online Activity Browser", 531 [0x1c6] = "AL Research/Search Browser", 532 [0x1c7] = "AL Audio Player", 533 [0x1c8] = "Reserved", 534 [0x1c9] = "Reserved", 535 [0x1ca] = "Reserved", 536 [0x1cb] = "Reserved", 537 [0x1cc] = "Reserved", 538 [0x1cd] = "Reserved", 539 [0x1ce] = "Reserved", 540 [0x1cf] = "Reserved", 541 [0x1d0] = "Reserved", 542 [0x1d1] = "Reserved", 543 [0x1d2] = "Reserved", 544 [0x1d3] = "Reserved", 545 [0x1d4] = "Reserved", 546 [0x1d5] = "Reserved", 547 [0x1d6] = "Reserved", 548 [0x1d7] = "Reserved", 549 [0x1d8] = "Reserved", 550 [0x1d9] = "Reserved", 551 [0x1da] = "Reserved", 552 [0x1db] = "Reserved", 553 [0x1dc] = "Reserved", 554 [0x1dd] = "Reserved", 555 [0x1de] = "Reserved", 556 [0x1df] = "Reserved", 557 [0x1e0] = "Reserved", 558 [0x1e1] = "Reserved", 559 [0x1e2] = "Reserved", 560 [0x1e3] = "Reserved", 561 [0x1e4] = "Reserved", 562 [0x1e5] = "Reserved", 563 [0x1e6] = "Reserved", 564 [0x1e7] = "Reserved", 565 [0x1e8] = "Reserved", 566 [0x1e9] = "Reserved", 567 [0x1ea] = "Reserved", 568 [0x1eb] = "Reserved", 569 [0x1ec] = "Reserved", 570 [0x1ed] = "Reserved", 571 [0x1ee] = "Reserved", 572 [0x1ef] = "Reserved", 573 [0x1f0] = "Reserved", 574 [0x1f1] = "Reserved", 575 [0x1f2] = "Reserved", 576 [0x1f3] = "Reserved", 577 [0x1f4] = "Reserved", 578 [0x1f5] = "Reserved", 579 [0x1f6] = "Reserved", 580 [0x1f7] = "Reserved", 581 [0x1f8] = "Reserved", 582 [0x1f9] = "Reserved", 583 [0x1fa] = "Reserved", 584 [0x1fb] = "Reserved", 585 [0x1fc] = "Reserved", 586 [0x1fd] = "Reserved", 587 [0x1fe] = "Reserved", 588 [0x1ff] = "Reserved", 589 [0x200] = "Generic GUI Application Controls", 590 [0x201] = "AC New", 591 [0x202] = "AC Open", 592 [0x203] = "AC Close", 593 [0x204] = "AC Exit", 594 [0x205] = "AC Maximize", 595 [0x206] = "AC Minimize", 596 [0x207] = "AC Save", 597 [0x208] = "AC Print", 598 [0x209] = "AC Properties", 599 [0x20a] = "", 600 [0x20b] = "", 601 [0x20c] = "", 602 [0x20d] = "", 603 [0x20e] = "", 604 [0x20f] = "", 605 [0x210] = "", 606 [0x211] = "", 607 [0x212] = "", 608 [0x213] = "", 609 [0x214] = "", 610 [0x215] = "", 611 [0x216] = "", 612 [0x217] = "", 613 [0x218] = "", 614 [0x219] = "", 615 [0x21a] = "AC Undo", 616 [0x21b] = "AC Copy", 617 [0x21c] = "AC Cut", 618 [0x21d] = "AC Paste", 619 [0x21e] = "AC Select All", 620 [0x21f] = "AC Find", 621 [0x220] = "AC Find and Replace", 622 [0x221] = "AC Search", 623 [0x222] = "AC Go To", 624 [0x223] = "AC Home", 625 [0x224] = "AC Back", 626 [0x225] = "AC Forward", 627 [0x226] = "AC Stop", 628 [0x227] = "AC Refresh", 629 [0x228] = "AC Previous Link", 630 [0x229] = "AC Next Link", 631 [0x22a] = "AC Bookmarks", 632 [0x22b] = "AC History", 633 [0x22c] = "AC Subscriptions", 634 [0x22d] = "AC Zoom In", 635 [0x22e] = "AC Zoom Out", 636 [0x22f] = "AC Zoom", 637 [0x230] = "AC Full Screen View", 638 [0x231] = "AC Normal View", 639 [0x232] = "AC View Toggle", 640 [0x233] = "AC Scroll Up", 641 [0x234] = "AC Scroll Down", 642 [0x235] = "AC Scroll", 643 [0x236] = "AC Pan Left", 644 [0x237] = "AC Pan Right", 645 [0x238] = "AC Pan", 646 [0x239] = "AC New Window", 647 [0x23a] = "AC Tile Horizontally", 648 [0x23b] = "AC Tile Vertically", 649 [0x23c] = "AC Format", 650 [0x23d] = "AC Edit", 651 [0x23e] = "AC Bold", 652 [0x23f] = "AC Italics", 653 [0x240] = "AC Undeline", 654 [0x241] = "AC Strikethrough", 655 [0x242] = "AC Subscript", 656 [0x243] = "AC Superscript", 657 [0x244] = "AC All Caps", 658 [0x245] = "AC Rotate", 659 [0x246] = "AC Resize", 660 [0x247] = "AC Flip Horizontal", 661 [0x248] = "AC Flip Vertical", 662 [0x249] = "AC Mirror Horizontal", 663 [0x24a] = "AC Mirror Vertical", 664 [0x24b] = "AC Font Select", 665 [0x24c] = "AC Font Color", 666 [0x24d] = "AC Font Size", 667 [0x24e] = "AC Justify Left", 668 [0x24f] = "AC Justify Center H", 669 [0x250] = "AC Justify Right", 670 [0x251] = "AC Justify Block H", 671 [0x252] = "AC Justify Top", 672 [0x253] = "AC Justify Center V", 673 [0x254] = "AC Justify Bottom", 674 [0x255] = "AC Justify Block V", 675 [0x256] = "AC Indent Decrease", 676 [0x257] = "AC Indent Increase", 677 [0x258] = "AC Numbered List", 678 [0x259] = "AC Restart Numbering", 679 [0x25a] = "AC Bulleted List", 680 [0x25b] = "AC Promote", 681 [0x25c] = "AC Demote", 682 [0x25d] = "AC Yes", 683 [0x25e] = "AC No", 684 [0x25f] = "AC Cancel", 685 [0x260] = "AC Catalog", 686 [0x261] = "AC Buy/Checkout", 687 [0x262] = "AC Add to Cart", 688 [0x263] = "AC Expand", 689 [0x264] = "AC Expand All", 690 [0x265] = "AC Collapse", 691 [0x266] = "AC Collapse All", 692 [0x267] = "AC Print Preview", 693 [0x268] = "AC Paste Special", 694 [0x269] = "AC Insert Mode", 695 [0x26a] = "AC Delete", 696 [0x26b] = "AC Lock", 697 [0x26c] = "AC Unlock", 698 [0x26d] = "AC Protect", 699 [0x26e] = "AC Unprotect", 700 [0x26f] = "AC Attach Comment", 701 [0x270] = "AC Delete Comment", 702 [0x271] = "AC View Comment", 703 [0x272] = "AC Select Word", 704 [0x273] = "AC Select Sentence", 705 [0x274] = "AC Select Paragraph", 706 [0x275] = "AC Select Column", 707 [0x276] = "AC Select Row", 708 [0x277] = "AC Select Table", 709 [0x278] = "AC Select Object", 710 [0x279] = "AC Redo/Repeat", 711 [0x27a] = "AC Sort", 712 [0x27b] = "AC Sort Ascending", 713 [0x27c] = "AC Sort Descending", 714 [0x27d] = "AC Filter", 715 [0x27e] = "AC Set Clock", 716 [0x27f] = "AC View Clock", 717 [0x280] = "AC Select Time Zone", 718 [0x281] = "AC Edit Time Zones", 719 [0x282] = "AC Set Alarm", 720 [0x283] = "AC Clear Alarm", 721 [0x284] = "AC Snooze Alarm", 722 [0x285] = "AC Reset Alarm", 723 [0x286] = "AC Synchronize", 724 [0x287] = "AC Send/Receive", 725 [0x288] = "AC Send To", 726 [0x289] = "AC Reply", 727 [0x28a] = "AC Reply All", 728 [0x28b] = "AC Forward Msg", 729 [0x28c] = "AC Send", 730 [0x28d] = "AC Attach File", 731 [0x28e] = "AC Upload", 732 [0x28f] = "AC Download (Save Target As)", 733 [0x290] = "AC Set Borders", 734 [0x291] = "AC Insert Row", 735 [0x292] = "AC Insert Column", 736 [0x293] = "AC Insert File", 737 [0x294] = "AC Insert Picture", 738 [0x295] = "AC Insert Object", 739 [0x296] = "AC Insert Symbol", 740 [0x297] = "AC Save and Close", 741 [0x298] = "AC Rename", 742 [0x299] = "AC Merge", 743 [0x29a] = "AC Split", 744 [0x29b] = "AC Distrubute Horizontally", 745 [0x29c] = "AC Distrubute Vertically" 68 746 }; 69 747 … … 91 769 92 770 /** 771 * Translates USB HID Usages from the Consumer Page into their string 772 * representation. 773 * 774 * @param usage USB HID Consumer Page Usage number. 775 * 776 * @retval HelenOS key code corresponding to the given USB Consumer Page Usage. 777 */ 778 const char *usb_multimedia_usage_to_str(int usage) 779 { 780 size_t map_length = sizeof(usb_hid_consumer_usage_str) / sizeof(char *); 781 782 if ((usage < 0) || ((size_t)usage >= map_length)) 783 return "Unknown usage"; 784 785 /*! @todo What if the usage is not in the table? */ 786 return usb_hid_consumer_usage_str[usage]; 787 } 788 789 /** 93 790 * @} 94 791 */ -
uspace/drv/usbhid/multimedia/keymap.h
r74341ed r9ca8539 39 39 unsigned int usb_multimedia_map_usage(int usage); 40 40 41 const char *usb_multimedia_usage_to_str(int usage); 42 41 43 #endif /* USB_HID_MULTIMEDIA_KEYMAP_H_ */ 42 44 -
uspace/drv/usbhid/multimedia/multimedia.c
r74341ed r9ca8539 43 43 #include <usb/debug.h> 44 44 #include <usb/hid/usages/core.h> 45 #include <usb/hid/usages/consumer.h>46 45 47 46 #include <errno.h> … … 59 58 typedef struct usb_multimedia_t { 60 59 /** Previously pressed keys (not translated to key codes). */ 61 //int32_t *keys_old;60 int32_t *keys_old; 62 61 /** Currently pressed keys (not translated to key codes). */ 63 //int32_t *keys;62 int32_t *keys; 64 63 /** Count of stored keys (i.e. number of keys in the report). */ 65 //size_t key_count;64 size_t key_count; 66 65 /** IPC phone to the console device (for sending key events). */ 67 66 int console_phone; … … 175 174 176 175 // free all buffers 177 //if ((*multim_dev)->keys != NULL) {178 //free((*multim_dev)->keys);179 //}180 //if ((*multim_dev)->keys_old != NULL) {181 //free((*multim_dev)->keys_old);182 //}176 if ((*multim_dev)->keys != NULL) { 177 free((*multim_dev)->keys); 178 } 179 if ((*multim_dev)->keys_old != NULL) { 180 free((*multim_dev)->keys_old); 181 } 183 182 184 183 free(*multim_dev); … … 210 209 return rc; 211 210 } 212 213 usb_log_debug("%s function created. Handle: %d\n", NAME, fun->handle);214 211 215 212 rc = ddf_fun_add_to_class(fun, "keyboard"); … … 244 241 multim_dev->console_phone = -1; 245 242 246 //usb_hid_report_path_t *path = usb_hid_report_path();247 //usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0);248 249 //usb_hid_report_path_set_report_id(path, 1);250 251 //multim_dev->key_count = usb_hid_report_size(252 // hid_dev->report, 1, USB_HID_REPORT_TYPE_INPUT);253 254 //usb_hid_report_path_free(path);255 256 //usb_log_debug(NAME " Size of the input report: %zu\n",257 //multim_dev->key_count);258 259 //multim_dev->keys = (int32_t *)calloc(multim_dev->key_count,260 //sizeof(int32_t));261 262 //if (multim_dev->keys == NULL) {263 //usb_log_fatal("No memory!\n");264 //free(multim_dev);265 //return ENOMEM;266 //}267 268 //multim_dev->keys_old =269 //(int32_t *)calloc(multim_dev->key_count, sizeof(int32_t));270 271 //if (multim_dev->keys_old == NULL) {272 //usb_log_fatal("No memory!\n");273 //free(multim_dev->keys);274 //free(multim_dev);275 //return ENOMEM;276 //}243 usb_hid_report_path_t *path = usb_hid_report_path(); 244 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0); 245 246 usb_hid_report_path_set_report_id(path, 1); 247 248 multim_dev->key_count = usb_hid_report_size( 249 hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT); 250 251 usb_hid_report_path_free(path); 252 253 usb_log_debug(NAME " Size of the input report: %zu\n", 254 multim_dev->key_count); 255 256 multim_dev->keys = (int32_t *)calloc(multim_dev->key_count, 257 sizeof(int32_t)); 258 259 if (multim_dev->keys == NULL) { 260 usb_log_fatal("No memory!\n"); 261 free(multim_dev); 262 return ENOMEM; 263 } 264 265 multim_dev->keys_old = 266 (int32_t *)calloc(multim_dev->key_count, sizeof(int32_t)); 267 268 if (multim_dev->keys_old == NULL) { 269 usb_log_fatal("No memory!\n"); 270 free(multim_dev->keys); 271 free(multim_dev); 272 return ENOMEM; 273 } 277 274 278 275 /*! @todo Autorepeat */ … … 360 357 usb_multimedia_map_usage(field->usage); 361 358 const char *key_str = 362 usb hid_multimedia_usage_to_str(field->usage);359 usb_multimedia_usage_to_str(field->usage); 363 360 usb_log_info("Pressed key: %s\n", key_str); 364 361 usb_multimedia_push_ev(hid_dev, multim_dev, KEY_PRESS, -
uspace/drv/usbhid/subdrivers.c
r74341ed r9ca8539 38 38 #include <usb/hid/hidpath.h> 39 39 40 //#include "lgtch-ultrax/lgtch-ultrax.h" 40 41 #include "multimedia/multimedia.h" 41 42 #include "mouse/mousedev.h" 42 #include "generic/hiddev.h"43 43 44 44 static usb_hid_subdriver_usage_t path_kbd[] = { … … 58 58 }; 59 59 60 //static usb_hid_subdriver_usage_t generic_hid_key_path[] = {61 // {0, 0}62 //};63 64 60 const usb_hid_subdriver_mapping_t usb_hid_subdrivers[] = { 65 61 { 66 62 path_kbd, 67 0,63 -1, 68 64 USB_HID_PATH_COMPARE_BEGIN, 69 65 -1, … … 92 88 { 93 89 path_mouse, 94 0,90 -1, 95 91 USB_HID_PATH_COMPARE_BEGIN, 96 92 -1, … … 103 99 } 104 100 }, 105 // {106 // generic_hid_key_path,107 // 0,108 // USB_HID_PATH_COMPARE_ANYWHERE,109 // -1,110 // -1,111 // {112 // .init = usb_generic_hid_init,113 // .deinit = NULL,114 // .poll = usb_generic_hid_polling_callback,115 // .poll_end = NULL116 // }117 // },118 101 {NULL, -1, 0, -1, -1, {NULL, NULL, NULL, NULL, NULL}} 119 102 }; -
uspace/drv/usbhid/usbhid.c
r74341ed r9ca8539 63 63 static const int USB_HID_MAX_SUBDRIVERS = 10; 64 64 65 /** @todo What happens if this is not fibril local? */ 66 //static fibril_local bool report_number; 65 static fibril_local bool report_received; 67 66 68 67 /*----------------------------------------------------------------------------*/ … … 235 234 } 236 235 237 // add one generic HID subdriver per device 238 239 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc((count + 1) * 236 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(count * 240 237 sizeof(usb_hid_subdriver_t)); 241 238 if (hid_dev->subdrivers == NULL) { … … 250 247 } 251 248 252 hid_dev->subdrivers[count].init = usb_generic_hid_init; 253 hid_dev->subdrivers[count].poll = usb_generic_hid_polling_callback; 254 hid_dev->subdrivers[count].deinit = NULL; 255 hid_dev->subdrivers[count].poll_end = NULL; 256 257 hid_dev->subdriver_count = count + 1; 249 hid_dev->subdriver_count = count; 258 250 259 251 return EOK; … … 315 307 316 308 if (matched) { 317 usb_log_debug("Subdriver matched.\n");318 309 subdrivers[count++] = &mapping->subdriver; 319 310 } … … 357 348 /*----------------------------------------------------------------------------*/ 358 349 359 static int usb_hid_init_report(usb_hid_dev_t *hid_dev)360 {361 assert(hid_dev != NULL && hid_dev->report != NULL);362 363 uint8_t report_id = 0;364 size_t size;/* = usb_hid_report_byte_size(hid_dev->report, report_id,365 USB_HID_REPORT_TYPE_INPUT);*/366 367 size_t max_size = 0;368 369 do {370 size = usb_hid_report_byte_size(hid_dev->report, report_id,371 USB_HID_REPORT_TYPE_INPUT);372 usb_log_debug("Report ID: %u, size: %zu\n", report_id, size);373 max_size = (size > max_size) ? size : max_size;374 report_id = usb_hid_get_next_report_id(hid_dev->report,375 report_id, USB_HID_REPORT_TYPE_INPUT);376 } while (report_id != 0);377 378 usb_log_debug("Max size of input report: %zu\n", max_size);379 380 hid_dev->max_input_report_size = max_size;381 assert(hid_dev->input_report == NULL);382 383 hid_dev->input_report = malloc(max_size);384 if (hid_dev->input_report == NULL) {385 return ENOMEM;386 }387 memset(hid_dev->input_report, 0, max_size);388 389 return EOK;390 }391 392 /*----------------------------------------------------------------------------*/393 394 350 usb_hid_dev_t *usb_hid_new(void) 395 351 { … … 446 402 /* Get the report descriptor and parse it. */ 447 403 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 448 hid_dev->report , &hid_dev->report_desc, &hid_dev->report_desc_size);404 hid_dev->report); 449 405 450 406 bool fallback = false; … … 527 483 } 528 484 529 // save max input report size and allocate space for the report530 rc = usb_hid_init_report(hid_dev);531 if (rc != EOK) {532 usb_log_error("Failed to initialize input report buffer.\n");533 }534 535 485 return rc; 536 486 } … … 550 500 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 551 501 552 // int allocated = (hid_dev->input_report != NULL); 553 assert(hid_dev->input_report != NULL); 554 usb_log_debug("Max input report size: %zu, buffer size: %zu\n", 555 hid_dev->max_input_report_size, buffer_size); 556 assert(hid_dev->max_input_report_size >= buffer_size); 557 558 // if (/*!allocated*/ 559 // /*|| *//*hid_dev->input_report_size < buffer_size*/) { 560 // uint8_t *input_old = hid_dev->input_report; 561 // uint8_t *input_new = (uint8_t *)malloc(buffer_size); 562 563 // if (input_new == NULL) { 564 // usb_log_error("Failed to allocate space for input " 565 // "buffer. This event may not be reported\n"); 566 // memset(hid_dev->input_report, 0, 567 // hid_dev->input_report_size); 568 // } else { 569 // memcpy(input_new, input_old, 570 // hid_dev->input_report_size); 571 // hid_dev->input_report = input_new; 572 // if (allocated) { 573 // free(input_old); 574 // } 575 // usb_hid_new_report(); 576 // } 577 // } 502 int allocated = (hid_dev->input_report != NULL); 503 504 if (!allocated 505 || hid_dev->input_report_size < buffer_size) { 506 uint8_t *input_old = hid_dev->input_report; 507 uint8_t *input_new = (uint8_t *)malloc(buffer_size); 508 509 if (input_new == NULL) { 510 usb_log_error("Failed to allocate space for input " 511 "buffer. This event may not be reported\n"); 512 memset(hid_dev->input_report, 0, 513 hid_dev->input_report_size); 514 } else { 515 memcpy(input_new, input_old, 516 hid_dev->input_report_size); 517 hid_dev->input_report = input_new; 518 if (allocated) { 519 free(input_old); 520 } 521 usb_hid_new_report(); 522 } 523 } 578 524 579 525 /*! @todo This should probably be atomic. */ 580 526 memcpy(hid_dev->input_report, buffer, buffer_size); 581 527 hid_dev->input_report_size = buffer_size; 582 usb_hid_new_report(hid_dev);583 528 584 529 bool cont = false; … … 656 601 /*----------------------------------------------------------------------------*/ 657 602 658 void usb_hid_new_report(usb_hid_dev_t *hid_dev) 659 { 660 ++hid_dev->report_nr; 661 } 662 663 /*----------------------------------------------------------------------------*/ 664 665 int usb_hid_report_number(usb_hid_dev_t *hid_dev) 666 { 667 return hid_dev->report_nr; 668 } 669 670 /*----------------------------------------------------------------------------*/ 671 672 //void usb_hid_report_received(void) 673 //{ 674 // ++report_number; 675 //} 676 677 /*----------------------------------------------------------------------------*/ 678 679 //bool usb_hid_report_ready(void) 680 //{ 681 // return !report_received; 682 //} 603 void usb_hid_new_report(void) 604 { 605 report_received = false; 606 } 607 608 /*----------------------------------------------------------------------------*/ 609 610 void usb_hid_report_received(void) 611 { 612 report_received = true; 613 } 614 615 /*----------------------------------------------------------------------------*/ 616 617 bool usb_hid_report_ready(void) 618 { 619 return !report_received; 620 } 683 621 684 622 /*----------------------------------------------------------------------------*/ -
uspace/drv/usbhid/usbhid.h
r74341ed r9ca8539 98 98 99 99 size_t input_report_size; 100 size_t max_input_report_size;101 102 int report_nr;103 100 } usb_hid_dev_t; 104 101 … … 130 127 //const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev); 131 128 132 void usb_hid_new_report( usb_hid_dev_t *hid_dev);129 void usb_hid_new_report(void); 133 130 134 int usb_hid_report_number(usb_hid_dev_t *hid_dev);131 void usb_hid_report_received(void); 135 132 136 //void usb_hid_report_received(void); 137 138 //bool usb_hid_report_ready(void); 133 bool usb_hid_report_ready(void); 139 134 140 135 void usb_hid_free(usb_hid_dev_t **hid_dev); -
uspace/lib/drv/Makefile
r74341ed r9ca8539 40 40 generic/remote_usb.c \ 41 41 generic/remote_pci.c \ 42 generic/remote_usbhc.c \ 43 generic/remote_usbhid.c 42 generic/remote_usbhc.c 44 43 45 44 include $(USPACE_PREFIX)/Makefile.common -
uspace/lib/drv/generic/dev_iface.c
r74341ed r9ca8539 46 46 #include "remote_pci.h" 47 47 48 #include <stdio.h>49 50 48 static iface_dipatch_table_t remote_ifaces = { 51 49 .ifaces = { … … 62 60 { 63 61 assert(is_valid_iface_idx(idx)); 64 65 62 return remote_ifaces.ifaces[idx]; 66 63 } -
uspace/lib/drv/generic/driver.c
r74341ed r9ca8539 405 405 /* The interface has not such method */ 406 406 printf("%s: driver_connection_gen error - " 407 "invalid interface method (%d).\n", 408 driver->name, iface_method_idx); 407 "invalid interface method.", driver->name); 409 408 async_answer_0(callid, ENOTSUP); 410 409 break; -
uspace/lib/drv/generic/remote_usbhid.c
r74341ed r9ca8539 36 36 #include <errno.h> 37 37 #include <assert.h> 38 #include <stdio.h>39 38 40 39 #include "usbhid_iface.h" … … 43 42 static void remote_usbhid_get_event_length(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 44 43 static void remote_usbhid_get_event(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 45 static void remote_usbhid_get_report_descriptor_length(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);46 static void remote_usbhid_get_report_descriptor(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);47 44 // static void remote_usbhid_(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 48 45 … … 50 47 static remote_iface_func_ptr_t remote_usbhid_iface_ops [] = { 51 48 remote_usbhid_get_event_length, 52 remote_usbhid_get_event, 53 remote_usbhid_get_report_descriptor_length, 54 remote_usbhid_get_report_descriptor 49 remote_usbhid_get_event 55 50 }; 56 51 … … 63 58 }; 64 59 65 //usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;60 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface; 66 61 67 62 … … 69 64 ipc_callid_t callid, ipc_call_t *call) 70 65 { 71 printf("remote_usbhid_get_event_length()\n");72 73 66 usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface; 74 67 75 68 if (!hid_iface->get_event_length) { 76 printf("Get event length not set!\n");77 69 async_answer_0(callid, ENOTSUP); 78 70 return; 79 71 } 80 72 81 size_t len = hid_iface->get_event_length(fun); 82 // if (len == 0) { 83 // len = EEMPTY; 84 // } 85 async_answer_1(callid, EOK, len); 86 87 // if (len < 0) { 88 // async_answer_0(callid, len); 89 // } else { 90 // async_answer_1(callid, EOK, len); 91 // } 73 int len = hid_iface->get_event_length(fun); 74 if (len == 0) { 75 len = EEMPTY; 76 } 77 if (len < 0) { 78 async_answer_0(callid, len); 79 } else { 80 async_answer_1(callid, EOK, len); 81 } 92 82 } 93 83 … … 110 100 return; 111 101 } 112 ///* Check that length is even number. Truncate otherwise. */113 //if ((len % 2) == 1) {114 //len--;115 //}102 /* Check that length is even number. Truncate otherwise. */ 103 if ((len % 2) == 1) { 104 len--; 105 } 116 106 if (len == 0) { 117 107 async_answer_0(data_callid, EINVAL); 118 108 async_answer_0(callid, EINVAL); 119 return;120 109 } 121 110 122 111 int rc; 123 112 124 uint8_t *data = malloc(len); 125 if (data == NULL) { 113 size_t items = len / 2; 114 uint16_t *usage_pages_and_usages = malloc(sizeof(uint16_t) * len); 115 if (usage_pages_and_usages == NULL) { 126 116 async_answer_0(data_callid, ENOMEM); 127 117 async_answer_0(callid, ENOMEM); 128 return;129 118 } 130 119 131 size_t act_ length;132 int event_nr;133 rc = hid_iface->get_event(fun, data, len, &act_length, &event_nr, flags);120 size_t act_items; 121 int rc = hid_iface->get_event(fun, usage_pages_and_usages, 122 usage_pages_and_usages + items, items, &act_items, flags); 134 123 if (rc != EOK) { 135 free( data);124 free(usage_pages_and_usages); 136 125 async_answer_0(data_callid, rc); 137 126 async_answer_0(callid, rc); 138 return;139 127 } 140 if (act_ length >= len) {128 if (act_items >= items) { 141 129 /* This shall not happen. */ 142 130 // FIXME: how about an assert here? 143 act_ length = len;131 act_items = items; 144 132 } 145 133 146 async_data_read_finalize(data_callid, data, act_length); 134 async_data_read_finalize(data_callid, usage_pages_and_usages, 135 act_items * 2 * sizeof(uint16_t)); 147 136 148 free( data);137 free(usage_pages_and_usages); 149 138 150 async_answer_ 1(callid, EOK, event_nr);139 async_answer_0(callid, EOK); 151 140 } 152 153 void remote_usbhid_get_report_descriptor_length(ddf_fun_t *fun, void *iface,154 ipc_callid_t callid, ipc_call_t *call)155 {156 usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface;157 158 if (!hid_iface->get_report_descriptor_length) {159 async_answer_0(callid, ENOTSUP);160 return;161 }162 163 size_t len = hid_iface->get_report_descriptor_length(fun);164 async_answer_1(callid, EOK, (sysarg_t) len);165 }166 167 void remote_usbhid_get_report_descriptor(ddf_fun_t *fun, void *iface,168 ipc_callid_t callid, ipc_call_t *call)169 {170 usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface;171 172 if (!hid_iface->get_report_descriptor) {173 async_answer_0(callid, ENOTSUP);174 return;175 }176 177 size_t len;178 ipc_callid_t data_callid;179 if (!async_data_read_receive(&data_callid, &len)) {180 async_answer_0(callid, EINVAL);181 return;182 }183 184 if (len == 0) {185 async_answer_0(data_callid, EINVAL);186 async_answer_0(callid, EINVAL);187 return;188 }189 190 uint8_t *descriptor = malloc(len);191 if (descriptor == NULL) {192 async_answer_0(data_callid, ENOMEM);193 async_answer_0(callid, ENOMEM);194 return;195 }196 197 size_t act_len = 0;198 int rc = hid_iface->get_report_descriptor(fun, descriptor, len,199 &act_len);200 if (act_len > len) {201 rc = ELIMIT;202 }203 if (rc != EOK) {204 free(descriptor);205 async_answer_0(data_callid, rc);206 async_answer_0(callid, rc);207 return;208 }209 210 async_data_read_finalize(data_callid, descriptor, act_len);211 async_answer_0(callid, EOK);212 213 free(descriptor);214 }215 216 217 141 218 142 /** -
uspace/lib/drv/include/remote_usbhid.h
r74341ed r9ca8539 36 36 #define LIBDRV_REMOTE_USBHID_H_ 37 37 38 externremote_iface_t remote_usbhid_iface;38 remote_iface_t remote_usbhid_iface; 39 39 40 40 #endif -
uspace/lib/drv/include/usbhid_iface.h
r74341ed r9ca8539 45 45 * Parameters: none 46 46 * Answer: 47 * - Size of one report in bytes. 47 * - EOK (expected always as long as device support USB HID interface) 48 * Parameters of the answer: 49 * - number of items 48 50 */ 49 51 IPC_M_USBHID_GET_EVENT_LENGTH, … … 61 63 * It is okay if the client requests less data. Extra data must 62 64 * be truncated by the driver. 63 *64 * @todo Change this comment.65 65 */ 66 IPC_M_USBHID_GET_EVENT, 67 68 /** Get the size of the report descriptor from the HID device. 69 * 70 * Parameters: 71 * - none 72 * Answer: 73 * - EOK - method is implemented (expected always) 74 * Parameters of the answer: 75 * - Size of the report in bytes. 76 */ 77 IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH, 78 79 /** Get the report descriptor from the HID device. 80 * 81 * Parameters: 82 * - none 83 * The call is followed by data read expecting the descriptor itself. 84 * Answer: 85 * - EOK - report descriptor returned. 86 */ 87 IPC_M_USBHID_GET_REPORT_DESCRIPTOR 66 IPC_M_USBHID_GET_EVENT 88 67 } usbhid_iface_funcs_t; 89 68 … … 96 75 * 97 76 * @param[in] fun DDF function answering the request. 98 * @return Size of the event in bytes.77 * @return Number of events or error code. 99 78 */ 100 79 size_t (*get_event_length)(ddf_fun_t *fun); … … 108 87 * @return Error code. 109 88 */ 110 int (*get_event)(ddf_fun_t *fun, uint8_t *buffer, size_t size, 111 size_t *act_size, int *event_nr, unsigned int flags); 112 113 /** Get size of the report descriptor in bytes. 114 * 115 * @param[in] fun DDF function answering the request. 116 * @return Size of the report descriptor in bytes. 117 */ 118 size_t (*get_report_descriptor_length)(ddf_fun_t *fun); 119 120 /** Get the report descriptor from the HID device. 121 * 122 * @param[in] fun DDF function answering the request. 123 * @param[out] desc Buffer with the report descriptor. 124 * @param[in] size Size of the allocated @p desc buffer. 125 * @param[out] act_size Actual size of the report descriptor returned. 126 * @return Error code. 127 */ 128 int (*get_report_descriptor)(ddf_fun_t *fun, uint8_t *desc, 129 size_t size, size_t *act_size); 89 int (*get_event)(ddf_fun_t *fun, int32_t *buffer, size_t size, 90 size_t *act_size, unsigned int flags); 130 91 } usbhid_iface_t; 131 92 -
uspace/lib/usbhid/Makefile
r74341ed r9ca8539 41 41 src/hidpath.c \ 42 42 src/hidreport.c \ 43 src/consumer.c \44 43 src/hidreq.c 45 44 -
uspace/lib/usbhid/include/usb/hid/hid_report_items.h
r74341ed r9ca8539 96 96 #define USB_HID_ITEM_FLAG_RELATIVE(flags) ((flags & 0x4) == 0x4) 97 97 98 /** Indicates whether the data “rolls over” when reaching either the extreme 98 /** 99 * Indicates whether the data “rolls over” when reaching either the extreme 99 100 * high or low value. For example, a dial that can spin freely 360 degrees 100 101 * might output values from 0 to 10. If Wrap is indicated, the next value -
uspace/lib/usbhid/include/usb/hid/hiddescriptor.h
r74341ed r9ca8539 43 43 44 44 int usb_hid_parse_report_descriptor(usb_hid_report_t *report, 45 45 const uint8_t *data, size_t size); 46 46 47 47 void usb_hid_free_report(usb_hid_report_t *report); … … 51 51 int usb_hid_report_init(usb_hid_report_t *report); 52 52 53 int usb_hid_report_append_fields(usb_hid_report_t *report, 54 53 int usb_hid_report_append_fields(usb_hid_report_t *report, 54 usb_hid_report_item_t *report_item); 55 55 56 usb_hid_report_description_t * usb_hid_report_find_description( 57 const usb_hid_report_t *report, uint8_t report_id, 58 usb_hid_report_type_t type); 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); 59 57 60 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, 61 size_t item_size, usb_hid_report_item_t *report_item, 62 usb_hid_report_path_t *usage_path); 58 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size, 59 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 63 60 64 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, 65 size_t item_size, usb_hid_report_item_t *report_item, 66 usb_hid_report_path_t *usage_path); 61 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size, 62 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 67 63 68 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, 69 size_t item_size, usb_hid_report_item_t *report_item, 70 usb_hid_report_path_t *usage_path); 64 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size, 65 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 71 66 72 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, 73 size_t item_size, usb_hid_report_item_t *report_item, 74 usb_hid_report_path_t *usage_path); 67 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, size_t item_size, 68 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); 75 69 76 70 void usb_hid_descriptor_print_list(link_t *head); … … 80 74 void usb_hid_free_report_list(link_t *head); 81 75 82 usb_hid_report_item_t *usb_hid_report_item_clone( 83 const usb_hid_report_item_t *item); 76 usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item); 84 77 85 78 uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size); 86 79 87 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t*report, 88 usb_hid_report_path_t *cmp_path); 80 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path); 89 81 90 82 -
uspace/lib/usbhid/include/usb/hid/hidparser.h
r74341ed r9ca8539 47 47 * Input report parser functions 48 48 */ 49 int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data, 50 size_t size, uint8_t *report_id); 49 /** */ 50 int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data, 51 size_t size, uint8_t *report_id); 51 52 52 53 /* 53 54 * Output report parser functions 54 55 */ 56 /** Allocates output report buffer*/ 55 57 uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, 56 58 uint8_t report_id); 57 59 60 /** Frees output report buffer*/ 58 61 void usb_hid_report_output_free(uint8_t *output); 59 62 60 size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id, 61 usb_hid_report_type_t type); 63 /** Returns size of report in items */ 64 size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id, 65 usb_hid_report_type_t type); 62 66 63 size_t usb_hid_report_byte_size(usb_hid_report_t *report, uint8_t report_id, 64 usb_hid_report_type_t type); 67 /** Makes the output report buffer by translated given data */ 68 int usb_hid_report_output_translate(usb_hid_report_t *report, uint8_t report_id, 69 uint8_t *buffer, size_t size); 65 70 71 /** */ 72 usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report, 73 usb_hid_report_field_t *field, 74 usb_hid_report_path_t *path, 75 int flags, 76 usb_hid_report_type_t type); 66 77 67 int usb_hid_report_output_translate(usb_hid_report_t *report, 68 uint8_t report_id, uint8_t *buffer, size_t size); 69 70 71 /* 72 * Report descriptor structure observing functions 73 */ 74 usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report, 75 usb_hid_report_field_t *field, usb_hid_report_path_t *path, 76 int flags, usb_hid_report_type_t type); 77 78 uint8_t usb_hid_get_next_report_id(usb_hid_report_t *report, 79 uint8_t report_id, usb_hid_report_type_t type); 78 /** */ 79 uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report, 80 uint8_t report_id, 81 usb_hid_report_type_t type); 80 82 81 83 #endif -
uspace/lib/usbhid/include/usb/hid/hidpath.h
r74341ed r9ca8539 42 42 43 43 /*---------------------------------------------------------------------------*/ 44 /* 44 /** 45 45 * Flags of usage paths comparison modes. 46 46 * 47 47 */ 48 /** Wanted usage path must be exactly the same as the searched one. This49 * option cannot be combined with the others.48 /** Wanted usage path must be exactly the same as the searched one. 49 * This option cannot be combined with the others. 50 50 */ 51 51 #define USB_HID_PATH_COMPARE_STRICT 0 … … 57 57 58 58 /** 59 * Only usage page are compared along the usage path. This option can be60 * combined with others.59 * Only usage page are compared along the usage path. 60 * This option can be combined with others. 61 61 */ 62 62 #define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY 2 … … 101 101 int depth; 102 102 103 /** Report id. Zero is reserved and means that report id is not used. 104 * */ 103 /** Report id. Zero is reserved and means that report id is not used. */ 105 104 uint8_t report_id; 106 105 … … 118 117 void usb_hid_report_path_free(usb_hid_report_path_t *path); 119 118 120 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path, 121 119 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path, 120 uint8_t report_id); 122 121 123 122 int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, 124 123 int32_t usage_page, int32_t usage); 125 124 126 125 void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path); … … 129 128 130 129 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, 131 130 int32_t tag, int32_t data); 132 131 133 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, 134 132 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, 133 usb_hid_report_path_t *path, int flags); 135 134 136 usb_hid_report_path_t *usb_hid_report_path_clone( 137 usb_hid_report_path_t *usage_path); 135 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path); 138 136 139 137 void usb_hid_print_usage_path(usb_hid_report_path_t *path); -
uspace/lib/usbhid/include/usb/hid/hidreport.h
r74341ed r9ca8539 44 44 * report parser. 45 45 * 46 * \param[in] dev USB device representing a HID device. 47 * \param[in/out] parser HID Report parser. 48 * \param[out] report_desc Place to save report descriptor into. 49 * \param[out] report_size 46 * \param dev USB device representing a HID device. 47 * \param parser HID Report parser. 50 48 * 51 49 * \retval EOK if successful. … … 59 57 */ 60 58 int usb_hid_process_report_descriptor(usb_device_t *dev, 61 usb_hid_report_t *report , uint8_t **report_desc, size_t *report_size);59 usb_hid_report_t *report); 62 60 63 61 #endif /* LIBUSB_HIDREPORT_H_ */ -
uspace/lib/usbhid/include/usb/hid/hidtypes.h
r74341ed r9ca8539 72 72 73 73 /** 74 * Enum of report types74 * Report type 75 75 */ 76 76 typedef enum { 77 /** Input report. Data are sent from device to system */78 77 USB_HID_REPORT_TYPE_INPUT = 1, 79 80 /** Output report. Data are sent from system to device */81 78 USB_HID_REPORT_TYPE_OUTPUT = 2, 82 83 /** Feature report. Describes device configuration information that84 * can be sent to the device */85 79 USB_HID_REPORT_TYPE_FEATURE = 3 86 80 } usb_hid_report_type_t; -
uspace/lib/usbhid/include/usb/hid/iface.h
r74341ed r9ca8539 38 38 #include <sys/types.h> 39 39 40 int usbhid_dev_get_event_length(int , size_t *);41 int usbhid_dev_get_event(int, uint 8_t *, size_t, size_t *, int *,40 int usbhid_dev_get_event_length(int); 41 int usbhid_dev_get_event(int, uint16_t *, uint16_t *, size_t, size_t *, 42 42 unsigned int); 43 int usbhid_dev_get_report_descriptor_length(int, size_t *);44 int usbhid_dev_get_report_descriptor(int, uint8_t *, size_t, size_t *);45 43 46 44 #endif -
uspace/lib/usbhid/src/hiddescriptor.c
r74341ed r9ca8539 41 41 #include <assert.h> 42 42 43 /*---------------------------------------------------------------------------*/ 44 /* 45 * Constants defining current parsing mode for correct parsing of the set of 46 * local tags (usage) enclosed in delimter tags. 47 */ 48 /** 49 * Second delimiter tag was read. The set of local items (usage) ended. 50 */ 43 51 44 #define OUTSIDE_DELIMITER_SET 0 52 53 /**54 * First delimiter tag was read. The set of local items (usage) started.55 */56 45 #define START_DELIMITER_SET 1 57 58 /**59 * Parser is in the set of local items.60 */61 46 #define INSIDE_DELIMITER_SET 2 62 63 /*---------------------------------------------------------------------------*/64 47 65 48 /** The new report item flag. Used to determine when the item is completly … … 78 61 #define USB_HID_UNKNOWN_TAG -99 79 62 80 /*---------------------------------------------------------------------------*/ 81 /** 82 * Checks if given collection path is already present in report structure and 83 * inserts it if not. 84 * 85 * @param report Report structure 86 * @param cmp_path The collection path 87 * @return Pointer to the result collection path in report structure. 88 * @retval NULL If some error occurs 89 */ 90 usb_hid_report_path_t *usb_hid_report_path_try_insert( 91 usb_hid_report_t *report, usb_hid_report_path_t *cmp_path) { 92 63 usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path) 64 { 65 /* find or append current collection path to the list */ 66 //link_t *path_it = report->collection_paths.next; 93 67 link_t *path_it = report->collection_paths.prev->next; 94 68 usb_hid_report_path_t *path = NULL; 95 69 96 if((report == NULL) || (cmp_path == NULL)) {97 return NULL;98 }99 70 100 71 while(path_it != &report->collection_paths) { 101 path = list_get_instance(path_it, usb_hid_report_path_t, 102 link); 103 104 if(usb_hid_report_compare_usage_path(path, cmp_path, 105 USB_HID_PATH_COMPARE_STRICT) == EOK){ 72 path = list_get_instance(path_it, usb_hid_report_path_t, link); 73 74 if(usb_hid_report_compare_usage_path(path, cmp_path, USB_HID_PATH_COMPARE_STRICT) == EOK){ 106 75 break; 107 76 } … … 109 78 } 110 79 if(path_it == &report->collection_paths) { 111 path = usb_hid_report_path_clone(cmp_path); 112 if(path == NULL) { 113 return NULL; 114 } 80 path = usb_hid_report_path_clone(cmp_path); 115 81 list_append(&path->link, &report->collection_paths); 116 82 report->collection_paths_count++; … … 119 85 } 120 86 else { 121 return list_get_instance(path_it, usb_hid_report_path_t, 122 link); 123 } 124 } 125 126 /*---------------------------------------------------------------------------*/ 87 return list_get_instance(path_it, usb_hid_report_path_t, link); 88 } 89 } 90 127 91 /** 128 92 * Initialize the report descriptor parser structure … … 130 94 * @param parser Report descriptor parser structure 131 95 * @return Error code 132 * @retval EINVAL If no report structure was given133 * @retval EOK If report structure was successfully initialized134 96 */ 135 97 int usb_hid_report_init(usb_hid_report_t *report) … … 147 109 } 148 110 149 /*---------------------------------------------------------------------------*/ 150 151 /** 152 * 153 * 154 * @param report Report structure in which the new report items should be 155 * stored 156 * @param report_item Current report descriptor's parsing state table 157 * @return Error code 158 * @retval EOK If all fields were successfully append to report 159 * @retval EINVAL If invalid parameters (NULL) was given 160 * @retval ENOMEM If there is no memmory to store new report description 161 * 162 */ 163 int usb_hid_report_append_fields(usb_hid_report_t *report, 164 usb_hid_report_item_t *report_item) { 165 111 112 /* 113 * 114 * 115 */ 116 int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item) 117 { 166 118 usb_hid_report_field_t *field; 167 119 int i; … … 169 121 uint32_t *usages; 170 122 int usages_used=0; 171 172 if((report == NULL) || (report_item == NULL)) {173 return EINVAL;174 }175 176 123 if(report_item->usages_count > 0){ 177 124 usages = malloc(sizeof(int32_t) * report_item->usages_count); 178 memcpy(usages, report_item->usages, sizeof(int32_t) * 179 report_item->usages_count); 125 memcpy(usages, report_item->usages, sizeof(int32_t) * report_item->usages_count); 180 126 } 181 127 else { … … 198 144 if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0){ 199 145 /* 200 Store usage array. The Correct Usage Page and Usage is201 dependingon data in report and will be filled later146 Store usage array. The Correct Usage Page and Usage is depending 147 on data in report and will be filled later 202 148 */ 203 149 field->usage = 0; … … 216 162 } 217 163 else { 218 usage = report_item->usages[ 219 report_item->usages_count- 1]; 164 usage = report_item->usages[report_item->usages_count - 1]; 220 165 } 221 166 222 167 if(USB_HID_IS_EXTENDED_USAGE(usage)){ 223 168 field->usage = USB_HID_EXTENDED_USAGE(usage); 224 field->usage_page = 225 USB_HID_EXTENDED_USAGE_PAGE(usage); 169 field->usage_page = USB_HID_EXTENDED_USAGE_PAGE(usage); 226 170 } 227 171 else { … … 232 176 } 233 177 234 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_GLOBAL, 235 field->usage_page); 236 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_LOCAL, 237 field->usage); 238 239 field->collection_path = 240 usb_hid_report_path_try_insert(report, path); 178 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_GLOBAL, field->usage_page); 179 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_LOCAL, field->usage); 180 181 field->collection_path = usb_hid_report_path_try_insert(report, path); 241 182 242 183 field->size = report_item->size; 243 184 244 size_t offset_byte = (report_item->offset + (i * 245 report_item->size)) / 8; 246 247 size_t offset_bit = 8 - ((report_item->offset + (i * 248 report_item->size)) % 8) - report_item->size; 185 size_t offset_byte = (report_item->offset + (i * report_item->size)) / 8; 186 size_t offset_bit = 8 - ((report_item->offset + (i * report_item->size)) % 8) - report_item->size; 249 187 250 188 field->offset = 8 * offset_byte + offset_bit; … … 257 195 /* find the right report list*/ 258 196 usb_hid_report_description_t *report_des; 259 report_des = usb_hid_report_find_description(report, 260 report_item->id, report_item->type); 261 197 report_des = usb_hid_report_find_description(report, report_item->id, report_item->type); 262 198 if(report_des == NULL){ 263 report_des = malloc( 264 sizeof(usb_hid_report_description_t)); 265 if(report_des == NULL) { 266 return ENOMEM; 267 } 268 269 memset(report_des, 0, 270 sizeof(usb_hid_report_description_t)); 199 report_des = malloc(sizeof(usb_hid_report_description_t)); 200 memset(report_des, 0, sizeof(usb_hid_report_description_t)); 271 201 272 202 report_des->type = report_item->type; 273 203 report_des->report_id = report_item->id; 274 if(report_des->report_id != 0) {275 /* set up the bit length by report_id field */276 report_des->bit_length = 8;277 }278 279 204 list_initialize (&report_des->link); 280 205 list_initialize (&report_des->report_items); … … 300 225 return EOK; 301 226 } 302 /*---------------------------------------------------------------------------*/ 303 /** 304 * Finds description of report with given report_id and of given type in 305 * opaque report structure. 306 * 307 * @param report Opaque structure containing the parsed report descriptor 308 * @param report_id ReportId of report we are searching 309 * @param type Type of report we are searching 310 * @return Pointer to the particular report description 311 * @retval NULL If no description is founded 312 */ 313 usb_hid_report_description_t * usb_hid_report_find_description( 314 const usb_hid_report_t *report, uint8_t report_id, 315 usb_hid_report_type_t type) { 316 227 228 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) 229 { 317 230 link_t *report_it = report->reports.next; 318 231 usb_hid_report_description_t *report_des = NULL; 319 232 320 233 while(report_it != &report->reports) { 321 report_des = list_get_instance(report_it, 322 usb_hid_report_description_t, link); 323 324 if((report_des->report_id == report_id) && 325 (report_des->type == type)) { 234 report_des = list_get_instance(report_it, usb_hid_report_description_t, link); 235 236 if((report_des->report_id == report_id) && (report_des->type == type)){ 326 237 return report_des; 327 238 } … … 332 243 return NULL; 333 244 } 334 /*---------------------------------------------------------------------------*/335 245 336 246 /** Parse HID report descriptor. … … 339 249 * @param data Data describing the report. 340 250 * @return Error code. 341 * @retval ENOMEM If no more memmory is available342 * @retval EINVAL If invalid data are founded343 * @retval EOK If report descriptor is successfully parsed344 251 */ 345 252 int usb_hid_parse_report_descriptor(usb_hid_report_t *report, … … 392 299 393 300 ret = usb_hid_report_parse_tag(tag,class,data+i+1, 394 item_size,report_item, usage_path); 395 301 item_size,report_item, usage_path); 396 302 switch(ret){ 397 case USB_HID_NEW_REPORT_ITEM: 398 /* store report item to report and create the 399 * new one store current collection path 400 */ 401 report_item->usage_path = usage_path; 303 case USB_HID_NEW_REPORT_ITEM: 304 // store report item to report and create the new one 305 // store current collection path 306 report_item->usage_path = usage_path; 402 307 403 usb_hid_report_path_set_report_id( 404 report_item->usage_path, report_item->id); 405 406 if(report_item->id != 0){ 407 report->use_report_ids = 1; 408 } 308 usb_hid_report_path_set_report_id(report_item->usage_path, report_item->id); 309 if(report_item->id != 0){ 310 report->use_report_ids = 1; 311 } 409 312 410 switch(tag) { 411 case USB_HID_REPORT_TAG_INPUT: 412 report_item->type = 413 USB_HID_REPORT_TYPE_INPUT; 414 415 report_item->offset = offset_input; 416 offset_input += report_item->count * 417 report_item->size; 313 switch(tag) { 314 case USB_HID_REPORT_TAG_INPUT: 315 report_item->type = USB_HID_REPORT_TYPE_INPUT; 316 report_item->offset = offset_input; 317 offset_input += report_item->count * report_item->size; 318 break; 319 case USB_HID_REPORT_TAG_OUTPUT: 320 report_item->type = USB_HID_REPORT_TYPE_OUTPUT; 321 report_item->offset = offset_output; 322 offset_output += report_item->count * report_item->size; 323 324 break; 325 case USB_HID_REPORT_TAG_FEATURE: 326 report_item->type = USB_HID_REPORT_TYPE_FEATURE; 327 report_item->offset = offset_feature; 328 offset_feature += report_item->count * report_item->size; 329 break; 330 default: 331 usb_log_debug("\tjump over - tag %X\n", tag); 332 break; 333 } 334 335 /* 336 * append new fields to the report 337 * structure 338 */ 339 usb_hid_report_append_fields(report, report_item); 340 341 /* reset local items */ 342 usb_hid_report_reset_local_items (report_item); 343 418 344 break; 419 420 case USB_HID_REPORT_TAG_OUTPUT: 421 report_item->type = 422 USB_HID_REPORT_TYPE_OUTPUT; 345 346 case USB_HID_RESET_OFFSET: 347 offset_input = 0; 348 offset_output = 0; 349 offset_feature = 0; 350 usb_hid_report_path_set_report_id (usage_path, report_item->id); 351 break; 352 353 case USB_HID_REPORT_TAG_PUSH: 354 // push current state to stack 355 new_report_item = usb_hid_report_item_clone(report_item); 356 usb_hid_report_path_t *tmp_path = usb_hid_report_path_clone(usage_path); 357 new_report_item->usage_path = tmp_path; 358 359 list_prepend (&new_report_item->link, &stack); 360 break; 361 case USB_HID_REPORT_TAG_POP: 362 // restore current state from stack 363 if(list_empty (&stack)) { 364 return EINVAL; 365 } 366 free(report_item); 367 368 report_item = list_get_instance(stack.next, usb_hid_report_item_t, link); 423 369 424 report_item->offset = offset_output; 425 offset_output += report_item->count * 426 report_item->size; 370 usb_hid_report_usage_path_t *tmp_usage_path; 371 tmp_usage_path = list_get_instance(report_item->usage_path->link.prev, usb_hid_report_usage_path_t, link); 372 373 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page); 374 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, tmp_usage_path->usage); 375 376 usb_hid_report_path_free(report_item->usage_path); 377 list_initialize(&report_item->usage_path->link); 378 list_remove (stack.next); 379 427 380 break; 428 429 case USB_HID_REPORT_TAG_FEATURE: 430 report_item->type = 431 USB_HID_REPORT_TYPE_FEATURE; 432 433 report_item->offset = offset_feature; 434 offset_feature += report_item->count * 435 report_item->size; 381 382 default: 383 // nothing special to do 436 384 break; 437 438 default:439 usb_log_debug2(440 "\tjump over - tag %X\n", tag);441 break;442 }443 444 /*445 * append new fields to the report structure446 */447 usb_hid_report_append_fields(report,448 report_item);449 450 /* reset local items */451 usb_hid_report_reset_local_items (report_item);452 break;453 454 case USB_HID_RESET_OFFSET:455 offset_input = 0;456 offset_output = 0;457 offset_feature = 0;458 usb_hid_report_path_set_report_id (usage_path,459 report_item->id);460 break;461 462 case USB_HID_REPORT_TAG_PUSH:463 // push current state to stack464 new_report_item = usb_hid_report_item_clone(465 report_item);466 467 usb_hid_report_path_t *tmp_path =468 usb_hid_report_path_clone(usage_path);469 470 new_report_item->usage_path = tmp_path;471 472 list_prepend (&new_report_item->link, &stack);473 break;474 case USB_HID_REPORT_TAG_POP:475 // restore current state from stack476 if(list_empty (&stack)) {477 return EINVAL;478 }479 free(report_item);480 481 report_item = list_get_instance(stack.next,482 usb_hid_report_item_t, link);483 484 usb_hid_report_usage_path_t *tmp_usage_path;485 tmp_usage_path = list_get_instance(486 report_item->usage_path->link.prev,487 usb_hid_report_usage_path_t, link);488 489 usb_hid_report_set_last_item(usage_path,490 USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page);491 492 usb_hid_report_set_last_item(usage_path,493 USB_HID_TAG_CLASS_LOCAL, tmp_usage_path->usage);494 495 usb_hid_report_path_free(report_item->usage_path);496 list_initialize(&report_item->usage_path->link);497 list_remove (stack.next);498 499 break;500 501 default:502 // nothing special to do503 break;504 385 } 505 386 … … 518 399 } 519 400 520 /*---------------------------------------------------------------------------*/521 401 522 402 /** … … 529 409 * @return Code of action to be done next 530 410 */ 531 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, 532 size_t item_size, usb_hid_report_item_t *report_item, 533 usb_hid_report_path_t *usage_path) { 534 411 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size, 412 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path) 413 { 535 414 int ret; 536 415 537 416 switch(class){ 538 case USB_HID_TAG_CLASS_MAIN: 539 540 if((ret=usb_hid_report_parse_main_tag(tag, data, item_size, 541 report_item, usage_path)) == EOK) { 542 543 return USB_HID_NEW_REPORT_ITEM; 544 } 545 else { 546 return ret; 547 } 548 break; 549 550 case USB_HID_TAG_CLASS_GLOBAL: 551 return usb_hid_report_parse_global_tag(tag, data, item_size, 552 report_item, usage_path); 553 break; 554 555 case USB_HID_TAG_CLASS_LOCAL: 556 return usb_hid_report_parse_local_tag(tag, data, item_size, 557 report_item, usage_path); 558 break; 559 560 default: 561 return USB_HID_NO_ACTION; 417 case USB_HID_TAG_CLASS_MAIN: 418 419 if((ret=usb_hid_report_parse_main_tag(tag,data,item_size,report_item, usage_path)) == EOK) { 420 return USB_HID_NEW_REPORT_ITEM; 421 } 422 else { 423 /*TODO process the error */ 424 return ret; 425 } 426 break; 427 428 case USB_HID_TAG_CLASS_GLOBAL: 429 return usb_hid_report_parse_global_tag(tag,data,item_size,report_item, usage_path); 430 break; 431 432 case USB_HID_TAG_CLASS_LOCAL: 433 return usb_hid_report_parse_local_tag(tag,data,item_size,report_item, usage_path); 434 break; 435 default: 436 return USB_HID_NO_ACTION; 562 437 } 563 438 } … … 573 448 */ 574 449 575 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, 576 size_t item_size, usb_hid_report_item_t *report_item, 577 usb_hid_report_path_t *usage_path) 450 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size, 451 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path) 578 452 { 579 453 usb_hid_report_usage_path_t *path_item; … … 581 455 switch(tag) 582 456 { 583 case USB_HID_REPORT_TAG_INPUT:584 case USB_HID_REPORT_TAG_OUTPUT:585 case USB_HID_REPORT_TAG_FEATURE:586 report_item->item_flags = *data;587 return EOK;588 break;457 case USB_HID_REPORT_TAG_INPUT: 458 case USB_HID_REPORT_TAG_OUTPUT: 459 case USB_HID_REPORT_TAG_FEATURE: 460 report_item->item_flags = *data; 461 return EOK; 462 break; 589 463 590 case USB_HID_REPORT_TAG_COLLECTION: 591 592 /* store collection atributes */ 593 path_item = list_get_instance(usage_path->head.prev, 594 usb_hid_report_usage_path_t, link); 595 path_item->flags = *data; 464 case USB_HID_REPORT_TAG_COLLECTION: 465 466 // store collection atributes 467 path_item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link); 468 path_item->flags = *data; 596 469 597 /* set last item */ 598 usb_hid_report_set_last_item(usage_path, 599 USB_HID_TAG_CLASS_GLOBAL, 600 USB_HID_EXTENDED_USAGE_PAGE(report_item->usages[ 601 report_item->usages_count-1])); 602 603 usb_hid_report_set_last_item(usage_path, 604 USB_HID_TAG_CLASS_LOCAL, 605 USB_HID_EXTENDED_USAGE(report_item->usages[ 606 report_item->usages_count-1])); 470 // set last item 471 usb_hid_report_set_last_item(usage_path, 472 USB_HID_TAG_CLASS_GLOBAL, 473 USB_HID_EXTENDED_USAGE_PAGE(report_item->usages[report_item->usages_count-1])); 474 usb_hid_report_set_last_item(usage_path, 475 USB_HID_TAG_CLASS_LOCAL, 476 USB_HID_EXTENDED_USAGE(report_item->usages[report_item->usages_count-1])); 607 477 608 /* append the new one which will be set by common usage/usage 609 * page */ 610 usb_hid_report_path_append_item(usage_path, 611 report_item->usage_page, 612 report_item->usages[report_item->usages_count-1]); 613 614 usb_hid_report_reset_local_items (report_item); 615 return USB_HID_NO_ACTION; 616 break; 478 // append the new one which will be set by common 479 // usage/usage page 480 usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]); 481 usb_hid_report_reset_local_items (report_item); 482 return USB_HID_NO_ACTION; 483 break; 617 484 618 case USB_HID_REPORT_TAG_END_COLLECTION: 619 usb_hid_report_remove_last_item(usage_path); 620 return USB_HID_NO_ACTION; 621 break; 622 623 default: 624 return USB_HID_NO_ACTION; 485 case USB_HID_REPORT_TAG_END_COLLECTION: 486 usb_hid_report_remove_last_item(usage_path); 487 return USB_HID_NO_ACTION; 488 break; 489 default: 490 return USB_HID_NO_ACTION; 625 491 } 626 492 … … 637 503 * @return Error code 638 504 */ 639 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, 640 size_t item_size, usb_hid_report_item_t *report_item, 641 usb_hid_report_path_t *usage_path) { 642 505 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size, 506 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path) 507 { 508 // TODO take care about the bit length of data 643 509 switch(tag) 644 510 { 645 case USB_HID_REPORT_TAG_USAGE_PAGE: 646 report_item->usage_page = 647 usb_hid_report_tag_data_uint32(data, item_size); 648 break; 649 650 case USB_HID_REPORT_TAG_LOGICAL_MINIMUM: 651 report_item->logical_minimum = USB_HID_UINT32_TO_INT32( 652 usb_hid_report_tag_data_uint32(data,item_size), 653 item_size * 8); 654 break; 655 656 case USB_HID_REPORT_TAG_LOGICAL_MAXIMUM: 657 report_item->logical_maximum = USB_HID_UINT32_TO_INT32( 658 usb_hid_report_tag_data_uint32(data,item_size), 659 item_size * 8); 660 break; 661 662 case USB_HID_REPORT_TAG_PHYSICAL_MINIMUM: 663 report_item->physical_minimum = USB_HID_UINT32_TO_INT32( 664 usb_hid_report_tag_data_uint32(data,item_size), 665 item_size * 8); 666 break; 667 668 case USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM: 669 report_item->physical_maximum = USB_HID_UINT32_TO_INT32( 670 usb_hid_report_tag_data_uint32(data,item_size), 671 item_size * 8); 672 break; 673 674 case USB_HID_REPORT_TAG_UNIT_EXPONENT: 675 report_item->unit_exponent = usb_hid_report_tag_data_uint32( 676 data,item_size); 677 break; 678 679 case USB_HID_REPORT_TAG_UNIT: 680 report_item->unit = usb_hid_report_tag_data_uint32( 681 data,item_size); 682 break; 683 684 case USB_HID_REPORT_TAG_REPORT_SIZE: 685 report_item->size = usb_hid_report_tag_data_uint32( 686 data,item_size); 687 break; 688 689 case USB_HID_REPORT_TAG_REPORT_COUNT: 690 report_item->count = usb_hid_report_tag_data_uint32( 691 data,item_size); 692 break; 693 694 case USB_HID_REPORT_TAG_REPORT_ID: 695 report_item->id = usb_hid_report_tag_data_uint32(data, 696 item_size); 697 return USB_HID_RESET_OFFSET; 698 break; 699 700 case USB_HID_REPORT_TAG_PUSH: 701 case USB_HID_REPORT_TAG_POP: 702 /* 703 * stack operations are done in top level parsing 704 * function 705 */ 706 return tag; 707 break; 511 case USB_HID_REPORT_TAG_USAGE_PAGE: 512 report_item->usage_page = usb_hid_report_tag_data_uint32(data, item_size); 513 break; 514 case USB_HID_REPORT_TAG_LOGICAL_MINIMUM: 515 report_item->logical_minimum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8); 516 break; 517 case USB_HID_REPORT_TAG_LOGICAL_MAXIMUM: 518 report_item->logical_maximum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8); 519 break; 520 case USB_HID_REPORT_TAG_PHYSICAL_MINIMUM: 521 report_item->physical_minimum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8); 522 break; 523 case USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM: 524 report_item->physical_maximum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8); 525 526 break; 527 case USB_HID_REPORT_TAG_UNIT_EXPONENT: 528 report_item->unit_exponent = usb_hid_report_tag_data_uint32(data,item_size); 529 break; 530 case USB_HID_REPORT_TAG_UNIT: 531 report_item->unit = usb_hid_report_tag_data_uint32(data,item_size); 532 break; 533 case USB_HID_REPORT_TAG_REPORT_SIZE: 534 report_item->size = usb_hid_report_tag_data_uint32(data,item_size); 535 break; 536 case USB_HID_REPORT_TAG_REPORT_COUNT: 537 report_item->count = usb_hid_report_tag_data_uint32(data,item_size); 538 break; 539 case USB_HID_REPORT_TAG_REPORT_ID: 540 report_item->id = usb_hid_report_tag_data_uint32(data,item_size); 541 return USB_HID_RESET_OFFSET; 542 break; 543 case USB_HID_REPORT_TAG_PUSH: 544 case USB_HID_REPORT_TAG_POP: 545 /* 546 * stack operations are done in top level parsing 547 * function 548 */ 549 return tag; 550 break; 708 551 709 default:710 return USB_HID_NO_ACTION;552 default: 553 return USB_HID_NO_ACTION; 711 554 } 712 555 … … 723 566 * @return Error code 724 567 */ 725 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, 726 size_t item_size, usb_hid_report_item_t *report_item, 727 usb_hid_report_path_t *usage_path) 568 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, size_t item_size, 569 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path) 728 570 { 729 571 int32_t extended_usage; 730 572 731 573 switch(tag) { 732 case USB_HID_REPORT_TAG_USAGE: 733 switch(report_item->in_delimiter) { 734 case INSIDE_DELIMITER_SET: 735 /* nothing to do 736 * we catch only the first one 737 */ 738 break; 739 740 case START_DELIMITER_SET: 741 report_item->in_delimiter = INSIDE_DELIMITER_SET; 742 case OUTSIDE_DELIMITER_SET: 743 extended_usage = ((report_item->usage_page) << 16); 744 extended_usage += usb_hid_report_tag_data_uint32( 745 data,item_size); 746 747 report_item->usages[report_item->usages_count] = 748 extended_usage; 749 750 report_item->usages_count++; 751 break; 752 } 753 break; 754 755 case USB_HID_REPORT_TAG_USAGE_MINIMUM: 756 if (item_size == 3) { 757 // usage extended usages 758 report_item->extended_usage_page = 759 USB_HID_EXTENDED_USAGE_PAGE( 760 usb_hid_report_tag_data_uint32(data,item_size)); 761 762 763 report_item->usage_minimum = 764 USB_HID_EXTENDED_USAGE( 765 usb_hid_report_tag_data_uint32(data,item_size)); 766 } 767 else { 768 report_item->usage_minimum = 769 usb_hid_report_tag_data_uint32(data,item_size); 770 } 771 break; 772 773 case USB_HID_REPORT_TAG_USAGE_MAXIMUM: 774 if (item_size == 3) { 775 if(report_item->extended_usage_page != 776 USB_HID_EXTENDED_USAGE_PAGE( 777 usb_hid_report_tag_data_uint32(data,item_size))) { 574 case USB_HID_REPORT_TAG_USAGE: 575 switch(report_item->in_delimiter) { 576 case INSIDE_DELIMITER_SET: 577 // nothing to do 578 break; 579 case START_DELIMITER_SET: 580 report_item->in_delimiter = INSIDE_DELIMITER_SET; 581 case OUTSIDE_DELIMITER_SET: 582 extended_usage = ((report_item->usage_page) << 16); 583 extended_usage += usb_hid_report_tag_data_uint32(data,item_size); 584 report_item->usages[report_item->usages_count] = extended_usage; 585 report_item->usages_count++; 586 break; 587 } 588 break; 589 case USB_HID_REPORT_TAG_USAGE_MINIMUM: 590 if (item_size == 3) { 591 // usage extended usages 592 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16; 593 report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF; 594 } 595 else { 596 report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size); 597 } 598 break; 599 case USB_HID_REPORT_TAG_USAGE_MAXIMUM: 600 if (item_size == 3) { 601 602 if(report_item->extended_usage_page != ((usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16)) { 603 return EINVAL; 604 } 778 605 779 return EINVAL; 780 } 781 782 // usage extended usages 783 report_item->extended_usage_page = 784 USB_HID_EXTENDED_USAGE_PAGE( 785 usb_hid_report_tag_data_uint32(data,item_size)); 786 787 report_item->usage_maximum = 788 USB_HID_EXTENDED_USAGE( 789 usb_hid_report_tag_data_uint32(data,item_size)); 790 } 791 else { 792 report_item->usage_maximum = 793 usb_hid_report_tag_data_uint32(data,item_size); 794 } 795 796 // vlozit zaznamy do pole usages 797 int32_t i; 798 for(i = report_item->usage_minimum; 799 i <= report_item->usage_maximum; i++) { 800 801 if(report_item->extended_usage_page) { 802 report_item->usages[report_item->usages_count++] = 803 (report_item->extended_usage_page << 16) + i; 804 } 805 else { 806 report_item->usages[report_item->usages_count++] = 807 (report_item->usage_page << 16) + i; 808 } 809 } 810 report_item->extended_usage_page = 0; 606 // usage extended usages 607 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16; 608 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF; 609 } 610 else { 611 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size); 612 } 613 614 // vlozit zaznamy do pole usages 615 int32_t i; 616 for(i=report_item->usage_minimum; i<=report_item->usage_maximum; i++) { 617 if(report_item->extended_usage_page) { 618 report_item->usages[report_item->usages_count++] = (report_item->extended_usage_page << 16) + i; 619 } 620 else { 621 622 report_item->usages[report_item->usages_count++] = (report_item->usage_page << 16) + i; 623 } 624 } 625 report_item->extended_usage_page = 0; 811 626 812 break; 813 814 case USB_HID_REPORT_TAG_DESIGNATOR_INDEX: 815 report_item->designator_index = 816 usb_hid_report_tag_data_uint32(data,item_size); 817 break; 818 819 case USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM: 820 report_item->designator_minimum = 821 usb_hid_report_tag_data_uint32(data,item_size); 822 break; 823 824 case USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM: 825 report_item->designator_maximum = 826 usb_hid_report_tag_data_uint32(data,item_size); 827 break; 828 829 case USB_HID_REPORT_TAG_STRING_INDEX: 830 report_item->string_index = 831 usb_hid_report_tag_data_uint32(data,item_size); 832 break; 833 834 case USB_HID_REPORT_TAG_STRING_MINIMUM: 835 report_item->string_minimum = 836 usb_hid_report_tag_data_uint32(data,item_size); 837 break; 838 839 case USB_HID_REPORT_TAG_STRING_MAXIMUM: 840 report_item->string_maximum = 841 usb_hid_report_tag_data_uint32(data,item_size); 842 break; 843 844 case USB_HID_REPORT_TAG_DELIMITER: 845 report_item->in_delimiter = 846 usb_hid_report_tag_data_uint32(data,item_size); 847 break; 848 849 default: 850 return USB_HID_NO_ACTION; 627 break; 628 case USB_HID_REPORT_TAG_DESIGNATOR_INDEX: 629 report_item->designator_index = usb_hid_report_tag_data_uint32(data,item_size); 630 break; 631 case USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM: 632 report_item->designator_minimum = usb_hid_report_tag_data_uint32(data,item_size); 633 break; 634 case USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM: 635 report_item->designator_maximum = usb_hid_report_tag_data_uint32(data,item_size); 636 break; 637 case USB_HID_REPORT_TAG_STRING_INDEX: 638 report_item->string_index = usb_hid_report_tag_data_uint32(data,item_size); 639 break; 640 case USB_HID_REPORT_TAG_STRING_MINIMUM: 641 report_item->string_minimum = usb_hid_report_tag_data_uint32(data,item_size); 642 break; 643 case USB_HID_REPORT_TAG_STRING_MAXIMUM: 644 report_item->string_maximum = usb_hid_report_tag_data_uint32(data,item_size); 645 break; 646 case USB_HID_REPORT_TAG_DELIMITER: 647 report_item->in_delimiter = usb_hid_report_tag_data_uint32(data,item_size); 648 break; 649 650 default: 651 return USB_HID_NO_ACTION; 851 652 } 852 653 853 654 return EOK; 854 655 } 855 /*---------------------------------------------------------------------------*/856 656 857 657 /** … … 874 674 return result; 875 675 } 876 /*---------------------------------------------------------------------------*/877 676 878 677 /** … … 895 694 for(item = head->next; item != head; item = item->next) { 896 695 897 report_item = list_get_instance(item, usb_hid_report_field_t, 898 link); 696 report_item = list_get_instance(item, usb_hid_report_field_t, link); 899 697 900 698 usb_log_debug("\t\tOFFSET: %X\n", report_item->offset); 901 usb_log_debug("\t\tSIZE: %zu\n", report_item->size); 902 usb_log_debug("\t\tLOGMIN: %d\n", 903 report_item->logical_minimum); 904 usb_log_debug("\t\tLOGMAX: %d\n", 905 report_item->logical_maximum); 906 usb_log_debug("\t\tPHYMIN: %d\n", 907 report_item->physical_minimum); 908 usb_log_debug("\t\tPHYMAX: %d\n", 909 report_item->physical_maximum); 910 usb_log_debug("\t\ttUSAGEMIN: %X\n", 911 report_item->usage_minimum); 912 usb_log_debug("\t\tUSAGEMAX: %X\n", 913 report_item->usage_maximum); 914 usb_log_debug("\t\tUSAGES COUNT: %zu\n", 915 report_item->usages_count); 699 usb_log_debug("\t\tSIZE: %zu\n", report_item->size); 700 usb_log_debug("\t\tLOGMIN: %d\n", report_item->logical_minimum); 701 usb_log_debug("\t\tLOGMAX: %d\n", report_item->logical_maximum); 702 usb_log_debug("\t\tPHYMIN: %d\n", report_item->physical_minimum); 703 usb_log_debug("\t\tPHYMAX: %d\n", report_item->physical_maximum); 704 usb_log_debug("\t\ttUSAGEMIN: %X\n", report_item->usage_minimum); 705 usb_log_debug("\t\tUSAGEMAX: %X\n", report_item->usage_maximum); 706 usb_log_debug("\t\tUSAGES COUNT: %zu\n", report_item->usages_count); 916 707 917 708 usb_log_debug("\t\tVALUE: %X\n", report_item->value); … … 925 716 } 926 717 927 } 928 /*---------------------------------------------------------------------------*/ 929 718 719 } 930 720 /** 931 721 * Prints content of given report descriptor in human readable format. … … 944 734 945 735 while(report_it != &report->reports) { 946 report_des = list_get_instance(report_it, 947 usb_hid_report_description_t, link); 736 report_des = list_get_instance(report_it, usb_hid_report_description_t, link); 948 737 usb_log_debug("Report ID: %d\n", report_des->report_id); 949 738 usb_log_debug("\tType: %d\n", report_des->type); 950 739 usb_log_debug("\tLength: %zu\n", report_des->bit_length); 951 usb_log_debug("\tB Size: %zu\n",952 usb_hid_report_byte_size(report,953 report_des->report_id,954 report_des->type));955 740 usb_log_debug("\tItems: %zu\n", report_des->item_length); 956 741 957 742 usb_hid_descriptor_print_list(&report_des->report_items); 958 743 744 /* 745 link_t *path_it = report->collection_paths.next; 746 while(path_it != &report->collection_paths) { 747 usb_hid_print_usage_path (list_get_instance(path_it, usb_hid_report_path_t, link)); 748 path_it = path_it->next; 749 } 750 */ 959 751 report_it = report_it->next; 960 752 } 961 753 } 962 /*---------------------------------------------------------------------------*/963 754 964 755 /** … … 985 776 986 777 while(!list_empty(&report_item->usage_path->link)) { 987 778 usb_hid_report_remove_last_item(report_item->usage_path); 988 779 } 989 780 … … 997 788 998 789 } 999 /*---------------------------------------------------------------------------*/1000 790 1001 791 /** Frees the HID report descriptor parser structure … … 1013 803 usb_hid_report_path_t *path; 1014 804 while(!list_empty(&report->collection_paths)) { 1015 path = list_get_instance(report->collection_paths.next, 1016 usb_hid_report_path_t, link); 1017 805 path = list_get_instance(report->collection_paths.next, usb_hid_report_path_t, link); 1018 806 usb_hid_report_path_free(path); 1019 807 } … … 1023 811 usb_hid_report_field_t *field; 1024 812 while(!list_empty(&report->reports)) { 1025 report_des = list_get_instance(report->reports.next, 1026 usb_hid_report_description_t, link); 1027 813 report_des = list_get_instance(report->reports.next, usb_hid_report_description_t, link); 1028 814 list_remove(&report_des->link); 1029 815 1030 816 while(!list_empty(&report_des->report_items)) { 1031 field = list_get_instance( 1032 report_des->report_items.next, 1033 usb_hid_report_field_t, link); 1034 817 field = list_get_instance(report_des->report_items.next, usb_hid_report_field_t, link); 1035 818 list_remove(&field->link); 1036 819 … … 1043 826 return; 1044 827 } 1045 /*---------------------------------------------------------------------------*/1046 828 1047 829 /** -
uspace/lib/usbhid/src/hidiface.c
r74341ed r9ca8539 46 46 * @return Number of usages returned or negative error code. 47 47 */ 48 int usbhid_dev_get_event_length(int dev_phone , size_t *size)48 int usbhid_dev_get_event_length(int dev_phone) 49 49 { 50 50 if (dev_phone < 0) { … … 56 56 IPC_M_USBHID_GET_EVENT_LENGTH, &len); 57 57 if (rc == EOK) { 58 if (size != NULL) {59 *size = (size_t) len;60 }58 return (int) len; 59 } else { 60 return rc; 61 61 } 62 63 return rc;64 62 } 65 63 … … 76 74 * @return Error code. 77 75 */ 78 int usbhid_dev_get_event(int dev_phone, uint 8_t *buf,79 size_t size, size_t *actual_size, int *event_nr, unsigned int flags)76 int usbhid_dev_get_event(int dev_phone, uint16_t *usage_pages, uint16_t *usages, 77 size_t usage_count, size_t *actual_usage_count, unsigned int flags) 80 78 { 81 79 if (dev_phone < 0) { 82 80 return EINVAL; 83 81 } 84 if (( buf== NULL)) {82 if ((usage_pages == NULL) || (usages == NULL)) { 85 83 return ENOMEM; 86 84 } 87 if ( size== 0) {85 if (usage_count == 0) { 88 86 return EINVAL; 89 87 } 90 91 // if (size == 0) {92 // return EOK;93 // }94 88 95 size_t buffer_size = size;96 uint 8_t *buffer = malloc(buffer_size);89 size_t buffer_size = sizeof(uint16_t) * usage_count * 2; 90 uint16_t *buffer = malloc(buffer_size); 97 91 if (buffer == NULL) { 98 92 return ENOMEM; 99 93 } 100 94 101 ipc_call_t opening_request_call;102 95 aid_t opening_request = async_send_2(dev_phone, 103 96 DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_EVENT, 104 flags, &opening_request_call);97 flags, NULL); 105 98 if (opening_request == 0) { 106 99 free(buffer); … … 135 128 } 136 129 137 size_t act_size = IPC_GET_ARG2(data_request_call); 130 size_t actual_size = IPC_GET_ARG2(data_request_call); 131 size_t items = actual_size / 2; 138 132 139 133 /* Copy the individual items. */ 140 memcpy( buf, buffer, act_size);141 // memcpy(usages, buffer + items, items * sizeof(int32_t));134 memcpy(usage_pages, buffer, items * sizeof(uint16_t)); 135 memcpy(usages, buffer + items, items * sizeof(uint16_t)); 142 136 143 if (actual_size != NULL) { 144 *actual_size = act_size; 145 } 146 147 if (event_nr != NULL) { 148 *event_nr = IPC_GET_ARG1(opening_request_call); 149 } 150 151 return EOK; 152 } 153 154 155 int usbhid_dev_get_report_descriptor_length(int dev_phone, size_t *size) 156 { 157 if (dev_phone < 0) { 158 return EINVAL; 159 } 160 161 sysarg_t arg_size; 162 int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(USBHID_DEV_IFACE), 163 IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH, &arg_size); 164 if (rc == EOK) { 165 if (size != NULL) { 166 *size = (size_t) arg_size; 167 } 168 } 169 return rc; 170 } 171 172 int usbhid_dev_get_report_descriptor(int dev_phone, uint8_t *buf, size_t size, 173 size_t *actual_size) 174 { 175 if (dev_phone < 0) { 176 return EINVAL; 177 } 178 if ((buf == NULL)) { 179 return ENOMEM; 180 } 181 if (size == 0) { 182 return EINVAL; 183 } 184 185 aid_t opening_request = async_send_1(dev_phone, 186 DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_REPORT_DESCRIPTOR, 187 NULL); 188 if (opening_request == 0) { 189 return ENOMEM; 190 } 191 192 ipc_call_t data_request_call; 193 aid_t data_request = async_data_read(dev_phone, buf, size, 194 &data_request_call); 195 if (data_request == 0) { 196 async_wait_for(opening_request, NULL); 197 return ENOMEM; 198 } 199 200 sysarg_t data_request_rc; 201 sysarg_t opening_request_rc; 202 async_wait_for(data_request, &data_request_rc); 203 async_wait_for(opening_request, &opening_request_rc); 204 205 if (data_request_rc != EOK) { 206 /* Prefer return code of the opening request. */ 207 if (opening_request_rc != EOK) { 208 return (int) opening_request_rc; 209 } else { 210 return (int) data_request_rc; 211 } 212 } 213 214 if (opening_request_rc != EOK) { 215 return (int) opening_request_rc; 216 } 217 218 size_t act_size = IPC_GET_ARG2(data_request_call); 219 220 if (actual_size != NULL) { 221 *actual_size = act_size; 137 if (actual_usage_count != NULL) { 138 *actual_usage_count = items; 222 139 } 223 140 -
uspace/lib/usbhid/src/hidparser.c
r74341ed r9ca8539 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; … … 154 125 155 126 report_des = usb_hid_report_find_description(report, *report_id, type); 156 if(report_des == NULL) {157 return EINVAL;158 }159 127 160 128 /* read data */ … … 162 130 while(list_item != &(report_des->report_items)) { 163 131 164 item = list_get_instance(list_item, usb_hid_report_field_t, 165 link); 132 item = list_get_instance(list_item, usb_hid_report_field_t, link); 166 133 167 134 if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) { … … 170 137 171 138 // array 172 item->value = 173 usb_hid_translate_data(item, data); 139 item->value = usb_hid_translate_data(item, data); 174 140 175 item->usage = USB_HID_EXTENDED_USAGE( 176 item->usages[item->value - item->physical_minimum]); 177 178 item->usage_page = USB_HID_EXTENDED_USAGE_PAGE( 179 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]); 180 143 181 144 usb_hid_report_set_last_item (item->collection_path, 182 USB_HID_TAG_CLASS_GLOBAL, item->usage_page);183 145 USB_HID_TAG_CLASS_GLOBAL, 146 item->usage_page); 184 147 usb_hid_report_set_last_item (item->collection_path, 185 USB_HID_TAG_CLASS_LOCAL, item->usage); 148 USB_HID_TAG_CLASS_LOCAL, 149 item->usage); 186 150 187 151 } … … 198 162 } 199 163 200 /*---------------------------------------------------------------------------*/201 164 /** 202 165 * Translate data from the report as specified in report descriptor item … … 204 167 * @param item Report descriptor item with definition of translation 205 168 * @param data Data to translate 169 * @param j Index of processed field in report descriptor item 206 170 * @return Translated data 207 171 */ … … 272 236 } 273 237 274 return (int)(((value - item->logical_minimum) / resolution) + 275 item->physical_minimum); 276 277 } 278 279 /*---------------------------------------------------------------------------*/ 280 /* OUTPUT API */ 238 return (int)(((value - item->logical_minimum) / resolution) + item->physical_minimum); 239 240 } 241 242 /*** OUTPUT API **/ 281 243 282 244 /** … … 288 250 * @return Returns allocated output buffer for specified output 289 251 */ 290 uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, 291 uint8_t report_id) 252 uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, uint8_t report_id) 292 253 { 293 254 if(report == NULL) { … … 299 260 usb_hid_report_description_t *report_des = NULL; 300 261 while(report_it != &report->reports) { 301 report_des = list_get_instance(report_it, 302 usb_hid_report_description_t, link); 303 304 if((report_des->report_id == report_id) && 305 (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)){ 306 264 break; 307 265 } … … 345 303 * @return Error code 346 304 */ 347 int usb_hid_report_output_translate(usb_hid_report_t *report, 348 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) 349 307 { 350 308 link_t *item; … … 362 320 } 363 321 322 usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0)); 323 364 324 usb_hid_report_description_t *report_des; 365 report_des = usb_hid_report_find_description (report, report_id, 366 USB_HID_REPORT_TYPE_OUTPUT); 367 325 report_des = usb_hid_report_find_description (report, report_id, USB_HID_REPORT_TYPE_OUTPUT); 368 326 if(report_des == NULL){ 369 327 return EINVAL; … … 375 333 report_item = list_get_instance(item, usb_hid_report_field_t, link); 376 334 335 usb_log_debug("OUTPUT ITEM usage(%x), value(%x)\n", report_item->usage, report_item->value); 336 377 337 if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) { 378 338 379 339 // array 380 value = usb_hid_translate_data_reverse(report_item, 381 report_item->value); 382 340 value = usb_hid_translate_data_reverse(report_item, report_item->value); 383 341 offset = report_item->offset; 384 342 length = report_item->size; … … 386 344 else { 387 345 // variable item 388 value = usb_hid_translate_data_reverse(report_item, 389 report_item->value); 390 346 value = usb_hid_translate_data_reverse(report_item, report_item->value); 391 347 offset = report_item->offset; 392 348 length = report_item->size; … … 397 353 if((offset/8) == ((offset+length-1)/8)) { 398 354 // je to v jednom bytu 399 if(((size_t)(offset/8) >= size) || 400 ((size_t)(offset+length-1)/8) >= size) { 355 if(((size_t)(offset/8) >= size) || ((size_t)(offset+length-1)/8) >= size) { 401 356 break; // TODO ErrorCode 402 357 } … … 415 370 if(i == (offset/8)) { 416 371 tmp_value = value; 417 tmp_value = tmp_value & 418 ((1 << (8-(offset%8)))-1); 419 372 tmp_value = tmp_value & ((1 << (8-(offset%8)))-1); 420 373 tmp_value = tmp_value << (offset%8); 421 374 422 mask = ~(((1 << (8-(offset%8)))-1) << 423 (offset%8)); 424 425 buffer[i] = (buffer[i] & mask) | 426 tmp_value; 375 mask = ~(((1 << (8-(offset%8)))-1) << (offset%8)); 376 buffer[i] = (buffer[i] & mask) | tmp_value; 427 377 } 428 378 else if (i == ((offset + length -1)/8)) { 429 379 430 value = value >> (length - 431 ((offset + length) % 8)); 432 433 value = value & ((1 << (length - 434 ((offset + length) % 8))) - 1); 380 value = value >> (length - ((offset + length) % 8)); 381 value = value & ((1 << (length - ((offset + length) % 8))) - 1); 435 382 436 mask = (1 << (length - 437 ((offset + length) % 8))) - 1; 438 383 mask = (1 << (length - ((offset + length) % 8))) - 1; 439 384 buffer[i] = (buffer[i] & mask) | value; 440 385 } … … 451 396 } 452 397 398 usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0)); 399 453 400 return EOK; 454 401 } 455 402 456 /*---------------------------------------------------------------------------*/457 403 /** 458 404 * Translate given data for putting them into the outoput report … … 461 407 * @return ranslated value 462 408 */ 463 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, 464 int value) 409 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int value) 465 410 { 466 411 int ret=0; … … 486 431 } 487 432 488 ret = ((value - item->physical_minimum) * resolution) + 489 item->logical_minimum; 490 491 usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), \ 492 ret(%x)\n", value, resolution, item->physical_minimum, 493 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); 494 435 495 436 if((item->logical_minimum < 0) || (item->logical_maximum < 0)){ … … 499 440 } 500 441 501 /*---------------------------------------------------------------------------*/ 502 /** 503 * Clones given state table 504 * 505 * @param item State table to clone 506 * @return Pointer to the cloned item 507 */ 508 usb_hid_report_item_t *usb_hid_report_item_clone( 509 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) 510 443 { 511 444 usb_hid_report_item_t *new_report_item; … … 520 453 } 521 454 522 /*---------------------------------------------------------------------------*/ 523 /** 524 * Function for sequence walking through the report. Returns next field in the 525 * report or the first one when no field is given. 526 * 527 * @param report Searched report structure 528 * @param field Current field. If NULL is given, the first one in the report 529 * is returned. Otherwise the next one i nthe list is returned. 530 * @param path Usage path specifying which fields wa are interested in. 531 * @param flags Flags defining mode of usage paths comparison 532 * @param type Type of report we search. 533 * @retval NULL if no field is founded 534 * @retval Pointer to the founded report structure when founded 535 */ 455 536 456 usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report, 537 usb_hid_report_field_t *field, usb_hid_report_path_t *path, int flags, 538 usb_hid_report_type_t type) 539 { 540 usb_hid_report_description_t *report_des = 541 usb_hid_report_find_description(report, path->report_id, type); 542 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); 543 462 link_t *field_it; 544 463 … … 548 467 549 468 if(field == NULL){ 469 // vezmu prvni co mathuje podle path!! 550 470 field_it = report_des->report_items.next; 551 471 } … … 555 475 556 476 while(field_it != &report_des->report_items) { 557 field = list_get_instance(field_it, usb_hid_report_field_t, 558 link); 477 field = list_get_instance(field_it, usb_hid_report_field_t, link); 559 478 560 479 if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) { 561 usb_hid_report_path_append_item ( 562 field->collection_path, field->usage_page, 563 field->usage); 564 565 if(usb_hid_report_compare_usage_path( 566 field->collection_path, path, flags) == EOK){ 567 568 usb_hid_report_remove_last_item( 569 field->collection_path); 570 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); 571 483 return field; 572 484 } 573 usb_hid_report_remove_last_item ( 574 field->collection_path); 485 usb_hid_report_remove_last_item (field->collection_path); 575 486 } 576 487 field_it = field_it->next; … … 580 491 } 581 492 582 /*---------------------------------------------------------------------------*/ 583 /** 584 * Returns next report_id of report of specified type. If zero is given than 585 * first report_id of specified type is returned (0 is not legal value for 586 * repotr_id) 587 * 588 * @param report_id Current report_id, 0 if there is no current report_id 589 * @param type Type of searched report 590 * @param report Report structure inwhich we search 591 * @retval 0 if report structure is null or there is no specified report 592 * @retval report_id otherwise 593 */ 594 uint8_t usb_hid_get_next_report_id(usb_hid_report_t *report, 595 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) 596 494 { 597 495 if(report == NULL){ … … 602 500 link_t *report_it; 603 501 604 if(report_id > 0) { 605 report_it = usb_hid_report_find_description(report, report_id, 606 type)->link.next; 502 if(report_id == 0) { 503 report_it = usb_hid_report_find_description (report, report_id, type)->link.next; 607 504 } 608 505 else { … … 611 508 612 509 while(report_it != &report->reports) { 613 report_des = list_get_instance(report_it, 614 usb_hid_report_description_t, link); 615 510 report_des = list_get_instance(report_it, usb_hid_report_description_t, link); 616 511 if(report_des->type == type){ 617 512 return report_des->report_id; … … 622 517 } 623 518 624 /*---------------------------------------------------------------------------*/625 /**626 * Reset all local items in given state table627 *628 * @param report_item State table containing current state of report629 * descriptor parsing630 *631 * @return void632 */633 519 void usb_hid_report_reset_local_items(usb_hid_report_item_t *report_item) 634 520 { -
uspace/lib/usbhid/src/hidpath.c
r74341ed r9ca8539 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 … … 225 192 226 193 switch(flags){ 227 /* path is somewhere in report_path */ 228 case USB_HID_PATH_COMPARE_ANYWHERE: 229 if(path->depth != 1){ 230 return 1; 231 } 232 233 report_link = report_path->head.next; 234 path_link = path->head.next; 235 path_item = list_get_instance(path_link, 236 usb_hid_report_usage_path_t, link); 237 238 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 245 if(only_page == 0){ 246 if(USB_HID_SAME_USAGE( 247 report_item->usage, 248 path_item->usage)) { 249 194 /* path is somewhere in report_path */ 195 case USB_HID_PATH_COMPARE_ANYWHERE: 196 if(path->depth != 1){ 197 return 1; 198 } 199 200 // projit skrz cestu a kdyz nekde sedi tak vratim EOK 201 // dojduli az za konec tak nnesedi 202 report_link = report_path->head.next; 203 path_link = path->head.next; 204 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link); 205 206 while(report_link != &report_path->head) { 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)){ 209 if(only_page == 0){ 210 if(USB_HID_SAME_USAGE(report_item->usage, path_item->usage)) { 211 return EOK; 212 } 213 } 214 else { 250 215 return EOK; 251 216 } 252 217 } 218 219 report_link = report_link->next; 220 } 221 222 return 1; 223 break; 224 /* the paths must be identical */ 225 case USB_HID_PATH_COMPARE_STRICT: 226 if(report_path->depth != path->depth){ 227 return 1; 228 } 229 230 /* path is prefix of the report_path */ 231 case USB_HID_PATH_COMPARE_BEGIN: 232 233 report_link = report_path->head.next; 234 path_link = path->head.next; 235 236 while((report_link != &report_path->head) && 237 (path_link != &path->head)) { 238 239 report_item = list_get_instance(report_link, 240 usb_hid_report_usage_path_t, 241 link); 242 243 path_item = list_get_instance(path_link, 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))) { 250 251 return 1; 252 } else { 253 report_link = report_link->next; 254 path_link = path_link->next; 255 } 256 257 } 258 259 if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && (path_link == &path->head)) || 260 ((report_link == &report_path->head) && (path_link == &path->head))) { 261 return EOK; 262 } 253 263 else { 264 return 1; 265 } 266 break; 267 268 /* path is suffix of report_path */ 269 case USB_HID_PATH_COMPARE_END: 270 271 report_link = report_path->head.prev; 272 path_link = path->head.prev; 273 274 if(list_empty(&path->head)){ 254 275 return EOK; 255 276 } 256 }257 258 report_link = report_link->next;259 }260 261 return 1;262 break;263 264 /* the paths must be identical */265 case USB_HID_PATH_COMPARE_STRICT:266 if(report_path->depth != path->depth){267 return 1;268 }269 270 /* path is prefix of the report_path */271 case USB_HID_PATH_COMPARE_BEGIN:272 273 report_link = report_path->head.next;274 path_link = path->head.next;275 277 276 while((report_link != &report_path->head) && 277 (path_link != &path->head)) { 278 279 report_item = list_get_instance(report_link, 280 usb_hid_report_usage_path_t, link); 281 282 path_item = list_get_instance(path_link, 283 usb_hid_report_usage_path_t, link); 284 285 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 286 path_item->usage_page) || ((only_page == 0) && 287 !USB_HID_SAME_USAGE(report_item->usage, 288 path_item->usage))) { 278 while((report_link != &report_path->head) && 279 (path_link != &path->head)) { 280 281 report_item = list_get_instance(report_link, 282 usb_hid_report_usage_path_t, 283 link); 284 path_item = list_get_instance(path_link, 285 usb_hid_report_usage_path_t, 286 link); 287 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))) { 291 return 1; 292 } else { 293 report_link = report_link->prev; 294 path_link = path_link->prev; 295 } 289 296 290 return 1; 291 } 292 else { 293 report_link = report_link->next; 294 path_link = path_link->next; 295 } 297 } 298 299 if(path_link == &path->head) { 300 return EOK; 301 } 302 else { 303 return 1; 304 } 296 305 297 } 298 299 if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && 300 (path_link == &path->head)) || 301 ((report_link == &report_path->head) && 302 (path_link == &path->head))) { 303 304 return EOK; 305 } 306 else { 307 return 1; 308 } 309 break; 310 311 /* path is suffix of report_path */ 312 case USB_HID_PATH_COMPARE_END: 313 314 report_link = report_path->head.prev; 315 path_link = path->head.prev; 316 317 if(list_empty(&path->head)){ 318 return EOK; 319 } 320 321 while((report_link != &report_path->head) && 322 (path_link != &path->head)) { 323 324 report_item = list_get_instance(report_link, 325 usb_hid_report_usage_path_t, link); 326 327 path_item = list_get_instance(path_link, 328 usb_hid_report_usage_path_t, link); 329 330 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 331 path_item->usage_page) || ((only_page == 0) && 332 !USB_HID_SAME_USAGE(report_item->usage, 333 path_item->usage))) { 334 335 return 1; 336 } else { 337 report_link = report_link->prev; 338 path_link = path_link->prev; 339 } 340 341 } 342 343 if(path_link == &path->head) { 344 return EOK; 345 } 346 else { 347 return 1; 348 } 349 350 break; 351 352 default: 353 return EINVAL; 354 } 355 } 356 357 /*---------------------------------------------------------------------------*/ 306 break; 307 308 default: 309 return EINVAL; 310 } 311 } 312 358 313 /** 359 314 * Allocates and initializes new usage path structure. … … 377 332 } 378 333 379 /*---------------------------------------------------------------------------*/380 334 /** 381 335 * Releases given usage path structure. … … 394 348 } 395 349 396 /*---------------------------------------------------------------------------*/ 350 397 351 /** 398 352 * Clone content of given usage path to the new one … … 401 355 * @return New copy of given usage path structure 402 356 */ 403 usb_hid_report_path_t *usb_hid_report_path_clone( 404 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) 405 358 { 406 359 link_t *path_link; … … 421 374 path_link = usage_path->head.next; 422 375 while(path_link != &usage_path->head) { 423 path_item = list_get_instance(path_link, 424 usb_hid_report_usage_path_t, link); 425 376 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, 377 link); 426 378 new_path_item = malloc(sizeof(usb_hid_report_usage_path_t)); 427 379 if(new_path_item == NULL) { … … 443 395 } 444 396 445 /*---------------------------------------------------------------------------*/ 397 446 398 /** 447 399 * Sets report id in usage path structure … … 451 403 * @return Error code 452 404 */ 453 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, 454 uint8_t report_id) 405 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, uint8_t report_id) 455 406 { 456 407 if(path == NULL){ -
uspace/lib/usbhid/src/hidreport.c
r74341ed r9ca8539 164 164 165 165 int usb_hid_process_report_descriptor(usb_device_t *dev, 166 usb_hid_report_t *report , uint8_t **report_desc, size_t *report_size)166 usb_hid_report_t *report) 167 167 { 168 168 if (dev == NULL || report == NULL) { … … 172 172 } 173 173 174 // uint8_t *report_desc = NULL; 175 // size_t report_size; 176 177 int rc = usb_hid_get_report_descriptor(dev, report_desc, report_size); 174 uint8_t *report_desc = NULL; 175 size_t report_size; 176 177 int rc = usb_hid_get_report_descriptor(dev, &report_desc, 178 &report_size); 178 179 179 180 if (rc != EOK) { 180 181 usb_log_error("Problem with getting Report descriptor: %s.\n", 181 182 str_error(rc)); 182 if (*report_desc != NULL) { 183 free(*report_desc); 184 *report_desc = NULL; 183 if (report_desc != NULL) { 184 free(report_desc); 185 185 } 186 186 return rc; 187 187 } 188 188 189 assert( *report_desc != NULL);190 191 rc = usb_hid_parse_report_descriptor(report, *report_desc, *report_size);189 assert(report_desc != NULL); 190 191 rc = usb_hid_parse_report_descriptor(report, report_desc, report_size); 192 192 if (rc != EOK) { 193 193 usb_log_error("Problem parsing Report descriptor: %s.\n", 194 194 str_error(rc)); 195 free(*report_desc); 196 *report_desc = NULL; 195 free(report_desc); 197 196 return rc; 198 197 } 199 198 200 199 usb_hid_descriptor_print(report); 200 free(report_desc); 201 201 202 202 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.