aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/include/usbh/internal.h
blob: 247377571d2e222b8b95199c529564730d46e53c (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
/*
    ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
              Copyright (C) 2015..2019 Diego Ismirlian, (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_INTERNAL_H_
#define USBH_INTERNAL_H_

#include "hal_usbh.h"

#if HAL_USE_USBH

/*===========================================================================*/
/* These declarations are not part of the public API.                        */
/*===========================================================================*/

#if HAL_USBH_USE_FTDI
extern const usbh_classdriverinfo_t usbhftdiClassDriverInfo;
#endif
#if HAL_USBH_USE_AOA
extern const usbh_classdriverinfo_t usbhaoaClassDriverInfo;
#endif
#if HAL_USBH_USE_MSD
extern const usbh_classdriverinfo_t usbhmsdClassDriverInfo;
#endif
#if HAL_USBH_USE_HID
extern const usbh_classdriverinfo_t usbhhidClassDriverInfo;
#endif
#if HAL_USBH_USE_UVC
extern const usbh_classdriverinfo_t usbhuvcClassDriverInfo;
#endif
#if HAL_USBH_USE_HUB
extern const usbh_classdriverinfo_t usbhhubClassDriverInfo;
void _usbhub_port_object_init(usbh_port_t *port, USBHDriver *usbh,
		USBHHubDriver *hub, uint8_t number);
#else
void _usbhub_port_object_init(usbh_port_t *port, USBHDriver *usbh, uint8_t number);
#endif

void _usbh_port_disconnected(usbh_port_t *port);
void _usbh_urb_completeI(usbh_urb_t *urb, usbh_urbstatus_t status);
bool _usbh_urb_abortI(usbh_urb_t *urb, usbh_urbstatus_t status);
void _usbh_urb_abort_and_waitS(usbh_urb_t *urb, usbh_urbstatus_t status);

bool _usbh_match_vid_pid(usbh_device_t *dev, int32_t vid, int32_t pid);
bool _usbh_match_descriptor(const uint8_t *descriptor, uint16_t rem,
		int16_t type, int16_t _class, int16_t subclass, int16_t protocol);

#define USBH_REQTYPE_CLASSIN(type)	\
	(USBH_REQTYPE_DIR_IN | type | USBH_REQTYPE_TYPE_CLASS)

#define USBH_REQTYPE_CLASSOUT(type)	\
	(USBH_REQTYPE_DIR_OUT | type | USBH_REQTYPE_TYPE_CLASS)

#define USBH_REQTYPE_STANDARDIN(type)	\
	(USBH_REQTYPE_DIR_IN | type | USBH_REQTYPE_TYPE_STANDARD)

#define USBH_REQTYPE_STANDARDOUT(type)	\
	(USBH_REQTYPE_DIR_OUT | type | USBH_REQTYPE_TYPE_STANDARD)


#define USBH_PID_DATA0            0
#define USBH_PID_DATA2            1
#define USBH_PID_DATA1            2
#define USBH_PID_MDATA            3
#define USBH_PID_SETUP            3


/* GetBusState and SetHubDescriptor are optional, omitted */
#define ClearHubFeature   (((USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_DEVICE) << 8) \
							| USBH_REQ_CLEAR_FEATURE)
#define SetHubFeature     (((USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_DEVICE) << 8) \
							| USBH_REQ_SET_FEATURE)
#define ClearPortFeature   (((USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER) << 8) \
							| USBH_REQ_CLEAR_FEATURE)
#define SetPortFeature     (((USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER) << 8) \
							| USBH_REQ_SET_FEATURE)
#define GetHubDescriptor  (((USBH_REQTYPE_DIR_IN | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_DEVICE) << 8) \
							| USBH_REQ_GET_DESCRIPTOR)
#define GetHubStatus      (((USBH_REQTYPE_DIR_IN | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_DEVICE) << 8) \
							| USBH_REQ_GET_STATUS)
#define GetPortStatus     (((USBH_REQTYPE_DIR_IN | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER) << 8) \
							| USBH_REQ_GET_STATUS)


#define USBH_PORTSTATUS_CONNECTION        0x0001
#define USBH_PORTSTATUS_ENABLE            0x0002
#define USBH_PORTSTATUS_SUSPEND           0x0004
#define USBH_PORTSTATUS_OVERCURRENT       0x0008
#define USBH_PORTSTATUS_RESET             0x0010
/* bits 5 to 7 are reserved */
#define USBH_PORTSTATUS_POWER             0x0100
#define USBH_PORTSTATUS_LOW_SPEED         0x0200
#define USBH_PORTSTATUS_HIGH_SPEED        0x0400
#define USBH_PORTSTATUS_TEST              0x0800
#define USBH_PORTSTATUS_INDICATOR         0x1000
/* bits 13 to 15 are reserved */

#define USBH_PORTSTATUS_C_CONNECTION      0x0001
#define USBH_PORTSTATUS_C_ENABLE          0x0002
#define USBH_PORTSTATUS_C_SUSPEND         0x0004
#define USBH_PORTSTATUS_C_OVERCURRENT     0x0008
#define USBH_PORTSTATUS_C_RESET           0x0010

#define USBH_HUBSTATUS_C_HUB_LOCAL_POWER       0x0001
#define USBH_HUBSTATUS_C_HUB_OVER_CURRENT      0x0002

/*
 * Port feature numbers
 * See USB 2.0 spec Table 11-17
 */
#define USBH_HUB_FEAT_C_HUB_LOCAL_POWER  0
#define USBH_HUB_FEAT_C_HUB_OVER_CURRENT 1
#define USBH_PORT_FEAT_CONNECTION        0
#define USBH_PORT_FEAT_ENABLE            1
#define USBH_PORT_FEAT_SUSPEND           2
#define USBH_PORT_FEAT_OVERCURRENT     	 3
#define USBH_PORT_FEAT_RESET             4
#define USBH_PORT_FEAT_POWER             8
#define USBH_PORT_FEAT_LOWSPEED          9
#define USBH_PORT_FEAT_C_CONNECTION      16
#define USBH_PORT_FEAT_C_ENABLE          17
#define USBH_PORT_FEAT_C_SUSPEND         18
#define USBH_PORT_FEAT_C_OVERCURRENT     19
#define USBH_PORT_FEAT_C_RESET           20
#define USBH_PORT_FEAT_TEST              21
#define USBH_PORT_FEAT_INDICATOR         22

#define sizeof_array(x) 	(sizeof(x)/sizeof(*(x)))

#include "usbh/desciter.h"	/* descriptor iterators */
#include "usbh/debug.h"

#endif

#endif /* USBH_INTERNAL_H_ */