Ignore:
File:
1 edited

Legend:

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

    r065064e6 r15f3c3f  
    5252        .direction = USB_DIRECTION_IN,
    5353        .interface_class = USB_CLASS_HID,
    54         .interface_subclass = -1,
    55         .interface_protocol = -1,
    5654        .flags = 0
    5755};
     
    9492        usb_log_debug2("Generic HID: Get event length (fun: %p, "
    9593            "fun->driver_data: %p.\n", fun, fun->driver_data);
    96 
     94       
    9795        if (fun == NULL || fun->driver_data == NULL) {
    9896                return 0;
     
    10098
    10199        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    102 
     100       
    103101        usb_log_debug2("hid_dev: %p, Max input report size (%zu).\n",
    104102            hid_dev, hid_dev->max_input_report_size);
    105 
     103       
    106104        return hid_dev->max_input_report_size;
    107105}
     
    113111{
    114112        usb_log_debug2("Generic HID: Get event.\n");
    115 
     113       
    116114        if (fun == NULL || fun->driver_data == NULL || buffer == NULL
    117115            || act_size == NULL || event_nr == NULL) {
     
    121119
    122120        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    123 
     121       
    124122        if (hid_dev->input_report_size > size) {
    125123                usb_log_debug("input_report_size > size (%zu, %zu)\n",
     
    127125                return EINVAL;  // TODO: other error code
    128126        }
    129 
     127       
    130128        /*! @todo This should probably be somehow atomic. */
    131129        memcpy(buffer, hid_dev->input_report,
     
    133131        *act_size = hid_dev->input_report_size;
    134132        *event_nr = usb_hid_report_number(hid_dev);
    135 
     133       
    136134        usb_log_debug2("OK\n");
    137 
     135       
    138136        return EOK;
    139137}
     
    144142{
    145143        usb_log_debug("Generic HID: Get report descriptor length.\n");
    146 
     144       
    147145        if (fun == NULL || fun->driver_data == NULL) {
    148146                usb_log_debug("No function");
    149147                return EINVAL;
    150148        }
    151 
    152         usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    153 
     149       
     150        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     151       
    154152        usb_log_debug2("hid_dev->report_desc_size = %zu\n",
    155153            hid_dev->report_desc_size);
    156 
     154       
    157155        return hid_dev->report_desc_size;
    158156}
     
    164162{
    165163        usb_log_debug2("Generic HID: Get report descriptor.\n");
    166 
     164       
    167165        if (fun == NULL || fun->driver_data == NULL) {
    168166                usb_log_debug("No function");
    169167                return EINVAL;
    170168        }
    171 
    172         usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    173 
     169       
     170        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     171       
    174172        if (hid_dev->report_desc_size > size) {
    175173                return EINVAL;
    176174        }
    177 
     175       
    178176        memcpy(desc, hid_dev->report_desc, hid_dev->report_desc_size);
    179177        *actual_size = hid_dev->report_desc_size;
    180 
     178       
    181179        return EOK;
    182180}
     
    192190/*----------------------------------------------------------------------------*/
    193191
    194 void usb_generic_hid_deinit(usb_hid_dev_t *hid_dev, void *data)
    195 {
    196         ddf_fun_t *fun = data;
    197         const int ret = ddf_fun_unbind(fun);
    198         if (ret != EOK) {
    199                 usb_log_error("Failed to unbind generic hid fun.\n");
    200                 return;
    201         }
    202         usb_log_debug2("%s unbound.\n", fun->name);
    203         /* We did not allocate this, so leave this alone
    204          * the device would take care of it */
    205         fun->driver_data = NULL;
    206         ddf_fun_destroy(fun);
    207 }
    208 
    209 /*----------------------------------------------------------------------------*/
    210 
    211 int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data)
    212 {
    213         if (hid_dev == NULL) {
    214                 return EINVAL;
    215         }
    216 
     192static int usb_generic_hid_create_function(usb_hid_dev_t *hid_dev)
     193{       
    217194        /* Create the exposed function. */
    218195        /** @todo Generate numbers for the devices? */
     
    224201                return ENOMEM;
    225202        }
    226 
     203       
    227204        fun->ops = &usb_generic_hid_ops;
     205        fun->driver_data = hid_dev;
    228206
    229207        int rc = ddf_fun_bind(fun);
     
    234212                return rc;
    235213        }
    236         /* This is nasty both device and this function have the same
    237          * driver data, thus destruction would lead to double free */
    238         fun->driver_data = hid_dev;
    239 
     214       
    240215        usb_log_debug("HID function created. Handle: %" PRIun "\n", fun->handle);
    241         *data = fun;
    242 
    243         return EOK;
     216       
     217        return EOK;
     218}
     219
     220/*----------------------------------------------------------------------------*/
     221
     222int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data)
     223{
     224        if (hid_dev == NULL) {
     225                return EINVAL;
     226        }
     227       
     228        return usb_generic_hid_create_function(hid_dev);
    244229}
    245230
Note: See TracChangeset for help on using the changeset viewer.