Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhid/kbd/kbddev.c

    r56fd7cf r2d1ba51  
    3434 * USB HID keyboard device structure and API.
    3535 */
    36 
    37 /* XXX Fix this */
    38 #define _DDF_DATA_IMPLANT
    3936
    4037#include <errno.h>
     
    7471#include "../usbhid.h"
    7572
    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/*----------------------------------------------------------------------------*/
    7974
    8075static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK;
     
    9186static const unsigned int DEFAULT_REPEAT_DELAY = 50 * 1000;
    9287
    93 
     88/*----------------------------------------------------------------------------*/
    9489/** Keyboard polling endpoint description for boot protocol class. */
    9590const usb_endpoint_description_t usb_hid_kbd_poll_endpoint_description = {
     
    106101
    107102static void usb_kbd_set_led(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev);
    108 
     103/*----------------------------------------------------------------------------*/
    109104static const uint8_t USB_KBD_BOOT_REPORT_DESCRIPTOR[] = {
    110105        0x05, 0x01,  /* Usage Page (Generic Desktop), */
     
    141136        0xC0         /* End Collection */
    142137};
    143 
     138/*----------------------------------------------------------------------------*/
    144139typedef enum usb_kbd_flags {
    145140        USB_KBD_STATUS_UNINITIALIZED = 0,
     
    147142        USB_KBD_STATUS_TO_DESTROY = -1
    148143} usb_kbd_flags;
    149 
     144/*----------------------------------------------------------------------------*/
    150145/* IPC method handler                                                         */
    151 
     146/*----------------------------------------------------------------------------*/
    152147/**
    153148 * Default handler for IPC methods not handled by DDF.
     
    165160    ipc_callid_t icallid, ipc_call_t *icall)
    166161{
     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
    167168        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;
    169170
    170171        switch (method) {
     
    186187                        break;
    187188                }
    188                 if (kbd_dev->client_sess == NULL) {
    189                         kbd_dev->client_sess = sess;
     189                if (kbd_dev->console_sess == NULL) {
     190                        kbd_dev->console_sess = sess;
    190191                        usb_log_debug("%s: OK\n", __FUNCTION__);
    191192                        async_answer_0(icallid, EOK);
     
    205206
    206207}
    207 
     208/*----------------------------------------------------------------------------*/
    208209/* Key processing functions                                                   */
    209 
     210/*----------------------------------------------------------------------------*/
    210211/**
    211212 * Handles turning of LED lights on and off.
     
    280281        }
    281282}
    282 
     283/*----------------------------------------------------------------------------*/
    283284/** Send key event.
    284285 *
     
    291292{
    292293        usb_log_debug2("Sending kbdev event %d/%d to the console\n", type, key);
    293         if (kbd_dev->client_sess == NULL) {
     294        if (kbd_dev->console_sess == NULL) {
    294295                usb_log_warning(
    295296                    "Connection to console not ready, key discarded.\n");
     
    297298        }
    298299
    299         async_exch_t *exch = async_exchange_begin(kbd_dev->client_sess);
     300        async_exch_t *exch = async_exchange_begin(kbd_dev->console_sess);
    300301        if (exch != NULL) {
    301302                async_msg_2(exch, KBDEV_EVENT, type, key);
     
    305306        }
    306307}
    307 
     308/*----------------------------------------------------------------------------*/
    308309static inline int usb_kbd_is_lock(unsigned int key_code)
    309310{
     
    312313            || key_code == KC_CAPS_LOCK);
    313314}
    314 
     315/*----------------------------------------------------------------------------*/
    315316static size_t find_in_array_int32(int32_t val, int32_t *arr, size_t arr_size)
    316317{
     
    323324        return (size_t) -1;
    324325}
    325 
     326/*----------------------------------------------------------------------------*/
    326327/**
    327328 * Checks if some keys were pressed or released and generates key events.
     
    406407        usb_log_debug2("Stored keys %s.\n", key_buffer);
    407408}
    408 
     409/*----------------------------------------------------------------------------*/
    409410/* General kbd functions                                                      */
    410 
     411/*----------------------------------------------------------------------------*/
    411412/**
    412413 * Processes data received from the device in form of report.
     
    478479        usb_kbd_check_key_changes(hid_dev, kbd_dev);
    479480}
    480 
     481/*----------------------------------------------------------------------------*/
    481482/* HID/KBD structure manipulation                                             */
    482 
     483/*----------------------------------------------------------------------------*/
    483484static int usb_kbd_create_function(usb_kbd_t *kbd_dev)
    484485{
     
    498499        /* Store the initialized HID device and HID ops
    499500         * 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;
    502503
    503504        int rc = ddf_fun_bind(fun);
     
    505506                usb_log_error("Could not bind DDF function: %s.\n",
    506507                    str_error(rc));
     508                fun->driver_data = NULL; /* We did not allocate this. */
    507509                ddf_fun_destroy(fun);
    508510                return rc;
     
    510512
    511513        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);
    513515
    514516        usb_log_debug("Adding DDF function to category %s...\n",
     
    520522                    HID_KBD_CLASS_NAME, str_error(rc));
    521523                if (ddf_fun_unbind(fun) == EOK) {
     524                        fun->driver_data = NULL; /* We did not allocate this. */
    522525                        ddf_fun_destroy(fun);
    523526                } else {
    524527                        usb_log_error(
    525528                            "Failed to unbind `%s', will not destroy.\n",
    526                             ddf_fun_get_name(fun));
     529                            fun->name);
    527530                }
    528531                return rc;
     
    532535        return EOK;
    533536}
    534 
     537/*----------------------------------------------------------------------------*/
    535538/* API functions                                                              */
    536 
     539/*----------------------------------------------------------------------------*/
    537540/**
    538541 * Initialization of the USB/HID keyboard structure.
     
    573576        fibril_mutex_initialize(&kbd_dev->repeat_mtx);
    574577        kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED;
     578        kbd_dev->ops.default_handler = default_connection_handler;
    575579
    576580        /* Store link to HID device */
     
    696700        return EOK;
    697701}
    698 
     702/*----------------------------------------------------------------------------*/
    699703bool usb_kbd_polling_callback(usb_hid_dev_t *hid_dev, void *data)
    700704{
     
    710714        return true;
    711715}
    712 
     716/*----------------------------------------------------------------------------*/
    713717int usb_kbd_is_initialized(const usb_kbd_t *kbd_dev)
    714718{
    715719        return (kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED);
    716720}
    717 
     721/*----------------------------------------------------------------------------*/
    718722int usb_kbd_is_ready_to_destroy(const usb_kbd_t *kbd_dev)
    719723{
    720724        return (kbd_dev->initialized == USB_KBD_STATUS_TO_DESTROY);
    721725}
    722 
     726/*----------------------------------------------------------------------------*/
    723727/**
    724728 * Properly destroys the USB/HID keyboard structure.
     
    733737
    734738        /* Hangup session to the console. */
    735         if (kbd_dev->client_sess)
    736                 async_hangup(kbd_dev->client_sess);
     739        if (kbd_dev->console_sess)
     740                async_hangup(kbd_dev->console_sess);
    737741
    738742        //assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));
     
    752756                if (ddf_fun_unbind(kbd_dev->fun) != EOK) {
    753757                        usb_log_warning("Failed to unbind %s.\n",
    754                             ddf_fun_get_name(kbd_dev->fun));
     758                            kbd_dev->fun->name);
    755759                } 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;
    758762                        ddf_fun_destroy(kbd_dev->fun);
    759763                }
    760764        }
    761 }
    762 
     765        free(kbd_dev);
     766}
     767/*----------------------------------------------------------------------------*/
    763768void usb_kbd_deinit(usb_hid_dev_t *hid_dev, void *data)
    764769{
     
    773778        }
    774779}
    775 
     780/*----------------------------------------------------------------------------*/
    776781int usb_kbd_set_boot_protocol(usb_hid_dev_t *hid_dev)
    777782{
Note: See TracChangeset for help on using the changeset viewer.