Ignore:
File:
1 edited

Legend:

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

    rbb655dab r58563585  
    3636#include <usb/dev/request.h>
    3737#include <usb/usb.h>
     38#include <usb_iface.h>
    3839
    3940#include <assert.h>
     
    5051        assert(pipe != NULL);
    5152
    52         if (!pipe->auto_reset_halt || (pipe->desc.endpoint_no != 0)) {
     53        if (!pipe->auto_reset_halt || (pipe->endpoint_no != 0)) {
    5354                return;
    5455        }
     
    5657        /* Prevent infinite recursion. */
    5758        pipe->auto_reset_halt = false;
    58         usb_pipe_clear_halt(pipe, pipe);
     59        usb_request_clear_endpoint_halt(pipe, 0);
    5960        pipe->auto_reset_halt = true;
    6061}
     
    6970 * @param[out] data_buffer Buffer for incoming data.
    7071 * @param[in] data_buffer_size Size of the buffer for incoming data (in bytes).
    71  * @param[out] data_transferred_size Number of bytes that were actually
    72  *                                  transferred during the DATA stage.
     72 * @param[out] data_transfered_size Number of bytes that were actually
     73 *                                  transfered during the DATA stage.
    7374 * @return Error code.
    7475 */
    7576int usb_pipe_control_read(usb_pipe_t *pipe,
    7677    const void *setup_buffer, size_t setup_buffer_size,
    77     void *buffer, size_t buffer_size, size_t *transferred_size)
     78    void *buffer, size_t buffer_size, size_t *transfered_size)
    7879{
    7980        assert(pipe);
     
    8788        }
    8889
    89         if ((pipe->desc.direction != USB_DIRECTION_BOTH)
    90             || (pipe->desc.transfer_type != USB_TRANSFER_CONTROL)) {
     90        if ((pipe->direction != USB_DIRECTION_BOTH)
     91            || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {
    9192                return EBADF;
    9293        }
     
    9798        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    9899        size_t act_size = 0;
    99         const int rc = usbhc_read(exch, pipe->desc.endpoint_no, setup_packet, buffer,
     100        const int rc = usb_read(exch, pipe->endpoint_no, setup_packet, buffer,
    100101            buffer_size, &act_size);
    101102        async_exchange_end(exch);
     
    105106        }
    106107
    107         if (rc == EOK && transferred_size != NULL) {
    108                 *transferred_size = act_size;
     108        if (rc == EOK && transfered_size != NULL) {
     109                *transfered_size = act_size;
    109110        }
    110111
     
    141142        }
    142143
    143         if ((pipe->desc.direction != USB_DIRECTION_BOTH)
    144             || (pipe->desc.transfer_type != USB_TRANSFER_CONTROL)) {
     144        if ((pipe->direction != USB_DIRECTION_BOTH)
     145            || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {
    145146                return EBADF;
    146147        }
     
    150151
    151152        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    152         const int rc = usbhc_write(exch,
    153             pipe->desc.endpoint_no, setup_packet, buffer, buffer_size);
     153        const int rc = usb_write(exch,
     154            pipe->endpoint_no, setup_packet, buffer, buffer_size);
    154155        async_exchange_end(exch);
    155156
     
    166167 * @param[out] buffer Buffer where to store the data.
    167168 * @param[in] size Size of the buffer (in bytes).
    168  * @param[out] size_transferred Number of bytes that were actually transferred.
     169 * @param[out] size_transfered Number of bytes that were actually transfered.
    169170 * @return Error code.
    170171 */
    171172int usb_pipe_read(usb_pipe_t *pipe,
    172     void *buffer, size_t size, size_t *size_transferred)
     173    void *buffer, size_t size, size_t *size_transfered)
    173174{
    174175        assert(pipe);
     
    182183        }
    183184
    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         }
     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;
    191197
    192198        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    193199        size_t act_size = 0;
    194200        const int rc =
    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;
     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;
    200206        }
    201207
     
    218224        }
    219225
    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);
     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);
    230241        async_exchange_end(exch);
    231242        return rc;
     
    235246 *
    236247 * @param pipe Endpoint pipe to be initialized.
    237  * @param bus_session Endpoint pipe to be initialized.
    238  * @return Error code.
    239  */
    240 int usb_pipe_initialize(usb_pipe_t *pipe, usb_dev_session_t *bus_session)
    241 {
    242         assert(pipe);
    243 
     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 */
     254int 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;
    244265        pipe->auto_reset_halt = false;
    245266        pipe->bus_session = bus_session;
     
    248269}
    249270
    250 static 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.
     271/** Initialize USB endpoint pipe as the default zero control pipe.
    260272 *
    261273 * @param pipe Endpoint pipe to be initialized.
    262  * @param bus_session Endpoint pipe to be initialized.
    263  * @return Error code.
    264  */
    265 int 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;
     274 * @return Error code.
     275 */
     276int 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
    272284        pipe->auto_reset_halt = true;
    273285
    274         return EOK;
     286        return rc;
    275287}
    276288
     
    278290 *
    279291 * @param pipe Pipe to be registered.
    280  * @param ep_desc Matched endpoint descriptor
    281  * @param comp_desc Matched superspeed companion descriptro, if any
    282  * @return Error code.
    283  */
    284 int usb_pipe_register(usb_pipe_t *pipe, const usb_standard_endpoint_descriptor_t *ep_desc, const usb_superspeed_endpoint_companion_descriptor_t *comp_desc)
     292 * @param interval Polling interval.
     293 * @return Error code.
     294 */
     295int usb_pipe_register(usb_pipe_t *pipe, unsigned interval)
    285296{
    286297        assert(pipe);
    287298        assert(pipe->bus_session);
    288         assert(ep_desc);
    289 
    290299        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    291300        if (!exch)
    292301                return ENOMEM;
    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);
     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);
    312305        async_exchange_end(exch);
    313306        return ret;
     
    326319        if (!exch)
    327320                return ENOMEM;
    328 
    329         const int ret = usbhc_unregister_endpoint(exch, &pipe->desc);
    330 
     321        const int ret = usb_unregister_endpoint(exch, pipe->endpoint_no,
     322            pipe->direction);
    331323        async_exchange_end(exch);
    332324        return ret;
Note: See TracChangeset for help on using the changeset viewer.