Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/src/pipes.c

    r58563585 rbb655dab  
    3636#include <usb/dev/request.h>
    3737#include <usb/usb.h>
    38 #include <usb_iface.h>
    3938
    4039#include <assert.h>
     
    5150        assert(pipe != NULL);
    5251
    53         if (!pipe->auto_reset_halt || (pipe->endpoint_no != 0)) {
     52        if (!pipe->auto_reset_halt || (pipe->desc.endpoint_no != 0)) {
    5453                return;
    5554        }
     
    5756        /* Prevent infinite recursion. */
    5857        pipe->auto_reset_halt = false;
    59         usb_request_clear_endpoint_halt(pipe, 0);
     58        usb_pipe_clear_halt(pipe, pipe);
    6059        pipe->auto_reset_halt = true;
    6160}
     
    7069 * @param[out] data_buffer Buffer for incoming data.
    7170 * @param[in] data_buffer_size Size of the buffer for incoming data (in bytes).
    72  * @param[out] data_transfered_size Number of bytes that were actually
    73  *                                  transfered during the DATA stage.
     71 * @param[out] data_transferred_size Number of bytes that were actually
     72 *                                  transferred during the DATA stage.
    7473 * @return Error code.
    7574 */
    7675int usb_pipe_control_read(usb_pipe_t *pipe,
    7776    const void *setup_buffer, size_t setup_buffer_size,
    78     void *buffer, size_t buffer_size, size_t *transfered_size)
     77    void *buffer, size_t buffer_size, size_t *transferred_size)
    7978{
    8079        assert(pipe);
     
    8887        }
    8988
    90         if ((pipe->direction != USB_DIRECTION_BOTH)
    91             || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {
     89        if ((pipe->desc.direction != USB_DIRECTION_BOTH)
     90            || (pipe->desc.transfer_type != USB_TRANSFER_CONTROL)) {
    9291                return EBADF;
    9392        }
     
    9897        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    9998        size_t act_size = 0;
    100         const int rc = usb_read(exch, pipe->endpoint_no, setup_packet, buffer,
     99        const int rc = usbhc_read(exch, pipe->desc.endpoint_no, setup_packet, buffer,
    101100            buffer_size, &act_size);
    102101        async_exchange_end(exch);
     
    106105        }
    107106
    108         if (rc == EOK && transfered_size != NULL) {
    109                 *transfered_size = act_size;
     107        if (rc == EOK && transferred_size != NULL) {
     108                *transferred_size = act_size;
    110109        }
    111110
     
    142141        }
    143142
    144         if ((pipe->direction != USB_DIRECTION_BOTH)
    145             || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {
     143        if ((pipe->desc.direction != USB_DIRECTION_BOTH)
     144            || (pipe->desc.transfer_type != USB_TRANSFER_CONTROL)) {
    146145                return EBADF;
    147146        }
     
    151150
    152151        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    153         const int rc = usb_write(exch,
    154             pipe->endpoint_no, setup_packet, buffer, buffer_size);
     152        const int rc = usbhc_write(exch,
     153            pipe->desc.endpoint_no, setup_packet, buffer, buffer_size);
    155154        async_exchange_end(exch);
    156155
     
    167166 * @param[out] buffer Buffer where to store the data.
    168167 * @param[in] size Size of the buffer (in bytes).
    169  * @param[out] size_transfered Number of bytes that were actually transfered.
     168 * @param[out] size_transferred Number of bytes that were actually transferred.
    170169 * @return Error code.
    171170 */
    172171int usb_pipe_read(usb_pipe_t *pipe,
    173     void *buffer, size_t size, size_t *size_transfered)
     172    void *buffer, size_t size, size_t *size_transferred)
    174173{
    175174        assert(pipe);
     
    183182        }
    184183
    185         if (pipe->direction != USB_DIRECTION_IN) {
    186                 return EBADF;
    187         }
    188 
    189         if (pipe->transfer_type == USB_TRANSFER_CONTROL) {
    190                 return EBADF;
    191         }
    192 
    193         /* Isochronous transfer are not supported (yet) */
    194         if (pipe->transfer_type != USB_TRANSFER_INTERRUPT &&
    195             pipe->transfer_type != USB_TRANSFER_BULK)
    196             return ENOTSUP;
     184        if (pipe->desc.direction != USB_DIRECTION_IN) {
     185                return EBADF;
     186        }
     187
     188        if (pipe->desc.transfer_type == USB_TRANSFER_CONTROL) {
     189                return EBADF;
     190        }
    197191
    198192        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    199193        size_t act_size = 0;
    200194        const int rc =
    201             usb_read(exch, pipe->endpoint_no, 0, buffer, size, &act_size);
    202         async_exchange_end(exch);
    203 
    204         if (rc == EOK && size_transfered != NULL) {
    205                 *size_transfered = act_size;
     195            usbhc_read(exch, pipe->desc.endpoint_no, 0, buffer, size, &act_size);
     196        async_exchange_end(exch);
     197
     198        if (rc == EOK && size_transferred != NULL) {
     199                *size_transferred = act_size;
    206200        }
    207201
     
    224218        }
    225219
    226         if (pipe->direction != USB_DIRECTION_OUT) {
    227                 return EBADF;
    228         }
    229 
    230         if (pipe->transfer_type == USB_TRANSFER_CONTROL) {
    231                 return EBADF;
    232         }
    233 
    234         /* Isochronous transfer are not supported (yet) */
    235         if (pipe->transfer_type != USB_TRANSFER_INTERRUPT &&
    236             pipe->transfer_type != USB_TRANSFER_BULK)
    237             return ENOTSUP;
    238 
    239         async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    240         const int rc = usb_write(exch, pipe->endpoint_no, 0, buffer, size);
     220        if (pipe->desc.direction != USB_DIRECTION_OUT) {
     221                return EBADF;
     222        }
     223
     224        if (pipe->desc.transfer_type == USB_TRANSFER_CONTROL) {
     225                return EBADF;
     226        }
     227
     228        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
     229        const int rc = usbhc_write(exch, pipe->desc.endpoint_no, 0, buffer, size);
    241230        async_exchange_end(exch);
    242231        return rc;
     
    246235 *
    247236 * @param pipe Endpoint pipe to be initialized.
    248  * @param endpoint_no Endpoint number (in USB 1.1 in range 0 to 15).
    249  * @param transfer_type Transfer type (e.g. interrupt or bulk).
    250  * @param max_packet_size Maximum packet size in bytes.
    251  * @param direction Endpoint direction (in/out).
    252  * @return Error code.
    253  */
    254 int usb_pipe_initialize(usb_pipe_t *pipe, usb_endpoint_t endpoint_no,
    255     usb_transfer_type_t transfer_type, size_t max_packet_size,
    256     usb_direction_t direction, unsigned packets, usb_dev_session_t *bus_session)
    257 {
    258         assert(pipe);
    259 
    260         pipe->endpoint_no = endpoint_no;
    261         pipe->transfer_type = transfer_type;
    262         pipe->packets = packets;
    263         pipe->max_packet_size = max_packet_size;
    264         pipe->direction = direction;
     237 * @param bus_session Endpoint pipe to be initialized.
     238 * @return Error code.
     239 */
     240int usb_pipe_initialize(usb_pipe_t *pipe, usb_dev_session_t *bus_session)
     241{
     242        assert(pipe);
     243
    265244        pipe->auto_reset_halt = false;
    266245        pipe->bus_session = bus_session;
     
    269248}
    270249
    271 /** Initialize USB endpoint pipe as the default zero control pipe.
     250static const usb_pipe_desc_t default_control_pipe = {
     251        .endpoint_no = 0,
     252        .transfer_type = USB_TRANSFER_CONTROL,
     253        .direction = USB_DIRECTION_BOTH,
     254        .max_transfer_size = CTRL_PIPE_MIN_PACKET_SIZE,
     255};
     256
     257/** Initialize USB default control pipe.
     258 *
     259 * This one is special because it must not be registered, it is registered automatically.
    272260 *
    273261 * @param pipe Endpoint pipe to be initialized.
    274  * @return Error code.
    275  */
    276 int usb_pipe_initialize_default_control(usb_pipe_t *pipe,
    277     usb_dev_session_t *bus_session)
    278 {
    279         assert(pipe);
    280 
    281         const int rc = usb_pipe_initialize(pipe, 0, USB_TRANSFER_CONTROL,
    282             CTRL_PIPE_MIN_PACKET_SIZE, USB_DIRECTION_BOTH, 1, bus_session);
    283 
     262 * @param bus_session Endpoint pipe to be initialized.
     263 * @return Error code.
     264 */
     265int usb_pipe_initialize_default_control(usb_pipe_t *pipe, usb_dev_session_t *bus_session)
     266{
     267        const int ret = usb_pipe_initialize(pipe, bus_session);
     268        if (ret)
     269                return ret;
     270
     271        pipe->desc = default_control_pipe;
    284272        pipe->auto_reset_halt = true;
    285273
    286         return rc;
     274        return EOK;
    287275}
    288276
     
    290278 *
    291279 * @param pipe Pipe to be registered.
    292  * @param interval Polling interval.
    293  * @return Error code.
    294  */
    295 int usb_pipe_register(usb_pipe_t *pipe, unsigned interval)
     280 * @param ep_desc Matched endpoint descriptor
     281 * @param comp_desc Matched superspeed companion descriptro, if any
     282 * @return Error code.
     283 */
     284int usb_pipe_register(usb_pipe_t *pipe, const usb_standard_endpoint_descriptor_t *ep_desc, const usb_superspeed_endpoint_companion_descriptor_t *comp_desc)
    296285{
    297286        assert(pipe);
    298287        assert(pipe->bus_session);
     288        assert(ep_desc);
     289
    299290        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    300291        if (!exch)
    301292                return ENOMEM;
    302         const int ret = usb_register_endpoint(exch, pipe->endpoint_no,
    303             pipe->transfer_type, pipe->direction, pipe->max_packet_size,
    304             pipe->packets, interval);
     293
     294        usb_endpoint_descriptors_t descriptors;
     295
     296#define COPY(field) descriptors.endpoint.field = ep_desc->field
     297        COPY(endpoint_address);
     298        COPY(attributes);
     299        COPY(max_packet_size);
     300        COPY(poll_interval);
     301#undef COPY
     302
     303#define COPY(field) descriptors.companion.field = comp_desc->field
     304        if (comp_desc) {
     305                COPY(max_burst);
     306                COPY(attributes);
     307                COPY(bytes_per_interval);
     308        }
     309#undef COPY
     310
     311        const int ret = usbhc_register_endpoint(exch, &pipe->desc, &descriptors);
    305312        async_exchange_end(exch);
    306313        return ret;
     
    319326        if (!exch)
    320327                return ENOMEM;
    321         const int ret = usb_unregister_endpoint(exch, pipe->endpoint_no,
    322             pipe->direction);
     328
     329        const int ret = usbhc_unregister_endpoint(exch, &pipe->desc);
     330
    323331        async_exchange_end(exch);
    324332        return ret;
Note: See TracChangeset for help on using the changeset viewer.