Ignore:
File:
1 edited

Legend:

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

    r2d1ba51 r56fd7cf  
    3434 * USB HID keyboard device structure and API.
    3535 */
     36
     37/* XXX Fix this */
     38#define _DDF_DATA_IMPLANT
    3639
    3740#include <errno.h>
     
    7174#include "../usbhid.h"
    7275
    73 /*----------------------------------------------------------------------------*/
     76static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
     77static ddf_dev_ops_t kbdops = { .default_handler = default_connection_handler };
     78
    7479
    7580static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK;
     
    8691static const unsigned int DEFAULT_REPEAT_DELAY = 50 * 1000;
    8792
    88 /*----------------------------------------------------------------------------*/
     93
    8994/** Keyboard polling endpoint description for boot protocol class. */
    9095const usb_endpoint_description_t usb_hid_kbd_poll_endpoint_description = {
     
    101106
    102107static void usb_kbd_set_led(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev);
    103 /*----------------------------------------------------------------------------*/
     108
    104109static const uint8_t USB_KBD_BOOT_REPORT_DESCRIPTOR[] = {
    105110        0x05, 0x01,  /* Usage Page (Generic Desktop), */
     
    136141        0xC0         /* End Collection */
    137142};
    138 /*----------------------------------------------------------------------------*/
     143
    139144typedef enum usb_kbd_flags {
    140145        USB_KBD_STATUS_UNINITIALIZED = 0,
     
    142147        USB_KBD_STATUS_TO_DESTROY = -1
    143148} usb_kbd_flags;
    144 /*----------------------------------------------------------------------------*/
     149
    145150/* IPC method handler                                                         */
    146 /*----------------------------------------------------------------------------*/
     151
    147152/**
    148153 * Default handler for IPC methods not handled by DDF.
     
    160165    ipc_callid_t icallid, ipc_call_t *icall)
    161166{
    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 
    168167        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);
    170169
    171170        switch (method) {
     
    187186                        break;
    188187                }
    189                 if (kbd_dev->console_sess == NULL) {
    190                         kbd_dev->console_sess = sess;
     188                if (kbd_dev->client_sess == NULL) {
     189                        kbd_dev->client_sess = sess;
    191190                        usb_log_debug("%s: OK\n", __FUNCTION__);
    192191                        async_answer_0(icallid, EOK);
     
    206205
    207206}
    208 /*----------------------------------------------------------------------------*/
     207
    209208/* Key processing functions                                                   */
    210 /*----------------------------------------------------------------------------*/
     209
    211210/**
    212211 * Handles turning of LED lights on and off.
     
    281280        }
    282281}
    283 /*----------------------------------------------------------------------------*/
     282
    284283/** Send key event.
    285284 *
     
    292291{
    293292        usb_log_debug2("Sending kbdev event %d/%d to the console\n", type, key);
    294         if (kbd_dev->console_sess == NULL) {
     293        if (kbd_dev->client_sess == NULL) {
    295294                usb_log_warning(
    296295                    "Connection to console not ready, key discarded.\n");
     
    298297        }
    299298
    300         async_exch_t *exch = async_exchange_begin(kbd_dev->console_sess);
     299        async_exch_t *exch = async_exchange_begin(kbd_dev->client_sess);
    301300        if (exch != NULL) {
    302301                async_msg_2(exch, KBDEV_EVENT, type, key);
     
    306305        }
    307306}
    308 /*----------------------------------------------------------------------------*/
     307
    309308static inline int usb_kbd_is_lock(unsigned int key_code)
    310309{
     
    313312            || key_code == KC_CAPS_LOCK);
    314313}
    315 /*----------------------------------------------------------------------------*/
     314
    316315static size_t find_in_array_int32(int32_t val, int32_t *arr, size_t arr_size)
    317316{
     
    324323        return (size_t) -1;
    325324}
    326 /*----------------------------------------------------------------------------*/
     325
    327326/**
    328327 * Checks if some keys were pressed or released and generates key events.
     
    407406        usb_log_debug2("Stored keys %s.\n", key_buffer);
    408407}
    409 /*----------------------------------------------------------------------------*/
     408
    410409/* General kbd functions                                                      */
    411 /*----------------------------------------------------------------------------*/
     410
    412411/**
    413412 * Processes data received from the device in form of report.
     
    479478        usb_kbd_check_key_changes(hid_dev, kbd_dev);
    480479}
    481 /*----------------------------------------------------------------------------*/
     480
    482481/* HID/KBD structure manipulation                                             */
    483 /*----------------------------------------------------------------------------*/
     482
    484483static int usb_kbd_create_function(usb_kbd_t *kbd_dev)
    485484{
     
    499498        /* Store the initialized HID device and HID ops
    500499         * 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);
    503502
    504503        int rc = ddf_fun_bind(fun);
     
    506505                usb_log_error("Could not bind DDF function: %s.\n",
    507506                    str_error(rc));
    508                 fun->driver_data = NULL; /* We did not allocate this. */
    509507                ddf_fun_destroy(fun);
    510508                return rc;
     
    512510
    513511        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));
    515513
    516514        usb_log_debug("Adding DDF function to category %s...\n",
     
    522520                    HID_KBD_CLASS_NAME, str_error(rc));
    523521                if (ddf_fun_unbind(fun) == EOK) {
    524                         fun->driver_data = NULL; /* We did not allocate this. */
    525522                        ddf_fun_destroy(fun);
    526523                } else {
    527524                        usb_log_error(
    528525                            "Failed to unbind `%s', will not destroy.\n",
    529                             fun->name);
     526                            ddf_fun_get_name(fun));
    530527                }
    531528                return rc;
     
    535532        return EOK;
    536533}
    537 /*----------------------------------------------------------------------------*/
     534
    538535/* API functions                                                              */
    539 /*----------------------------------------------------------------------------*/
     536
    540537/**
    541538 * Initialization of the USB/HID keyboard structure.
     
    576573        fibril_mutex_initialize(&kbd_dev->repeat_mtx);
    577574        kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED;
    578         kbd_dev->ops.default_handler = default_connection_handler;
    579575
    580576        /* Store link to HID device */
     
    700696        return EOK;
    701697}
    702 /*----------------------------------------------------------------------------*/
     698
    703699bool usb_kbd_polling_callback(usb_hid_dev_t *hid_dev, void *data)
    704700{
     
    714710        return true;
    715711}
    716 /*----------------------------------------------------------------------------*/
     712
    717713int usb_kbd_is_initialized(const usb_kbd_t *kbd_dev)
    718714{
    719715        return (kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED);
    720716}
    721 /*----------------------------------------------------------------------------*/
     717
    722718int usb_kbd_is_ready_to_destroy(const usb_kbd_t *kbd_dev)
    723719{
    724720        return (kbd_dev->initialized == USB_KBD_STATUS_TO_DESTROY);
    725721}
    726 /*----------------------------------------------------------------------------*/
     722
    727723/**
    728724 * Properly destroys the USB/HID keyboard structure.
     
    737733
    738734        /* Hangup session to the console. */
    739         if (kbd_dev->console_sess)
    740                 async_hangup(kbd_dev->console_sess);
     735        if (kbd_dev->client_sess)
     736                async_hangup(kbd_dev->client_sess);
    741737
    742738        //assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));
     
    756752                if (ddf_fun_unbind(kbd_dev->fun) != EOK) {
    757753                        usb_log_warning("Failed to unbind %s.\n",
    758                             kbd_dev->fun->name);
     754                            ddf_fun_get_name(kbd_dev->fun));
    759755                } 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));
    762758                        ddf_fun_destroy(kbd_dev->fun);
    763759                }
    764760        }
    765         free(kbd_dev);
    766 }
    767 /*----------------------------------------------------------------------------*/
     761}
     762
    768763void usb_kbd_deinit(usb_hid_dev_t *hid_dev, void *data)
    769764{
     
    778773        }
    779774}
    780 /*----------------------------------------------------------------------------*/
     775
    781776int usb_kbd_set_boot_protocol(usb_hid_dev_t *hid_dev)
    782777{
Note: See TracChangeset for help on using the changeset viewer.