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