Changeset 61257f4 in mainline for uspace/drv/usbhid/main.c


Ignore:
Timestamp:
2011-04-07T20:19:24Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f8e8738
Parents:
fd9ba204
Message:

Initial implementation of general HID driver.

  • Should handle:
    • keyboard (most of functions from usbkbd driver), more-or-less works
    • mouse (not implemented yet)
    • generic HID device (just dummy polling callback now)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/main.c

    rfd9ba204 r61257f4  
    7171 * @return Other error code inherited from one of functions usb_kbd_init(),
    7272 *         ddf_fun_bind() and ddf_fun_add_to_class().
    73  *
    74  * @sa usb_kbd_fibril(), usb_kbd_repeat_fibril()
    7573 */
    7674static int usb_hid_try_add_device(usb_device_t *dev)
    7775{
     76        /*
     77         * Initialize device (get and process descriptors, get address, etc.)
     78         */
     79        usb_log_debug("Initializing USB/HID device...\n");
     80       
     81        usb_hid_dev_t *hid_dev = usb_hid_new();
     82        if (hid_dev == NULL) {
     83                usb_log_error("Error while creating USB/HID device "
     84                    "structure.\n");
     85                return ENOMEM;
     86        }
     87       
     88        int rc = usb_hid_init(hid_dev, dev);
     89       
     90        if (rc != EOK) {
     91                usb_log_error("Failed to initialize USB/HID device.\n");
     92                usb_hid_free(&hid_dev);
     93                return rc;
     94        }       
     95       
     96        usb_log_debug("USB/HID device structure initialized.\n");
     97       
    7898        /* Create the function exposed under /dev/devices. */
    7999        ddf_fun_t *hid_fun = ddf_fun_create(dev->ddf_dev, fun_exposed,
    80             "hid");
     100            usb_hid_get_function_name(hid_dev->device_type));
    81101        if (hid_fun == NULL) {
    82102                usb_log_error("Could not create DDF function node.\n");
     103                usb_hid_free(&hid_dev);
    83104                return ENOMEM;
    84105        }
    85106       
    86         /*
    87          * Initialize device (get and process descriptors, get address, etc.)
    88          */
    89         usb_log_debug("Initializing USB/HID device...\n");
    90        
    91 //      usb_kbd_t *kbd_dev = usb_kbd_new();
    92 //      if (kbd_dev == NULL) {
    93 //              usb_log_error("Error while creating USB/HID KBD device "
    94 //                  "structure.\n");
    95 //              ddf_fun_destroy(hid_fun);
    96 //              return ENOMEM;  // TODO: some other code??
    97 //      }
    98        
    99 //      int rc = usb_kbd_init(kbd_dev, dev);
    100        
    101 //      if (rc != EOK) {
    102 //              usb_log_error("Failed to initialize USB/HID KBD device.\n");
    103 //              ddf_fun_destroy(hid_fun);
    104 //              usb_kbd_free(&kbd_dev);
    105 //              return rc;
    106 //      }       
    107        
    108 //      usb_log_debug("USB/HID KBD device structure initialized.\n");
    109        
    110107        /*
    111          * Store the initialized keyboard device and keyboard ops
     108         * Store the initialized HID device and HID ops
    112109         * to the DDF function.
    113110         */
    114         //kbd_fun->driver_data = kbd_dev;
    115         hid_fun->ops = &hid_ops;
    116 
    117         int rc = ddf_fun_bind(hid_fun);
     111        hid_fun->ops = &hid_dev->ops;
     112        hid_fun->driver_data = hid_dev;   // TODO: maybe change to hid_dev->data
     113
     114        rc = ddf_fun_bind(hid_fun);
    118115        if (rc != EOK) {
    119116                usb_log_error("Could not bind DDF function: %s.\n",
     
    121118                // TODO: Can / should I destroy the DDF function?
    122119                ddf_fun_destroy(hid_fun);
    123                 return rc;
    124         }
    125        
    126         rc = ddf_fun_add_to_class(hid_fun, "hid");
     120                usb_hid_free(&hid_dev);
     121                return rc;
     122        }
     123       
     124        rc = ddf_fun_add_to_class(hid_fun,
     125            usb_hid_get_class_name(hid_dev->device_type));
    127126        if (rc != EOK) {
    128127                usb_log_error(
     
    131130                // TODO: Can / should I destroy the DDF function?
    132131                ddf_fun_destroy(hid_fun);
    133                 return rc;
    134         }
    135        
    136 
     132                usb_hid_free(&hid_dev);
     133                return rc;
     134        }
     135       
    137136        /* Start automated polling function.
    138137         * This will create a separate fibril that will query the device
     
    141140       rc = usb_device_auto_poll(dev,
    142141           /* Index of the polling pipe. */
    143            USB_HID_POLL_EP_NO,
     142           hid_dev->poll_pipe_index,
    144143           /* Callback when data arrives. */
    145            usb_hid_polling_callback,
     144           hid_dev->poll_callback,
    146145           /* How much data to request. */
    147            dev->pipes[USB_HID_POLL_EP_NO].pipe->max_packet_size,
     146           dev->pipes[hid_dev->poll_pipe_index].pipe->max_packet_size,
    148147           /* Callback when the polling ends. */
    149148           usb_hid_polling_ended_callback,
    150149           /* Custom argument. */
    151            NULL);
     150           hid_dev);
    152151       
    153152       
     
    157156                return rc;
    158157        }
    159 
    160         (void)hid_ops;
    161158
    162159        /*
     
    183180        if (dev->interface_no < 0) {
    184181                usb_log_warning("Device is not a supported HID device.\n");
    185                 usb_log_error("Failed to add HID device: endpoint not found."
     182                usb_log_error("Failed to add HID device: endpoints not found."
    186183                    "\n");
    187184                return ENOTSUP;
Note: See TracChangeset for help on using the changeset viewer.