Changeset a8c4e871 in mainline
- Timestamp:
- 2011-10-15T14:09:14Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ce2a1c2
- Parents:
- a044f71
- Location:
- uspace
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mkbd/main.c
ra044f71 ra8c4e871 69 69 int rc = usb_hid_report_init(*report); 70 70 if (rc != EOK) { 71 usb_hid_ free_report(*report);71 usb_hid_report_deinit(*report); 72 72 *report = NULL; 73 73 return rc; … … 79 79 &report_desc_size); 80 80 if (rc != EOK) { 81 usb_hid_ free_report(*report);81 usb_hid_report_deinit(*report); 82 82 *report = NULL; 83 83 return rc; … … 85 85 86 86 if (report_desc_size == 0) { 87 usb_hid_ free_report(*report);87 usb_hid_report_deinit(*report); 88 88 *report = NULL; 89 89 // TODO: other error code? … … 93 93 uint8_t *desc = (uint8_t *) malloc(report_desc_size); 94 94 if (desc == NULL) { 95 usb_hid_ free_report(*report);95 usb_hid_report_deinit(*report); 96 96 *report = NULL; 97 97 return ENOMEM; … … 103 103 &actual_size); 104 104 if (rc != EOK) { 105 usb_hid_ free_report(*report);105 usb_hid_report_deinit(*report); 106 106 *report = NULL; 107 107 free(desc); … … 110 110 111 111 if (actual_size != report_desc_size) { 112 usb_hid_ free_report(*report);112 usb_hid_report_deinit(*report); 113 113 *report = NULL; 114 114 free(desc); -
uspace/app/usbinfo/hid.c
ra044f71 ra8c4e871 167 167 168 168 free(raw_report); 169 usb_hid_ free_report(&report);169 usb_hid_report_deinit(&report); 170 170 } 171 171 -
uspace/drv/bus/usb/usbhid/kbd/kbddev.c
ra044f71 ra8c4e871 237 237 238 238 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 239 hid_dev->report, NULL, kbd_dev->led_path,239 &hid_dev->report, NULL, kbd_dev->led_path, 240 240 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 241 241 USB_HID_REPORT_TYPE_OUTPUT); 242 242 243 243 while (field != NULL) { 244 245 if ((field->usage == USB_HID_LED_NUM_LOCK) 244 245 if ((field->usage == USB_HID_LED_NUM_LOCK) 246 246 && (kbd_dev->mods & KM_NUM_LOCK)){ 247 247 field->value = 1; 248 248 } 249 249 250 if ((field->usage == USB_HID_LED_CAPS_LOCK) 250 if ((field->usage == USB_HID_LED_CAPS_LOCK) 251 251 && (kbd_dev->mods & KM_CAPS_LOCK)){ 252 252 field->value = 1; 253 253 } 254 254 255 if ((field->usage == USB_HID_LED_SCROLL_LOCK) 255 if ((field->usage == USB_HID_LED_SCROLL_LOCK) 256 256 && (kbd_dev->mods & KM_SCROLL_LOCK)){ 257 257 field->value = 1; 258 258 } 259 260 field = usb_hid_report_get_sibling( hid_dev->report, field,261 kbd_dev->led_path,262 263 259 260 field = usb_hid_report_get_sibling( 261 &hid_dev->report, field, kbd_dev->led_path, 262 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 263 USB_HID_REPORT_TYPE_OUTPUT); 264 264 } 265 265 266 266 // TODO: what about the Report ID? 267 int rc = usb_hid_report_output_translate( hid_dev->report, 0,267 int rc = usb_hid_report_output_translate(&hid_dev->report, 0, 268 268 kbd_dev->output_buffer, kbd_dev->output_size); 269 269 … … 432 432 static void usb_kbd_process_data(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev) 433 433 { 434 assert(hid_dev->report != NULL);435 434 assert(hid_dev != NULL); 436 435 assert(kbd_dev != NULL); … … 444 443 445 444 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 446 hid_dev->report, NULL, path,447 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 445 &hid_dev->report, NULL, path, 446 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 448 447 USB_HID_REPORT_TYPE_INPUT); 449 448 unsigned i = 0; … … 454 453 455 454 assert(i < kbd_dev->key_count); 456 455 457 456 // save the key usage 458 457 if (field->value != 0) { … … 463 462 } 464 463 usb_log_debug2("Saved %u. key usage %d\n", i, kbd_dev->keys[i]); 465 464 466 465 ++i; 467 field = usb_hid_report_get_sibling( hid_dev->report, field, path,468 USB_HID_PATH_COMPARE_END469 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,466 field = usb_hid_report_get_sibling( 467 &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END 468 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 470 469 USB_HID_REPORT_TYPE_INPUT); 471 470 } … … 616 615 617 616 kbd_dev->key_count = usb_hid_report_size( 618 hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);617 &hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT); 619 618 usb_hid_report_path_free(path); 620 619 621 620 usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count); 622 621 623 kbd_dev->keys = (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t));622 kbd_dev->keys = calloc(kbd_dev->key_count, sizeof(int32_t)); 624 623 625 624 if (kbd_dev->keys == NULL) { … … 643 642 */ 644 643 kbd_dev->output_size = 0; 645 kbd_dev->output_buffer = usb_hid_report_output( hid_dev->report,644 kbd_dev->output_buffer = usb_hid_report_output(&hid_dev->report, 646 645 &kbd_dev->output_size, 0); 647 646 if (kbd_dev->output_buffer == NULL) { … … 657 656 kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0); 658 657 659 kbd_dev->led_output_size = usb_hid_report_size( hid_dev->report,660 0, USB_HID_REPORT_TYPE_OUTPUT);658 kbd_dev->led_output_size = usb_hid_report_size( 659 &hid_dev->report, 0, USB_HID_REPORT_TYPE_OUTPUT); 661 660 662 661 usb_log_debug("Output report size (in items): %zu\n", … … 826 825 int usb_kbd_set_boot_protocol(usb_hid_dev_t *hid_dev) 827 826 { 828 int rc = usb_hid_parse_report_descriptor( hid_dev->report,829 USB_KBD_BOOT_REPORT_DESCRIPTOR,827 int rc = usb_hid_parse_report_descriptor( 828 &hid_dev->report, USB_KBD_BOOT_REPORT_DESCRIPTOR, 830 829 USB_KBD_BOOT_REPORT_DESCRIPTOR_SIZE); 831 830 … … 836 835 } 837 836 838 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 837 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 839 838 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 840 839 -
uspace/drv/bus/usb/usbhid/main.c
ra044f71 ra8c4e871 92 92 if (rc != EOK) { 93 93 usb_log_error("Failed to initialize USB/HID device.\n"); 94 usb_hid_de stroy(hid_dev);94 usb_hid_deinit(hid_dev); 95 95 return rc; 96 96 } … … 128 128 usb_log_error("Failed to start polling fibril for `%s'.\n", 129 129 dev->ddf_dev->name); 130 usb_hid_de stroy(hid_dev);130 usb_hid_deinit(hid_dev); 131 131 return rc; 132 132 } 133 133 hid_dev->running = true; 134 dev->driver_data = hid_dev;135 134 136 135 /* … … 204 203 205 204 assert(!hid_dev->running); 206 usb_hid_de stroy(hid_dev);205 usb_hid_deinit(hid_dev); 207 206 usb_log_debug2("%s destruction complete.\n", dev->ddf_dev->name); 208 207 return EOK; -
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
ra044f71 ra8c4e871 268 268 269 269 int shift_x = get_mouse_axis_move_value(hid_dev->report_id, 270 hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X);270 &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X); 271 271 int shift_y = get_mouse_axis_move_value(hid_dev->report_id, 272 hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);272 &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y); 273 273 int wheel = get_mouse_axis_move_value(hid_dev->report_id, 274 hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);274 &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL); 275 275 276 276 if ((shift_x != 0) || (shift_y != 0)) { 277 async_exch_t *exch = async_exchange_begin(mouse_dev->mouse_sess); 277 async_exch_t *exch = 278 async_exchange_begin(mouse_dev->mouse_sess); 278 279 async_req_2_0(exch, MOUSEEV_MOVE_EVENT, shift_x, shift_y); 279 280 async_exchange_end(exch); … … 291 292 292 293 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 293 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END 294 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 295 USB_HID_REPORT_TYPE_INPUT); 294 &hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END 295 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, USB_HID_REPORT_TYPE_INPUT); 296 296 297 297 while (field != NULL) { … … 314 314 async_req_2_0(exch, MOUSEEV_BUTTON_EVENT, field->usage, 0); 315 315 async_exchange_end(exch); 316 316 317 317 mouse_dev->buttons[field->usage - field->usage_minimum] = 318 318 field->value; 319 319 } 320 320 321 321 field = usb_hid_report_get_sibling( 322 hid_dev->report, field, path, USB_HID_PATH_COMPARE_END323 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 322 &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END 323 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 324 324 USB_HID_REPORT_TYPE_INPUT); 325 325 } … … 474 474 // that the current solution is good enough. 475 475 /* Adding 1 because we will be accessing buttons[highest]. */ 476 mouse_dev->buttons_count = usb_mouse_get_highest_button(hid_dev->report,477 hid_dev->report_id) + 1;476 mouse_dev->buttons_count = 1 + usb_mouse_get_highest_button( 477 &hid_dev->report, hid_dev->report_id); 478 478 mouse_dev->buttons = calloc(mouse_dev->buttons_count, sizeof(int32_t)); 479 479 … … 532 532 int usb_mouse_set_boot_protocol(usb_hid_dev_t *hid_dev) 533 533 { 534 int rc = usb_hid_parse_report_descriptor( hid_dev->report,535 USB_MOUSE_BOOT_REPORT_DESCRIPTOR,534 int rc = usb_hid_parse_report_descriptor( 535 &hid_dev->report, USB_MOUSE_BOOT_REPORT_DESCRIPTOR, 536 536 USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE); 537 537 … … 542 542 } 543 543 544 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 544 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 545 545 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 546 546 -
uspace/drv/bus/usb/usbhid/multimedia/multimedia.c
ra044f71 ra8c4e871 272 272 273 273 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 274 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END275 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 274 &hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END 275 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 276 276 USB_HID_REPORT_TYPE_INPUT); 277 277 … … 293 293 294 294 field = usb_hid_report_get_sibling( 295 hid_dev->report, field, path, USB_HID_PATH_COMPARE_END295 &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END 296 296 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 297 297 USB_HID_REPORT_TYPE_INPUT); -
uspace/drv/bus/usb/usbhid/usbhid.c
ra044f71 ra8c4e871 204 204 } 205 205 206 assert(hid_dev->report != NULL);207 208 206 usb_log_debug("Compare flags: %d\n", mapping->compare); 209 207 … … 213 211 do { 214 212 usb_log_debug("Trying report id %u\n", report_id); 215 213 216 214 if (report_id != 0) { 217 215 usb_hid_report_path_set_report_id(usage_path, … … 220 218 221 219 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 222 hid_dev->report, 223 NULL, usage_path, mapping->compare, 220 &hid_dev->report, NULL, usage_path, mapping->compare, 224 221 USB_HID_REPORT_TYPE_INPUT); 225 222 226 223 usb_log_debug("Field: %p\n", field); 227 224 … … 230 227 break; 231 228 } 232 229 233 230 report_id = usb_hid_get_next_report_id( 234 hid_dev->report, report_id, 235 USB_HID_REPORT_TYPE_INPUT); 231 &hid_dev->report, report_id, USB_HID_REPORT_TYPE_INPUT); 236 232 } while (!matches && report_id != 0); 237 233 … … 378 374 static int usb_hid_init_report(usb_hid_dev_t *hid_dev) 379 375 { 380 assert(hid_dev != NULL && hid_dev->report != NULL);376 assert(hid_dev != NULL); 381 377 382 378 uint8_t report_id = 0; 383 size_t size;384 385 379 size_t max_size = 0; 386 380 387 381 do { 388 382 usb_log_debug("Getting size of the report.\n"); 389 size = usb_hid_report_byte_size(hid_dev->report, report_id, 390 USB_HID_REPORT_TYPE_INPUT); 383 const size_t size = 384 usb_hid_report_byte_size(&hid_dev->report, report_id, 385 USB_HID_REPORT_TYPE_INPUT); 391 386 usb_log_debug("Report ID: %u, size: %zu\n", report_id, size); 392 387 max_size = (size > max_size) ? size : max_size; 393 388 usb_log_debug("Getting next report ID\n"); 394 report_id = usb_hid_get_next_report_id( hid_dev->report,389 report_id = usb_hid_get_next_report_id(&hid_dev->report, 395 390 report_id, USB_HID_REPORT_TYPE_INPUT); 396 391 } while (report_id != 0); … … 430 425 } 431 426 432 hid_dev->report = (usb_hid_report_t *)(malloc(sizeof( 433 usb_hid_report_t))); 434 if (hid_dev->report == NULL) { 435 usb_log_error("No memory!\n"); 436 return ENOMEM; 437 } 438 usb_hid_report_init(hid_dev->report); 427 usb_hid_report_init(&hid_dev->report); 439 428 440 429 /* The USB device should already be initialized, save it in structure */ … … 446 435 return rc; 447 436 } 448 437 449 438 /* Get the report descriptor and parse it. */ 450 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 451 hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size);439 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 440 &hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size); 452 441 453 442 bool fallback = false; … … 524 513 } 525 514 } 526 515 527 516 rc = (ok) ? EOK : -1; // what error to report 528 517 } … … 570 559 // parse the input report 571 560 572 int rc = usb_hid_parse_report( hid_dev->report, buffer, buffer_size,561 int rc = usb_hid_parse_report(&hid_dev->report, buffer, buffer_size, 573 562 &hid_dev->report_id); 574 563 … … 576 565 usb_log_warning("Error in usb_hid_parse_report():" 577 566 "%s\n", str_error(rc)); 578 } 567 } 579 568 580 569 bool cont = false; … … 631 620 /*----------------------------------------------------------------------------*/ 632 621 633 void usb_hid_de stroy(usb_hid_dev_t *hid_dev)622 void usb_hid_deinit(usb_hid_dev_t *hid_dev) 634 623 { 635 624 int i; … … 657 646 658 647 /* Destroy the parser */ 659 if (hid_dev->report != NULL) { 660 usb_hid_free_report(hid_dev->report); 661 } 648 usb_hid_report_deinit(&hid_dev->report); 662 649 663 650 } -
uspace/drv/bus/usb/usbhid/usbhid.h
ra044f71 ra8c4e871 119 119 120 120 /** HID Report parser. */ 121 usb_hid_report_t *report;121 usb_hid_report_t report; 122 122 123 123 uint8_t report_id; … … 146 146 147 147 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev); 148 void usb_hid_deinit(usb_hid_dev_t *hid_dev); 148 149 149 bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer,150 size_t buffer_size, void *arg);150 bool usb_hid_polling_callback(usb_device_t *dev, 151 uint8_t *buffer, size_t buffer_size, void *arg); 151 152 152 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, 153 void *arg); 153 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg); 154 154 155 155 void usb_hid_new_report(usb_hid_dev_t *hid_dev); 156 156 157 157 int usb_hid_report_number(usb_hid_dev_t *hid_dev); 158 159 void usb_hid_destroy(usb_hid_dev_t *hid_dev);160 158 161 159 #endif /* USB_HID_USBHID_H_ */ -
uspace/lib/usbhid/include/usb/hid/hiddescriptor.h
ra044f71 ra8c4e871 42 42 #include <usb/hid/hidtypes.h> 43 43 44 int usb_hid_parse_report_descriptor(usb_hid_report_t *report, 44 int usb_hid_parse_report_descriptor(usb_hid_report_t *report, 45 45 const uint8_t *data, size_t size); 46 47 void usb_hid_free_report(usb_hid_report_t *report);48 46 49 47 void usb_hid_descriptor_print(usb_hid_report_t *report); 50 48 51 49 int usb_hid_report_init(usb_hid_report_t *report); 50 51 void usb_hid_report_deinit(usb_hid_report_t *report); 52 52 53 53 int usb_hid_report_append_fields(usb_hid_report_t *report, -
uspace/lib/usbhid/src/hiddescriptor.c
ra044f71 ra8c4e871 1016 1016 * @return void 1017 1017 */ 1018 void usb_hid_ free_report(usb_hid_report_t *report)1018 void usb_hid_report_deinit(usb_hid_report_t *report) 1019 1019 { 1020 1020 if(report == NULL){
Note:
See TracChangeset
for help on using the changeset viewer.