Ignore:
File:
1 edited

Legend:

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

    rce2a1c2 r5da7199  
    6464        //int32_t *keys;
    6565        /** Count of stored keys (i.e. number of keys in the report). */
    66         //size_t key_count;
     66        //size_t key_count;     
    6767        /** IPC session to the console device (for sending key events). */
    6868        async_sess_t *console_sess;
    69         /** DDF function */
    70         ddf_fun_t *fun;
    7169} usb_multimedia_t;
    7270
     
    8886{
    8987        usb_log_debug(NAME " default_connection_handler()\n");
    90 
     88       
    9189        usb_multimedia_t *multim_dev = (usb_multimedia_t *)fun->driver_data;
    92 
     90       
    9391        if (multim_dev == NULL) {
    9492                async_answer_0(icallid, EINVAL);
    9593                return;
    9694        }
    97 
     95       
    9896        async_sess_t *sess =
    9997            async_callback_receive_start(EXCHANGE_SERIALIZE, icall);
     
    139137        assert(hid_dev != NULL);
    140138        assert(multim_dev != NULL);
    141 
     139       
    142140        kbd_event_t ev;
    143 
     141       
    144142        ev.type = type;
    145143        ev.key = key;
     
    153151                return;
    154152        }
    155 
     153       
    156154        async_exch_t *exch = async_exchange_begin(multim_dev->console_sess);
    157155        async_msg_4(exch, KBDEV_EVENT, ev.type, ev.key, ev.mods, ev.c);
     
    161159/*----------------------------------------------------------------------------*/
    162160
    163 int usb_multimedia_init(struct usb_hid_dev *hid_dev, void **data)
    164 {
    165         if (hid_dev == NULL || hid_dev->usb_dev == NULL) {
    166                 return EINVAL; /*! @todo Other return code? */
    167         }
    168 
    169         usb_log_debug(NAME " Initializing HID/multimedia structure...\n");
    170 
     161static int usb_multimedia_create_function(usb_hid_dev_t *hid_dev,
     162    usb_multimedia_t *multim_dev)
     163{
    171164        /* Create the exposed function. */
    172         ddf_fun_t *fun = ddf_fun_create(
    173             hid_dev->usb_dev->ddf_dev, fun_exposed, NAME);
     165        ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     166            NAME);
    174167        if (fun == NULL) {
    175168                usb_log_error("Could not create DDF function node.\n");
    176169                return ENOMEM;
    177170        }
    178 
     171       
    179172        fun->ops = &multimedia_ops;
    180 
    181         usb_multimedia_t *multim_dev =
    182             ddf_fun_data_alloc(fun, sizeof(usb_multimedia_t));
    183         if (multim_dev == NULL) {
    184                 ddf_fun_destroy(fun);
    185                 return ENOMEM;
    186         }
    187 
    188         multim_dev->console_sess = NULL;
    189         multim_dev->fun = fun;
    190 
    191         //todo Autorepeat?
    192 
     173        fun->driver_data = multim_dev;   // TODO: maybe change to hid_dev->data
     174       
    193175        int rc = ddf_fun_bind(fun);
    194176        if (rc != EOK) {
    195177                usb_log_error("Could not bind DDF function: %s.\n",
    196178                    str_error(rc));
     179                // TODO: Can / should I destroy the DDF function?
    197180                ddf_fun_destroy(fun);
    198181                return rc;
    199182        }
    200 
     183       
    201184        usb_log_debug("%s function created (handle: %" PRIun ").\n",
    202185            NAME, fun->handle);
    203 
     186       
    204187        rc = ddf_fun_add_to_category(fun, "keyboard");
    205188        if (rc != EOK) {
     
    207190                    "Could not add DDF function to category 'keyboard': %s.\n",
    208191                    str_error(rc));
     192                // TODO: Can / should I destroy the DDF function?
    209193                ddf_fun_destroy(fun);
    210194                return rc;
    211195        }
    212 
    213         /* Save the KBD device structure into the HID device structure. */
     196       
     197        return EOK;
     198}
     199
     200/*----------------------------------------------------------------------------*/
     201
     202int usb_multimedia_init(struct usb_hid_dev *hid_dev, void **data)
     203{
     204        if (hid_dev == NULL || hid_dev->usb_dev == NULL) {
     205                return EINVAL; /*! @todo Other return code? */
     206        }
     207       
     208        usb_log_debug(NAME " Initializing HID/multimedia structure...\n");
     209       
     210        usb_multimedia_t *multim_dev = (usb_multimedia_t *)malloc(
     211            sizeof(usb_multimedia_t));
     212        if (multim_dev == NULL) {
     213                return ENOMEM;
     214        }
     215       
     216        multim_dev->console_sess = NULL;
     217       
     218        /*! @todo Autorepeat */
     219       
     220        // save the KBD device structure into the HID device structure
    214221        *data = multim_dev;
    215 
     222       
     223        usb_log_debug(NAME " HID/multimedia device structure initialized.\n");
     224       
     225        int rc = usb_multimedia_create_function(hid_dev, multim_dev);
     226        if (rc != EOK)
     227                return rc;
     228       
    216229        usb_log_debug(NAME " HID/multimedia structure initialized.\n");
     230       
    217231        return EOK;
    218232}
     
    225239                return;
    226240        }
    227 
     241       
    228242        if (data != NULL) {
    229243                usb_multimedia_t *multim_dev = (usb_multimedia_t *)data;
    230244                // hangup session to the console
    231245                async_hangup(multim_dev->console_sess);
    232                 const int ret = ddf_fun_unbind(multim_dev->fun);
    233                 if (ret != EOK) {
    234                         usb_log_error("Failed to unbind multim function.\n");
    235                 } else {
    236                         usb_log_debug2("%s unbound.\n", multim_dev->fun->name);
    237                         ddf_fun_destroy(multim_dev->fun);
    238                 }
    239246        }
    240247}
     
    250257
    251258        usb_multimedia_t *multim_dev = (usb_multimedia_t *)data;
    252 
     259       
    253260        usb_hid_report_path_t *path = usb_hid_report_path();
    254261        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0);
     
    257264
    258265        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    259             &hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
    260             | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     266            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
     267            | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
    261268            USB_HID_REPORT_TYPE_INPUT);
    262269
     
    276283                                               key);
    277284                }
    278 
     285               
    279286                field = usb_hid_report_get_sibling(
    280                     &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
     287                    hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
    281288                    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    282289                    USB_HID_REPORT_TYPE_INPUT);
    283         }
     290        }       
    284291
    285292        usb_hid_report_path_free(path);
    286 
     293       
    287294        return true;
    288295}
Note: See TracChangeset for help on using the changeset viewer.