Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/mouse/mousedev.c

    r61f49a0 rfaa44e58  
    122122        sysarg_t method = IPC_GET_IMETHOD(*icall);
    123123       
    124         usb_mouse_t *mouse_dev = (usb_mouse_t *)fun->driver_data;
    125        
    126         if (mouse_dev == NULL) {
     124        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     125       
     126        if (hid_dev == NULL || hid_dev->data == NULL) {
    127127                usb_log_debug("default_connection_handler: Missing "
    128128                    "parameters.\n");
     
    131131        }
    132132       
    133         usb_log_debug("default_connection_handler: fun->name: %s\n",
    134                       fun->name);
    135         usb_log_debug("default_connection_handler: mouse_phone: %d, wheel "
    136             "phone: %d\n", mouse_dev->mouse_phone, mouse_dev->wheel_phone);
     133        assert(hid_dev != NULL);
     134        assert(hid_dev->data != NULL);
     135        usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data;
    137136       
    138137        int *phone = (str_cmp(fun->name, HID_MOUSE_FUN_NAME) == 0)
     
    146145                            "phone to mouse already set.\n");
    147146                        async_answer_0(icallid, ELIMIT);
     147                        //async_answer_0(icallid, EOK);
    148148                        return;
    149149                }
    150150
    151151                *phone = callback;
    152                 usb_log_debug("Console phone to mouse set ok (%d).\n", *phone);
     152                usb_log_debug("Console phone to mouse set ok (%d).\n", callback);
    153153                async_answer_0(icallid, EOK);
    154154                return;
     
    224224/*----------------------------------------------------------------------------*/
    225225
    226 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev,
    227                                      usb_mouse_t *mouse_dev, uint8_t *buffer,
    228                                      size_t buffer_size)
    229 {
    230         assert(mouse_dev != NULL);
     226static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, uint8_t *buffer,
     227    size_t buffer_size)
     228{
     229        usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data;
    231230       
    232231        usb_log_debug2("got buffer: %s.\n",
     
    234233       
    235234        if (mouse_dev->mouse_phone < 0) {
    236                 usb_log_warning(NAME " No console phone.\n");
    237                 return true;
     235                usb_log_error(NAME " No console phone.\n");
     236                return false;   // ??
    238237        }
    239238
     
    379378/*----------------------------------------------------------------------------*/
    380379
    381 static int usb_mouse_create_function(usb_hid_dev_t *hid_dev, usb_mouse_t *mouse)
    382 {
    383         assert(hid_dev != NULL);
    384         assert(mouse != NULL);
    385        
     380static int usb_mouse_create_function(usb_hid_dev_t *hid_dev)
     381{
    386382        /* Create the function exposed under /dev/devices. */
    387383        usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
     
    393389        }
    394390       
    395         fun->ops = &mouse->ops;
    396         fun->driver_data = mouse;   // TODO: maybe change to hid_dev->data
     391        /*
     392         * Store the initialized HID device and HID ops
     393         * to the DDF function.
     394         */
     395        fun->ops = &hid_dev->ops;
     396        fun->driver_data = hid_dev;   // TODO: maybe change to hid_dev->data
    397397
    398398        int rc = ddf_fun_bind(fun);
     
    431431         * to the DDF function.
    432432         */
    433         fun->ops = &mouse->ops;
    434         fun->driver_data = mouse;   // TODO: maybe change to hid_dev->data
     433        fun->ops = &hid_dev->ops;
     434        fun->driver_data = hid_dev;   // TODO: maybe change to hid_dev->data
    435435
    436436        rc = ddf_fun_bind(fun);
     
    458458/*----------------------------------------------------------------------------*/
    459459
    460 int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data)
     460int usb_mouse_init(usb_hid_dev_t *hid_dev)
    461461{
    462462        usb_log_debug("Initializing HID/Mouse structure...\n");
     
    485485       
    486486        // save the Mouse device structure into the HID device structure
    487         *data = mouse_dev;
     487        hid_dev->data = mouse_dev;
    488488       
    489489        // set handler for incoming calls
    490         // TODO: must be one for each subdriver!!
    491         mouse_dev->ops.default_handler = default_connection_handler;
     490        hid_dev->ops.default_handler = default_connection_handler;
    492491       
    493492        // TODO: how to know if the device supports the request???
     
    495494//          hid_dev->usb_dev->interface_no, IDLE_RATE);
    496495       
    497         int rc = usb_mouse_create_function(hid_dev, mouse_dev);
     496        int rc = usb_mouse_create_function(hid_dev);
    498497        if (rc != EOK) {
    499498                usb_mouse_free(&mouse_dev);
     
    506505/*----------------------------------------------------------------------------*/
    507506
    508 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data,
    509      uint8_t *buffer, size_t buffer_size)
     507bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, uint8_t *buffer,
     508     size_t buffer_size)
    510509{
    511510        usb_log_debug("usb_mouse_polling_callback()\n");
    512511        usb_debug_str_buffer(buffer, buffer_size, 0);
    513512       
    514         if (hid_dev == NULL || data == NULL) {
     513        if (hid_dev == NULL) {
    515514                usb_log_error("Missing argument to the mouse polling callback."
    516515                    "\n");
     
    518517        }
    519518       
    520         usb_mouse_t *mouse_dev = (usb_mouse_t *)data;
    521                
    522         return usb_mouse_process_report(hid_dev, mouse_dev, buffer,
    523                                         buffer_size);
    524 }
    525 
    526 /*----------------------------------------------------------------------------*/
    527 
    528 void usb_mouse_deinit(usb_hid_dev_t *hid_dev, void *data)
    529 {
    530         if (data != NULL) {
    531                 usb_mouse_free((usb_mouse_t **)&data);
    532         }
     519        if (hid_dev->data == NULL) {
     520                usb_log_error("Wrong argument to the mouse polling callback."
     521                    "\n");
     522                return false;
     523        }
     524       
     525        return usb_mouse_process_report(hid_dev, buffer, buffer_size);
     526}
     527
     528/*----------------------------------------------------------------------------*/
     529
     530void usb_mouse_deinit(usb_hid_dev_t *hid_dev)
     531{
     532        usb_mouse_free((usb_mouse_t **)&hid_dev->data);
    533533}
    534534
Note: See TracChangeset for help on using the changeset viewer.