Changeset 6326155b in mainline


Ignore:
Timestamp:
2012-12-22T22:39:05Z (12 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.

Location:
uspace/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/include/usb/request.h

    r971fbfde r6326155b  
    3737
    3838#include <sys/types.h>
    39 #include <usb/usb.h>
    4039
    4140/** Standard device request. */
     
    5453        USB_DEVREQ_LAST_STD
    5554} usb_stddevreq_t;
     55
     56/** USB device status - device is self powered (opposed to bus powered). */
     57#define USB_DEVICE_STATUS_SELF_POWERED ((uint16_t)(1 << 0))
     58
     59/** USB device status - remote wake-up signaling is enabled. */
     60#define USB_DEVICE_STATUS_REMOTE_WAKEUP ((uint16_t)(1 << 1))
     61
     62/** USB endpoint status - endpoint is halted (stalled). */
     63#define USB_ENDPOINT_STATUS_HALTED ((uint16_t)(1 << 0))
     64
     65/** USB feature selector - endpoint halt (stall). */
     66#define USB_FEATURE_SELECTOR_ENDPOINT_HALT (0)
     67
     68/** USB feature selector - device remote wake-up. */
     69#define USB_FEATURE_SELECTOR_REMOTE_WAKEUP (1)
    5670
    5771/** Device request setup packet.
     
    93107int assert[(sizeof(usb_device_request_setup_packet_t) == 8) ? 1: -1];
    94108
     109int usb_request_needs_toggle_reset(
     110    const usb_device_request_setup_packet_t *request);
    95111
    96112#endif
  • 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 * @}
  • uspace/lib/usbdev/include/usb/dev/request.h

    r971fbfde r6326155b  
    4242#include <usb/descriptor.h>
    4343#include <usb/request.h>
    44 
    45 /** USB device status - device is self powered (opposed to bus powered). */
    46 #define USB_DEVICE_STATUS_SELF_POWERED ((uint16_t)(1 << 0))
    47 
    48 /** USB device status - remote wake-up signaling is enabled. */
    49 #define USB_DEVICE_STATUS_REMOTE_WAKEUP ((uint16_t)(1 << 1))
    50 
    51 /** USB endpoint status - endpoint is halted (stalled). */
    52 #define USB_ENDPOINT_STATUS_HALTED ((uint16_t)(1 << 0))
    53 
    54 /** USB feature selector - endpoint halt (stall). */
    55 #define USB_FEATURE_SELECTOR_ENDPOINT_HALT (0)
    56 
    57 /** USB feature selector - device remote wake-up. */
    58 #define USB_FEATURE_SELECTOR_REMOTE_WAKEUP (1)
    59 
    6044
    6145int usb_control_request_set(usb_pipe_t *,
Note: See TracChangeset for help on using the changeset viewer.