Changes in uspace/drv/bus/usb/usbhid/kbd/kbddev.c [56fd7cf:2d1ba51] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/kbd/kbddev.c
r56fd7cf r2d1ba51 34 34 * USB HID keyboard device structure and API. 35 35 */ 36 37 /* XXX Fix this */38 #define _DDF_DATA_IMPLANT39 36 40 37 #include <errno.h> … … 74 71 #include "../usbhid.h" 75 72 76 static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *); 77 static ddf_dev_ops_t kbdops = { .default_handler = default_connection_handler }; 78 73 /*----------------------------------------------------------------------------*/ 79 74 80 75 static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK; … … 91 86 static const unsigned int DEFAULT_REPEAT_DELAY = 50 * 1000; 92 87 93 88 /*----------------------------------------------------------------------------*/ 94 89 /** Keyboard polling endpoint description for boot protocol class. */ 95 90 const usb_endpoint_description_t usb_hid_kbd_poll_endpoint_description = { … … 106 101 107 102 static void usb_kbd_set_led(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev); 108 103 /*----------------------------------------------------------------------------*/ 109 104 static const uint8_t USB_KBD_BOOT_REPORT_DESCRIPTOR[] = { 110 105 0x05, 0x01, /* Usage Page (Generic Desktop), */ … … 141 136 0xC0 /* End Collection */ 142 137 }; 143 138 /*----------------------------------------------------------------------------*/ 144 139 typedef enum usb_kbd_flags { 145 140 USB_KBD_STATUS_UNINITIALIZED = 0, … … 147 142 USB_KBD_STATUS_TO_DESTROY = -1 148 143 } usb_kbd_flags; 149 144 /*----------------------------------------------------------------------------*/ 150 145 /* IPC method handler */ 151 146 /*----------------------------------------------------------------------------*/ 152 147 /** 153 148 * Default handler for IPC methods not handled by DDF. … … 165 160 ipc_callid_t icallid, ipc_call_t *icall) 166 161 { 162 if (fun == NULL || fun->driver_data == NULL) { 163 usb_log_error("%s: Missing parameter.\n", __FUNCTION__); 164 async_answer_0(icallid, EINVAL); 165 return; 166 } 167 167 168 const sysarg_t method = IPC_GET_IMETHOD(*icall); 168 usb_kbd_t *kbd_dev = ddf_fun_data_get(fun);169 usb_kbd_t *kbd_dev = fun->driver_data; 169 170 170 171 switch (method) { … … 186 187 break; 187 188 } 188 if (kbd_dev->c lient_sess == NULL) {189 kbd_dev->c lient_sess = sess;189 if (kbd_dev->console_sess == NULL) { 190 kbd_dev->console_sess = sess; 190 191 usb_log_debug("%s: OK\n", __FUNCTION__); 191 192 async_answer_0(icallid, EOK); … … 205 206 206 207 } 207 208 /*----------------------------------------------------------------------------*/ 208 209 /* Key processing functions */ 209 210 /*----------------------------------------------------------------------------*/ 210 211 /** 211 212 * Handles turning of LED lights on and off. … … 280 281 } 281 282 } 282 283 /*----------------------------------------------------------------------------*/ 283 284 /** Send key event. 284 285 * … … 291 292 { 292 293 usb_log_debug2("Sending kbdev event %d/%d to the console\n", type, key); 293 if (kbd_dev->c lient_sess == NULL) {294 if (kbd_dev->console_sess == NULL) { 294 295 usb_log_warning( 295 296 "Connection to console not ready, key discarded.\n"); … … 297 298 } 298 299 299 async_exch_t *exch = async_exchange_begin(kbd_dev->c lient_sess);300 async_exch_t *exch = async_exchange_begin(kbd_dev->console_sess); 300 301 if (exch != NULL) { 301 302 async_msg_2(exch, KBDEV_EVENT, type, key); … … 305 306 } 306 307 } 307 308 /*----------------------------------------------------------------------------*/ 308 309 static inline int usb_kbd_is_lock(unsigned int key_code) 309 310 { … … 312 313 || key_code == KC_CAPS_LOCK); 313 314 } 314 315 /*----------------------------------------------------------------------------*/ 315 316 static size_t find_in_array_int32(int32_t val, int32_t *arr, size_t arr_size) 316 317 { … … 323 324 return (size_t) -1; 324 325 } 325 326 /*----------------------------------------------------------------------------*/ 326 327 /** 327 328 * Checks if some keys were pressed or released and generates key events. … … 406 407 usb_log_debug2("Stored keys %s.\n", key_buffer); 407 408 } 408 409 /*----------------------------------------------------------------------------*/ 409 410 /* General kbd functions */ 410 411 /*----------------------------------------------------------------------------*/ 411 412 /** 412 413 * Processes data received from the device in form of report. … … 478 479 usb_kbd_check_key_changes(hid_dev, kbd_dev); 479 480 } 480 481 /*----------------------------------------------------------------------------*/ 481 482 /* HID/KBD structure manipulation */ 482 483 /*----------------------------------------------------------------------------*/ 483 484 static int usb_kbd_create_function(usb_kbd_t *kbd_dev) 484 485 { … … 498 499 /* Store the initialized HID device and HID ops 499 500 * to the DDF function. */ 500 ddf_fun_set_ops(fun, &kbdops);501 ddf_fun_data_implant(fun, kbd_dev);501 fun->ops = &kbd_dev->ops; 502 fun->driver_data = kbd_dev; 502 503 503 504 int rc = ddf_fun_bind(fun); … … 505 506 usb_log_error("Could not bind DDF function: %s.\n", 506 507 str_error(rc)); 508 fun->driver_data = NULL; /* We did not allocate this. */ 507 509 ddf_fun_destroy(fun); 508 510 return rc; … … 510 512 511 513 usb_log_debug("%s function created. Handle: %" PRIun "\n", 512 HID_KBD_FUN_NAME, ddf_fun_get_handle(fun));514 HID_KBD_FUN_NAME, fun->handle); 513 515 514 516 usb_log_debug("Adding DDF function to category %s...\n", … … 520 522 HID_KBD_CLASS_NAME, str_error(rc)); 521 523 if (ddf_fun_unbind(fun) == EOK) { 524 fun->driver_data = NULL; /* We did not allocate this. */ 522 525 ddf_fun_destroy(fun); 523 526 } else { 524 527 usb_log_error( 525 528 "Failed to unbind `%s', will not destroy.\n", 526 ddf_fun_get_name(fun));529 fun->name); 527 530 } 528 531 return rc; … … 532 535 return EOK; 533 536 } 534 537 /*----------------------------------------------------------------------------*/ 535 538 /* API functions */ 536 539 /*----------------------------------------------------------------------------*/ 537 540 /** 538 541 * Initialization of the USB/HID keyboard structure. … … 573 576 fibril_mutex_initialize(&kbd_dev->repeat_mtx); 574 577 kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED; 578 kbd_dev->ops.default_handler = default_connection_handler; 575 579 576 580 /* Store link to HID device */ … … 696 700 return EOK; 697 701 } 698 702 /*----------------------------------------------------------------------------*/ 699 703 bool usb_kbd_polling_callback(usb_hid_dev_t *hid_dev, void *data) 700 704 { … … 710 714 return true; 711 715 } 712 716 /*----------------------------------------------------------------------------*/ 713 717 int usb_kbd_is_initialized(const usb_kbd_t *kbd_dev) 714 718 { 715 719 return (kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED); 716 720 } 717 721 /*----------------------------------------------------------------------------*/ 718 722 int usb_kbd_is_ready_to_destroy(const usb_kbd_t *kbd_dev) 719 723 { 720 724 return (kbd_dev->initialized == USB_KBD_STATUS_TO_DESTROY); 721 725 } 722 726 /*----------------------------------------------------------------------------*/ 723 727 /** 724 728 * Properly destroys the USB/HID keyboard structure. … … 733 737 734 738 /* Hangup session to the console. */ 735 if (kbd_dev->c lient_sess)736 async_hangup(kbd_dev->c lient_sess);739 if (kbd_dev->console_sess) 740 async_hangup(kbd_dev->console_sess); 737 741 738 742 //assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx)); … … 752 756 if (ddf_fun_unbind(kbd_dev->fun) != EOK) { 753 757 usb_log_warning("Failed to unbind %s.\n", 754 ddf_fun_get_name(kbd_dev->fun));758 kbd_dev->fun->name); 755 759 } else { 756 usb_log_debug2("%s unbound.\n", 757 ddf_fun_get_name(kbd_dev->fun));760 usb_log_debug2("%s unbound.\n", kbd_dev->fun->name); 761 kbd_dev->fun->driver_data = NULL; 758 762 ddf_fun_destroy(kbd_dev->fun); 759 763 } 760 764 } 761 } 762 765 free(kbd_dev); 766 } 767 /*----------------------------------------------------------------------------*/ 763 768 void usb_kbd_deinit(usb_hid_dev_t *hid_dev, void *data) 764 769 { … … 773 778 } 774 779 } 775 780 /*----------------------------------------------------------------------------*/ 776 781 int usb_kbd_set_boot_protocol(usb_hid_dev_t *hid_dev) 777 782 {
Note:
See TracChangeset
for help on using the changeset viewer.