Changeset d2cfe72 in mainline


Ignore:
Timestamp:
2013-01-27T19:13:53Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d3a1ad58
Parents:
70a422b
Message:

libusbhost: Implement endpoint management for usb iface.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/ddf_helpers.c

    r70a422b rd2cfe72  
    11/*
    2  * Copyright (c) 2012 Jan Vesely
     2 * Copyright (c) 2013 Jan Vesely
    33 * All rights reserved.
    44 *
     
    7777} usb_dev_t;
    7878
     79/** Register endpoint interface function.
     80 * @param fun DDF function.
     81 * @param address USB address of the device.
     82 * @param endpoint USB endpoint number to be registered.
     83 * @param transfer_type Endpoint's transfer type.
     84 * @param direction USB communication direction the endpoint is capable of.
     85 * @param max_packet_size Maximu size of packets the endpoint accepts.
     86 * @param interval Preferred timeout between communication.
     87 * @return Error code.
     88 */
     89static int register_endpoint(
     90    ddf_fun_t *fun, usb_endpoint_t endpoint,
     91    usb_transfer_type_t transfer_type, usb_direction_t direction,
     92    size_t max_packet_size, unsigned interval)
     93{
     94        assert(fun);
     95        hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
     96        usb_dev_t *dev = ddf_fun_data_get(fun);
     97        assert(hcd);
     98        assert(dev);
     99        const size_t size = max_packet_size;
     100        const usb_target_t target =
     101            {{.address = dev->address, .endpoint = endpoint}};
     102
     103        usb_log_debug("Register endpoint %d:%d %s-%s %zuB %ums.\n",
     104            dev->address, endpoint, usb_str_transfer_type(transfer_type),
     105            usb_str_direction(direction), max_packet_size, interval);
     106
     107        return hcd_add_ep(hcd, target, direction, transfer_type,
     108            max_packet_size, size);
     109}
     110
     111/** Unregister endpoint interface function.
     112 * @param fun DDF function.
     113 * @param address USB address of the endpoint.
     114 * @param endpoint USB endpoint number.
     115 * @param direction Communication direction of the enpdoint to unregister.
     116 * @return Error code.
     117 */
     118static int unregister_endpoint(
     119    ddf_fun_t *fun, usb_endpoint_t endpoint, usb_direction_t direction)
     120{
     121        assert(fun);
     122        hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
     123        usb_dev_t *dev = ddf_fun_data_get(fun);
     124        assert(hcd);
     125        assert(dev);
     126        const usb_target_t target =
     127            {{.address = dev->address, .endpoint = endpoint}};
     128        usb_log_debug("Unregister endpoint %d:%d %s.\n",
     129            dev->address, endpoint, usb_str_direction(direction));
     130        return hcd_remove_ep(hcd, target, direction);
     131}
     132
    79133static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
    80134{
     
    171225        .device_enumerate = device_enumerate,
    172226        .device_remove = device_remove,
     227        .register_endpoint = register_endpoint,
     228        .unregister_endpoint = unregister_endpoint,
    173229};
    174230/** Standard USB RH options (RH interface) */
Note: See TracChangeset for help on using the changeset viewer.