Changeset 6326155b in mainline for uspace/lib/usb/src/usb.c


Ignore:
Timestamp:
2012-12-22T22:39:05Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
52f9c57
Parents:
971fbfde
Message:

libusb: Add toggle guessing function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/usb.c

    r971fbfde r6326155b  
    3434 */
    3535#include <usb/usb.h>
     36#include <usb/request.h>
     37
    3638#include <errno.h>
     39#include <assert.h>
    3740
    3841#define ARR_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
     
    116119}
    117120
     121/** Check setup packet data for signs of toggle reset.
     122 *
     123 * @param[in] requst Setup requst data.
     124 * @retval -1 No endpoints need reset.
     125 * @retval 0 All endpoints need reset.
     126 * @retval >0 Specified endpoint needs reset.
     127 */
     128int usb_request_needs_toggle_reset(
     129    const usb_device_request_setup_packet_t *request)
     130{
     131        assert(request);
     132        switch (request->request)
     133        {
     134        /* Clear Feature ENPOINT_STALL */
     135        case USB_DEVREQ_CLEAR_FEATURE: /*resets only cleared ep */
     136                /* 0x2 ( HOST to device | STANDART | TO ENPOINT) */
     137                if ((request->request_type == 0x2) &&
     138                    (request->value == USB_FEATURE_SELECTOR_ENDPOINT_HALT))
     139                        return uint16_usb2host(request->index);
     140                break;
     141        case USB_DEVREQ_SET_CONFIGURATION:
     142        case USB_DEVREQ_SET_INTERFACE:
     143                /* Recipient must be device, this resets all endpoints,
     144                 * In fact there should be no endpoints but EP 0 registered
     145                 * as different interfaces use different endpoints,
     146                 * unless you're changing configuration or alternative
     147                 * interface of an already setup device. */
     148                if (!(request->request_type & SETUP_REQUEST_TYPE_DEVICE_TO_HOST))
     149                        return 0;
     150                break;
     151        default:
     152                break;
     153        }
     154        return -1;
     155}
     156
    118157/**
    119158 * @}
Note: See TracChangeset for help on using the changeset viewer.