Changeset cd83f25 in mainline for uspace/drv/usbhid/generic/hiddev.c


Ignore:
Timestamp:
2011-05-27T09:58:08Z (14 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e89bb50
Parents:
63d4d4fd (diff), 848dafc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge from usb/development

File:
1 edited

Legend:

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

    r63d4d4fd rcd83f25  
    6262static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun);
    6363
    64 static int usb_generic_hid_get_event(ddf_fun_t *fun, int32_t *buffer,
    65     size_t size, size_t *act_size, unsigned int flags);
     64static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer,
     65    size_t size, size_t *act_size, int *event_nr, unsigned int flags);
    6666
    6767static int usb_generic_hid_client_connected(ddf_fun_t *fun);
     68
     69static size_t usb_generic_get_report_descriptor_length(ddf_fun_t *fun);
     70
     71static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc,
     72    size_t size, size_t *actual_size);
    6873
    6974/*----------------------------------------------------------------------------*/
     
    7176static usbhid_iface_t usb_generic_iface = {
    7277        .get_event = usb_generic_hid_get_event,
    73         .get_event_length = usb_generic_hid_get_event_length
     78        .get_event_length = usb_generic_hid_get_event_length,
     79        .get_report_descriptor_length = usb_generic_get_report_descriptor_length,
     80        .get_report_descriptor = usb_generic_get_report_descriptor
    7481};
    7582
     
    8390static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun)
    8491{
    85         if (fun == NULL || fun->driver_data) {
     92        usb_log_debug2("Generic HID: Get event length (fun: %p, "
     93            "fun->driver_data: %p.\n", fun, fun->driver_data);
     94       
     95        if (fun == NULL || fun->driver_data == NULL) {
    8696                return 0;
    8797        }
     
    8999        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    90100       
    91         return hid_dev->input_report_size;
    92 }
    93 
    94 /*----------------------------------------------------------------------------*/
    95 
    96 static int usb_generic_hid_get_event(ddf_fun_t *fun, int32_t *buffer,
    97     size_t size, size_t *act_size, unsigned int flags)
    98 {
    99         if (fun == NULL || fun->driver_data) {
     101        usb_log_debug2("hid_dev: %p, Max input report size (%d).\n",
     102            hid_dev, hid_dev->max_input_report_size);
     103       
     104        return hid_dev->max_input_report_size;
     105}
     106
     107/*----------------------------------------------------------------------------*/
     108
     109static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer,
     110    size_t size, size_t *act_size, int *event_nr, unsigned int flags)
     111{
     112        usb_log_debug2("Generic HID: Get event.\n");
     113       
     114        if (fun == NULL || fun->driver_data == NULL || buffer == NULL
     115            || act_size == NULL || event_nr == NULL) {
     116                usb_log_debug("No function");
    100117                return EINVAL;
    101118        }
     
    104121       
    105122        if (hid_dev->input_report_size > size) {
     123                usb_log_debug("input_report_size > size (%zu, %zu)\n",
     124                    hid_dev->input_report_size, size);
    106125                return EINVAL;  // TODO: other error code
    107126        }
    108127       
    109128        /*! @todo This should probably be atomic. */
    110         if (usb_hid_report_ready()) {
    111                 memcpy(buffer, hid_dev->input_report,
    112                     hid_dev->input_report_size);
    113                 *act_size = hid_dev->input_report_size;
    114                 usb_hid_report_received();
    115         }
     129//      if (usb_hid_report_ready()) {
     130//              usb_log_debug2("Report ready, size: %zu\n",
     131//                  hid_dev->input_report_size);
     132               
     133//              usb_hid_report_received();
     134//      } else {
     135//              memset(buffer, 0, hid_dev->input_report_size);
     136//      }
     137        memcpy(buffer, hid_dev->input_report,
     138            hid_dev->input_report_size);
     139        *act_size = hid_dev->input_report_size;
     140        *event_nr = usb_hid_report_number(hid_dev);
    116141       
    117142        // clear the buffer so that it will not be received twice
     
    120145        // note that we already received this report
    121146//      report_received = true;
     147        usb_log_debug2("OK\n");
     148       
     149        return EOK;
     150}
     151
     152/*----------------------------------------------------------------------------*/
     153
     154static size_t usb_generic_get_report_descriptor_length(ddf_fun_t *fun)
     155{
     156        usb_log_debug("Generic HID: Get report descriptor length.\n");
     157       
     158        if (fun == NULL || fun->driver_data == NULL) {
     159                usb_log_debug("No function");
     160                return EINVAL;
     161        }
     162       
     163        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     164       
     165        usb_log_debug2("hid_dev->report_desc_size = %zu\n",
     166            hid_dev->report_desc_size);
     167       
     168        return hid_dev->report_desc_size;
     169}
     170
     171/*----------------------------------------------------------------------------*/
     172
     173static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc,
     174    size_t size, size_t *actual_size)
     175{
     176        usb_log_debug2("Generic HID: Get report descriptor.\n");
     177       
     178        if (fun == NULL || fun->driver_data == NULL) {
     179                usb_log_debug("No function");
     180                return EINVAL;
     181        }
     182       
     183        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     184       
     185        if (hid_dev->report_desc_size > size) {
     186                return EINVAL;  // TODO: other error code
     187        }
     188       
     189        memcpy(desc, hid_dev->report_desc, hid_dev->report_desc_size);
     190        *actual_size = hid_dev->report_desc_size;
    122191       
    123192        return EOK;
     
    128197static int usb_generic_hid_client_connected(ddf_fun_t *fun)
    129198{
    130         usb_hid_report_received();
     199        usb_log_debug("Generic HID: Client connected.\n");
    131200        return EOK;
    132201}
     
    145214                return ENOMEM;
    146215        }
     216       
     217        fun->ops = &usb_generic_hid_ops;
     218        fun->driver_data = hid_dev;
    147219
    148220        int rc = ddf_fun_bind(fun);
     
    154226        }
    155227       
    156         fun->ops = &usb_generic_hid_ops;
    157         fun->driver_data = hid_dev;
     228        usb_log_debug("HID function created. Handle: %d\n", fun->handle);
    158229       
    159230        return EOK;
     
    176247    uint8_t *buffer, size_t buffer_size)
    177248{
    178         usb_log_debug("usb_hid_polling_callback(%p, %p, %zu)\n",
     249        usb_log_debug2("usb_hid_polling_callback(%p, %p, %zu)\n",
    179250            hid_dev, buffer, buffer_size);
    180251        usb_debug_str_buffer(buffer, buffer_size, 0);
Note: See TracChangeset for help on using the changeset viewer.