Open FFBoard
Open source force feedback firmware
cdc_device.c
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Ha Thach (tinyusb.org)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
27#include "tusb_option.h"
28
29#if (CFG_TUD_ENABLED && CFG_TUD_CDC)
30
31#include "device/usbd.h"
32#include "device/usbd_pvt.h"
33
34#include "cdc_device.h"
35
36// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
37#ifndef CFG_TUD_CDC_LOG_LEVEL
38 #define CFG_TUD_CDC_LOG_LEVEL CFG_TUD_LOG_LEVEL
39#endif
40
41#define TU_LOG_DRV(...) TU_LOG(CFG_TUD_CDC_LOG_LEVEL, __VA_ARGS__)
42
43//--------------------------------------------------------------------+
44// MACRO CONSTANT TYPEDEF
45//--------------------------------------------------------------------+
46#define BULK_PACKET_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
47
48typedef struct {
49 uint8_t itf_num;
50 uint8_t ep_notif;
51 uint8_t ep_in;
52 uint8_t ep_out;
53
54 // Bit 0: DTR (Data Terminal Ready), Bit 1: RTS (Request to Send)
55 uint8_t line_state;
56
57 /*------------- From this point, data is not cleared by bus reset -------------*/
60
61 // FIFO
62 tu_fifo_t rx_ff;
63 tu_fifo_t tx_ff;
64
65 uint8_t rx_ff_buf[CFG_TUD_CDC_RX_BUFSIZE];
66 uint8_t tx_ff_buf[CFG_TUD_CDC_TX_BUFSIZE];
67
68 OSAL_MUTEX_DEF(rx_ff_mutex);
69 OSAL_MUTEX_DEF(tx_ff_mutex);
70
71 // Endpoint Transfer buffer
72 CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_CDC_EP_BUFSIZE];
73 CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_CDC_EP_BUFSIZE];
75
76#define ITF_MEM_RESET_SIZE offsetof(cdcd_interface_t, wanted_char)
77
78//--------------------------------------------------------------------+
79// INTERNAL OBJECT & FUNCTION DECLARATION
80//--------------------------------------------------------------------+
81CFG_TUD_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
82static tud_cdc_configure_fifo_t _cdcd_fifo_cfg;
83
85 uint8_t const rhport = 0;
86
87 // Skip if usb is not ready yet
88 TU_VERIFY(tud_ready() && p_cdc->ep_out);
89
90 uint16_t available = tu_fifo_remaining(&p_cdc->rx_ff);
91
92 // Prepare for incoming data but only allow what we can store in the ring buffer.
93 // TODO Actually we can still carry out the transfer, keeping count of received bytes
94 // and slowly move it to the FIFO when read().
95 // This pre-check reduces endpoint claiming
96 TU_VERIFY(available >= sizeof(p_cdc->epout_buf));
97
98 // claim endpoint
99 TU_VERIFY(usbd_edpt_claim(rhport, p_cdc->ep_out));
100
101 // fifo can be changed before endpoint is claimed
102 available = tu_fifo_remaining(&p_cdc->rx_ff);
103
104 if ( available >= sizeof(p_cdc->epout_buf) ) {
105 return usbd_edpt_xfer(rhport, p_cdc->ep_out, p_cdc->epout_buf, sizeof(p_cdc->epout_buf));
106 }else {
107 // Release endpoint since we don't make any transfer
108 usbd_edpt_release(rhport, p_cdc->ep_out);
109 return false;
110 }
111}
112
113//--------------------------------------------------------------------+
114// APPLICATION API
115//--------------------------------------------------------------------+
116
117bool tud_cdc_configure_fifo(tud_cdc_configure_fifo_t const* cfg) {
118 TU_VERIFY(cfg);
119 _cdcd_fifo_cfg = (*cfg);
120 return true;
121}
122
123bool tud_cdc_n_ready(uint8_t itf) {
124 return tud_ready() && _cdcd_itf[itf].ep_in != 0 && _cdcd_itf[itf].ep_out != 0;
125}
126
127bool tud_cdc_n_connected(uint8_t itf) {
128 // DTR (bit 0) active is considered as connected
129 return tud_ready() && tu_bit_test(_cdcd_itf[itf].line_state, 0);
130}
131
132uint8_t tud_cdc_n_get_line_state(uint8_t itf) {
133 return _cdcd_itf[itf].line_state;
134}
135
137 (*coding) = _cdcd_itf[itf].line_coding;
138}
139
140void tud_cdc_n_set_wanted_char(uint8_t itf, char wanted) {
141 _cdcd_itf[itf].wanted_char = wanted;
142}
143
144//--------------------------------------------------------------------+
145// READ API
146//--------------------------------------------------------------------+
147uint32_t tud_cdc_n_available(uint8_t itf) {
148 return tu_fifo_count(&_cdcd_itf[itf].rx_ff);
149}
150
151uint32_t tud_cdc_n_read(uint8_t itf, void* buffer, uint32_t bufsize) {
152 cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
153 uint32_t num_read = tu_fifo_read_n(&p_cdc->rx_ff, buffer, (uint16_t) TU_MIN(bufsize, UINT16_MAX));
155 return num_read;
156}
157
158bool tud_cdc_n_peek(uint8_t itf, uint8_t* chr) {
159 return tu_fifo_peek(&_cdcd_itf[itf].rx_ff, chr);
160}
161
162void tud_cdc_n_read_flush(uint8_t itf) {
163 cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
164 tu_fifo_clear(&p_cdc->rx_ff);
166}
167
168//--------------------------------------------------------------------+
169// WRITE API
170//--------------------------------------------------------------------+
171uint32_t tud_cdc_n_write(uint8_t itf, void const* buffer, uint32_t bufsize) {
172 cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
173 uint16_t ret = tu_fifo_write_n(&p_cdc->tx_ff, buffer, (uint16_t) TU_MIN(bufsize, UINT16_MAX));
174
175 // flush if queue more than packet size
176 if (tu_fifo_count(&p_cdc->tx_ff) >= BULK_PACKET_SIZE
177 #if CFG_TUD_CDC_TX_BUFSIZE < BULK_PACKET_SIZE
178 || tu_fifo_full(&p_cdc->tx_ff) // check full if fifo size is less than packet size
179 #endif
180 ) {
182 }
183
184 return ret;
185}
186
187uint32_t tud_cdc_n_write_flush(uint8_t itf) {
188 cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
189
190 // Skip if usb is not ready yet
191 TU_VERIFY(tud_ready(), 0);
192
193 // No data to send
194 if (!tu_fifo_count(&p_cdc->tx_ff)) return 0;
195
196 uint8_t const rhport = 0;
197
198 // Claim the endpoint
199 TU_VERIFY(usbd_edpt_claim(rhport, p_cdc->ep_in), 0);
200
201 // Pull data from FIFO
202 uint16_t const count = tu_fifo_read_n(&p_cdc->tx_ff, p_cdc->epin_buf, sizeof(p_cdc->epin_buf));
203
204 if (count) {
205 TU_ASSERT(usbd_edpt_xfer(rhport, p_cdc->ep_in, p_cdc->epin_buf, count), 0);
206 return count;
207 } else {
208 // Release endpoint since we don't make any transfer
209 // Note: data is dropped if terminal is not connected
210 usbd_edpt_release(rhport, p_cdc->ep_in);
211 return 0;
212 }
213}
214
215uint32_t tud_cdc_n_write_available(uint8_t itf) {
216 return tu_fifo_remaining(&_cdcd_itf[itf].tx_ff);
217}
218
219bool tud_cdc_n_write_clear(uint8_t itf) {
220 return tu_fifo_clear(&_cdcd_itf[itf].tx_ff);
221}
222
223//--------------------------------------------------------------------+
224// USBD Driver API
225//--------------------------------------------------------------------+
226void cdcd_init(void) {
227 tu_memclr(_cdcd_itf, sizeof(_cdcd_itf));
228 tu_memclr(&_cdcd_fifo_cfg, sizeof(_cdcd_fifo_cfg));
229
230 for (uint8_t i = 0; i < CFG_TUD_CDC; i++) {
231 cdcd_interface_t* p_cdc = &_cdcd_itf[i];
232
233 p_cdc->wanted_char = (char) -1;
234
235 // default line coding is : stop bit = 1, parity = none, data bits = 8
236 p_cdc->line_coding.bit_rate = 115200;
237 p_cdc->line_coding.stop_bits = 0;
238 p_cdc->line_coding.parity = 0;
239 p_cdc->line_coding.data_bits = 8;
240
241 // Config RX fifo
242 tu_fifo_config(&p_cdc->rx_ff, p_cdc->rx_ff_buf, TU_ARRAY_SIZE(p_cdc->rx_ff_buf), 1, false);
243
244 // Config TX fifo as overwritable at initialization and will be changed to non-overwritable
245 // if terminal supports DTR bit. Without DTR we do not know if data is actually polled by terminal.
246 // In this way, the most current data is prioritized.
247 tu_fifo_config(&p_cdc->tx_ff, p_cdc->tx_ff_buf, TU_ARRAY_SIZE(p_cdc->tx_ff_buf), 1, true);
248
249 #if OSAL_MUTEX_REQUIRED
250 osal_mutex_t mutex_rd = osal_mutex_create(&p_cdc->rx_ff_mutex);
251 osal_mutex_t mutex_wr = osal_mutex_create(&p_cdc->tx_ff_mutex);
252 TU_ASSERT(mutex_rd != NULL && mutex_wr != NULL, );
253
254 tu_fifo_config_mutex(&p_cdc->rx_ff, NULL, mutex_rd);
255 tu_fifo_config_mutex(&p_cdc->tx_ff, mutex_wr, NULL);
256 #endif
257 }
258}
259
260bool cdcd_deinit(void) {
261 #if OSAL_MUTEX_REQUIRED
262 for(uint8_t i=0; i<CFG_TUD_CDC; i++) {
263 cdcd_interface_t* p_cdc = &_cdcd_itf[i];
264 osal_mutex_t mutex_rd = p_cdc->rx_ff.mutex_rd;
265 osal_mutex_t mutex_wr = p_cdc->tx_ff.mutex_wr;
266
267 if (mutex_rd) {
268 osal_mutex_delete(mutex_rd);
269 tu_fifo_config_mutex(&p_cdc->rx_ff, NULL, NULL);
270 }
271
272 if (mutex_wr) {
273 osal_mutex_delete(mutex_wr);
274 tu_fifo_config_mutex(&p_cdc->tx_ff, NULL, NULL);
275 }
276 }
277 #endif
278
279 return true;
280}
281
282void cdcd_reset(uint8_t rhport) {
283 (void) rhport;
284
285 for (uint8_t i = 0; i < CFG_TUD_CDC; i++) {
286 cdcd_interface_t* p_cdc = &_cdcd_itf[i];
287
288 tu_memclr(p_cdc, ITF_MEM_RESET_SIZE);
289 if (!_cdcd_fifo_cfg.rx_persistent) tu_fifo_clear(&p_cdc->rx_ff);
290 if (!_cdcd_fifo_cfg.tx_persistent) tu_fifo_clear(&p_cdc->tx_ff);
291 tu_fifo_set_overwritable(&p_cdc->tx_ff, true);
292 }
293}
294
295uint16_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len) {
296 // Only support ACM subclass
297 TU_VERIFY( TUSB_CLASS_CDC == itf_desc->bInterfaceClass &&
298 CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL == itf_desc->bInterfaceSubClass, 0);
299
300 // Find available interface
301 cdcd_interface_t* p_cdc = NULL;
302 for (uint8_t cdc_id = 0; cdc_id < CFG_TUD_CDC; cdc_id++) {
303 if (_cdcd_itf[cdc_id].ep_in == 0) {
304 p_cdc = &_cdcd_itf[cdc_id];
305 break;
306 }
307 }
308 TU_ASSERT(p_cdc, 0);
309
310 //------------- Control Interface -------------//
311 p_cdc->itf_num = itf_desc->bInterfaceNumber;
312
313 uint16_t drv_len = sizeof(tusb_desc_interface_t);
314 uint8_t const* p_desc = tu_desc_next(itf_desc);
315
316 // Communication Functional Descriptors
317 while (TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) && drv_len <= max_len) {
318 drv_len += tu_desc_len(p_desc);
319 p_desc = tu_desc_next(p_desc);
320 }
321
322 if (TUSB_DESC_ENDPOINT == tu_desc_type(p_desc)) {
323 // notification endpoint
324 tusb_desc_endpoint_t const* desc_ep = (tusb_desc_endpoint_t const*) p_desc;
325
326 TU_ASSERT(usbd_edpt_open(rhport, desc_ep), 0);
327 p_cdc->ep_notif = desc_ep->bEndpointAddress;
328
329 drv_len += tu_desc_len(p_desc);
330 p_desc = tu_desc_next(p_desc);
331 }
332
333 //------------- Data Interface (if any) -------------//
334 if ((TUSB_DESC_INTERFACE == tu_desc_type(p_desc)) &&
335 (TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const*) p_desc)->bInterfaceClass)) {
336 // next to endpoint descriptor
337 drv_len += tu_desc_len(p_desc);
338 p_desc = tu_desc_next(p_desc);
339
340 // Open endpoint pair
341 TU_ASSERT(usbd_open_edpt_pair(rhport, p_desc, 2, TUSB_XFER_BULK, &p_cdc->ep_out, &p_cdc->ep_in), 0);
342
343 drv_len += 2 * sizeof(tusb_desc_endpoint_t);
344 }
345
346 // Prepare for incoming data
348
349 return drv_len;
350}
351
352// Invoked when a control transfer occurred on an interface of this class
353// Driver response accordingly to the request and the transfer stage (setup/data/ack)
354// return false to stall control endpoint (e.g unsupported request)
355bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const* request) {
356 // Handle class request only
358
359 uint8_t itf = 0;
361
362 // Identify which interface to use
363 for (;; itf++, p_cdc++) {
364 if (itf >= TU_ARRAY_SIZE(_cdcd_itf)) return false;
365
366 if (p_cdc->itf_num == request->wIndex) break;
367 }
368
369 switch (request->bRequest) {
371 if (stage == CONTROL_STAGE_SETUP) {
372 TU_LOG_DRV(" Set Line Coding\r\n");
373 tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t));
374 } else if (stage == CONTROL_STAGE_ACK) {
375 if (tud_cdc_line_coding_cb) tud_cdc_line_coding_cb(itf, &p_cdc->line_coding);
376 }
377 break;
378
380 if (stage == CONTROL_STAGE_SETUP) {
381 TU_LOG_DRV(" Get Line Coding\r\n");
382 tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t));
383 }
384 break;
385
387 if (stage == CONTROL_STAGE_SETUP) {
389 } else if (stage == CONTROL_STAGE_ACK) {
390 // CDC PSTN v1.2 section 6.3.12
391 // Bit 0: Indicates if DTE is present or not.
392 // This signal corresponds to V.24 signal 108/2 and RS-232 signal DTR (Data Terminal Ready)
393 // Bit 1: Carrier control for half-duplex modems.
394 // This signal corresponds to V.24 signal 105 and RS-232 signal RTS (Request to Send)
395 bool const dtr = tu_bit_test(request->wValue, 0);
396 bool const rts = tu_bit_test(request->wValue, 1);
397
398 p_cdc->line_state = (uint8_t) request->wValue;
399
400 // Disable fifo overwriting if DTR bit is set
401 tu_fifo_set_overwritable(&p_cdc->tx_ff, !dtr);
402
403 TU_LOG_DRV(" Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts);
404
405 // Invoke callback
407 }
408 break;
409
411 if (stage == CONTROL_STAGE_SETUP) {
413 } else if (stage == CONTROL_STAGE_ACK) {
414 TU_LOG_DRV(" Send Break\r\n");
416 }
417 break;
418
419 default:
420 return false; // stall unsupported request
421 }
422
423 return true;
424}
425
426bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {
427 (void) result;
428
429 uint8_t itf;
430 cdcd_interface_t* p_cdc;
431
432 // Identify which interface to use
433 for (itf = 0; itf < CFG_TUD_CDC; itf++) {
434 p_cdc = &_cdcd_itf[itf];
435 if ((ep_addr == p_cdc->ep_out) || (ep_addr == p_cdc->ep_in)) break;
436 }
437 TU_ASSERT(itf < CFG_TUD_CDC);
438
439 // Received new data
440 if (ep_addr == p_cdc->ep_out) {
441 tu_fifo_write_n(&p_cdc->rx_ff, p_cdc->epout_buf, (uint16_t) xferred_bytes);
442
443 // Check for wanted char and invoke callback if needed
444 if (tud_cdc_rx_wanted_cb && (((signed char) p_cdc->wanted_char) != -1)) {
445 for (uint32_t i = 0; i < xferred_bytes; i++) {
446 if ((p_cdc->wanted_char == p_cdc->epout_buf[i]) && !tu_fifo_empty(&p_cdc->rx_ff)) {
448 }
449 }
450 }
451
452 // invoke receive callback (if there is still data)
453 if (tud_cdc_rx_cb && !tu_fifo_empty(&p_cdc->rx_ff)) tud_cdc_rx_cb(itf);
454
455 // prepare for OUT transaction
457 }
458
459 // Data sent to host, we continue to fetch from tx fifo to send.
460 // Note: This will cause incorrect baudrate set in line coding.
461 // Though maybe the baudrate is not really important !!!
462 if (ep_addr == p_cdc->ep_in) {
463 // invoke transmit callback to possibly refill tx fifo
465
466 if (0 == tud_cdc_n_write_flush(itf)) {
467 // If there is no data left, a ZLP should be sent if
468 // xferred_bytes is multiple of EP Packet size and not zero
469 if (!tu_fifo_count(&p_cdc->tx_ff) && xferred_bytes && (0 == (xferred_bytes & (BULK_PACKET_SIZE - 1)))) {
470 if (usbd_edpt_claim(rhport, p_cdc->ep_in)) {
471 usbd_edpt_xfer(rhport, p_cdc->ep_in, NULL, 0);
472 }
473 }
474 }
475 }
476
477 // nothing to do with notif endpoint for now
478
479 return true;
480}
481
482#endif
uint32_t tud_cdc_n_write_flush(uint8_t itf)
Definition: cdc_device.c:187
uint16_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
Definition: cdc_device.c:295
bool tud_cdc_n_ready(uint8_t itf)
Definition: cdc_device.c:123
bool tud_cdc_n_write_clear(uint8_t itf)
Definition: cdc_device.c:219
bool cdcd_deinit(void)
Definition: cdc_device.c:260
static bool _prep_out_transaction(cdcd_interface_t *p_cdc)
Definition: cdc_device.c:84
void tud_cdc_n_set_wanted_char(uint8_t itf, char wanted)
Definition: cdc_device.c:140
void cdcd_reset(uint8_t rhport)
Definition: cdc_device.c:282
static CFG_TUD_MEM_SECTION cdcd_interface_t _cdcd_itf[CFG_TUD_CDC]
Definition: cdc_device.c:81
void tud_cdc_n_get_line_coding(uint8_t itf, cdc_line_coding_t *coding)
Definition: cdc_device.c:136
void cdcd_init(void)
Definition: cdc_device.c:226
uint8_t tud_cdc_n_get_line_state(uint8_t itf)
Definition: cdc_device.c:132
bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request)
Definition: cdc_device.c:355
static tud_cdc_configure_fifo_t _cdcd_fifo_cfg
Definition: cdc_device.c:82
bool tud_cdc_n_connected(uint8_t itf)
Definition: cdc_device.c:127
bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
Definition: cdc_device.c:426
uint32_t tud_cdc_n_write_available(uint8_t itf)
Definition: cdc_device.c:215
void tud_cdc_n_read_flush(uint8_t itf)
Definition: cdc_device.c:162
bool tud_cdc_configure_fifo(tud_cdc_configure_fifo_t const *cfg)
Definition: cdc_device.c:117
bool tud_cdc_n_peek(uint8_t itf, uint8_t *chr)
Definition: cdc_device.c:158
uint32_t tud_cdc_n_read(uint8_t itf, void *buffer, uint32_t bufsize)
Definition: cdc_device.c:151
uint32_t tud_cdc_n_write(uint8_t itf, void const *buffer, uint32_t bufsize)
Definition: cdc_device.c:171
uint32_t tud_cdc_n_available(uint8_t itf)
Definition: cdc_device.c:147
TU_ATTR_WEAK void tud_cdc_send_break_cb(uint8_t itf, uint16_t duration_ms)
TU_ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
TU_ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const *p_line_coding)
TU_ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char)
struct TU_ATTR_ALIGNED(4)
Definition: dcd.h:55
void tud_cdc_tx_complete_cb(uint8_t itf)
void tud_cdc_rx_cb(uint8_t itf)
@ CDC_REQUEST_SET_LINE_CODING
Definition: cdc.h:153
@ CDC_REQUEST_GET_LINE_CODING
Definition: cdc.h:154
@ CDC_REQUEST_SEND_BREAK
Definition: cdc.h:156
@ CDC_REQUEST_SET_CONTROL_LINE_STATE
Definition: cdc.h:155
uint8_t const * buffer
Definition: midi_device.h:100
uint32_t bufsize
Definition: midi_device.h:95
static TU_ATTR_ALWAYS_INLINE bool osal_mutex_delete(osal_mutex_t mutex_hdl)
SemaphoreHandle_t osal_mutex_t
Definition: osal_freertos.h:54
static TU_ATTR_ALWAYS_INLINE osal_mutex_t osal_mutex_create(osal_mutex_def_t *mdef)
AUDIO Channel Cluster Descriptor (4.1)
Definition: audio.h:647
uint16_t wValue
Definition: audio.h:934
struct TU_ATTR_PACKED::@16::TU_ATTR_PACKED bmRequestType_bit
uint16_t wIndex
Definition: audio.h:943
uint8_t bInterfaceClass
Class code (assigned by the USB-IF).
Definition: tusb_types.h:349
uint8_t bEndpointAddress
Definition: video.h:306
uint8_t bInterfaceSubClass
Subclass code (assigned by the USB-IF). These codes are qualified by the value of the bInterfaceCla...
Definition: tusb_types.h:350
uint8_t bRequest
Request type audio_cs_req_t.
Definition: audio.h:831
uint8_t bInterfaceNumber
Number of this interface. Zero-based value identifying the index in the array of concurrent interface...
Definition: tusb_types.h:346
uint8_t ep_out
Definition: cdc_device.c:52
uint8_t itf_num
Definition: cdc_device.c:49
uint8_t line_state
Definition: cdc_device.c:55
uint8_t ep_notif
Definition: cdc_device.c:50
static TU_ATTR_ALWAYS_INLINE bool tu_bit_test(uint32_t value, uint8_t pos)
Definition: tusb_common.h:151
uint16_t tu_fifo_count(tu_fifo_t *f)
Get number of items in FIFO.
Definition: tusb_fifo.c:590
bool tu_fifo_config(tu_fifo_t *f, void *buffer, uint16_t depth, uint16_t item_size, bool overwritable)
Definition: tusb_fifo.c:70
bool tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable)
Change the fifo mode to overwritable or not overwritable.
Definition: tusb_fifo.c:919
uint16_t tu_fifo_write_n(tu_fifo_t *f, const void *data, uint16_t n)
This function will write n elements into the array index specified by the write pointer and increment...
Definition: tusb_fifo.c:861
bool tu_fifo_peek(tu_fifo_t *f, void *p_buffer)
Read one item without removing it from the FIFO. This function checks for an overflow and corrects re...
Definition: tusb_fifo.c:772
bool tu_fifo_full(tu_fifo_t *f)
Check if FIFO is full.
Definition: tusb_fifo.c:626
uint16_t tu_fifo_read_n(tu_fifo_t *f, void *buffer, uint16_t n)
This function will read n elements from the array index specified by the read pointer and increment t...
Definition: tusb_fifo.c:730
bool tu_fifo_empty(tu_fifo_t *f)
Check if FIFO is empty.
Definition: tusb_fifo.c:608
uint16_t tu_fifo_remaining(tu_fifo_t *f)
Get remaining space in FIFO.
Definition: tusb_fifo.c:644
bool tu_fifo_clear(tu_fifo_t *f)
Clear the fifo read and write pointers.
Definition: tusb_fifo.c:896
static TU_ATTR_ALWAYS_INLINE void tu_fifo_config_mutex(tu_fifo_t *f, osal_mutex_t wr_mutex, osal_mutex_t rd_mutex)
Definition: tusb_fifo.h:149
@ TUSB_CLASS_CDC
Definition: tusb_types.h:161
@ TUSB_CLASS_CDC_DATA
Definition: tusb_types.h:169
static TU_ATTR_ALWAYS_INLINE uint8_t tu_desc_len(void const *desc)
Definition: tusb_types.h:542
xfer_result_t
Definition: tusb_types.h:236
@ TUSB_XFER_BULK
Definition: tusb_types.h:61
struct TU_ATTR_PACKED tusb_desc_endpoint_t
USB Endpoint Descriptor.
@ CONTROL_STAGE_ACK
Definition: tusb_types.h:270
@ CONTROL_STAGE_SETUP
Definition: tusb_types.h:268
static TU_ATTR_ALWAYS_INLINE uint8_t tu_desc_type(void const *desc)
Definition: tusb_types.h:537
@ TUSB_REQ_TYPE_CLASS
Definition: tusb_types.h:145
struct TU_ATTR_PACKED tusb_desc_interface_t
USB Interface Descriptor.
static TU_ATTR_ALWAYS_INLINE uint8_t const * tu_desc_next(void const *desc)
Definition: tusb_types.h:531
@ TUSB_DESC_CS_INTERFACE
Definition: tusb_types.h:114
@ TUSB_DESC_ENDPOINT
Definition: tusb_types.h:97
@ TUSB_DESC_INTERFACE
Definition: tusb_types.h:96
bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes)
Definition: usbd.c:1309
bool usbd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_ep)
Definition: usbd.c:1277
bool usbd_edpt_claim(uint8_t rhport, uint8_t ep_addr)
Definition: usbd.c:1286
bool usbd_edpt_release(uint8_t rhport, uint8_t ep_addr)
Definition: usbd.c:1299
bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const *p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t *ep_out, uint8_t *ep_in)
Definition: usbd.c:1238
bool tud_control_xfer(uint8_t rhport, tusb_control_request_t const *request, void *buffer, uint16_t len)
Definition: usbd_control.c:111
static TU_ATTR_ALWAYS_INLINE bool tud_ready(void)
Definition: usbd.h:97
bool tud_control_status(uint8_t rhport, tusb_control_request_t const *request)
Definition: usbd_control.c:81
CFG_TUH_MEM_ALIGN tusb_control_request_t request
Definition: usbh.c:259
volatile uint8_t stage
Definition: usbh.c:265
static OSAL_MUTEX_DEF(usbtmcLockBuffer)