aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/os/hal/include/usbh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/os/hal/include/usbh')
-rw-r--r--lib/chibios-contrib/os/hal/include/usbh/debug.h77
-rw-r--r--lib/chibios-contrib/os/hal/include/usbh/debug_helpers.h163
-rw-r--r--lib/chibios-contrib/os/hal/include/usbh/defs.h159
-rw-r--r--lib/chibios-contrib/os/hal/include/usbh/desciter.h63
-rw-r--r--lib/chibios-contrib/os/hal/include/usbh/dev/aoa.h153
-rw-r--r--lib/chibios-contrib/os/hal/include/usbh/dev/ftdi.h151
-rw-r--r--lib/chibios-contrib/os/hal/include/usbh/dev/hid.h144
-rw-r--r--lib/chibios-contrib/os/hal/include/usbh/dev/hub.h137
-rw-r--r--lib/chibios-contrib/os/hal/include/usbh/dev/msd.h105
-rw-r--r--lib/chibios-contrib/os/hal/include/usbh/dev/uvc.h459
-rw-r--r--lib/chibios-contrib/os/hal/include/usbh/internal.h148
-rw-r--r--lib/chibios-contrib/os/hal/include/usbh/list.h590
12 files changed, 2349 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/hal/include/usbh/debug.h b/lib/chibios-contrib/os/hal/include/usbh/debug.h
new file mode 100644
index 000000000..964324b7b
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/include/usbh/debug.h
@@ -0,0 +1,77 @@
1/*
2 ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
3 Copyright (C) 2015..2019 Diego Ismirlian, (dismirlian(at)google's mail)
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18
19#ifndef USBH_DEBUG_H_
20#define USBH_DEBUG_H_
21
22#include "hal_usbh.h"
23
24#if HAL_USE_USBH
25
26#if USBH_DEBUG_ENABLE
27#if USBH_DEBUG_MULTI_HOST
28 /* output callback */
29 void USBH_DEBUG_OUTPUT_CALLBACK(USBHDriver *host, const uint8_t *buff, size_t len);
30
31 /* printing functions */
32 void usbDbgPrintf(USBHDriver *host, const char *fmt, ...);
33 void usbDbgPuts(USBHDriver *host, const char *s);
34 void usbDbgInit(USBHDriver *host);
35#else
36 /* output callback */
37 void USBH_DEBUG_OUTPUT_CALLBACK(const uint8_t *buff, size_t len);
38
39 /* printing functions */
40 void usbDbgPrintf(const char *fmt, ...);
41 void usbDbgPuts(const char *s);
42 void usbDbgInit(void);
43#endif
44
45 void usbDbgReset(void);
46#else
47
48#if USBH_DEBUG_MULTI_HOST
49# define usbDbgPrintf(host, fmt, ...) do {} while(0)
50# define usbDbgPuts(host, s) do {} while(0)
51# define usbDbgInit(host) do {} while(0)
52#else
53# define usbDbgPrintf(fmt, ...) do {} while(0)
54# define usbDbgPuts(s) do {} while(0)
55# define usbDbgInit() do {} while(0)
56#endif
57# define usbDbgReset() do {} while(0)
58#endif
59
60#if USBH_DEBUG_MULTI_HOST
61#define _usbh_dbg(host, s) usbDbgPuts(host, s)
62#define _usbh_dbgf(host, f, ...) usbDbgPrintf(host, f, ##__VA_ARGS__)
63#define _usbh_ldbg(host, lvl, n, s) do {if (lvl >= n) usbDbgPuts(host, s); } while(0)
64#define _usbh_ldbgf(host, lvl, n, f, ...) do {if (lvl >= n) usbDbgPrintf(host, f, ##__VA_ARGS__); } while(0)
65#else
66
67#define _usbh_dbg(host, s) usbDbgPuts(s)
68#define _usbh_dbgf(host, f, ...) usbDbgPrintf(f, ##__VA_ARGS__)
69#define _usbh_ldbg(host, lvl, n, s) do {if (lvl >= n) usbDbgPuts(s); } while(0)
70#define _usbh_ldbgf(host, lvl, n, f, ...) do {if (lvl >= n) usbDbgPrintf(f, ##__VA_ARGS__); } while(0)
71
72#endif
73
74
75#endif
76
77#endif /* USBH_DEBUG_H_ */
diff --git a/lib/chibios-contrib/os/hal/include/usbh/debug_helpers.h b/lib/chibios-contrib/os/hal/include/usbh/debug_helpers.h
new file mode 100644
index 000000000..ea88502ee
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/include/usbh/debug_helpers.h
@@ -0,0 +1,163 @@
1#ifndef USBH_INTERNAL_H_
2#error "Internal use only"
3#endif
4
5#ifndef _USBH_DEBUG_HELPER_ENABLE_TRACE
6#error "_USBH_DEBUG_HELPER_ENABLE_TRACE must be set"
7#endif
8#ifndef _USBH_DEBUG_HELPER_ENABLE_INFO
9#error "_USBH_DEBUG_HELPER_ENABLE_INFO must be set"
10#endif
11#ifndef _USBH_DEBUG_HELPER_ENABLE_WARNINGS
12#error "_USBH_DEBUG_HELPER_ENABLE_WARNINGS must be set"
13#endif
14#ifndef _USBH_DEBUG_HELPER_ENABLE_ERRORS
15#error "_USBH_DEBUG_HELPER_ENABLE_ERRORS must be set"
16#endif
17
18#define _usbh_dbg_host(s) _usbh_dbg(host, s)
19#define _usbh_dbg_port(s) _usbh_dbg(port->device.host, s)
20#define _usbh_dbg_dev(s) _usbh_dbg(dev->host, s)
21#define _usbh_dbg_ep(lvl, s) _usbh_ldbg(ep->device->host, ep->trace_level, lvl, s)
22#define _usbh_dbg_urb(lvl, s) _usbh_ldbg(urb->ep->device->host, urb->ep->trace_level, lvl, s)
23
24#define _usbh_dbgf_host(f, ...) _usbh_dbgf(host, f, ##__VA_ARGS__)
25#define _usbh_dbgf_port(f, ...) _usbh_dbgf(port->device.host, f, ##__VA_ARGS__)
26#define _usbh_dbgf_dev(f, ...) _usbh_dbgf(dev->host, f, ##__VA_ARGS__)
27#define _usbh_dbgf_ep(f, lvl, ...) _usbh_ldbgf(ep->device->host, ep->trace_level, lvl, "\t%s: " f, ep->name, ##__VA_ARGS__)
28#define _usbh_dbgf_urb(f, lvl, ...) _usbh_ldbgf(urb->ep->device->host, urb->ep->trace_level, lvl, "\t%s: " f, urb->ep->name, ##__VA_ARGS__)
29
30#if defined(_USBH_DEBUG_HELPER_CLASS_DRIVER)
31#define _usbh_dbg_classdrv(drv, s) _usbh_dbg(drv->dev->host, s)
32#define _usbh_dbgf_classdrv(drv, f, ...) _usbh_dbgf(drv->dev->host, f, ##__VA_ARGS__)
33#endif
34
35#define _usbh_dbg_dummy do {} while(0)
36
37#if _USBH_DEBUG_HELPER_ENABLE_TRACE
38#define udbg(s) _usbh_dbg_host(s)
39#define uportdbg(s) _usbh_dbg_port(s)
40#define udevdbg(s) _usbh_dbg_dev(s)
41#define uepdbg(s) _usbh_dbg_ep(4, s)
42#define uurbdbg(s) _usbh_dbg_urb(4, s)
43#define udbgf(f, ...) _usbh_dbgf_host(f, ##__VA_ARGS__)
44#define uportdbgf(f, ...) _usbh_dbgf_port(f, ##__VA_ARGS__)
45#define udevdbgf(f, ...) _usbh_dbgf_dev(f, ##__VA_ARGS__)
46#define uepdbgf(f, ...) _usbh_dbgf_ep(f, 4, ##__VA_ARGS__)
47#define uurbdbgf(f, ...) _usbh_dbgf_urb(f, 4, ##__VA_ARGS__)
48#else
49#define udbg(s) _usbh_dbg_dummy
50#define uportdbg(s) _usbh_dbg_dummy
51#define udevdbg(s) _usbh_dbg_dummy
52#define uurbdbg(s) _usbh_dbg_dummy
53#define uepdbg(s) _usbh_dbg_dummy
54#define udbgf(f, ...) _usbh_dbg_dummy
55#define uportdbgf(f, ...) _usbh_dbg_dummy
56#define udevdbgf(f, ...) _usbh_dbg_dummy
57#define uepdbgf(f, ...) _usbh_dbg_dummy
58#define uurbdbgf(f, ...) _usbh_dbg_dummy
59#endif
60
61#if _USBH_DEBUG_HELPER_ENABLE_INFO
62#define uinfo(s) _usbh_dbg_host(s)
63#define uportinfo(s) _usbh_dbg_port(s)
64#define udevinfo(s) _usbh_dbg_dev(s)
65#define uepinfo(s) _usbh_dbg_ep(3, s)
66#define uurbinfo(s) _usbh_dbg_urb(3, s)
67#define uinfof(f, ...) _usbh_dbgf_host(f, ##__VA_ARGS__)
68#define uportinfof(f, ...) _usbh_dbgf_port(f, ##__VA_ARGS__)
69#define udevinfof(f, ...) _usbh_dbgf_dev(f, ##__VA_ARGS__)
70#define uepinfof(f, ...) _usbh_dbgf_ep(f, 3, ##__VA_ARGS__)
71#define uurbinfof(f, ...) _usbh_dbgf_urb(f, 3, ##__VA_ARGS__)
72#else
73#define uinfo(s) _usbh_dbg_dummy
74#define udevinfo(s) _usbh_dbg_dummy
75#define uportinfo(s) _usbh_dbg_dummy
76#define uepinfo(s) _usbh_dbg_dummy
77#define uurbinfo(s) _usbh_dbg_dummy
78#define uinfof(f, ...) _usbh_dbg_dummy
79#define uportinfof(f, ...) _usbh_dbg_dummy
80#define udevinfof(f, ...) _usbh_dbg_dummy
81#define uepinfof(f, ...) _usbh_dbg_dummy
82#define uurbinfof(f, ...) _usbh_dbg_dummy
83#endif
84
85#if _USBH_DEBUG_HELPER_ENABLE_WARNINGS
86#define uwarn(s) _usbh_dbg_host(s)
87#define uportwarn(s) _usbh_dbg_port(s)
88#define udevwarn(s) _usbh_dbg_dev(s)
89#define uepwarn(s) _usbh_dbg_ep(3, s)
90#define uurbwarn(s) _usbh_dbg_urb(3, s)
91#define uwarnf(f, ...) _usbh_dbgf_host(f, ##__VA_ARGS__)
92#define uportwarnf(f, ...) _usbh_dbgf_port(f, ##__VA_ARGS__)
93#define udevwarnf(f, ...) _usbh_dbgf_dev(f, ##__VA_ARGS__)
94#define uepwarnf(f, ...) _usbh_dbgf_ep(f, 3, ##__VA_ARGS__)
95#define uurbwarnf(f, ...) _usbh_dbgf_urb(f, 3, ##__VA_ARGS__)
96#else
97#define uwarn(s) _usbh_dbg_dummy
98#define udevwarn(s) _usbh_dbg_dummy
99#define uportwarn(s) _usbh_dbg_dummy
100#define uepwarn(s) _usbh_dbg_dummy
101#define uurbwarn(s) _usbh_dbg_dummy
102#define uwarnf(f, ...) _usbh_dbg_dummy
103#define uportwarnf(f, ...) _usbh_dbg_dummy
104#define udevwarnf(f, ...) _usbh_dbg_dummy
105#define uepwarnf(f, ...) _usbh_dbg_dummy
106#define uurbwarnf(f, ...) _usbh_dbg_dummy
107#endif
108
109
110#if _USBH_DEBUG_HELPER_ENABLE_ERRORS
111#define uerr(s) _usbh_dbg_host(s)
112#define uporterr(s) _usbh_dbg_port(s)
113#define udeverr(s) _usbh_dbg_dev(s)
114#define ueperr(s) _usbh_dbg_ep(3, s)
115#define uurberr(s) _usbh_dbg_urb(3, s)
116#define uerrf(f, ...) _usbh_dbgf_host(f, ##__VA_ARGS__)
117#define uporterrf(f, ...) _usbh_dbgf_port(f, ##__VA_ARGS__)
118#define udeverrf(f, ...) _usbh_dbgf_dev(f, ##__VA_ARGS__)
119#define ueperrf(f, ...) _usbh_dbgf_ep(f, 3, ##__VA_ARGS__)
120#define uurberrf(f, ...) _usbh_dbgf_urb(f, 3, ##__VA_ARGS__)
121#else
122#define uerr(s) _usbh_dbg_dummy
123#define udeverr(s) _usbh_dbg_dummy
124#define uporterr(s) _usbh_dbg_dummy
125#define ueperr(s) _usbh_dbg_dummy
126#define uurberr(s) _usbh_dbg_dummy
127#define uerrf(f, ...) _usbh_dbg_dummy
128#define uporterrf(f, ...) _usbh_dbg_dummy
129#define udeverrf(f, ...) _usbh_dbg_dummy
130#define ueperrf(f, ...) _usbh_dbg_dummy
131#define uurberrf(f, ...) _usbh_dbg_dummy
132#endif
133
134#if defined(_USBH_DEBUG_HELPER_CLASS_DRIVER)
135#if _USBH_DEBUG_HELPER_ENABLE_TRACE
136#define uclassdrvdbg(s) _usbh_dbg_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, s)
137#define uclassdrvdbgf(f, ...) _usbh_dbgf_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, f, ##__VA_ARGS__)
138#else
139#define uclassdrvdbg(s) _usbh_dbg_dummy
140#define uclassdrvdbgf(f, ...) _usbh_dbg_dummy
141#endif
142#if _USBH_DEBUG_HELPER_ENABLE_INFO
143#define uclassdrvinfo(s) _usbh_dbg_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, s)
144#define uclassdrvinfof(f, ...) _usbh_dbgf_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, f, ##__VA_ARGS__)
145#else
146#define uclassdrvinfo(s) _usbh_dbg_dummy
147#define uclassdrvinfof(f, ...) _usbh_dbg_dummy
148#endif
149#if _USBH_DEBUG_HELPER_ENABLE_WARNINGS
150#define uclassdrvwarn(s) _usbh_dbg_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, s)
151#define uclassdrvwarnf(f, ...) _usbh_dbgf_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, f, ##__VA_ARGS__)
152#else
153#define uclassdrvwarn(s) _usbh_dbg_dummy
154#define uclassdrvwarnf(f, ...) _usbh_dbg_dummy
155#endif
156#if _USBH_DEBUG_HELPER_ENABLE_ERRORS
157#define uclassdrverr(s) _usbh_dbg_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, s)
158#define uclassdrverrf(f, ...) _usbh_dbgf_classdrv(_USBH_DEBUG_HELPER_CLASS_DRIVER, f, ##__VA_ARGS__)
159#else
160#define uclassdrverr(s) _usbh_dbg_dummy
161#define uclassdrverrf(f, ...) _usbh_dbg_dummy
162#endif
163#endif
diff --git a/lib/chibios-contrib/os/hal/include/usbh/defs.h b/lib/chibios-contrib/os/hal/include/usbh/defs.h
new file mode 100644
index 000000000..9fed388fe
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/include/usbh/defs.h
@@ -0,0 +1,159 @@
1/*
2 ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
3 Copyright (C) 2015..2019 Diego Ismirlian, (dismirlian(at)google's mail)
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18#ifndef USBH_DEFS_H_
19#define USBH_DEFS_H_
20
21#include "hal.h"
22
23#if HAL_USE_USBH
24
25#include "osal.h"
26
27#ifdef __IAR_SYSTEMS_ICC__
28#define PACKED_STRUCT PACKED_VAR struct
29#else
30#define PACKED_STRUCT struct PACKED_VAR
31#endif
32
33typedef PACKED_STRUCT {
34 uint8_t bLength;
35 uint8_t bDescriptorType;
36 uint16_t bcdUSB;
37 uint8_t bDeviceClass;
38 uint8_t bDeviceSubClass;
39 uint8_t bDeviceProtocol;
40 uint8_t bMaxPacketSize0;
41 uint16_t idVendor;
42 uint16_t idProduct;
43 uint16_t bcdDevice;
44 uint8_t iManufacturer;
45 uint8_t iProduct;
46 uint8_t iSerialNumber;
47 uint8_t bNumConfigurations;
48} usbh_device_descriptor_t;
49#define USBH_DT_DEVICE 0x01
50#define USBH_DT_DEVICE_SIZE 18
51
52typedef PACKED_STRUCT {
53 uint8_t bLength;
54 uint8_t bDescriptorType;
55 uint16_t wTotalLength;
56 uint8_t bNumInterfaces;
57 uint8_t bConfigurationValue;
58 uint8_t iConfiguration;
59 uint8_t bmAttributes;
60 uint8_t bMaxPower;
61} usbh_config_descriptor_t;
62#define USBH_DT_CONFIG 0x02
63#define USBH_DT_CONFIG_SIZE 9
64
65typedef PACKED_STRUCT {
66 uint8_t bLength;
67 uint8_t bDescriptorType;
68 uint16_t wData[1];
69} usbh_string_descriptor_t;
70#define USBH_DT_STRING 0x03
71#define USBH_DT_STRING_SIZE 2
72
73typedef PACKED_STRUCT {
74 uint8_t bLength;
75 uint8_t bDescriptorType;
76 uint8_t bInterfaceNumber;
77 uint8_t bAlternateSetting;
78 uint8_t bNumEndpoints;
79 uint8_t bInterfaceClass;
80 uint8_t bInterfaceSubClass;
81 uint8_t bInterfaceProtocol;
82 uint8_t iInterface;
83} usbh_interface_descriptor_t;
84#define USBH_DT_INTERFACE 0x04
85#define USBH_DT_INTERFACE_SIZE 9
86
87typedef PACKED_STRUCT {
88 uint8_t bLength;
89 uint8_t bDescriptorType;
90 uint8_t bEndpointAddress;
91 uint8_t bmAttributes;
92 uint16_t wMaxPacketSize;
93 uint8_t bInterval;
94} usbh_endpoint_descriptor_t;
95#define USBH_DT_ENDPOINT 0x05
96#define USBH_DT_ENDPOINT_SIZE 7
97
98typedef PACKED_STRUCT {
99 uint8_t bLength;
100 uint8_t bDescriptorType;
101 uint8_t bFirstInterface;
102 uint8_t bInterfaceCount;
103 uint8_t bFunctionClass;
104 uint8_t bFunctionSubClass;
105 uint8_t bFunctionProtocol;
106 uint8_t iFunction;
107} usbh_ia_descriptor_t;
108#define USBH_DT_INTERFACE_ASSOCIATION 0x0b
109#define USBH_DT_INTERFACE_ASSOCIATION_SIZE 8
110
111typedef PACKED_STRUCT {
112 uint8_t bDescLength;
113 uint8_t bDescriptorType;
114 uint8_t bNbrPorts;
115 uint16_t wHubCharacteristics;
116 uint8_t bPwrOn2PwrGood;
117 uint8_t bHubContrCurrent;
118 uint32_t DeviceRemovable;
119} usbh_hub_descriptor_t;
120#define USBH_DT_HUB 0x29
121#define USBH_DT_HUB_SIZE (7 + 4)
122
123typedef PACKED_STRUCT {
124 uint8_t bmRequestType;
125 uint8_t bRequest;
126 uint16_t wValue;
127 uint16_t wIndex;
128 uint16_t wLength;
129} usbh_control_request_t;
130
131
132#define USBH_REQ_GET_STATUS 0x00
133#define USBH_REQ_CLEAR_FEATURE 0x01
134#define USBH_REQ_SET_FEATURE 0x03
135#define USBH_REQ_SET_ADDRESS 0x05
136#define USBH_REQ_GET_DESCRIPTOR 0x06
137#define USBH_REQ_SET_DESCRIPTOR 0x07
138#define USBH_REQ_GET_CONFIGURATION 0x08
139#define USBH_REQ_SET_CONFIGURATION 0x09
140#define USBH_REQ_GET_INTERFACE 0x0A
141#define USBH_REQ_SET_INTERFACE 0x0B
142#define USBH_REQ_SYNCH_FRAME 0x0C
143
144#define USBH_REQTYPE_DIR_IN 0x80
145#define USBH_REQTYPE_DIR_OUT 0x00
146
147#define USBH_REQTYPE_TYPE_STANDARD 0x00
148#define USBH_REQTYPE_TYPE_CLASS 0x20
149#define USBH_REQTYPE_TYPE_VENDOR 0x40
150
151#define USBH_REQTYPE_RECIP_DEVICE 0x00
152#define USBH_REQTYPE_RECIP_INTERFACE 0x01
153#define USBH_REQTYPE_RECIP_ENDPOINT 0x02
154#define USBH_REQTYPE_RECIP_OTHER 0x03
155
156#endif
157
158
159#endif /* USBH_DEFS_H_ */
diff --git a/lib/chibios-contrib/os/hal/include/usbh/desciter.h b/lib/chibios-contrib/os/hal/include/usbh/desciter.h
new file mode 100644
index 000000000..bab2f0457
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/include/usbh/desciter.h
@@ -0,0 +1,63 @@
1/*
2 ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
3 Copyright (C) 2015..2019 Diego Ismirlian, (dismirlian(at)google's mail)
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18
19#ifndef USBH_DESCITER_H_
20#define USBH_DESCITER_H_
21
22#include "hal.h"
23
24#if HAL_USE_USBH
25
26#include "usbh/defs.h"
27
28
29/* DESCRIPTOR PARSING */
30#define _generic_iterator_fields \
31 const uint8_t *curr; \
32 uint16_t rem; \
33 bool valid;
34
35typedef struct {
36 _generic_iterator_fields
37} generic_iterator_t;
38
39typedef struct {
40 _generic_iterator_fields
41 const usbh_ia_descriptor_t *iad;
42} if_iterator_t;
43
44void cfg_iter_init(generic_iterator_t *icfg, const uint8_t *buff, uint16_t rem);
45void if_iter_init(if_iterator_t *iif, const generic_iterator_t *icfg);
46void ep_iter_init(generic_iterator_t *iep, const if_iterator_t *iif);
47void cs_iter_init(generic_iterator_t *ics, const generic_iterator_t *iter);
48void if_iter_next(if_iterator_t *iif);
49void ep_iter_next(generic_iterator_t *iep);
50void cs_iter_next(generic_iterator_t *ics);
51static inline const usbh_config_descriptor_t *cfg_get(generic_iterator_t *icfg) {
52 return (const usbh_config_descriptor_t *)icfg->curr;
53}
54static inline const usbh_interface_descriptor_t *if_get(if_iterator_t *iif) {
55 return (const usbh_interface_descriptor_t *)iif->curr;
56}
57static inline const usbh_endpoint_descriptor_t *ep_get(generic_iterator_t *iep) {
58 return (const usbh_endpoint_descriptor_t *)iep->curr;
59}
60
61#endif
62
63#endif /* USBH_DESCITER_H_ */
diff --git a/lib/chibios-contrib/os/hal/include/usbh/dev/aoa.h b/lib/chibios-contrib/os/hal/include/usbh/dev/aoa.h
new file mode 100644
index 000000000..1f36370fb
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/include/usbh/dev/aoa.h
@@ -0,0 +1,153 @@
1/*
2 ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
3 Copyright (C) 2015..2019 Diego Ismirlian, (dismirlian(at)google's mail)
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18#ifndef USBH_AOA_H_
19#define USBH_AOA_H_
20
21#include "hal_usbh.h"
22
23#if HAL_USE_USBH && HAL_USBH_USE_AOA
24
25/*===========================================================================*/
26/* Driver pre-compile time settings. */
27/*===========================================================================*/
28
29/*===========================================================================*/
30/* Derived constants and error checks. */
31/*===========================================================================*/
32
33/*===========================================================================*/
34/* Driver data structures and types. */
35/*===========================================================================*/
36
37typedef enum {
38 USBHAOA_CHANNEL_STATE_UNINIT = 0,
39 USBHAOA_CHANNEL_STATE_STOP = 1,
40 USBHAOA_CHANNEL_STATE_ACTIVE = 2,
41 USBHAOA_CHANNEL_STATE_READY = 3
42} usbhaoa_channel_state_t;
43
44typedef enum {
45 USBHAOA_STATE_UNINIT = 0,
46 USBHAOA_STATE_STOP = 1,
47 USBHAOA_STATE_ACTIVE = 2,
48 USBHAOA_STATE_READY = 3
49} usbhaoa_state_t;
50
51typedef enum {
52 USBHAOA_AUDIO_MODE_DISABLED = 0,
53 USBHAOA_AUDIO_MODE_2CH_16BIT_PCM_44100 = 1,
54} usbhaoa_audio_mode_t;
55
56typedef struct {
57 struct _aoa_channel_cfg {
58 const char *manufacturer;
59 const char *model;
60 const char *description;
61 const char *version;
62 const char *uri;
63 const char *serial;
64 } channel;
65
66 struct _aoa_audio_cfg {
67 usbhaoa_audio_mode_t mode;
68 } audio;
69
70} USBHAOAConfig;
71
72#define _aoa_driver_methods \
73 _base_asynchronous_channel_methods
74
75struct AOADriverVMT {
76 _aoa_driver_methods
77};
78
79typedef struct USBHAOAChannel USBHAOAChannel;
80typedef struct USBHAOADriver USBHAOADriver;
81
82struct USBHAOAChannel {
83 /* inherited from abstract asyncrhonous channel driver */
84 const struct AOADriverVMT *vmt;
85 _base_asynchronous_channel_data
86
87 usbh_ep_t epin;
88 usbh_urb_t iq_urb;
89 threads_queue_t iq_waiting;
90 uint32_t iq_counter;
91 USBH_DECLARE_STRUCT_MEMBER(uint8_t iq_buff[64]);
92 uint8_t *iq_ptr;
93
94 usbh_ep_t epout;
95 usbh_urb_t oq_urb;
96 threads_queue_t oq_waiting;
97 uint32_t oq_counter;
98 USBH_DECLARE_STRUCT_MEMBER(uint8_t oq_buff[64]);
99 uint8_t *oq_ptr;
100
101 virtual_timer_t vt;
102
103 usbhaoa_channel_state_t state;
104};
105
106struct USBHAOADriver {
107 /* inherited from abstract class driver */
108 _usbh_base_classdriver_data
109
110 USBHAOAChannel channel;
111
112 usbhaoa_state_t state;
113
114};
115
116#define USBHAOA_ACCESSORY_STRING_MANUFACTURER 0
117#define USBHAOA_ACCESSORY_STRING_MODEL 1
118#define USBHAOA_ACCESSORY_STRING_DESCRIPTION 2
119#define USBHAOA_ACCESSORY_STRING_VERSION 3
120#define USBHAOA_ACCESSORY_STRING_URI 4
121#define USBHAOA_ACCESSORY_STRING_SERIAL 5
122
123typedef bool (*usbhaoa_filter_callback_t)(usbh_device_t *dev, const uint8_t *descriptor, uint16_t rem, USBHAOAConfig *config);
124
125/*===========================================================================*/
126/* Driver macros. */
127/*===========================================================================*/
128#define usbhaoaStop(aoap)
129
130#define usbhaoaGetState(aoap) ((aoap)->state)
131
132#define usbhaoaGetChannelState(aoap) ((aoap)->channel.state)
133#define usbhaoaGetHost(aoap) ((aoap)->dev->host)
134
135/*===========================================================================*/
136/* External declarations. */
137/*===========================================================================*/
138extern USBHAOADriver USBHAOAD[HAL_USBHAOA_MAX_INSTANCES];
139
140#ifdef __cplusplus
141extern "C" {
142#endif
143 /* AOA device driver */
144 void usbhaoaChannelStart(USBHAOADriver *aoap);
145 void usbhaoaChannelStop(USBHAOADriver *aoap);
146#ifdef __cplusplus
147}
148#endif
149
150
151#endif
152
153#endif /* USBH_AOA_H_ */
diff --git a/lib/chibios-contrib/os/hal/include/usbh/dev/ftdi.h b/lib/chibios-contrib/os/hal/include/usbh/dev/ftdi.h
new file mode 100644
index 000000000..c27950693
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/include/usbh/dev/ftdi.h
@@ -0,0 +1,151 @@
1/*
2 ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
3 Copyright (C) 2015..2019 Diego Ismirlian, (dismirlian(at)google's mail)
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18#ifndef USBH_FTDI_H_
19#define USBH_FTDI_H_
20
21#include "hal_usbh.h"
22
23#if HAL_USE_USBH && HAL_USBH_USE_FTDI
24
25/*===========================================================================*/
26/* Driver pre-compile time settings. */
27/*===========================================================================*/
28
29/*===========================================================================*/
30/* Derived constants and error checks. */
31/*===========================================================================*/
32#define USBHFTDI_FRAMING_DATABITS_7 (0x7 << 0)
33#define USBHFTDI_FRAMING_DATABITS_8 (0x8 << 0)
34#define USBHFTDI_FRAMING_PARITY_NONE (0x0 << 8)
35#define USBHFTDI_FRAMING_PARITY_NONE (0x0 << 8)
36#define USBHFTDI_FRAMING_PARITY_ODD (0x1 << 8)
37#define USBHFTDI_FRAMING_PARITY_EVEN (0x2 << 8)
38#define USBHFTDI_FRAMING_PARITY_MARK (0x3 << 8)
39#define USBHFTDI_FRAMING_PARITY_SPACE (0x4 << 8)
40#define USBHFTDI_FRAMING_STOP_BITS_1 (0x0 << 11)
41#define USBHFTDI_FRAMING_STOP_BITS_15 (0x1 << 11)
42#define USBHFTDI_FRAMING_STOP_BITS_2 (0x2 << 11)
43
44#define USBHFTDI_HANDSHAKE_NONE (0x0)
45#define USBHFTDI_HANDSHAKE_RTS_CTS (0x1)
46#define USBHFTDI_HANDSHAKE_DTR_DSR (0x2)
47#define USBHFTDI_HANDSHAKE_XON_XOFF (0x4)
48
49
50
51/*===========================================================================*/
52/* Driver data structures and types. */
53/*===========================================================================*/
54typedef struct {
55 uint32_t speed;
56 uint16_t framing;
57 uint8_t handshake;
58 uint8_t xon_character;
59 uint8_t xoff_character;
60} USBHFTDIPortConfig;
61
62typedef enum {
63 USBHFTDI_TYPE_A,
64 USBHFTDI_TYPE_B,
65 USBHFTDI_TYPE_H,
66} usbhftdi_type_t;
67
68typedef enum {
69 USBHFTDIP_STATE_UNINIT = 0,
70 USBHFTDIP_STATE_STOP = 1,
71 USBHFTDIP_STATE_ACTIVE = 2,
72 USBHFTDIP_STATE_READY = 3
73} usbhftdip_state_t;
74
75
76#define _ftdi_port_driver_methods \
77 _base_asynchronous_channel_methods
78
79struct FTDIPortDriverVMT {
80 _ftdi_port_driver_methods
81};
82
83typedef struct USBHFTDIPortDriver USBHFTDIPortDriver;
84typedef struct USBHFTDIDriver USBHFTDIDriver;
85
86struct USBHFTDIPortDriver {
87 /* inherited from abstract asyncrhonous channel driver */
88 const struct FTDIPortDriverVMT *vmt;
89 _base_asynchronous_channel_data
90
91 USBHFTDIDriver *ftdip;
92
93 usbhftdip_state_t state;
94
95 usbh_ep_t epin;
96 usbh_urb_t iq_urb;
97 threads_queue_t iq_waiting;
98 uint32_t iq_counter;
99 USBH_DECLARE_STRUCT_MEMBER(uint8_t iq_buff[64]);
100 uint8_t *iq_ptr;
101
102
103 usbh_ep_t epout;
104 usbh_urb_t oq_urb;
105 threads_queue_t oq_waiting;
106 uint32_t oq_counter;
107 USBH_DECLARE_STRUCT_MEMBER(uint8_t oq_buff[64]);
108 uint8_t *oq_ptr;
109
110 virtual_timer_t vt;
111 uint8_t ifnum;
112
113 USBHFTDIPortDriver *next;
114};
115
116struct USBHFTDIDriver {
117 /* inherited from abstract class driver */
118 _usbh_base_classdriver_data
119
120 usbhftdi_type_t type;
121 USBHFTDIPortDriver *ports;
122
123 mutex_t mtx;
124};
125
126/*===========================================================================*/
127/* Driver macros. */
128/*===========================================================================*/
129#define usbhftdipGetState(ftdipp) ((ftdipp)->state)
130#define usbhftdipGetHost(ftdipp) ((ftdipp)->ftdip->dev->host)
131
132/*===========================================================================*/
133/* External declarations. */
134/*===========================================================================*/
135extern USBHFTDIDriver USBHFTDID[HAL_USBHFTDI_MAX_INSTANCES];
136extern USBHFTDIPortDriver FTDIPD[HAL_USBHFTDI_MAX_PORTS];
137
138#ifdef __cplusplus
139extern "C" {
140#endif
141 /* FTDI port driver */
142 void usbhftdipStart(USBHFTDIPortDriver *ftdipp, const USBHFTDIPortConfig *config);
143 void usbhftdipStop(USBHFTDIPortDriver *ftdipp);
144#ifdef __cplusplus
145}
146#endif
147
148
149#endif
150
151#endif /* USBH_FTDI_H_ */
diff --git a/lib/chibios-contrib/os/hal/include/usbh/dev/hid.h b/lib/chibios-contrib/os/hal/include/usbh/dev/hid.h
new file mode 100644
index 000000000..de001ab3c
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/include/usbh/dev/hid.h
@@ -0,0 +1,144 @@
1/*
2 ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
3 Copyright (C) 2015..2019 Diego Ismirlian, (dismirlian(at)google's mail)
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18#ifndef USBH_HID_H_
19#define USBH_HID_H_
20
21#include "hal_usbh.h"
22
23#if HAL_USE_USBH && HAL_USBH_USE_HID
24
25/* TODO:
26 *
27 */
28
29
30/*===========================================================================*/
31/* Driver pre-compile time settings. */
32/*===========================================================================*/
33#if !defined(HAL_USBHHID_USE_INTERRUPT_OUT)
34#define HAL_USBHHID_USE_INTERRUPT_OUT FALSE
35#endif
36
37/*===========================================================================*/
38/* Derived constants and error checks. */
39/*===========================================================================*/
40
41
42/*===========================================================================*/
43/* Driver data structures and types. */
44/*===========================================================================*/
45
46typedef enum {
47 USBHHID_STATE_UNINIT = 0,
48 USBHHID_STATE_STOP = 1,
49 USBHHID_STATE_ACTIVE = 2,
50 USBHHID_STATE_READY = 3
51} usbhhid_state_t;
52
53typedef enum {
54 USBHHID_DEVTYPE_GENERIC = 0,
55 USBHHID_DEVTYPE_BOOT_KEYBOARD = 1,
56 USBHHID_DEVTYPE_BOOT_MOUSE = 2,
57} usbhhid_devtype_t;
58
59typedef enum {
60 USBHHID_REPORTTYPE_INPUT = 1,
61 USBHHID_REPORTTYPE_OUTPUT = 2,
62 USBHHID_REPORTTYPE_FEATURE = 3,
63} usbhhid_reporttype_t;
64
65typedef enum {
66 USBHHID_PROTOCOL_BOOT = 0,
67 USBHHID_PROTOCOL_REPORT = 1,
68} usbhhid_protocol_t;
69
70typedef struct USBHHIDDriver USBHHIDDriver;
71typedef struct USBHHIDConfig USBHHIDConfig;
72
73typedef void (*usbhhid_report_callback)(USBHHIDDriver *hidp, uint16_t len);
74
75struct USBHHIDConfig {
76 usbhhid_report_callback cb_report;
77 void *report_buffer;
78 uint16_t report_len;
79 usbhhid_protocol_t protocol;
80};
81
82struct USBHHIDDriver {
83 /* inherited from abstract class driver */
84 _usbh_base_classdriver_data
85
86 usbh_ep_t epin;
87#if HAL_USBHHID_USE_INTERRUPT_OUT
88 usbh_ep_t epout;
89#endif
90 uint8_t ifnum;
91
92 usbhhid_devtype_t type;
93 usbhhid_state_t state;
94
95 usbh_urb_t in_urb;
96
97 const USBHHIDConfig *config;
98
99 semaphore_t sem;
100};
101
102
103/*===========================================================================*/
104/* Driver macros. */
105/*===========================================================================*/
106
107
108/*===========================================================================*/
109/* External declarations. */
110/*===========================================================================*/
111
112extern USBHHIDDriver USBHHIDD[HAL_USBHHID_MAX_INSTANCES];
113
114#ifdef __cplusplus
115extern "C" {
116#endif
117 /* HID Common API */
118 usbh_urbstatus_t usbhhidGetReport(USBHHIDDriver *hidp,
119 uint8_t report_id, usbhhid_reporttype_t report_type,
120 void *data, uint16_t len);
121 usbh_urbstatus_t usbhhidSetReport(USBHHIDDriver *hidp,
122 uint8_t report_id, usbhhid_reporttype_t report_type,
123 const void *data, uint16_t len);
124 usbh_urbstatus_t usbhhidGetIdle(USBHHIDDriver *hidp, uint8_t report_id, uint8_t *duration);
125 usbh_urbstatus_t usbhhidSetIdle(USBHHIDDriver *hidp, uint8_t report_id, uint8_t duration);
126 usbh_urbstatus_t usbhhidGetProtocol(USBHHIDDriver *hidp, uint8_t *protocol);
127 usbh_urbstatus_t usbhhidSetProtocol(USBHHIDDriver *hidp, uint8_t protocol);
128
129 static inline uint8_t usbhhidGetType(USBHHIDDriver *hidp) {
130 return hidp->type;
131 }
132
133 static inline usbhhid_state_t usbhhidGetState(USBHHIDDriver *hidp) {
134 return hidp->state;
135 }
136
137 void usbhhidStart(USBHHIDDriver *hidp, const USBHHIDConfig *cfg);
138#ifdef __cplusplus
139}
140#endif
141
142#endif
143
144#endif /* USBH_HID_H_ */
diff --git a/lib/chibios-contrib/os/hal/include/usbh/dev/hub.h b/lib/chibios-contrib/os/hal/include/usbh/dev/hub.h
new file mode 100644
index 000000000..4e7493b02
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/include/usbh/dev/hub.h
@@ -0,0 +1,137 @@
1/*
2 ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
3 Copyright (C) 2015..2019 Diego Ismirlian, (dismirlian(at)google's mail)
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18#ifndef USBH_HUB_H_
19#define USBH_HUB_H_
20
21#include "hal_usbh.h"
22
23#if HAL_USE_USBH
24#if HAL_USBH_USE_HUB
25
26struct USBHHubDriver {
27 /* inherited from abstract class driver */
28 _usbh_base_classdriver_data
29
30 struct list_head node;
31
32 usbh_ep_t epint;
33 usbh_urb_t urb;
34
35 USBH_DECLARE_STRUCT_MEMBER(uint8_t scbuff[4]);
36 volatile uint32_t statuschange;
37 uint16_t status;
38 uint16_t c_status;
39
40 usbh_port_t *ports;
41
42 USBH_DECLARE_STRUCT_MEMBER(usbh_hub_descriptor_t hubDesc);
43
44 /* Low level part */
45 _usbh_hub_ll_data
46
47};
48
49extern USBHHubDriver USBHHUBD[HAL_USBHHUB_MAX_INSTANCES];
50
51
52usbh_urbstatus_t usbhhubControlRequest(USBHDriver *host, USBHHubDriver *hub,
53 uint8_t bmRequestType,
54 uint8_t bRequest,
55 uint16_t wValue,
56 uint16_t wIndex,
57 uint16_t wLength,
58 uint8_t *buf);
59
60
61static inline usbh_urbstatus_t usbhhubClearFeaturePort(usbh_port_t *port, uint8_t feature) {
62 return usbhhubControlRequest(port->device.host, port->hub,
63 USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER,
64 USBH_REQ_CLEAR_FEATURE,
65 feature,
66 port->number,
67 0,
68 0);
69}
70
71static inline usbh_urbstatus_t usbhhubClearFeatureHub(USBHDriver *host, USBHHubDriver *hub, uint8_t feature) {
72 return usbhhubControlRequest(host, hub,
73 USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_DEVICE,
74 USBH_REQ_CLEAR_FEATURE,
75 feature,
76 0,
77 0,
78 0);
79}
80
81static inline usbh_urbstatus_t usbhhubSetFeaturePort(usbh_port_t *port, uint8_t feature) {
82 return usbhhubControlRequest(port->device.host, port->hub,
83 USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER,
84 USBH_REQ_SET_FEATURE,
85 feature,
86 port->number,
87 0,
88 0);
89}
90
91#else
92
93static inline usbh_urbstatus_t usbhhubControlRequest(USBHDriver *host,
94 uint8_t bmRequestType,
95 uint8_t bRequest,
96 uint16_t wValue,
97 uint16_t wIndex,
98 uint16_t wLength,
99 uint8_t *buf) {
100 return usbh_lld_root_hub_request(host, bmRequestType, bRequest, wValue, wIndex, wLength, buf);
101}
102
103static inline usbh_urbstatus_t usbhhubClearFeaturePort(usbh_port_t *port, uint8_t feature) {
104 return usbhhubControlRequest(port->device.host,
105 USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER,
106 USBH_REQ_CLEAR_FEATURE,
107 feature,
108 port->number,
109 0,
110 0);
111}
112
113static inline usbh_urbstatus_t usbhhubClearFeatureHub(USBHDriver *host, uint8_t feature) {
114 return usbhhubControlRequest(host,
115 USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_DEVICE,
116 USBH_REQ_CLEAR_FEATURE,
117 feature,
118 0,
119 0,
120 0);
121}
122
123static inline usbh_urbstatus_t usbhhubSetFeaturePort(usbh_port_t *port, uint8_t feature) {
124 return usbhhubControlRequest(port->device.host,
125 USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER,
126 USBH_REQ_SET_FEATURE,
127 feature,
128 port->number,
129 0,
130 0);
131}
132
133#endif
134
135#endif
136
137#endif /* USBH_HUB_H_ */
diff --git a/lib/chibios-contrib/os/hal/include/usbh/dev/msd.h b/lib/chibios-contrib/os/hal/include/usbh/dev/msd.h
new file mode 100644
index 000000000..6b10b469e
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/include/usbh/dev/msd.h
@@ -0,0 +1,105 @@
1/*
2 ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
3 Copyright (C) 2015..2019 Diego Ismirlian, (dismirlian(at)google's mail)
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18#ifndef USBH_MSD_H_
19#define USBH_MSD_H_
20
21#include "hal_usbh.h"
22
23#if HAL_USE_USBH && HAL_USBH_USE_MSD
24
25/* TODO:
26 *
27 * - Implement of conditional compilation of multiple-luns per instance.
28 *
29 */
30
31
32/*===========================================================================*/
33/* Driver pre-compile time settings. */
34/*===========================================================================*/
35
36
37/*===========================================================================*/
38/* Derived constants and error checks. */
39/*===========================================================================*/
40
41
42/*===========================================================================*/
43/* Driver data structures and types. */
44/*===========================================================================*/
45
46#define _usbhmsd_driver_methods \
47 _base_block_device_methods
48
49struct USBHMassStorageDriverVMT {
50 _usbhmsd_driver_methods
51};
52
53typedef struct USBHMassStorageLUNDriver USBHMassStorageLUNDriver;
54typedef struct USBHMassStorageDriver USBHMassStorageDriver;
55
56struct USBHMassStorageLUNDriver {
57 /* inherited from abstract block driver */
58 const struct USBHMassStorageDriverVMT *vmt;
59 _base_block_device_data
60
61 /* for serializing access to the LUN driver */
62 semaphore_t sem;
63
64 BlockDeviceInfo info;
65 USBHMassStorageDriver *msdp;
66
67 USBHMassStorageLUNDriver *next;
68};
69
70
71/*===========================================================================*/
72/* Driver macros. */
73/*===========================================================================*/
74
75/*===========================================================================*/
76/* External declarations. */
77/*===========================================================================*/
78
79extern USBHMassStorageLUNDriver MSBLKD[HAL_USBHMSD_MAX_LUNS];
80
81#ifdef __cplusplus
82extern "C" {
83#endif
84 /* Mass Storage LUN Driver (block driver) */
85// void usbhmsdLUNStart(USBHMassStorageLUNDriver *lunp);
86// void usbhmsdLUNStop(USBHMassStorageLUNDriver *lunp);
87 bool usbhmsdLUNConnect(USBHMassStorageLUNDriver *lunp);
88 bool usbhmsdLUNDisconnect(USBHMassStorageLUNDriver *lunp);
89 bool usbhmsdLUNRead(USBHMassStorageLUNDriver *lunp, uint32_t startblk,
90 uint8_t *buffer, uint32_t n);
91 bool usbhmsdLUNWrite(USBHMassStorageLUNDriver *lunp, uint32_t startblk,
92 const uint8_t *buffer, uint32_t n);
93 bool usbhmsdLUNSync(USBHMassStorageLUNDriver *lunp);
94 bool usbhmsdLUNGetInfo(USBHMassStorageLUNDriver *lunp, BlockDeviceInfo *bdip);
95 bool usbhmsdLUNIsInserted(USBHMassStorageLUNDriver *lunp);
96 bool usbhmsdLUNIsProtected(USBHMassStorageLUNDriver *lunp);
97
98 USBHDriver *usbhmsdLUNGetHost(const USBHMassStorageLUNDriver *lunp);
99#ifdef __cplusplus
100}
101#endif
102
103#endif
104
105#endif /* USBH_MSD_H_ */
diff --git a/lib/chibios-contrib/os/hal/include/usbh/dev/uvc.h b/lib/chibios-contrib/os/hal/include/usbh/dev/uvc.h
new file mode 100644
index 000000000..7116c91c8
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/include/usbh/dev/uvc.h
@@ -0,0 +1,459 @@
1/*
2 ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
3 Copyright (C) 2015..2019 Diego Ismirlian, (dismirlian(at)google's mail)
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 */
17
18#ifndef USBH_INCLUDE_USBH_UVC_H_
19#define USBH_INCLUDE_USBH_UVC_H_
20
21#include "hal_usbh.h"
22
23#if HAL_USE_USBH && HAL_USBH_USE_UVC
24
25#include "usbh/desciter.h"
26
27/*===========================================================================*/
28/* Driver pre-compile time settings. */
29/*===========================================================================*/
30
31
32/*===========================================================================*/
33/* Derived constants and error checks. */
34/*===========================================================================*/
35#define USBHUVC_MAX_STATUS_PACKET_SZ 16
36
37
38/*===========================================================================*/
39/* Driver data structures and types. */
40/*===========================================================================*/
41
42
43typedef enum {
44 UVC_CS_INTERFACE = 0x24,
45 UVC_CS_ENDPOINT = 0x25
46} usbh_uvc_cstype_t;
47
48typedef enum {
49 UVC_CC_VIDEO = 0x0e
50} usbh_uvc_cctype_t;
51
52typedef enum {
53 UVC_SC_UNKNOWN = 0x00,
54 UVC_SC_VIDEOCONTROL,
55 UVC_SC_VIDEOSTREAMING,
56 UVC_SC_VIDEO_INTERFACE_COLLECTION
57} usbh_uvc_sctype_t;
58
59typedef enum {
60 UVC_VC_UNDEF = 0x00,
61 UVC_VC_HEADER,
62 UVC_VC_INPUT_TERMINAL,
63 UVC_VC_OUTPUT_TERMINAL,
64 UVC_VC_SELECTOR_UNIT,
65 UVC_VC_PROCESSING_UNIT,
66 UVC_VC_EXTENSION_UNIT
67} usbh_uvc_vctype_t;
68
69typedef enum {
70 UVC_VS_UNDEF = 0x00,
71 UVC_VS_INPUT_HEADER,
72 UVC_VS_OUTPUT_HEADER,
73 UVC_VS_STILL_IMAGE_FRAME,
74 UVC_VS_FORMAT_UNCOMPRESSED,
75 UVC_VS_FRAME_UNCOMPRESSED,
76 UVC_VS_FORMAT_MJPEG,
77 UVC_VS_FRAME_MJPEG,
78 UVC_VS_RESERVED_0,
79 UVC_VS_RESERVED_1,
80 UVC_VS_FORMAT_MPEG2TS,
81 UVC_VS_RESERVED_2,
82 UVC_VS_FORMAT_DV,
83 UVC_VS_COLOR_FORMAT,
84 UVC_VS_RESERVED_3,
85 UVC_VS_RESERVED_4,
86 UVC_VS_FORMAT_FRAME_BASED,
87 UVC_VS_FRAME_FRAME_BASED,
88 UVC_VS_FORMAT_STREAM_BASED
89} usbh_uvc_vstype_t;
90
91typedef enum {
92 UVC_TT_VENDOR_SPECIFIC = 0x0100,
93 UVC_TT_STREAMING = 0x0101,
94 UVC_ITT_VENDOR_SPECIFIC = 0x0200,
95 UVC_ITT_CAMERA = 0x0201,
96 UVC_ITT_MEDIA_TRANSPORT_INPUT = 0x0202,
97 UVC_OTT_VENDOR_SPECIFIC = 0x0300,
98 UVC_OTT_DISPLAY = 0x0301,
99 UVC_OTT_MEDIA_TRANSPORT = 0x0302
100} usbh_uvc_tttype_t;
101
102typedef enum {
103 UVC_SET_CUR = 0x01,
104 UVC_GET_CUR = 0x81,
105 UVC_GET_MIN = 0x82,
106 UVC_GET_MAX = 0x83,
107 UVC_GET_RES = 0x84,
108 UVC_GET_LEN = 0x85,
109 UVC_GET_INFO = 0x86,
110 UVC_GET_DEF = 0x87
111} usbh_uvc_ctrlops_t;
112
113typedef enum {
114 UVC_CTRL_VC_CONTROL_UNDEFINED = 0x00,
115 UVC_CTRL_VC_VIDEO_POWER_MODE_CONTROL = 0x01,
116 UVC_CTRL_VC_REQUEST_ERROR_CODE_CONTROL = 0x02,
117} usbh_uvc_ctrl_vc_interface_controls_t;
118
119typedef enum {
120 UVC_CTRL_SU_CONTROL_UNDEFINED = 0x00,
121 UVC_CTRL_SU_INPUT_SELECT_CONTROL = 0x01,
122} usbh_uvc_ctrl_vc_selectorunit_controls_t;
123
124typedef enum {
125 UVC_CTRL_CT_CONTROL_UNDEFINED = 0x00,
126 UVC_CTRL_CT_SCANNING_MODE_CONTROL = 0x01,
127 UVC_CTRL_CT_AE_MODE_CONTROL = 0x02,
128 UVC_CTRL_CT_AE_PRIORITY_CONTROL = 0x03,
129 UVC_CTRL_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL = 0x04,
130 UVC_CTRL_CT_EXPOSURE_TIME_RELATIVE_CONTROL = 0x05,
131 UVC_CTRL_CT_FOCUS_ABSOLUTE_CONTROL = 0x06,
132 UVC_CTRL_CT_FOCUS_RELATIVE_CONTROL = 0x07,
133 UVC_CTRL_CT_FOCUS_AUTO_CONTROL = 0x08,
134 UVC_CTRL_CT_IRIS_ABSOLUTE_CONTROL = 0x09,
135 UVC_CTRL_CT_IRIS_RELATIVE_CONTROL = 0x0A,
136 UVC_CTRL_CT_ZOOM_ABSOLUTE_CONTROL = 0x0B,
137 UVC_CTRL_CT_ZOOM_RELATIVE_CONTROL = 0x0C,
138 UVC_CTRL_CT_PANTILT_ABSOLUTE_CONTROL = 0x0D,
139 UVC_CTRL_CT_PANTILT_RELATIVE_CONTROL = 0x0E,
140 UVC_CTRL_CT_ROLL_ABSOLUTE_CONTROL = 0x0F,
141 UVC_CTRL_CT_ROLL_RELATIVE_CONTROL = 0x10,
142 UVC_CTRL_CT_PRIVACY_CONTROL = 0x11
143} usbh_uvc_ctrl_vc_cameraterminal_controls_t;
144
145typedef enum {
146 UVC_CTRL_PU_CONTROL_UNDEFINED = 0x00,
147 UVC_CTRL_PU_BACKLIGHT_COMPENSATION_CONTROL = 0x01,
148 UVC_CTRL_PU_BRIGHTNESS_CONTROL = 0x02,
149 UVC_CTRL_PU_CONTRAST_CONTROL = 0x03,
150 UVC_CTRL_PU_GAIN_CONTROL = 0x04,
151 UVC_CTRL_PU_POWER_LINE_FREQUENCY_CONTROL = 0x05,
152 UVC_CTRL_PU_HUE_CONTROL = 0x06,
153 UVC_CTRL_PU_SATURATION_CONTROL = 0x07,
154 UVC_CTRL_PU_SHARPNESS_CONTROL = 0x08,
155 UVC_CTRL_PU_GAMMA_CONTROL = 0x09,
156 UVC_CTRL_PU_WHITE_BALANCE_TEMPERATURE_CONTROL = 0x0A,
157 UVC_CTRL_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL = 0x0B,
158 UVC_CTRL_PU_WHITE_BALANCE_COMPONENT_CONTROL = 0x0C,
159 UVC_CTRL_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL = 0x0D,
160 UVC_CTRL_PU_DIGITAL_MULTIPLIER_CONTROL = 0x0E,
161 UVC_CTRL_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL = 0x0F,
162 UVC_CTRL_PU_HUE_AUTO_CONTROL = 0x10,
163 UVC_CTRL_PU_ANALOG_VIDEO_STANDARD_CONTROL = 0x11,
164 UVC_CTRL_PU_ANALOG_LOCK_STATUS_CONTROL = 0x12,
165} usbh_uvc_ctrl_vc_processingunit_controls_t;
166
167typedef enum {
168 UVC_CTRL_VS_CONTROL_UNDEFINED = 0x00,
169 UVC_CTRL_VS_PROBE_CONTROL = 0x01,
170 UVC_CTRL_VS_COMMIT_CONTROL = 0x02,
171 UVC_CTRL_VS_STILL_PROBE_CONTROL = 0x03,
172 UVC_CTRL_VS_STILL_COMMIT_CONTROL = 0x04,
173 UVC_CTRL_VS_STILL_IMAGE_TRIGGER_CONTROL = 0x05,
174 UVC_CTRL_VS_STREAM_ERROR_CODE_CONTROL = 0x06,
175 UVC_CTRL_VS_GENERATE_KEY_FRAME_CONTROL = 0x07,
176 UVC_CTRL_VS_UPDATE_FRAME_SEGMENT_CONTROL = 0x08,
177 UVC_CTRL_VS_SYNCH_DELAY_CONTROL = 0x09
178} usbh_uvc_ctrl_vs_interface_controls_t;
179
180
181typedef PACKED_STRUCT {
182 uint8_t bLength;
183 uint8_t bDescriptorType;
184 uint8_t bDescriptorSubType;
185 uint8_t bFormatIndex;
186 uint8_t bNumFrameDescriptors;
187 uint8_t bmFlags;
188 uint8_t bDefaultFrameIndex;
189 uint8_t bAspectRatioX;
190 uint8_t bAspectRatioY;
191 uint8_t bmInterfaceFlags;
192 uint8_t bCopyProtect;
193} usbh_uvc_format_mjpeg_t;
194
195typedef PACKED_STRUCT {
196 uint8_t bLength;
197 uint8_t bDescriptorType;
198 uint8_t bDescriptorSubType;
199 uint8_t bFrameIndex;
200 uint8_t bmCapabilities;
201 uint16_t wWidth;
202 uint16_t wHeight;
203 uint32_t dwMinBitRate;
204 uint32_t dwMaxBitRate;
205 uint32_t dwMaxVideoFrameBufferSize;
206 uint32_t dwDefaultFrameInterval;
207 uint8_t bFrameIntervalType;
208 uint32_t dwFrameInterval[0];
209} usbh_uvc_frame_mjpeg_t;
210
211
212typedef PACKED_STRUCT {
213 uint8_t bLength;
214 uint8_t bDescriptorType;
215 uint8_t bDescriptorSubType;
216 uint8_t bFrameIndex;
217 uint8_t bmCapabilities;
218 uint16_t wWidth;
219 uint16_t wHeight;
220 uint32_t dwMinBitRate;
221 uint32_t dwMaxBitRate;
222 uint32_t dwMaxVideoFrameBufferSize;
223 uint32_t dwDefaultFrameInterval;
224 uint8_t bFrameIntervalType;
225 uint32_t dwFrameInterval[0];
226} usbh_uvc_frame_uncompressed_t;
227
228typedef PACKED_STRUCT {
229 uint8_t bLength;
230 uint8_t bDescriptorType;
231 uint8_t bDescriptorSubType;
232 uint8_t bFormatIndex;
233 uint8_t bNumFrameDescriptors;
234 uint8_t guidFormat[16];
235 uint8_t bBitsPerPixel;
236 uint8_t bDefaultFrameIndex;
237 uint8_t bAspectRatioX;
238 uint8_t bAspectRatioY;
239 uint8_t bmInterfaceFlags;
240 uint8_t bCopyProtect;
241} usbh_uvc_format_uncompressed;
242
243typedef PACKED_STRUCT {
244 uint16_t bmHint;
245 uint8_t bFormatIndex;
246 uint8_t bFrameIndex;
247 uint32_t dwFrameInterval;
248 uint16_t wKeyFrameRate;
249 uint16_t wPFrameRate;
250 uint16_t wCompQuality;
251 uint16_t wCompWindowSize;
252 uint16_t wDelay;
253 uint32_t dwMaxVideoFrameSize;
254 uint32_t dwMaxPayloadTransferSize;
255// uint32_t dwClockFrequency;
256// uint8_t bmFramingInfo;
257// uint8_t bPreferedVersion;
258// uint8_t bMinVersion;
259// uint8_t bMaxVersion;
260} usbh_uvc_ctrl_vs_probecommit_data_t;
261
262
263
264/* D0: Frame ID.
265 * For frame-based formats, this bit toggles between 0 and 1 every time a new video frame begins.
266 * For stream-based formats, this bit toggles between 0 and 1 at the start of each new codec-specific
267 * segment. This behavior is required for frame-based payload formats (e.g., DV) and is optional
268 * for stream-based payload formats (e.g., MPEG-2 TS). For stream-based formats, support for this
269 * bit must be indicated via the bmFramingInfofield of the Video Probe and Commitcontrols
270 * (see section 4.3.1.1, �Video Probe and Commit Controls�).
271 *
272 * D1: End of Frame.
273 * This bit is set if the following payload data marks the end of the current video or still image
274 * frame (for framebased formats), or to indicate the end of a codec-specific segment
275 * (for stream-based formats). This behavior is optional for all payload formats.
276 * For stream-based formats, support for this bit must be indicated via the bmFramingInfofield
277 * of the Video Probe and CommitControls (see section 4.3.1.1, �Video Probe and Commit Controls�).
278 *
279 * D2: Presentation Time.
280 * This bit is set if the dwPresentationTimefield is being sent as part of the header.
281 *
282 * D3: Source Clock Reference
283 * This bit is set if the dwSourceClockfield is being sent as part of the header.
284 *
285 * D4: Reserved
286 *
287 * D5: Still Image
288 * This bit is set ifthe following data is part of a still image frame, and is only used for
289 * methods 2 and 3 of still image capture.
290 *
291 * D6: Error
292 * This bit is set ifthere was an error in the video or still image transmission
293 * for this payload. The StreamError Code control would reflect the cause of the error.
294 *
295 * D7: End of header
296 * This bit is set if this is the last header group in the packet, where the
297 * header group refers to this field and any optional fields identified by the bits in this
298 * field (Defined for future extension)
299*/
300
301#define UVC_HDR_EOH (1 << 7) /* End of header */
302#define UVC_HDR_ERR (1 << 6) /* Error */
303#define UVC_HDR_STILL (1 << 5) /* Still Image */
304#define UVC_HDR_SCR (1 << 3) /* Source Clock Reference */
305#define UVC_HDR_PT (1 << 2) /* Presentation Time */
306#define UVC_HDR_EOF (1 << 1) /* End of Frame */
307#define UVC_HDR_FID (1 << 0) /* Frame ID */
308
309
310
311typedef struct USBHUVCDriver USBHUVCDriver;
312
313#define USBHUVC_MESSAGETYPE_STATUS 1
314#define USBHUVC_MESSAGETYPE_DATA 2
315
316
317#define _usbhuvc_message_base_data \
318 uint16_t type; \
319 uint16_t length; \
320 systime_t timestamp;
321
322typedef struct {
323 _usbhuvc_message_base_data
324} usbhuvc_message_base_t;
325
326typedef struct {
327 _usbhuvc_message_base_data
328 USBH_DECLARE_STRUCT_MEMBER(uint8_t data[0]);
329} usbhuvc_message_data_t;
330
331typedef struct {
332 _usbhuvc_message_base_data
333 USBH_DECLARE_STRUCT_MEMBER(uint8_t data[USBHUVC_MAX_STATUS_PACKET_SZ]);
334} usbhuvc_message_status_t;
335
336
337typedef enum {
338 USBHUVC_STATE_UNINITIALIZED = 0, //must call usbhuvcObjectInit
339 USBHUVC_STATE_STOP = 1, //the device is disconnected
340 USBHUVC_STATE_ACTIVE = 2, //the device is connected
341 USBHUVC_STATE_READY = 3, //the device has negotiated the parameters
342 USBHUVC_STATE_STREAMING = 4, //the device is streaming data
343 USBHUVC_STATE_BUSY = 5 //the driver is busy performing some action
344} usbhuvc_state_t;
345
346
347struct USBHUVCDriver {
348 /* inherited from abstract class driver */
349 _usbh_base_classdriver_data
350
351 usbhuvc_state_t state;
352
353 usbh_ep_t ep_int;
354 usbh_ep_t ep_iso;
355
356 usbh_urb_t urb_iso;
357 usbh_urb_t urb_int;
358
359 if_iterator_t ivc;
360 if_iterator_t ivs;
361
362 USBH_DECLARE_STRUCT_MEMBER(usbh_uvc_ctrl_vs_probecommit_data_t pc);
363 USBH_DECLARE_STRUCT_MEMBER(usbh_uvc_ctrl_vs_probecommit_data_t pc_min);
364 USBH_DECLARE_STRUCT_MEMBER(usbh_uvc_ctrl_vs_probecommit_data_t pc_max);
365
366 mailbox_t mb;
367 msg_t mb_buff[HAL_USBHUVC_MAX_MAILBOX_SZ];
368
369 memory_pool_t mp_data;
370 void *mp_data_buffer;
371
372 memory_pool_t mp_status;
373 usbhuvc_message_status_t mp_status_buffer[HAL_USBHUVC_STATUS_PACKETS_COUNT];
374
375 mutex_t mtx;
376};
377
378
379/*===========================================================================*/
380/* Driver macros. */
381/*===========================================================================*/
382
383
384/*===========================================================================*/
385/* External declarations. */
386/*===========================================================================*/
387
388extern USBHUVCDriver USBHUVCD[HAL_USBHUVC_MAX_INSTANCES];
389
390#ifdef __cplusplus
391extern "C" {
392#endif
393 static inline usbhuvc_state_t usbhuvcGetState(USBHUVCDriver *uvcd) {
394 return uvcd->state;
395 }
396
397 bool usbhuvcVCRequest(USBHUVCDriver *uvcdp,
398 uint8_t bRequest, uint8_t entity, uint8_t control,
399 uint16_t wLength, uint8_t *data);
400 bool usbhuvcVSRequest(USBHUVCDriver *uvcdp,
401 uint8_t bRequest, uint8_t control,
402 uint16_t wLength, uint8_t *data);
403 bool usbhuvcFindVSDescriptor(USBHUVCDriver *uvcdp,
404 generic_iterator_t *ics,
405 uint8_t bDescriptorSubtype,
406 bool start);
407 uint32_t usbhuvcEstimateRequiredEPSize(USBHUVCDriver *uvcdp, const uint8_t *formatdesc,
408 const uint8_t *framedesc, uint32_t dwFrameInterval);
409
410#if USBH_DEBUG_ENABLE && USBHUVC_DEBUG_ENABLE_INFO
411 void usbhuvcPrintProbeCommit(USBHUVCDriver *uvcdp, const usbh_uvc_ctrl_vs_probecommit_data_t *pc);
412#else
413# define usbhuvcPrintProbeCommit(uvcdp, pc) do {} while(0)
414#endif
415 bool usbhuvcProbe(USBHUVCDriver *uvcdp);
416 bool usbhuvcCommit(USBHUVCDriver *uvcdp);
417 void usbhuvcResetPC(USBHUVCDriver *uvcdp);
418 static inline const usbh_uvc_ctrl_vs_probecommit_data_t *usbhuvcGetPCMin(USBHUVCDriver *uvcdp) {
419 return &uvcdp->pc_min;
420 }
421 static inline const usbh_uvc_ctrl_vs_probecommit_data_t *usbhuvcGetPCMax(USBHUVCDriver *uvcdp) {
422 return &uvcdp->pc_min;
423 }
424 static inline usbh_uvc_ctrl_vs_probecommit_data_t *usbhuvcGetPC(USBHUVCDriver *uvcdp) {
425 return &uvcdp->pc;
426 }
427
428 bool usbhuvcStreamStart(USBHUVCDriver *uvcdp, uint16_t min_ep_sz);
429 bool usbhuvcStreamStop(USBHUVCDriver *uvcdp);
430
431 static inline msg_t usbhuvcLockAndFetchS(USBHUVCDriver *uvcdp, msg_t *msg, systime_t timeout) {
432 chMtxLockS(&uvcdp->mtx);
433 msg_t ret = chMBFetchTimeoutS(&uvcdp->mb, msg, timeout);
434 if (ret != MSG_OK)
435 chMtxUnlockS(&uvcdp->mtx);
436 return ret;
437 }
438 static inline msg_t usbhuvcLockAndFetch(USBHUVCDriver *uvcdp, msg_t *msg, systime_t timeout) {
439 osalSysLock();
440 msg_t ret = usbhuvcLockAndFetchS(uvcdp, msg, timeout);
441 osalSysUnlock();
442 return ret;
443 }
444 static inline void usbhuvcUnlock(USBHUVCDriver *uvcdp) {
445 chMtxUnlock(&uvcdp->mtx);
446 }
447 static inline void usbhuvcFreeDataMessage(USBHUVCDriver *uvcdp, usbhuvc_message_data_t *msg) {
448 chPoolFree(&uvcdp->mp_data, msg);
449 }
450 static inline void usbhuvcFreeStatusMessage(USBHUVCDriver *uvcdp, usbhuvc_message_status_t *msg) {
451 chPoolFree(&uvcdp->mp_status, msg);
452 }
453#ifdef __cplusplus
454}
455#endif
456
457#endif
458
459#endif /* USBH_INCLUDE_USBH_UVC_H_ */
diff --git a/lib/chibios-contrib/os/hal/include/usbh/internal.h b/lib/chibios-contrib/os/hal/include/usbh/internal.h
new file mode 100644
index 000000000..61bbb953e
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/include/usbh/internal.h
@@ -0,0 +1,148 @@
1/*
2 ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
3 Copyright (C) 2015..2019 Diego Ismirlian, (dismirlian(at)google's mail)
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18#ifndef USBH_INTERNAL_H_
19#define USBH_INTERNAL_H_
20
21#include "hal_usbh.h"
22
23#if HAL_USE_USBH
24
25/*===========================================================================*/
26/* These declarations are not part of the public API. */
27/*===========================================================================*/
28
29#if HAL_USBH_USE_FTDI
30extern const usbh_classdriverinfo_t usbhftdiClassDriverInfo;
31#endif
32#if HAL_USBH_USE_AOA
33extern const usbh_classdriverinfo_t usbhaoaClassDriverInfo;
34#endif
35#if HAL_USBH_USE_MSD
36extern const usbh_classdriverinfo_t usbhmsdClassDriverInfo;
37#endif
38#if HAL_USBH_USE_HID
39extern const usbh_classdriverinfo_t usbhhidClassDriverInfo;
40#endif
41#if HAL_USBH_USE_UVC
42extern const usbh_classdriverinfo_t usbhuvcClassDriverInfo;
43#endif
44#if HAL_USBH_USE_HUB
45extern const usbh_classdriverinfo_t usbhhubClassDriverInfo;
46void _usbhub_port_object_init(usbh_port_t *port, USBHDriver *usbh,
47 USBHHubDriver *hub, uint8_t number);
48#else
49void _usbhub_port_object_init(usbh_port_t *port, USBHDriver *usbh, uint8_t number);
50#endif
51
52void _usbh_port_disconnected(usbh_port_t *port);
53void _usbh_urb_completeI(usbh_urb_t *urb, usbh_urbstatus_t status);
54bool _usbh_urb_abortI(usbh_urb_t *urb, usbh_urbstatus_t status);
55void _usbh_urb_abort_and_waitS(usbh_urb_t *urb, usbh_urbstatus_t status);
56
57bool _usbh_match_vid_pid(usbh_device_t *dev, int32_t vid, int32_t pid);
58bool _usbh_match_descriptor(const uint8_t *descriptor, uint16_t rem,
59 int16_t type, int16_t _class, int16_t subclass, int16_t protocol);
60
61#define USBH_REQTYPE_CLASSIN(type) \
62 (USBH_REQTYPE_DIR_IN | type | USBH_REQTYPE_TYPE_CLASS)
63
64#define USBH_REQTYPE_CLASSOUT(type) \
65 (USBH_REQTYPE_DIR_OUT | type | USBH_REQTYPE_TYPE_CLASS)
66
67#define USBH_REQTYPE_STANDARDIN(type) \
68 (USBH_REQTYPE_DIR_IN | type | USBH_REQTYPE_TYPE_STANDARD)
69
70#define USBH_REQTYPE_STANDARDOUT(type) \
71 (USBH_REQTYPE_DIR_OUT | type | USBH_REQTYPE_TYPE_STANDARD)
72
73
74#define USBH_PID_DATA0 0
75#define USBH_PID_DATA2 1
76#define USBH_PID_DATA1 2
77#define USBH_PID_MDATA 3
78#define USBH_PID_SETUP 3
79
80
81/* GetBusState and SetHubDescriptor are optional, omitted */
82#define ClearHubFeature (((USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_DEVICE) << 8) \
83 | USBH_REQ_CLEAR_FEATURE)
84#define SetHubFeature (((USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_DEVICE) << 8) \
85 | USBH_REQ_SET_FEATURE)
86#define ClearPortFeature (((USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER) << 8) \
87 | USBH_REQ_CLEAR_FEATURE)
88#define SetPortFeature (((USBH_REQTYPE_DIR_OUT | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER) << 8) \
89 | USBH_REQ_SET_FEATURE)
90#define GetHubDescriptor (((USBH_REQTYPE_DIR_IN | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_DEVICE) << 8) \
91 | USBH_REQ_GET_DESCRIPTOR)
92#define GetHubStatus (((USBH_REQTYPE_DIR_IN | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_DEVICE) << 8) \
93 | USBH_REQ_GET_STATUS)
94#define GetPortStatus (((USBH_REQTYPE_DIR_IN | USBH_REQTYPE_TYPE_CLASS | USBH_REQTYPE_RECIP_OTHER) << 8) \
95 | USBH_REQ_GET_STATUS)
96
97
98#define USBH_PORTSTATUS_CONNECTION 0x0001
99#define USBH_PORTSTATUS_ENABLE 0x0002
100#define USBH_PORTSTATUS_SUSPEND 0x0004
101#define USBH_PORTSTATUS_OVERCURRENT 0x0008
102#define USBH_PORTSTATUS_RESET 0x0010
103/* bits 5 to 7 are reserved */
104#define USBH_PORTSTATUS_POWER 0x0100
105#define USBH_PORTSTATUS_LOW_SPEED 0x0200
106#define USBH_PORTSTATUS_HIGH_SPEED 0x0400
107#define USBH_PORTSTATUS_TEST 0x0800
108#define USBH_PORTSTATUS_INDICATOR 0x1000
109/* bits 13 to 15 are reserved */
110
111#define USBH_PORTSTATUS_C_CONNECTION 0x0001
112#define USBH_PORTSTATUS_C_ENABLE 0x0002
113#define USBH_PORTSTATUS_C_SUSPEND 0x0004
114#define USBH_PORTSTATUS_C_OVERCURRENT 0x0008
115#define USBH_PORTSTATUS_C_RESET 0x0010
116
117#define USBH_HUBSTATUS_C_HUB_LOCAL_POWER 0x0001
118#define USBH_HUBSTATUS_C_HUB_OVER_CURRENT 0x0002
119
120/*
121 * Port feature numbers
122 * See USB 2.0 spec Table 11-17
123 */
124#define USBH_HUB_FEAT_C_HUB_LOCAL_POWER 0
125#define USBH_HUB_FEAT_C_HUB_OVER_CURRENT 1
126#define USBH_PORT_FEAT_CONNECTION 0
127#define USBH_PORT_FEAT_ENABLE 1
128#define USBH_PORT_FEAT_SUSPEND 2
129#define USBH_PORT_FEAT_OVERCURRENT 3
130#define USBH_PORT_FEAT_RESET 4
131#define USBH_PORT_FEAT_POWER 8
132#define USBH_PORT_FEAT_LOWSPEED 9
133#define USBH_PORT_FEAT_C_CONNECTION 16
134#define USBH_PORT_FEAT_C_ENABLE 17
135#define USBH_PORT_FEAT_C_SUSPEND 18
136#define USBH_PORT_FEAT_C_OVERCURRENT 19
137#define USBH_PORT_FEAT_C_RESET 20
138#define USBH_PORT_FEAT_TEST 21
139#define USBH_PORT_FEAT_INDICATOR 22
140
141#define sizeof_array(x) (sizeof(x)/sizeof(*(x)))
142
143#include "usbh/desciter.h" /* descriptor iterators */
144#include "usbh/debug.h"
145
146#endif
147
148#endif /* USBH_INTERNAL_H_ */
diff --git a/lib/chibios-contrib/os/hal/include/usbh/list.h b/lib/chibios-contrib/os/hal/include/usbh/list.h
new file mode 100644
index 000000000..034c6ff17
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/include/usbh/list.h
@@ -0,0 +1,590 @@
1#ifndef USBH_LIST_H_
2#define USBH_LIST_H_
3
4/* TODO: re-write this file; stolen from linux */
5
6#ifndef offsetof
7#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
8#endif
9
10#ifndef container_of
11#define container_of(ptr, type, member) ((type *)(void *)((char *)(ptr) - offsetof(type, member)))
12#endif
13
14/*
15 * Simple doubly linked list implementation.
16 *
17 * Some of the internal functions ("__xxx") are useful when
18 * manipulating whole lists rather than single entries, as
19 * sometimes we already know the next/prev entries and we can
20 * generate better code by using them directly rather than
21 * using the generic single-entry routines.
22 */
23struct list_head {
24 struct list_head *next, *prev;
25};
26
27#define LIST_HEAD_INIT(name) { &(name), &(name) }
28
29#define LIST_HEAD(name) \
30 struct list_head name = LIST_HEAD_INIT(name)
31
32static inline void INIT_LIST_HEAD(struct list_head *list)
33{
34 list->next = list;
35 list->prev = list;
36}
37
38/*
39 * Insert a new entry between two known consecutive entries.
40 *
41 * This is only for internal list manipulation where we know
42 * the prev/next entries already!
43 */
44static inline void __list_add(struct list_head *_new,
45 struct list_head *prev,
46 struct list_head *next)
47{
48 next->prev = _new;
49 _new->next = next;
50 _new->prev = prev;
51 prev->next = _new;
52}
53
54/**
55 * list_add - add a new entry
56 * @new: new entry to be added
57 * @head: list head to add it after
58 *
59 * Insert a new entry after the specified head.
60 * This is good for implementing stacks.
61 */
62static inline void list_add(struct list_head *_new, struct list_head *head)
63{
64 __list_add(_new, head, head->next);
65}
66
67
68/**
69 * list_add_tail - add a new entry
70 * @new: new entry to be added
71 * @head: list head to add it before
72 *
73 * Insert a new entry before the specified head.
74 * This is useful for implementing queues.
75 */
76static inline void list_add_tail(struct list_head *_new, struct list_head *head)
77{
78 __list_add(_new, head->prev, head);
79}
80
81/*
82 * Delete a list entry by making the prev/next entries
83 * point to each other.
84 *
85 * This is only for internal list manipulation where we know
86 * the prev/next entries already!
87 */
88static inline void __list_del(struct list_head * prev, struct list_head * next)
89{
90 next->prev = prev;
91 prev->next = next;
92}
93
94/**
95 * list_del - deletes entry from list.
96 * @entry: the element to delete from the list.
97 * Note: list_empty() on entry does not return true after this, the entry is
98 * in an undefined state.
99 */
100
101static inline void __list_del_entry(struct list_head *entry)
102{
103 __list_del(entry->prev, entry->next);
104}
105
106static inline void list_del(struct list_head *entry)
107{
108 __list_del(entry->prev, entry->next);
109}
110
111/**
112 * list_del_init - deletes entry from list and reinitialize it.
113 * @entry: the element to delete from the list.
114 */
115static inline void list_del_init(struct list_head *entry)
116{
117 __list_del_entry(entry);
118 INIT_LIST_HEAD(entry);
119}
120
121/**
122 * list_move_tail - delete from one list and add as another's tail
123 * @list: the entry to move
124 * @head: the head that will follow our entry
125 */
126static inline void list_move_tail(struct list_head *list,
127 struct list_head *head)
128{
129 __list_del_entry(list);
130 list_add_tail(list, head);
131}
132
133
134/**
135 * list_empty - tests whether a list is empty
136 * @head: the list to test.
137 */
138static inline int list_empty(const struct list_head *head)
139{
140 return head->next == head;
141}
142
143/**
144 * list_entry - get the struct for this entry
145 * @ptr: the &struct list_head pointer.
146 * @type: the type of the struct this is embedded in.
147 * @member: the name of the list_head within the struct.
148 */
149#define list_entry(ptr, type, member) \
150 container_of(ptr, type, member)
151
152/**
153 * list_first_entry - get the first element from a list
154 * @ptr: the list head to take the element from.
155 * @type: the type of the struct this is embedded in.
156 * @member: the name of the list_head within the struct.
157 *
158 * Note, that list is expected to be not empty.
159 */
160#define list_first_entry(ptr, type, member) \
161 list_entry((ptr)->next, type, member)
162
163/**
164 * list_next_entry - get the next element in list
165 * @pos: the type * to cursor
166 * @member: the name of the list_head within the struct.
167 */
168#define list_next_entry(pos, type, member) \
169 list_entry((pos)->member.next, type, member)
170
171/**
172 * list_for_each_entry - iterate over list of given type
173 * @pos: the type * to use as a loop cursor.
174 * @head: the head for your list.
175 * @member: the name of the list_head within the struct.
176 */
177#define list_for_each_entry(pos, type, head, member) \
178 for (pos = list_first_entry(head, type, member); \
179 &pos->member != (head); \
180 pos = list_next_entry(pos, type, member))
181
182
183/**
184 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
185 * @pos: the type * to use as a loop cursor.
186 * @n: another type * to use as temporary storage
187 * @head: the head for your list.
188 * @member: the name of the list_head within the struct.
189 */
190#define list_for_each_entry_safe(pos, type, n, head, member) \
191 for (pos = list_first_entry(head, type, member), \
192 n = list_next_entry(pos, type, member); \
193 &pos->member != (head); \
194 pos = n, n = list_next_entry(n, type, member))
195
196#if 0
197
198/**
199 * list_for_each - iterate over a list
200 * @pos: the &struct list_head to use as a loop cursor.
201 * @head: the head for your list.
202 */
203#define list_for_each(pos, head) \
204 for (pos = (head)->next; pos != (head); pos = pos->next)
205
206/**
207 * list_for_each_safe - iterate over a list safe against removal of list entry
208 * @pos: the &struct list_head to use as a loop cursor.
209 * @n: another &struct list_head to use as temporary storage
210 * @head: the head for your list.
211 */
212#define list_for_each_safe(pos, n, head) \
213 for (pos = (head)->next, n = pos->next; pos != (head); \
214 pos = n, n = pos->next)
215
216/**
217 * list_prev_entry - get the prev element in list
218 * @pos: the type * to cursor
219 * @member: the name of the list_head within the struct.
220 */
221#define list_prev_entry(pos, type, member) \
222 list_entry((pos)->member.prev, type, member)
223
224/**
225 * list_for_each_prev - iterate over a list backwards
226 * @pos: the &struct list_head to use as a loop cursor.
227 * @head: the head for your list.
228 */
229#define list_for_each_prev(pos, head) \
230 for (pos = (head)->prev; pos != (head); pos = pos->prev)
231
232/**
233 * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
234 * @pos: the &struct list_head to use as a loop cursor.
235 * @n: another &struct list_head to use as temporary storage
236 * @head: the head for your list.
237 */
238#define list_for_each_prev_safe(pos, n, head) \
239 for (pos = (head)->prev, n = pos->prev; \
240 pos != (head); \
241 pos = n, n = pos->prev)
242
243/**
244 * list_last_entry - get the last element from a list
245 * @ptr: the list head to take the element from.
246 * @type: the type of the struct this is embedded in.
247 * @member: the name of the list_head within the struct.
248 *
249 * Note, that list is expected to be not empty.
250 */
251#define list_last_entry(ptr, type, member) \
252 list_entry((ptr)->prev, type, member)
253
254/**
255 * list_first_entry_or_null - get the first element from a list
256 * @ptr: the list head to take the element from.
257 * @type: the type of the struct this is embedded in.
258 * @member: the name of the list_head within the struct.
259 *
260 * Note that if the list is empty, it returns NULL.
261 */
262#define list_first_entry_or_null(ptr, type, member) \
263 (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL)
264
265
266/**
267 * list_move - delete from one list and add as another's head
268 * @list: the entry to move
269 * @head: the head that will precede our entry
270 */
271static inline void list_move(struct list_head *list, struct list_head *head)
272{
273 __list_del_entry(list);
274 list_add(list, head);
275}
276
277/**
278 * list_is_last - tests whether @list is the last entry in list @head
279 * @list: the entry to test
280 * @head: the head of the list
281 */
282static inline int list_is_last(const struct list_head *list,
283 const struct list_head *head)
284{
285 return list->next == head;
286}
287
288/**
289 * list_empty_careful - tests whether a list is empty and not being modified
290 * @head: the list to test
291 *
292 * Description:
293 * tests whether a list is empty _and_ checks that no other CPU might be
294 * in the process of modifying either member (next or prev)
295 *
296 * NOTE: using list_empty_careful() without synchronization
297 * can only be safe if the only activity that can happen
298 * to the list entry is list_del_init(). Eg. it cannot be used
299 * if another CPU could re-list_add() it.
300 */
301static inline int list_empty_careful(const struct list_head *head)
302{
303 struct list_head *next = head->next;
304 return (next == head) && (next == head->prev);
305}
306
307/**
308 * list_rotate_left - rotate the list to the left
309 * @head: the head of the list
310 */
311static inline void list_rotate_left(struct list_head *head)
312{
313 struct list_head *first;
314
315 if (!list_empty(head)) {
316 first = head->next;
317 list_move_tail(first, head);
318 }
319}
320
321/**
322 * list_is_singular - tests whether a list has just one entry.
323 * @head: the list to test.
324 */
325static inline int list_is_singular(const struct list_head *head)
326{
327 return !list_empty(head) && (head->next == head->prev);
328}
329
330static inline void __list_cut_position(struct list_head *list,
331 struct list_head *head, struct list_head *entry)
332{
333 struct list_head *new_first = entry->next;
334 list->next = head->next;
335 list->next->prev = list;
336 list->prev = entry;
337 entry->next = list;
338 head->next = new_first;
339 new_first->prev = head;
340}
341
342/**
343 * list_cut_position - cut a list into two
344 * @list: a new list to add all removed entries
345 * @head: a list with entries
346 * @entry: an entry within head, could be the head itself
347 * and if so we won't cut the list
348 *
349 * This helper moves the initial part of @head, up to and
350 * including @entry, from @head to @list. You should
351 * pass on @entry an element you know is on @head. @list
352 * should be an empty list or a list you do not care about
353 * losing its data.
354 *
355 */
356static inline void list_cut_position(struct list_head *list,
357 struct list_head *head, struct list_head *entry)
358{
359 if (list_empty(head))
360 return;
361 if (list_is_singular(head) &&
362 (head->next != entry && head != entry))
363 return;
364 if (entry == head)
365 INIT_LIST_HEAD(list);
366 else
367 __list_cut_position(list, head, entry);
368}
369
370static inline void __list_splice(const struct list_head *list,
371 struct list_head *prev,
372 struct list_head *next)
373{
374 struct list_head *first = list->next;
375 struct list_head *last = list->prev;
376
377 first->prev = prev;
378 prev->next = first;
379
380 last->next = next;
381 next->prev = last;
382}
383
384/**
385 * list_splice - join two lists, this is designed for stacks
386 * @list: the new list to add.
387 * @head: the place to add it in the first list.
388 */
389static inline void list_splice(const struct list_head *list,
390 struct list_head *head)
391{
392 if (!list_empty(list))
393 __list_splice(list, head, head->next);
394}
395
396/**
397 * list_splice_tail - join two lists, each list being a queue
398 * @list: the new list to add.
399 * @head: the place to add it in the first list.
400 */
401static inline void list_splice_tail(struct list_head *list,
402 struct list_head *head)
403{
404 if (!list_empty(list))
405 __list_splice(list, head->prev, head);
406}
407
408/**
409 * list_splice_init - join two lists and reinitialise the emptied list.
410 * @list: the new list to add.
411 * @head: the place to add it in the first list.
412 *
413 * The list at @list is reinitialised
414 */
415static inline void list_splice_init(struct list_head *list,
416 struct list_head *head)
417{
418 if (!list_empty(list)) {
419 __list_splice(list, head, head->next);
420 INIT_LIST_HEAD(list);
421 }
422}
423
424/**
425 * list_splice_tail_init - join two lists and reinitialise the emptied list
426 * @list: the new list to add.
427 * @head: the place to add it in the first list.
428 *
429 * Each of the lists is a queue.
430 * The list at @list is reinitialised
431 */
432static inline void list_splice_tail_init(struct list_head *list,
433 struct list_head *head)
434{
435 if (!list_empty(list)) {
436 __list_splice(list, head->prev, head);
437 INIT_LIST_HEAD(list);
438 }
439}
440
441/**
442 * list_replace - replace old entry by new one
443 * @old : the element to be replaced
444 * @new : the new element to insert
445 *
446 * If @old was empty, it will be overwritten.
447 */
448static inline void list_replace(struct list_head *old,
449 struct list_head *_new)
450{
451 _new->next = old->next;
452 _new->next->prev = _new;
453 _new->prev = old->prev;
454 _new->prev->next = _new;
455}
456
457static inline void list_replace_init(struct list_head *old,
458 struct list_head *_new)
459{
460 list_replace(old, _new);
461 INIT_LIST_HEAD(old);
462}
463
464
465/**
466 * list_for_each_entry_reverse - iterate backwards over list of given type.
467 * @pos: the type * to use as a loop cursor.
468 * @head: the head for your list.
469 * @member: the name of the list_head within the struct.
470 */
471#define list_for_each_entry_reverse(pos, type, head, member) \
472 for (pos = list_last_entry(head, type, member); \
473 &pos->member != (head); \
474 pos = list_prev_entry(pos, type, member))
475
476/**
477 * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
478 * @pos: the type * to use as a start point
479 * @head: the head of the list
480 * @member: the name of the list_head within the struct.
481 *
482 * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
483 */
484#define list_prepare_entry(pos, type, head, member) \
485 ((pos) ? : list_entry(head, type, member))
486
487/**
488 * list_for_each_entry_continue - continue iteration over list of given type
489 * @pos: the type * to use as a loop cursor.
490 * @head: the head for your list.
491 * @member: the name of the list_head within the struct.
492 *
493 * Continue to iterate over list of given type, continuing after
494 * the current position.
495 */
496#define list_for_each_entry_continue(pos, type, head, member) \
497 for (pos = list_next_entry(pos, type, member); \
498 &pos->member != (head); \
499 pos = list_next_entry(pos, type, member))
500
501/**
502 * list_for_each_entry_continue_reverse - iterate backwards from the given point
503 * @pos: the type * to use as a loop cursor.
504 * @head: the head for your list.
505 * @member: the name of the list_head within the struct.
506 *
507 * Start to iterate over list of given type backwards, continuing after
508 * the current position.
509 */
510#define list_for_each_entry_continue_reverse(pos, type, head, member) \
511 for (pos = list_prev_entry(pos, type, member); \
512 &pos->member != (head); \
513 pos = list_prev_entry(pos, type, member))
514
515/**
516 * list_for_each_entry_from - iterate over list of given type from the current point
517 * @pos: the type * to use as a loop cursor.
518 * @head: the head for your list.
519 * @member: the name of the list_head within the struct.
520 *
521 * Iterate over list of given type, continuing from current position.
522 */
523#define list_for_each_entry_from(pos, type, head, member) \
524 for (; &pos->member != (head); \
525 pos = list_next_entry(pos, type, member))
526
527/**
528 * list_for_each_entry_safe_continue - continue list iteration safe against removal
529 * @pos: the type * to use as a loop cursor.
530 * @n: another type * to use as temporary storage
531 * @head: the head for your list.
532 * @member: the name of the list_head within the struct.
533 *
534 * Iterate over list of given type, continuing after current point,
535 * safe against removal of list entry.
536 */
537#define list_for_each_entry_safe_continue(pos, type, n, head, member) \
538 for (pos = list_next_entry(pos, type, member), \
539 n = list_next_entry(pos, type, member); \
540 &pos->member != (head); \
541 pos = n, n = list_next_entry(n, type, member))
542
543/**
544 * list_for_each_entry_safe_from - iterate over list from current point safe against removal
545 * @pos: the type * to use as a loop cursor.
546 * @n: another type * to use as temporary storage
547 * @head: the head for your list.
548 * @member: the name of the list_head within the struct.
549 *
550 * Iterate over list of given type from current point, safe against
551 * removal of list entry.
552 */
553#define list_for_each_entry_safe_from(pos, type, n, head, member) \
554 for (n = list_next_entry(pos, type, member); \
555 &pos->member != (head); \
556 pos = n, n = list_next_entry(n, type, member))
557
558/**
559 * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal
560 * @pos: the type * to use as a loop cursor.
561 * @n: another type * to use as temporary storage
562 * @head: the head for your list.
563 * @member: the name of the list_head within the struct.
564 *
565 * Iterate backwards over list of given type, safe against removal
566 * of list entry.
567 */
568#define list_for_each_entry_safe_reverse(pos, type, n, head, member) \
569 for (pos = list_last_entry(head, type, member), \
570 n = list_prev_entry(pos, type, member); \
571 &pos->member != (head); \
572 pos = n, n = list_prev_entry(n, type, member))
573
574/**
575 * list_safe_reset_next - reset a stale list_for_each_entry_safe loop
576 * @pos: the loop cursor used in the list_for_each_entry_safe loop
577 * @n: temporary storage used in list_for_each_entry_safe
578 * @member: the name of the list_head within the struct.
579 *
580 * list_safe_reset_next is not safe to use in general if the list may be
581 * modified concurrently (eg. the lock is dropped in the loop body). An
582 * exception to this is if the cursor element (pos) is pinned in the list,
583 * and list_safe_reset_next is called after re-taking the lock and before
584 * completing the current iteration of the loop body.
585 */
586#define list_safe_reset_next(pos, type, n, member) \
587 n = list_next_entry(pos, type, member)
588#endif
589
590#endif /* USBH_LIST_H_ */