Changeset b4b534ac in mainline for uspace/lib/usb/src/usb.c


Ignore:
Timestamp:
2016-07-22T08:24:47Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f76d2c2
Parents:
5b18137 (diff), 8351f9a4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jan.vesely/helenos/usb

File:
1 edited

Legend:

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

    r5b18137 rb4b534ac  
    3434 */
    3535#include <usb/usb.h>
    36 #include <errno.h>
     36#include <usb/request.h>
    3737
    38 #define ARR_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
     38#include <assert.h>
     39#include <byteorder.h>
     40#include <macros.h>
    3941
    4042static const char *str_speed[] = {
     
    7173const char *usb_str_transfer_type(usb_transfer_type_t t)
    7274{
    73         if (t >= ARR_SIZE(str_transfer_type)) {
     75        if (t >= ARRAY_SIZE(str_transfer_type)) {
    7476                return "invalid";
    7577        }
     
    8486const char *usb_str_transfer_type_short(usb_transfer_type_t t)
    8587{
    86         if (t >= ARR_SIZE(str_transfer_type_short)) {
     88        if (t >= ARRAY_SIZE(str_transfer_type_short)) {
    8789                return "invl";
    8890        }
     
    9799const char *usb_str_direction(usb_direction_t d)
    98100{
    99         if (d >= ARR_SIZE(str_direction)) {
     101        if (d >= ARRAY_SIZE(str_direction)) {
    100102                return "invalid";
    101103        }
     
    110112const char *usb_str_speed(usb_speed_t s)
    111113{
    112         if (s >= ARR_SIZE(str_speed)) {
     114        if (s >= ARRAY_SIZE(str_speed)) {
    113115                return "invalid";
    114116        }
     
    116118}
    117119
     120/** Check setup packet data for signs of toggle reset.
     121 *
     122 * @param[in] requst Setup requst data.
     123 * @retval -1 No endpoints need reset.
     124 * @retval 0 All endpoints need reset.
     125 * @retval >0 Specified endpoint needs reset.
     126 */
     127int usb_request_needs_toggle_reset(
     128    const usb_device_request_setup_packet_t *request)
     129{
     130        assert(request);
     131        switch (request->request)
     132        {
     133        /* Clear Feature ENPOINT_STALL */
     134        case USB_DEVREQ_CLEAR_FEATURE: /*resets only cleared ep */
     135                /* 0x2 ( HOST to device | STANDART | TO ENPOINT) */
     136                if ((request->request_type == 0x2) &&
     137                    (request->value == USB_FEATURE_ENDPOINT_HALT))
     138                        return uint16_usb2host(request->index);
     139                break;
     140        case USB_DEVREQ_SET_CONFIGURATION:
     141        case USB_DEVREQ_SET_INTERFACE:
     142                /* Recipient must be device, this resets all endpoints,
     143                 * In fact there should be no endpoints but EP 0 registered
     144                 * as different interfaces use different endpoints,
     145                 * unless you're changing configuration or alternative
     146                 * interface of an already setup device. */
     147                if (!(request->request_type & SETUP_REQUEST_TYPE_DEVICE_TO_HOST))
     148                        return 0;
     149                break;
     150        default:
     151                break;
     152        }
     153        return -1;
     154}
     155
    118156/**
    119157 * @}
Note: See TracChangeset for help on using the changeset viewer.