summaryrefslogtreecommitdiff
path: root/bsp/synwit/libraries/SWM341_CSL/SWM341_StdPeriph_Driver/SWM341_usb.h
blob: eef8780bba9a96ccd16c16d96529e2b385d72132 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#ifndef __SWM341_USB_H__
#define __SWM341_USB_H__

#include <stdint.h>


typedef struct {
    uint8_t  bRequestType;
    uint8_t  bRequest;
    uint16_t wValue;
    uint16_t wIndex;
    uint16_t wLength;
} USB_Setup_Packet_t;


/* bRequestType D7 Data Phase Transfer Direction  */
#define  USB_REQ_DIR_MASK           0x80
#define  USB_REQ_H2D                0x00
#define  USB_REQ_D2H                0x80

/* bRequestType D6..5 Type */
#define  USB_REQ_STANDARD           0x00
#define  USB_REQ_CLASS              0x20
#define  USB_REQ_VENDOR             0x40

/* bRequestType D4..0 Recipient */
#define  USB_REQ_TO_DEVICE          0x00
#define  USB_REQ_TO_INTERFACE       0x01
#define  USB_REQ_TO_ENDPOINT        0x02

/* USB Standard Request */
#define USB_GET_STATUS              0x00
#define USB_CLEAR_FEATURE           0x01
#define USB_SET_FEATURE             0x03
#define USB_SET_ADDRESS             0x05
#define USB_GET_DESCRIPTOR          0x06
#define USB_SET_DESCRIPTOR          0x07
#define USB_GET_CONFIGURATION       0x08
#define USB_SET_CONFIGURATION       0x09
#define USB_GET_INTERFACE           0x0A
#define USB_SET_INTERFACE           0x0B
#define USB_SYNC_FRAME              0x0C

/* USB Descriptor Type */
#define USB_DESC_DEVICE             0x01
#define USB_DESC_CONFIG             0x02
#define USB_DESC_STRING             0x03
#define USB_DESC_INTERFACE          0x04
#define USB_DESC_ENDPOINT           0x05
#define USB_DESC_QUALIFIER          0x06
#define USB_DESC_OTHERSPEED         0x07
#define USB_DESC_IFPOWER            0x08
#define USB_DESC_OTG                0x09
#define USB_DESC_BOS                0x0F
#define USB_DESC_CAPABILITY         0x10
#define USB_DESC_CS_INTERFACE       0x24    // Class Specific Interface

/* USB HID Descriptor Type */
#define USB_DESC_HID                0x21
#define USB_DESC_HID_RPT            0x22

/* USB Endpoint Type */
#define USB_EP_CTRL                 0x00
#define USB_EP_ISO                  0x01
#define USB_EP_BULK                 0x02
#define USB_EP_INT                  0x03

#define USB_EP_IN                   0x80
#define USB_EP_OUT                  0x00

/* USB Feature Selector */
#define USB_FEATURE_REMOTE_WAKEUP   0x01
#define USB_FEATURE_ENDPOINT_HALT   0x00

/* USB HID Class Report Type */
#define HID_RPT_TYPE_INPUT          0x01
#define HID_RPT_TYPE_OUTPUT         0x02
#define HID_RPT_TYPE_FEATURE        0x03

/* Define HID Class Specific Request */
#define USB_HID_GET_REPORT          0x01
#define USB_HID_GET_IDLE            0x02
#define USB_HID_GET_PROTOCOL        0x03
#define USB_HID_SET_REPORT          0x09
#define USB_HID_SET_IDLE            0x0A
#define USB_HID_SET_PROTOCOL        0x0B


/* Class */
#define USB_CDC_CLASS               0x02    // for Device
#define USB_CDC_CTRL_CLASS          0x02    // for Interface
#define USB_CDC_DATA_CLASS          0x0A    // for Interface
#define USB_HID_CLASS               0x03    // for Interface
#define USB_MTP_CLASS               0x06    // for Interface
#define USB_MSC_CLASS               0x08    // for Interface
#define USB_UVC_CLASS               0x0E    // for Interface


/* SubClass */
#define USB_CDC_ACM                 0x02    // Abstract Control Model
#define USB_HID_BOOT                0x01
#define USB_UVC_VIDEOCONTROL                0x01
#define USB_UVC_VIDEOSTREAMING              0x02
#define USB_UVC_VIDEO_INTERFACE_COLLECTION  0x03

/* Protocol */
#define USB_CDC_ATCMD               0x01    // AT Commands defined by ITU-T V.250
#define USB_HID_NONE                0x00
#define USB_HID_KEYBD               0x01
#define USB_HID_MOUSE               0x02
#define USB_MSC_BOT                 0x50    // Bulk-Only Transport


typedef struct {
    uint8_t  bLength;
    uint8_t  bDescriptorType;
} USB_DescHeader_t;

typedef struct __attribute__((packed)) {
    uint8_t   bLength;
    uint8_t   bDescriptorType;
    uint16_t  bcdUSB;               // USB Specification Number which device complies to
    uint8_t   bDeviceClass;         // 0x00: each interface specifies its own class code
    uint8_t   bDeviceSubClass;
    uint8_t   bDeviceProtocol;
    uint8_t   bMaxPacketSize;
    uint16_t  idVendor;             // Vendor ID (Assigned by USB Org)
    uint16_t  idProduct;            // Product ID (Assigned by Manufacturer)
    uint16_t  bcdDevice;            // Device Release Number
    uint8_t   iManufacturer;        // Index of Manufacturer String Descriptor
    uint8_t   iProduct;             // Index of Product String Descriptor
    uint8_t   iSerialNumber;        // Index of Serial Number String Descriptor
    uint8_t   bNumConfigurations;   // Number of Possible Configurations
} USB_DevDesc_t;

typedef struct __attribute__((packed)) {
    uint8_t   bLength;
    uint8_t   bDescriptorType;
    uint16_t  wTotalLength;         // Total Length
    uint8_t   bNumInterfaces;       // Number of Interfaces
    uint8_t   bConfigurationValue;  // Value to use as an argument to select this configuration
    uint8_t   iConfiguration;       // Index of String Descriptor Describing this configuration
    uint8_t   bmAttributes;         // D7 Bus Powered , D6 Self Powered, D5 Remote Wakeup , D4..0 Reserved (0)
    uint8_t   bMaxPower;            // Maximum Power Consumption
} USB_CfgDesc_t;

typedef struct __attribute__((packed)) {
    uint8_t bLength;
    uint8_t bDescriptorType;
    uint8_t bInterfaceNumber;
    uint8_t bAlternateSetting;      // Value used to select alternative setting
    uint8_t bNumEndpoints;          // Number of Endpoints used for this interface
    uint8_t bInterfaceClass;
    uint8_t bInterfaceSubClass;
    uint8_t bInterfaceProtocol;
    uint8_t iInterface;             // Index of String Descriptor Describing this interface
} USB_IntfDesc_t;

typedef struct __attribute__((packed)) {
    uint8_t   bLength;
    uint8_t   bDescriptorType;
    uint8_t   bEndpointAddress;     // indicates what endpoint this descriptor is describing
    uint8_t   bmAttributes;         // specifies the transfer type.
    uint16_t  wMaxPacketSize;       // Maximum Packet Size this endpoint is capable of sending or receiving
    uint8_t   bInterval;            // is used to specify the polling interval of certain transfers.
} USB_EpDesc_t;

typedef struct __attribute__((packed)) {
    uint8_t   bLength;
    uint8_t   bDescriptorType;
    uint16_t  bcdHID;               // indicates what endpoint this descriptor is describing
    uint8_t   bCountryCode;
    uint8_t   bNumDescriptors;
    uint8_t   bReportDescriptorType;
    uint16_t  wItemLength;
} USB_HIDDesc_t;


/* Header Functional Descriptor, which marks the beginning of the
   concatenated set of functional descriptors for the interface. */
typedef struct __attribute__((packed)) {
    uint8_t  bLength;
    uint8_t  bDescriptorType;       // CS_INTERFACE (0x24)
    uint8_t  bDescriptorSubType;    // 0x00
    uint16_t bcdCDC;
} USB_CDC_HeaderFuncDesc_t;


/* Call Management Functional Descriptor */
typedef struct __attribute__((packed)) {
    uint8_t  bLength;
    uint8_t  bDescriptorType;       // CS_INTERFACE (0x24)
    uint8_t  bDescriptorSubType;    // 0x01
    uint8_t  bmCapabilities;
    uint8_t  bDataInterface;
} USB_CDC_CallMgmtFuncDesc_t;


/* Abstract Control Management Functional Descriptor */
typedef struct __attribute__((packed)) {
    uint8_t  bLength;
    uint8_t  bDescriptorType;       // CS_INTERFACE (0x24)
    uint8_t  bDescriptorSubType;    // 0x02
    uint8_t  bmCapabilities;
} USB_CDC_AbstCntrlMgmtFuncDesc_t;


/* Union Functional Descriptor */
typedef struct __attribute__((packed)) {
    uint8_t  bLength;
    uint8_t  bDescriptorType;       // CS_INTERFACE (0x24)
    uint8_t  bDescriptorSubType;    // 0x06
    uint8_t  bMasterInterface;      // Interface number of the Communication or Data Class interface
    uint8_t  bSlaveInterface0;      // Interface number of first slave
} USB_CDC_UnionFuncDesc_t;


#endif //__SWM341_USB_H__