source: mainline/uspace/lib/usb/include/usb/request.h

Last change on this file was 0a520db, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Change static_assert to its standard definition

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * Copyright (c) 2012 Jan Vesely
3 * Copyright (c) 2018 Ondrej Hlavaty
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup libusb
31 * @{
32 */
33/** @file
34 * Standard USB request format.
35 */
36#ifndef LIBUSB_REQUEST_H_
37#define LIBUSB_REQUEST_H_
38
39#include <stdint.h>
40#include <assert.h>
41
42/** Standard device request. */
43typedef enum {
44 USB_DEVREQ_GET_STATUS = 0,
45 USB_DEVREQ_CLEAR_FEATURE = 1,
46 USB_DEVREQ_SET_FEATURE = 3,
47 USB_DEVREQ_SET_ADDRESS = 5,
48 USB_DEVREQ_GET_DESCRIPTOR = 6,
49 USB_DEVREQ_SET_DESCRIPTOR = 7,
50 USB_DEVREQ_GET_CONFIGURATION = 8,
51 USB_DEVREQ_SET_CONFIGURATION = 9,
52 USB_DEVREQ_GET_INTERFACE = 10,
53 USB_DEVREQ_SET_INTERFACE = 11,
54 USB_DEVREQ_SYNCH_FRAME = 12,
55 USB_DEVREQ_LAST_STD
56} usb_stddevreq_t;
57
58/** Standard device features */
59typedef enum {
60 USB_FEATURE_ENDPOINT_HALT = 0,
61 USB_FEATURE_DEVICE_REMOTE_WAKEUP = 1,
62 USB_FEATURE_TEST_MODE = 2
63} usb_std_feature_t;
64
65/** USB device status - device is self powered (opposed to bus powered). */
66#define USB_DEVICE_STATUS_SELF_POWERED ((uint16_t)(1 << 0))
67
68/** USB device status - remote wake-up signaling is enabled. */
69#define USB_DEVICE_STATUS_REMOTE_WAKEUP ((uint16_t)(1 << 1))
70
71/** USB endpoint status - endpoint is halted (stalled). */
72#define USB_ENDPOINT_STATUS_HALTED ((uint16_t)(1 << 0))
73
74/** Size of the USB setup packet */
75#define USB_SETUP_PACKET_SIZE 8
76
77#define SETUP_REQUEST_TYPE_DEVICE_TO_HOST (1 << 7)
78#define SETUP_REQUEST_TYPE_HOST_TO_DEVICE (0 << 7)
79#define SETUP_REQUEST_TYPE_IS_DEVICE_TO_HOST(rt) ((rt) & (1 << 7))
80#define SETUP_REQUEST_TYPE_GET_TYPE(rt) ((rt >> 5) & 0x3)
81#define SETUP_REQUEST_TYPE_GET_RECIPIENT(rec) (rec & 0x1f)
82#define SETUP_REQUEST_TO_HOST(type, recipient) \
83 (uint8_t)((1 << 7) | ((type & 0x3) << 5) | (recipient & 0x1f))
84#define SETUP_REQUEST_TO_DEVICE(type, recipient) \
85 (uint8_t)(((type & 0x3) << 5) | (recipient & 0x1f))
86
87/** Device request setup packet.
88 * The setup packet describes the request.
89 */
90typedef union {
91 struct __attribute__((packed)) {
92 /** Request type.
93 * The type combines transfer direction, request type and
94 * intended recipient.
95 */
96 uint8_t request_type;
97
98 /** Request identification. */
99 uint8_t request;
100 /** Main parameter to the request. */
101 union __attribute__((packed)) {
102 uint16_t value;
103 /* FIXME: add #ifdefs according to host endianness */
104 struct __attribute__((packed)) {
105 uint8_t value_low;
106 uint8_t value_high;
107 };
108 };
109 /** Auxiliary parameter to the request.
110 * Typically, it is offset to something.
111 */
112 uint16_t index;
113 /** Length of extra data. */
114 uint16_t length;
115 };
116 uint64_t raw;
117} __attribute__((packed)) usb_device_request_setup_packet_t;
118
119static_assert(sizeof(usb_device_request_setup_packet_t) == USB_SETUP_PACKET_SIZE, "");
120
121#define GET_DEVICE_DESC(size) \
122{ \
123 .request_type = SETUP_REQUEST_TYPE_DEVICE_TO_HOST \
124 | (USB_REQUEST_TYPE_STANDARD << 5) \
125 | USB_REQUEST_RECIPIENT_DEVICE, \
126 .request = USB_DEVREQ_GET_DESCRIPTOR, \
127 .value = uint16_host2usb(USB_DESCTYPE_DEVICE << 8), \
128 .index = uint16_host2usb(0), \
129 .length = uint16_host2usb(size), \
130};
131
132#define SET_ADDRESS(address) \
133{ \
134 .request_type = SETUP_REQUEST_TYPE_HOST_TO_DEVICE \
135 | (USB_REQUEST_TYPE_STANDARD << 5) \
136 | USB_REQUEST_RECIPIENT_DEVICE, \
137 .request = USB_DEVREQ_SET_ADDRESS, \
138 .value = uint16_host2usb(address), \
139 .index = uint16_host2usb(0), \
140 .length = uint16_host2usb(0), \
141};
142
143#define CTRL_PIPE_MIN_PACKET_SIZE 8
144
145#endif
146/**
147 * @}
148 */
Note: See TracBrowser for help on using the repository browser.