Loading...
Searching...
No Matches
tinyusb_descriptors.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 Gunar Schorcht
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
19#ifndef TINYUSB_DESCRIPTORS_H
20#define TINYUSB_DESCRIPTORS_H
21
22#include "tusb_config.h" /* defined by the application */
23#include "tinyusb.h"
24
25#if !DOXYGEN
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/* don't compile this part if CONFIG_TUSBD_USE_CUSTOM_DESC is set */
32#if !defined(CONFIG_TUSBD_USE_CUSTOM_DESC)
33
34#if !defined(HAVE_TUSBD_ITF_TYPE)
35enum {
36#if CONFIG_TUSBD_CDC_NUMOF > 0
37 TUSBD_ITF_CDC_0, /* CDC0 Notification interface */
38 TUSBD_ITF_CDC_0_DATA,
39#endif
40#if CONFIG_TUSBD_CDC_NUMOF > 1
41 TUSBD_ITF_CDC_1,
42 TUSBD_ITF_CDC_1_DATA,
43#endif
44#if CONFIG_TUSBD_DFU_NUMOF
45 TUSBD_ITF_DFU,
46#endif
47#if CONFIG_TUSBD_DFU_RT_NUMOF
48 TUSBD_ITF_DFU_RT,
49#endif
50#if CONFIG_TUSBD_HID_NUMOF > 0
51 TUSBD_ITF_HID_0,
52#endif
53#if CONFIG_TUSBD_HID_NUMOF > 1
54 TUSBD_ITF_HID_1,
55#endif
56#if CONFIG_TUSBD_MSC_NUMOF
57 TUSBD_ITF_MSC,
58#endif
59#if CONFIG_TUSBD_NET_NUMOF
60 TUSBD_ITF_NET,
61 TUSBD_ITF_NET_DATA,
62#endif
63#if CONFIG_TUSBD_VENDOR_NUMOF
64 TUSBD_ITF_VENDOR,
65#endif
66 TUSBD_ITF_NUMOF,
67};
68#endif /* !defined(HAVE_TUSBD_ITF_TYPE) */
69
70#if !defined(HAVE_TUSBD_EP_TYPE)
71enum {
72#if CONFIG_TUSBD_CDC_NUMOF > 0
73 TUSBD_EP_CDC_0_NOTIF = TUSBD_ITF_CDC_0 + 0x81,
74 TUSBD_EP_CDC_0_OUT = TUSBD_ITF_CDC_0_DATA + 0x01,
75 TUSBD_EP_CDC_0_IN = TUSBD_ITF_CDC_0_DATA + 0x81,
76#endif
77#if CONFIG_TUSBD_CDC_NUMOF > 1
78 TUSBD_EP_CDC_1_NOTIF = TUSBD_ITF_CDC_1 + 0x81,
79 TUSBD_EP_CDC_1_OUT = TUSBD_ITF_CDC_1_DATA + 0x01,
80 TUSBD_EP_CDC_1_IN = TUSBD_ITF_CDC_1_DATA + 0x81,
81#endif
82#if CONFIG_TUSBD_HID_NUMOF > 0
83 TUSBD_EP_HID_0_OUT = TUSBD_ITF_HID_0 + 0x01,
84 TUSBD_EP_HID_0_IN = TUSBD_ITF_HID_0 + 0x81,
85#endif
86#if CONFIG_TUSBD_HID_NUMOF > 1
87 TUSBD_EP_HID_1_OUT = TUSBD_ITF_HID_1 + 0x01,
88 TUSBD_EP_HID_1_IN = TUSBD_ITF_HID_1 + 0x81,
89#endif
90#if CONFIG_TUSBD_MSC_NUMOF
91 TUSBD_EP_MSC_OUT = TUSBD_ITF_MSC + 0x01,
92 TUSBD_EP_MSC_IN = TUSBD_ITF_MSC + 0x81,
93#endif
94#if CONFIG_TUSBD_NET_NUMOF
95 TUSBD_EP_NET_NOTIF = TUSBD_ITF_NET + 0x81,
96 TUSBD_EP_NET_OUT = TUSBD_ITF_NET_DATA + 0x01,
97 TUSBD_EP_NET_IN = TUSBD_ITF_NET_DATA + 0x81,
98#endif
99#if CONFIG_TUSBD_VENDOR_NUMOF
100 TUSBD_EP_VENDOR_OUT = TUSBD_ITF_VENDOR + 0x01,
101 TUSBD_EP_VENDOR_IN = TUSBD_ITF_VENDOR + 0x81,
102#endif
103 TUSBD_EP_NUMOF,
104};
105#endif /* !defined(HAVE_TUSBD_EP_TYPE) */
106
107#if !defined(HAVE_TUSBD_STR_IDX_TYPE)
108enum {
109 TUSBD_STR_IDX_LANGUAGE = 0,
110 TUSBD_STR_IDX_MANUFACTURER,
111 TUSBD_STR_IDX_PRODUCT,
112 TUSBD_STR_IDX_SERIAL,
113#if CONFIG_TUSBD_CDC_NUMOF > 0
114 TUSBD_STR_IDX_CDC_0,
115#endif
116#if CONFIG_TUSBD_CDC_NUMOF > 1
117 TUSBD_STR_IDX_CDC_1,
118#endif
119#if CONFIG_TUSBD_DFU_NUMOF
120 TUSBD_STR_IDX_DFU_SLOT_0,
121 TUSBD_STR_IDX_DFU_SLOT_1,
122#endif
123#if CONFIG_TUSBD_DFU_RT_NUMOF
124 TUSBD_STR_IDX_DFU_RT,
125#endif
126#if CONFIG_TUSBD_HID_NUMOF > 0
127 TUSBD_STR_IDX_HID_0,
128#endif
129#if CONFIG_TUSBD_HID_NUMOF > 1
130 TUSBD_STR_IDX_HID_1,
131#endif
132#if CONFIG_TUSBD_MSC_NUMOF
133 TUSBD_STR_IDX_MSC,
134#endif
135
136#if CONFIG_TUSBD_NET_NUMOF
137#if CONFIG_TUSBD_NET_CDC_ECM
138 TUSBD_STR_IDX_NET_CDC_ECM,
139#endif /* CONFIG_TUSBD_NET_CDC_ECM */
140#if CONFIG_TUSBD_NET_CDC_NCM
141 TUSBD_STR_IDX_NET_CDC_NCM,
142#endif /* CONFIG_TUSBD_NET_CDC_NCM */
143#if CONFIG_TUSBD_NET_RNDIS
144 TUSBD_STR_IDX_NET_RNDIS,
145#endif /* CONFIG_TUSBD_NET_RNDIS */
146 TUSBD_STR_IDX_NET_MAC,
147#endif /* CONFIG_TUSBD_NET_NUMOF */
148
149#if CONFIG_TUSBD_VENDOR_NUMOF
150 TUSBD_STR_IDX_VENDOR,
151#endif
152 TUSBD_STR_IDX_NUMOF,
153};
154#endif /* !defined(HAVE_TUSBD_STR_IDX_TYPE) */
155
156/* only two slots are supported */
157#define CONFIG_TUSBD_DFU_ALT_NUMOF 2
158
159#if !defined(TUSBD_DESC_TOTAL_LEN)
160
161#if CONFIG_TUSBD_NET_CDC_ECM
162#define TUSBD_DESC_NET_LEN TUD_CDC_ECM_DESC_LEN
163#elif CONFIG_TUSBD_NET_CDC_NCM
164#define TUSBD_DESC_NET_LEN TUD_CDC_NCM_DESC_LEN
165#elif CONFIG_TUSBD_NET_RNDIS
166#define TUSBD_DESC_NET_LEN TUD_RNDIS_DESC_LEN
167#else
168#define TUSBD_DESC_NET_LEN 0
169#endif
170
171#define TUSBD_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN + \
172 (CONFIG_TUSBD_CDC_NUMOF * TUD_CDC_DESC_LEN) + \
173 (CONFIG_TUSBD_DFU_NUMOF * TUD_DFU_DESC_LEN(CONFIG_TUSBD_DFU_ALT_NUMOF)) + \
174 (CONFIG_TUSBD_DFU_RT_NUMOF * TUD_DFU_RT_DESC_LEN) + \
175 (CONFIG_TUSBD_HID_NUMOF * TUD_HID_INOUT_DESC_LEN) + \
176 (CONFIG_TUSBD_MSC_NUMOF * TUD_MSC_DESC_LEN) + \
177 (CONFIG_TUSBD_VENDOR_NUMOF * TUD_VENDOR_DESC_LEN) + \
178 TUSBD_DESC_NET_LEN)
179
180#endif /* !defined(TUSBD_DESC_TOTAL_LEN) */
181
182/* If CDC ECM and RNDIS are used simultaneously, an alternative configuration
183 * descriptor is required. In this case, the main configuration descriptor
184 * contains the CDC ECM interface descriptor and the alternative configuration
185 * descriptor contains the RNDIS interface descriptor. */
186#if CONFIG_TUSBD_NET_CDC_ECM && CONFIG_TUSBD_NET_RNDIS
187
188#define TUSBD_DESC_ALT_NET_LEN TUD_RNDIS_DESC_LEN
189
190#define TUSBD_DESC_ALT_TOTAL_LEN (TUD_CONFIG_DESC_LEN + \
191 (CONFIG_TUSBD_CDC_NUMOF * TUD_CDC_DESC_LEN) + \
192 (CONFIG_TUSBD_DFU_NUMOF * TUD_DFU_DESC_LEN(CONFIG_TUSBD_DFU_ALT_NUMOF)) + \
193 (CONFIG_TUSBD_DFU_RT_NUMOF * TUD_DFU_RT_DESC_LEN) + \
194 (CONFIG_TUSBD_HID_NUMOF * TUD_HID_INOUT_DESC_LEN) + \
195 (CONFIG_TUSBD_MSC_NUMOF * TUD_MSC_DESC_LEN) + \
196 (CONFIG_TUSBD_VENDOR_NUMOF * TUD_VENDOR_DESC_LEN) + \
197 TUSBD_DESC_ALT_NET_LEN)
198
199#endif /* CONFIG_TUSBD_NET_CDC_ECM && CONFIG_TUSBD_NET_RNDIS */
200
201#endif /* !defined(CONFIG_TUSBD_USE_CUSTOM_DESC) */
202
203#ifdef __cplusplus
204}
205#endif
206
207#endif /* !DOXYGEN */
208#endif /* TINYUSB_DESCRIPTORS_H */
TinyUSB API.
TinyUSB default configurations.