aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/include/usbh/defs.h
blob: c3d8a9a22e6f67979ab3644ee864ff02b04ff3a8 (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
/*
    ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
              Copyright (C) 2015 Diego Ismirlian, TISA, (dismirlian (at) google's mail)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

#ifndef USBH_DEFS_H_
#define USBH_DEFS_H_

#include "hal.h"

#if HAL_USE_USBH

#include "osal.h"

#ifdef __IAR_SYSTEMS_ICC__
#define PACKED_STRUCT typedef PACKED_VAR struct
#else
#define PACKED_STRUCT typedef struct PACKED_VAR
#endif

PACKED_STRUCT {
	uint8_t  bLength;
	uint8_t  bDescriptorType;
	uint16_t bcdUSB;
	uint8_t  bDeviceClass;
	uint8_t  bDeviceSubClass;
	uint8_t  bDeviceProtocol;
	uint8_t  bMaxPacketSize0;
	uint16_t idVendor;
	uint16_t idProduct;
	uint16_t bcdDevice;
	uint8_t  iManufacturer;
	uint8_t  iProduct;
	uint8_t  iSerialNumber;
	uint8_t  bNumConfigurations;
} usbh_device_descriptor_t;
#define USBH_DT_DEVICE                   0x01
#define USBH_DT_DEVICE_SIZE              18

PACKED_STRUCT {
	uint8_t  bLength;
	uint8_t  bDescriptorType;
	uint16_t wTotalLength;
	uint8_t  bNumInterfaces;
	uint8_t  bConfigurationValue;
	uint8_t  iConfiguration;
	uint8_t  bmAttributes;
	uint8_t  bMaxPower;
} usbh_config_descriptor_t;
#define USBH_DT_CONFIG                   0x02
#define USBH_DT_CONFIG_SIZE              9

PACKED_STRUCT {
	uint8_t  bLength;
	uint8_t  bDescriptorType;
	uint16_t wData[1];
} usbh_string_descriptor_t;
#define USBH_DT_STRING                   0x03
#define USBH_DT_STRING_SIZE              2

PACKED_STRUCT {
	uint8_t  bLength;
	uint8_t  bDescriptorType;
	uint8_t  bInterfaceNumber;
	uint8_t  bAlternateSetting;
	uint8_t  bNumEndpoints;
	uint8_t  bInterfaceClass;
	uint8_t  bInterfaceSubClass;
	uint8_t  bInterfaceProtocol;
	uint8_t  iInterface;
} usbh_interface_descriptor_t;
#define USBH_DT_INTERFACE                0x04
#define USBH_DT_INTERFACE_SIZE           9

PACKED_STRUCT {
	uint8_t	bLength;
	uint8_t	bDescriptorType;
	uint8_t	bEndpointAddress;
	uint8_t	bmAttributes;
	uint16_t wMaxPacketSize;
	uint8_t	bInterval;
} usbh_endpoint_descriptor_t;
#define USBH_DT_ENDPOINT                 0x05
#define USBH_DT_ENDPOINT_SIZE            7

PACKED_STRUCT {
	uint8_t  bLength;
	uint8_t  bDescriptorType;
	uint8_t  bFirstInterface;
	uint8_t  bInterfaceCount;
	uint8_t  bFunctionClass;
	uint8_t  bFunctionSubClass;
	uint8_t  bFunctionProtocol;
	uint8_t  iFunction;
} usbh_ia_descriptor_t;
#define USBH_DT_INTERFACE_ASSOCIATION    	0x0b
#define USBH_DT_INTERFACE_ASSOCIATION_SIZE	8

PACKED_STRUCT {
	uint8_t  bDescLength;
	uint8_t  bDescriptorType;
	uint8_t  bNbrPorts;
	uint16_t wHubCharacteristics;
	uint8_t  bPwrOn2PwrGood;
	uint8_t  bHubContrCurrent;
	uint32_t DeviceRemovable;
} usbh_hub_descriptor_t;
#define USBH_DT_HUB				    	0x29
#define USBH_DT_HUB_SIZE		    	(7 + 4)

PACKED_STRUCT {
	uint8_t  bmRequestType;
	uint8_t  bRequest;
	uint16_t wValue;
	uint16_t wIndex;
	uint16_t wLength;
} usbh_control_request_t;


#define USBH_REQ_GET_STATUS              0x00
#define USBH_REQ_CLEAR_FEATURE           0x01
#define USBH_REQ_SET_FEATURE             0x03
#define USBH_REQ_SET_ADDRESS             0x05
#define USBH_REQ_GET_DESCRIPTOR          0x06
#define USBH_REQ_SET_DESCRIPTOR          0x07
#define USBH_REQ_GET_CONFIGURATION       0x08
#define USBH_REQ_SET_CONFIGURATION       0x09
#define USBH_REQ_GET_INTERFACE           0x0A
#define USBH_REQ_SET_INTERFACE           0x0B
#define USBH_REQ_SYNCH_FRAME             0x0C


#define USBH_REQTYPE_IN					0x80
#define USBH_REQTYPE_OUT				0x00

#define USBH_REQTYPE_STANDARD			0x00
#define USBH_REQTYPE_CLASS				0x20
#define USBH_REQTYPE_VENDOR				0x40

#define USBH_REQTYPE_DEVICE				0x00
#define USBH_REQTYPE_INTERFACE			0x01
#define USBH_REQTYPE_ENDPOINT			0x02
#define USBH_REQTYPE_OTHER				0x03

#endif


#endif /* USBH_DEFS_H_ */