Ignore:
File:
1 edited

Legend:

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

    r2f593872 r77ab674  
    5353/* Non-API functions                                                          */
    5454/*----------------------------------------------------------------------------*/
    55 
     55/**
     56 * Retreives HID Report descriptor from the device.
     57 *
     58 * This function first parses the HID descriptor from the Interface descriptor
     59 * to get the size of the Report descriptor and then requests the Report
     60 * descriptor from the device.
     61 *
     62 * @param hid_dev HID device structure.
     63 * @param config_desc Full configuration descriptor (including all nested
     64 *                    descriptors).
     65 * @param config_desc_size Size of the full configuration descriptor (in bytes).
     66 * @param iface_desc Pointer to the interface descriptor inside the full
     67 *                   configuration descriptor (@a config_desc) for the interface
     68 *                   assigned with this device (@a hid_dev).
     69 *
     70 * @retval EOK if successful.
     71 * @retval ENOENT if no HID descriptor could be found.
     72 * @retval EINVAL if the HID descriptor  or HID report descriptor have different
     73 *                size than expected.
     74 * @retval ENOMEM if some allocation failed.
     75 * @return Other value inherited from function usb_request_get_descriptor().
     76 *
     77 * @sa usb_request_get_descriptor()
     78 */
    5679static int usbhid_dev_get_report_descriptor(usbhid_dev_t *hid_dev,
    5780    uint8_t *config_desc, size_t config_desc_size, uint8_t *iface_desc)
     
    135158        }
    136159       
    137         hid_dev->report_desc_size = length;
    138        
    139160        usb_log_debug("Done.\n");
    140161       
     
    143164
    144165/*----------------------------------------------------------------------------*/
    145 
     166/**
     167 * Retreives descriptors from the device, initializes pipes and stores
     168 * important information from descriptors.
     169 *
     170 * Initializes the polling pipe described by the given endpoint description
     171 * (@a poll_ep_desc).
     172 *
     173 * Information retreived from descriptors and stored in the HID device structure:
     174 *    - Assigned interface number (the interface controlled by this instance of
     175 *                                 the driver)
     176 *    - Polling interval (from the interface descriptor)
     177 *    - Report descriptor
     178 *
     179 * @param hid_dev HID device structure to be initialized.
     180 * @param poll_ep_desc Description of the polling (Interrupt In) endpoint
     181 *                     that has to be present in the device in order to
     182 *                     successfuly initialize the structure.
     183 *
     184 * @sa usb_endpoint_pipe_initialize_from_configuration(),
     185 *     usbhid_dev_get_report_descriptor()
     186 */
    146187static int usbhid_dev_process_descriptors(usbhid_dev_t *hid_dev,
    147188    usb_endpoint_description_t *poll_ep_desc)
     
    221262       
    222263        if (rc != EOK) {
    223                 usb_log_warning("Problem with getting Report descriptor: %s.\n",
     264                usb_log_warning("Problem with parsing Report descriptor: %s.\n",
    224265                    str_error(rc));
    225266                return rc;
    226267        }
    227        
    228         rc = usb_hid_parse_report_descriptor(hid_dev->parser,
    229             hid_dev->report_desc, hid_dev->report_desc_size);
    230         if (rc != EOK) {
    231                 usb_log_warning("Problem parsing Report descriptor: %s.\n",
    232                     str_error(rc));
    233                 return rc;
    234         }
    235        
    236         usb_hid_descriptor_print(hid_dev->parser);
    237268       
    238269        return EOK;
     
    242273/* API functions                                                              */
    243274/*----------------------------------------------------------------------------*/
    244 
     275/**
     276 * Creates new uninitialized HID device structure.
     277 *
     278 * @return Pointer to the new HID device structure, or NULL if an error occured.
     279 */
    245280usbhid_dev_t *usbhid_dev_new(void)
    246281{
     
    255290        memset(dev, 0, sizeof(usbhid_dev_t));
    256291       
    257         dev->parser = (usb_hid_report_parser_t *)(malloc(sizeof(
    258             usb_hid_report_parser_t)));
    259         if (dev->parser == NULL) {
    260                 usb_log_fatal("No memory!\n");
    261                 free(dev);
    262                 return NULL;
    263         }
    264        
    265292        dev->initialized = 0;
    266293       
     
    269296
    270297/*----------------------------------------------------------------------------*/
    271 
     298/**
     299 * Properly destroys the HID device structure.
     300 *
     301 * @note Currently does not clean-up the used pipes, as there are no functions
     302 *       offering such functionality.
     303 *
     304 * @param hid_dev Pointer to the structure to be destroyed.
     305 */
    272306void usbhid_dev_free(usbhid_dev_t **hid_dev)
    273307{
     
    292326
    293327/*----------------------------------------------------------------------------*/
    294 
     328/**
     329 * Initializes HID device structure.
     330 *
     331 * @param hid_dev HID device structure to be initialized.
     332 * @param dev DDF device representing the HID device.
     333 * @param poll_ep_desc Description of the polling (Interrupt In) endpoint
     334 *                     that has to be present in the device in order to
     335 *                     successfuly initialize the structure.
     336 *
     337 * @retval EOK if successful.
     338 * @retval EINVAL if some argument is missing.
     339 * @return Other value inherited from one of functions
     340 *         usb_device_connection_initialize_from_device(),
     341 *         usb_endpoint_pipe_initialize_default_control(),
     342 *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
     343 *         usbhid_dev_process_descriptors().
     344 *
     345 * @sa usbhid_dev_process_descriptors()
     346 */
    295347int usbhid_dev_init(usbhid_dev_t *hid_dev, ddf_dev_t *dev,
    296348    usb_endpoint_description_t *poll_ep_desc)
     
    339391                return rc;
    340392        }
    341        
    342         /*
    343          * Initialize the report parser.
    344          */
    345         rc = usb_hid_parser_init(hid_dev->parser);
    346         if (rc != EOK) {
    347                 usb_log_error("Failed to initialize report parser.\n");
    348                 return rc;
    349         }
    350393
    351394        /*
    352395         * Get descriptors, parse descriptors and save endpoints.
    353396         */
    354         usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
     397        rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
     398        if (rc != EOK) {
     399                usb_log_error("Failed to start session on the control pipe: %s"
     400                    ".\n", str_error(rc));
     401                return rc;
     402        }
    355403       
    356404        rc = usbhid_dev_process_descriptors(hid_dev, poll_ep_desc);
    357        
    358         usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
    359         if (rc != EOK) {
     405        if (rc != EOK) {
     406                /* TODO: end session?? */
    360407                usb_log_error("Failed to process descriptors: %s.\n",
    361408                    str_error(rc));
     
    363410        }
    364411       
     412        rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
     413        if (rc != EOK) {
     414                usb_log_warning("Failed to start session on the control pipe: "
     415                    "%s.\n", str_error(rc));
     416                return rc;
     417        }
     418       
    365419        hid_dev->initialized = 1;
    366420        usb_log_info("HID device structure initialized.\n");
Note: See TracChangeset for help on using the changeset viewer.