Ignore:
File:
1 edited

Legend:

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

    r76fbd9a r2d1ba51  
    7171#include "../usbhid.h"
    7272
    73 static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
    74 static ddf_dev_ops_t kbdops = { .default_handler = default_connection_handler };
    75 
     73/*----------------------------------------------------------------------------*/
    7674
    7775static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK;
     
    8886static const unsigned int DEFAULT_REPEAT_DELAY = 50 * 1000;
    8987
    90 
     88/*----------------------------------------------------------------------------*/
    9189/** Keyboard polling endpoint description for boot protocol class. */
    9290const usb_endpoint_description_t usb_hid_kbd_poll_endpoint_description = {
     
    103101
    104102static void usb_kbd_set_led(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev);
    105 
     103/*----------------------------------------------------------------------------*/
    106104static const uint8_t USB_KBD_BOOT_REPORT_DESCRIPTOR[] = {
    107105        0x05, 0x01,  /* Usage Page (Generic Desktop), */
     
    138136        0xC0         /* End Collection */
    139137};
    140 
     138/*----------------------------------------------------------------------------*/
    141139typedef enum usb_kbd_flags {
    142140        USB_KBD_STATUS_UNINITIALIZED = 0,
     
    144142        USB_KBD_STATUS_TO_DESTROY = -1
    145143} usb_kbd_flags;
    146 
     144/*----------------------------------------------------------------------------*/
    147145/* IPC method handler                                                         */
    148 
     146/*----------------------------------------------------------------------------*/
    149147/**
    150148 * Default handler for IPC methods not handled by DDF.
     
    189187                        break;
    190188                }
    191                 if (kbd_dev->client_sess == NULL) {
    192                         kbd_dev->client_sess = sess;
     189                if (kbd_dev->console_sess == NULL) {
     190                        kbd_dev->console_sess = sess;
    193191                        usb_log_debug("%s: OK\n", __FUNCTION__);
    194192                        async_answer_0(icallid, EOK);
     
    208206
    209207}
    210 
     208/*----------------------------------------------------------------------------*/
    211209/* Key processing functions                                                   */
    212 
     210/*----------------------------------------------------------------------------*/
    213211/**
    214212 * Handles turning of LED lights on and off.
     
    283281        }
    284282}
    285 
     283/*----------------------------------------------------------------------------*/
    286284/** Send key event.
    287285 *
     
    294292{
    295293        usb_log_debug2("Sending kbdev event %d/%d to the console\n", type, key);
    296         if (kbd_dev->client_sess == NULL) {
     294        if (kbd_dev->console_sess == NULL) {
    297295                usb_log_warning(
    298296                    "Connection to console not ready, key discarded.\n");
     
    300298        }
    301299
    302         async_exch_t *exch = async_exchange_begin(kbd_dev->client_sess);
     300        async_exch_t *exch = async_exchange_begin(kbd_dev->console_sess);
    303301        if (exch != NULL) {
    304302                async_msg_2(exch, KBDEV_EVENT, type, key);
     
    308306        }
    309307}
    310 
     308/*----------------------------------------------------------------------------*/
    311309static inline int usb_kbd_is_lock(unsigned int key_code)
    312310{
     
    315313            || key_code == KC_CAPS_LOCK);
    316314}
    317 
     315/*----------------------------------------------------------------------------*/
    318316static size_t find_in_array_int32(int32_t val, int32_t *arr, size_t arr_size)
    319317{
     
    326324        return (size_t) -1;
    327325}
    328 
     326/*----------------------------------------------------------------------------*/
    329327/**
    330328 * Checks if some keys were pressed or released and generates key events.
     
    409407        usb_log_debug2("Stored keys %s.\n", key_buffer);
    410408}
    411 
     409/*----------------------------------------------------------------------------*/
    412410/* General kbd functions                                                      */
    413 
     411/*----------------------------------------------------------------------------*/
    414412/**
    415413 * Processes data received from the device in form of report.
     
    481479        usb_kbd_check_key_changes(hid_dev, kbd_dev);
    482480}
    483 
     481/*----------------------------------------------------------------------------*/
    484482/* HID/KBD structure manipulation                                             */
    485 
     483/*----------------------------------------------------------------------------*/
    486484static int usb_kbd_create_function(usb_kbd_t *kbd_dev)
    487485{
     
    501499        /* Store the initialized HID device and HID ops
    502500         * to the DDF function. */
    503         fun->ops = &kbdops;
     501        fun->ops = &kbd_dev->ops;
    504502        fun->driver_data = kbd_dev;
    505503
     
    537535        return EOK;
    538536}
    539 
     537/*----------------------------------------------------------------------------*/
    540538/* API functions                                                              */
    541 
     539/*----------------------------------------------------------------------------*/
    542540/**
    543541 * Initialization of the USB/HID keyboard structure.
     
    578576        fibril_mutex_initialize(&kbd_dev->repeat_mtx);
    579577        kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED;
     578        kbd_dev->ops.default_handler = default_connection_handler;
    580579
    581580        /* Store link to HID device */
     
    701700        return EOK;
    702701}
    703 
     702/*----------------------------------------------------------------------------*/
    704703bool usb_kbd_polling_callback(usb_hid_dev_t *hid_dev, void *data)
    705704{
     
    715714        return true;
    716715}
    717 
     716/*----------------------------------------------------------------------------*/
    718717int usb_kbd_is_initialized(const usb_kbd_t *kbd_dev)
    719718{
    720719        return (kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED);
    721720}
    722 
     721/*----------------------------------------------------------------------------*/
    723722int usb_kbd_is_ready_to_destroy(const usb_kbd_t *kbd_dev)
    724723{
    725724        return (kbd_dev->initialized == USB_KBD_STATUS_TO_DESTROY);
    726725}
    727 
     726/*----------------------------------------------------------------------------*/
    728727/**
    729728 * Properly destroys the USB/HID keyboard structure.
     
    738737
    739738        /* Hangup session to the console. */
    740         if (kbd_dev->client_sess)
    741                 async_hangup(kbd_dev->client_sess);
     739        if (kbd_dev->console_sess)
     740                async_hangup(kbd_dev->console_sess);
    742741
    743742        //assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));
     
    766765        free(kbd_dev);
    767766}
    768 
     767/*----------------------------------------------------------------------------*/
    769768void usb_kbd_deinit(usb_hid_dev_t *hid_dev, void *data)
    770769{
     
    779778        }
    780779}
    781 
     780/*----------------------------------------------------------------------------*/
    782781int usb_kbd_set_boot_protocol(usb_hid_dev_t *hid_dev)
    783782{
Note: See TracChangeset for help on using the changeset viewer.