Open FFBoard
Open source force feedback firmware
midi_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_MIDI)
30
31//--------------------------------------------------------------------+
32// INCLUDE
33//--------------------------------------------------------------------+
34#include "device/usbd.h"
35#include "device/usbd_pvt.h"
36
37#include "midi_device.h"
38
39//--------------------------------------------------------------------+
40// MACRO CONSTANT TYPEDEF
41//--------------------------------------------------------------------+
42
43typedef struct
44{
45 uint8_t buffer[4];
46 uint8_t index;
47 uint8_t total;
49
50typedef struct
51{
52 uint8_t itf_num;
53 uint8_t ep_in;
54 uint8_t ep_out;
55
56 // For Stream read()/write() API
57 // Messages are always 4 bytes long, queue them for reading and writing so the
58 // callers can use the Stream interface with single-byte read/write calls.
61
62 /*------------- From this point, data is not cleared by bus reset -------------*/
63 // FIFO
66 uint8_t rx_ff_buf[CFG_TUD_MIDI_RX_BUFSIZE];
67 uint8_t tx_ff_buf[CFG_TUD_MIDI_TX_BUFSIZE];
68
69 #if CFG_FIFO_MUTEX
72 #endif
73
74 // Endpoint Transfer buffer
75 CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_MIDI_EP_BUFSIZE];
76 CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_MIDI_EP_BUFSIZE];
77
79
80#define ITF_MEM_RESET_SIZE offsetof(midid_interface_t, rx_ff)
81
82//--------------------------------------------------------------------+
83// INTERNAL OBJECT & FUNCTION DECLARATION
84//--------------------------------------------------------------------+
85CFG_TUD_MEM_SECTION midid_interface_t _midid_itf[CFG_TUD_MIDI];
86
87bool tud_midi_n_mounted (uint8_t itf)
88{
89 midid_interface_t* midi = &_midid_itf[itf];
90 return midi->ep_in && midi->ep_out;
91}
92
94{
95 uint8_t const rhport = 0;
96 uint16_t available = tu_fifo_remaining(&p_midi->rx_ff);
97
98 // Prepare for incoming data but only allow what we can store in the ring buffer.
99 // TODO Actually we can still carry out the transfer, keeping count of received bytes
100 // and slowly move it to the FIFO when read().
101 // This pre-check reduces endpoint claiming
102 TU_VERIFY(available >= sizeof(p_midi->epout_buf), );
103
104 // claim endpoint
105 TU_VERIFY(usbd_edpt_claim(rhport, p_midi->ep_out), );
106
107 // fifo can be changed before endpoint is claimed
108 available = tu_fifo_remaining(&p_midi->rx_ff);
109
110 if ( available >= sizeof(p_midi->epout_buf) ) {
111 usbd_edpt_xfer(rhport, p_midi->ep_out, p_midi->epout_buf, sizeof(p_midi->epout_buf));
112 }else
113 {
114 // Release endpoint since we don't make any transfer
115 usbd_edpt_release(rhport, p_midi->ep_out);
116 }
117}
118
119//--------------------------------------------------------------------+
120// READ API
121//--------------------------------------------------------------------+
122uint32_t tud_midi_n_available(uint8_t itf, uint8_t cable_num)
123{
124 (void) cable_num;
125
126 midid_interface_t* midi = &_midid_itf[itf];
127 midid_stream_t const* stream = &midi->stream_read;
128
129 // when using with packet API stream total & index are both zero
130 return tu_fifo_count(&midi->rx_ff) + (uint8_t) (stream->total - stream->index);
131}
132
133uint32_t tud_midi_n_stream_read(uint8_t itf, uint8_t cable_num, void* buffer, uint32_t bufsize)
134{
135 (void) cable_num;
136 TU_VERIFY(bufsize, 0);
137
138 uint8_t* buf8 = (uint8_t*) buffer;
139
140 midid_interface_t* midi = &_midid_itf[itf];
141 midid_stream_t* stream = &midi->stream_read;
142
143 uint32_t total_read = 0;
144 while( bufsize )
145 {
146 // Get new packet from fifo, then set packet expected bytes
147 if ( stream->total == 0 )
148 {
149 // return if there is no more data from fifo
150 if ( !tud_midi_n_packet_read(itf, stream->buffer) ) return total_read;
151
152 uint8_t const code_index = stream->buffer[0] & 0x0f;
153
154 // MIDI 1.0 Table 4-1: Code Index Number Classifications
155 switch(code_index)
156 {
157 case MIDI_CIN_MISC:
159 // These are reserved and unused, possibly issue somewhere, skip this packet
160 return 0;
161 break;
162
165 stream->total = 1;
166 break;
167
172 stream->total = 2;
173 break;
174
175 default:
176 stream->total = 3;
177 break;
178 }
179 }
180
181 // Copy data up to bufsize
182 uint8_t const count = (uint8_t) tu_min32(stream->total - stream->index, bufsize);
183
184 // Skip the header (1st byte) in the buffer
185 TU_VERIFY(0 == tu_memcpy_s(buf8, bufsize, stream->buffer + 1 + stream->index, count));
186
187 total_read += count;
188 stream->index += count;
189 buf8 += count;
190 bufsize -= count;
191
192 // complete current event packet, reset stream
193 if ( stream->total == stream->index )
194 {
195 stream->index = 0;
196 stream->total = 0;
197 }
198 }
199
200 return total_read;
201}
202
203bool tud_midi_n_packet_read (uint8_t itf, uint8_t packet[4])
204{
205 midid_interface_t* midi = &_midid_itf[itf];
206 TU_VERIFY(midi->ep_out);
207
208 uint32_t const num_read = tu_fifo_read_n(&midi->rx_ff, packet, 4);
210 return (num_read == 4);
211}
212
213//--------------------------------------------------------------------+
214// WRITE API
215//--------------------------------------------------------------------+
216
217static uint32_t write_flush(midid_interface_t* midi)
218{
219 // No data to send
220 if ( !tu_fifo_count(&midi->tx_ff) ) return 0;
221
222 uint8_t const rhport = 0;
223
224 // skip if previous transfer not complete
225 TU_VERIFY( usbd_edpt_claim(rhport, midi->ep_in), 0 );
226
227 uint16_t count = tu_fifo_read_n(&midi->tx_ff, midi->epin_buf, CFG_TUD_MIDI_EP_BUFSIZE);
228
229 if (count)
230 {
231 TU_ASSERT( usbd_edpt_xfer(rhport, midi->ep_in, midi->epin_buf, count), 0 );
232 return count;
233 }else
234 {
235 // Release endpoint since we don't make any transfer
236 usbd_edpt_release(rhport, midi->ep_in);
237 return 0;
238 }
239}
240
241uint32_t tud_midi_n_stream_write(uint8_t itf, uint8_t cable_num, uint8_t const* buffer, uint32_t bufsize)
242{
243 midid_interface_t* midi = &_midid_itf[itf];
244 TU_VERIFY(midi->ep_in, 0);
245
246 midid_stream_t* stream = &midi->stream_write;
247
248 uint32_t i = 0;
249 while ( (i < bufsize) && (tu_fifo_remaining(&midi->tx_ff) >= 4) )
250 {
251 uint8_t const data = buffer[i];
252 i++;
253
254 if ( stream->index == 0 )
255 {
256 //------------- New event packet -------------//
257
258 uint8_t const msg = data >> 4;
259
260 stream->index = 2;
261 stream->buffer[1] = data;
262
263 // Check to see if we're still in a SysEx transmit.
264 if ( ((stream->buffer[0]) & 0xF) == MIDI_CIN_SYSEX_START )
265 {
267 {
268 stream->buffer[0] = (uint8_t) ((cable_num << 4) | MIDI_CIN_SYSEX_END_1BYTE);
269 stream->total = 2;
270 }
271 else
272 {
273 stream->total = 4;
274 }
275 }
276 else if ( (msg >= 0x8 && msg <= 0xB) || msg == 0xE )
277 {
278 // Channel Voice Messages
279 stream->buffer[0] = (uint8_t) ((cable_num << 4) | msg);
280 stream->total = 4;
281 }
282 else if ( msg == 0xC || msg == 0xD)
283 {
284 // Channel Voice Messages, two-byte variants (Program Change and Channel Pressure)
285 stream->buffer[0] = (uint8_t) ((cable_num << 4) | msg);
286 stream->total = 3;
287 }
288 else if ( msg == 0xf )
289 {
290 // System message
292 {
293 stream->buffer[0] = MIDI_CIN_SYSEX_START;
294 stream->total = 4;
295 }
297 {
298 stream->buffer[0] = MIDI_CIN_SYSCOM_2BYTE;
299 stream->total = 3;
300 }
302 {
303 stream->buffer[0] = MIDI_CIN_SYSCOM_3BYTE;
304 stream->total = 4;
305 }
306 else
307 {
308 stream->buffer[0] = MIDI_CIN_SYSEX_END_1BYTE;
309 stream->total = 2;
310 }
311 stream->buffer[0] |= (uint8_t)(cable_num << 4);
312 }
313 else
314 {
315 // Pack individual bytes if we don't support packing them into words.
316 stream->buffer[0] = (uint8_t) (cable_num << 4 | 0xf);
317 stream->buffer[2] = 0;
318 stream->buffer[3] = 0;
319 stream->index = 2;
320 stream->total = 2;
321 }
322 }
323 else
324 {
325 //------------- On-going (buffering) packet -------------//
326
327 TU_ASSERT(stream->index < 4, i);
328 stream->buffer[stream->index] = data;
329 stream->index++;
330
331 // See if this byte ends a SysEx.
332 if ( (stream->buffer[0] & 0xF) == MIDI_CIN_SYSEX_START && data == MIDI_STATUS_SYSEX_END )
333 {
334 stream->buffer[0] = (uint8_t) ((cable_num << 4) | (MIDI_CIN_SYSEX_START + (stream->index - 1)));
335 stream->total = stream->index;
336 }
337 }
338
339 // Send out packet
340 if ( stream->index == stream->total )
341 {
342 // zeroes unused bytes
343 for(uint8_t idx = stream->total; idx < 4; idx++) stream->buffer[idx] = 0;
344
345 uint16_t const count = tu_fifo_write_n(&midi->tx_ff, stream->buffer, 4);
346
347 // complete current event packet, reset stream
348 stream->index = stream->total = 0;
349
350 // FIFO overflown, since we already check fifo remaining. It is probably race condition
351 TU_ASSERT(count == 4, i);
352 }
353 }
354
355 write_flush(midi);
356
357 return i;
358}
359
360bool tud_midi_n_packet_write (uint8_t itf, uint8_t const packet[4])
361{
362 midid_interface_t* midi = &_midid_itf[itf];
363 TU_VERIFY(midi->ep_in);
364
365 if (tu_fifo_remaining(&midi->tx_ff) < 4) return false;
366
367 tu_fifo_write_n(&midi->tx_ff, packet, 4);
368 write_flush(midi);
369
370 return true;
371}
372
373//--------------------------------------------------------------------+
374// USBD Driver API
375//--------------------------------------------------------------------+
376void midid_init(void) {
377 tu_memclr(_midid_itf, sizeof(_midid_itf));
378
379 for (uint8_t i = 0; i < CFG_TUD_MIDI; i++) {
380 midid_interface_t* midi = &_midid_itf[i];
381
382 // config fifo
383 tu_fifo_config(&midi->rx_ff, midi->rx_ff_buf, CFG_TUD_MIDI_RX_BUFSIZE, 1, false); // true, true
384 tu_fifo_config(&midi->tx_ff, midi->tx_ff_buf, CFG_TUD_MIDI_TX_BUFSIZE, 1, false); // OBVS.
385
386 #if CFG_FIFO_MUTEX
387 osal_mutex_t mutex_rd = osal_mutex_create(&midi->rx_ff_mutex);
388 osal_mutex_t mutex_wr = osal_mutex_create(&midi->tx_ff_mutex);
389 TU_ASSERT(mutex_wr != NULL && mutex_wr != NULL, );
390
391 tu_fifo_config_mutex(&midi->rx_ff, NULL, mutex_rd);
392 tu_fifo_config_mutex(&midi->tx_ff, mutex_wr, NULL);
393 #endif
394 }
395}
396
397bool midid_deinit(void) {
398 #if CFG_FIFO_MUTEX
399 for(uint8_t i=0; i<CFG_TUD_MIDI; i++) {
400 midid_interface_t* midi = &_midid_itf[i];
401 osal_mutex_t mutex_rd = midi->rx_ff.mutex_rd;
402 osal_mutex_t mutex_wr = midi->tx_ff.mutex_wr;
403
404 if (mutex_rd) {
405 osal_mutex_delete(mutex_rd);
406 tu_fifo_config_mutex(&midi->rx_ff, NULL, NULL);
407 }
408
409 if (mutex_wr) {
410 osal_mutex_delete(mutex_wr);
411 tu_fifo_config_mutex(&midi->tx_ff, NULL, NULL);
412 }
413 }
414 #endif
415
416 return true;
417}
418
419void midid_reset(uint8_t rhport)
420{
421 (void) rhport;
422
423 for(uint8_t i=0; i<CFG_TUD_MIDI; i++)
424 {
425 midid_interface_t* midi = &_midid_itf[i];
426 tu_memclr(midi, ITF_MEM_RESET_SIZE);
427 tu_fifo_clear(&midi->rx_ff);
428 tu_fifo_clear(&midi->tx_ff);
429 }
430}
431
432uint16_t midid_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t max_len)
433{
434 // 1st Interface is Audio Control v1
435 TU_VERIFY(TUSB_CLASS_AUDIO == desc_itf->bInterfaceClass &&
438
439 uint16_t drv_len = tu_desc_len(desc_itf);
440 uint8_t const * p_desc = tu_desc_next(desc_itf);
441
442 // Skip Class Specific descriptors
443 while ( TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) && drv_len <= max_len )
444 {
445 drv_len += tu_desc_len(p_desc);
446 p_desc = tu_desc_next(p_desc);
447 }
448
449 // 2nd Interface is MIDI Streaming
450 TU_VERIFY(TUSB_DESC_INTERFACE == tu_desc_type(p_desc), 0);
451 tusb_desc_interface_t const * desc_midi = (tusb_desc_interface_t const *) p_desc;
452
453 TU_VERIFY(TUSB_CLASS_AUDIO == desc_midi->bInterfaceClass &&
456
457 // Find available interface
458 midid_interface_t * p_midi = NULL;
459 for(uint8_t i=0; i<CFG_TUD_MIDI; i++)
460 {
461 if ( _midid_itf[i].ep_in == 0 && _midid_itf[i].ep_out == 0 )
462 {
463 p_midi = &_midid_itf[i];
464 break;
465 }
466 }
467 TU_ASSERT(p_midi);
468
469 p_midi->itf_num = desc_midi->bInterfaceNumber;
470 (void) p_midi->itf_num;
471
472 // next descriptor
473 drv_len += tu_desc_len(p_desc);
474 p_desc = tu_desc_next(p_desc);
475
476 // Find and open endpoint descriptors
477 uint8_t found_endpoints = 0;
478 while ( (found_endpoints < desc_midi->bNumEndpoints) && (drv_len <= max_len) )
479 {
480 if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) )
481 {
482 TU_ASSERT(usbd_edpt_open(rhport, (tusb_desc_endpoint_t const *) p_desc), 0);
483 uint8_t ep_addr = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress;
484
485 if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN)
486 {
487 p_midi->ep_in = ep_addr;
488 } else {
489 p_midi->ep_out = ep_addr;
490 }
491
492 // Class Specific MIDI Stream endpoint descriptor
493 drv_len += tu_desc_len(p_desc);
494 p_desc = tu_desc_next(p_desc);
495
496 found_endpoints += 1;
497 }
498
499 drv_len += tu_desc_len(p_desc);
500 p_desc = tu_desc_next(p_desc);
501 }
502
503 // Prepare for incoming data
504 _prep_out_transaction(p_midi);
505
506 return drv_len;
507}
508
509// Invoked when a control transfer occurred on an interface of this class
510// Driver response accordingly to the request and the transfer stage (setup/data/ack)
511// return false to stall control endpoint (e.g unsupported request)
512bool midid_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
513{
514 (void) rhport;
515 (void) stage;
516 (void) request;
517
518 // driver doesn't support any request yet
519 return false;
520}
521
522bool midid_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
523{
524 (void) result;
525 (void) rhport;
526
527 uint8_t itf;
528 midid_interface_t* p_midi;
529
530 // Identify which interface to use
531 for (itf = 0; itf < CFG_TUD_MIDI; itf++)
532 {
533 p_midi = &_midid_itf[itf];
534 if ( ( ep_addr == p_midi->ep_out ) || ( ep_addr == p_midi->ep_in ) ) break;
535 }
536 TU_ASSERT(itf < CFG_TUD_MIDI);
537
538 // receive new data
539 if ( ep_addr == p_midi->ep_out )
540 {
541 tu_fifo_write_n(&p_midi->rx_ff, p_midi->epout_buf, (uint16_t) xferred_bytes);
542
543 // invoke receive callback if available
545
546 // prepare for next
547 // TODO for now ep_out is not used by public API therefore there is no race condition,
548 // and does not need to claim like ep_in
549 _prep_out_transaction(p_midi);
550 }
551 else if ( ep_addr == p_midi->ep_in )
552 {
553 if (0 == write_flush(p_midi))
554 {
555 // If there is no data left, a ZLP should be sent if
556 // xferred_bytes is multiple of EP size and not zero
557 if ( !tu_fifo_count(&p_midi->tx_ff) && xferred_bytes && (0 == (xferred_bytes % CFG_TUD_MIDI_EP_BUFSIZE)) )
558 {
559 if ( usbd_edpt_claim(rhport, p_midi->ep_in) )
560 {
561 usbd_edpt_xfer(rhport, p_midi->ep_in, NULL, 0);
562 }
563 }
564 }
565 }
566
567 return true;
568}
569
570#endif
static struct @612 data
void tud_midi_rx_cb(uint8_t itf)
@ AUDIO_SUBCLASS_MIDI_STREAMING
MIDI Streaming.
Definition: audio.h:63
@ AUDIO_SUBCLASS_CONTROL
Audio Control.
Definition: audio.h:61
@ AUDIO_FUNC_PROTOCOL_CODE_UNDEF
Definition: audio.h:53
@ MIDI_STATUS_SYSCOM_SONG_SELECT
Definition: midi.h:94
@ MIDI_STATUS_SYSCOM_SONG_POSITION_POINTER
Definition: midi.h:93
@ MIDI_STATUS_SYSCOM_TIME_CODE_QUARTER_FRAME
Definition: midi.h:92
@ MIDI_STATUS_SYSEX_END
Definition: midi.h:89
@ MIDI_STATUS_SYSEX_START
Definition: midi.h:88
@ MIDI_CIN_PROGRAM_CHANGE
Definition: midi.h:78
@ MIDI_CIN_SYSCOM_3BYTE
Definition: midi.h:69
@ MIDI_CIN_CABLE_EVENT
Definition: midi.h:67
@ MIDI_CIN_SYSEX_END_1BYTE
Definition: midi.h:71
@ MIDI_CIN_CHANNEL_PRESSURE
Definition: midi.h:79
@ MIDI_CIN_SYSCOM_2BYTE
Definition: midi.h:68
@ MIDI_CIN_SYSEX_END_2BYTE
Definition: midi.h:72
@ MIDI_CIN_1BYTE_DATA
Definition: midi.h:81
@ MIDI_CIN_SYSEX_START
Definition: midi.h:70
@ MIDI_CIN_MISC
Definition: midi.h:66
bool tud_midi_n_packet_write(uint8_t itf, uint8_t const packet[4])
Definition: midi_device.c:360
CFG_TUD_MEM_SECTION midid_interface_t _midid_itf[CFG_TUD_MIDI]
Definition: midi_device.c:85
uint32_t tud_midi_n_stream_write(uint8_t itf, uint8_t cable_num, uint8_t const *buffer, uint32_t bufsize)
Definition: midi_device.c:241
void midid_init(void)
Definition: midi_device.c:376
bool midid_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
Definition: midi_device.c:522
uint32_t tud_midi_n_stream_read(uint8_t itf, uint8_t cable_num, void *buffer, uint32_t bufsize)
Definition: midi_device.c:133
static uint32_t write_flush(midid_interface_t *midi)
Definition: midi_device.c:217
uint16_t midid_open(uint8_t rhport, tusb_desc_interface_t const *desc_itf, uint16_t max_len)
Definition: midi_device.c:432
uint32_t tud_midi_n_available(uint8_t itf, uint8_t cable_num)
Definition: midi_device.c:122
static void _prep_out_transaction(midid_interface_t *p_midi)
Definition: midi_device.c:93
bool tud_midi_n_mounted(uint8_t itf)
Definition: midi_device.c:87
bool tud_midi_n_packet_read(uint8_t itf, uint8_t packet[4])
Definition: midi_device.c:203
void midid_reset(uint8_t rhport)
Definition: midi_device.c:419
bool midid_deinit(void)
Definition: midi_device.c:397
bool midid_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request)
Definition: midi_device.c:512
uint8_t const * buffer
Definition: midi_device.h:100
uint32_t bufsize
Definition: midi_device.h:95
StaticSemaphore_t osal_mutex_def_t
Definition: osal_freertos.h:46
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
uint8_t bInterfaceClass
Class code (assigned by the USB-IF).
Definition: tusb_types.h:349
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 bInterfaceProtocol
Protocol code (assigned by the USB). These codes are qualified by the value of the bInterfaceClass ...
Definition: tusb_types.h:351
uint8_t bInterfaceNumber
Number of this interface. Zero-based value identifying the index in the array of concurrent interface...
Definition: tusb_types.h:346
osal_mutex_def_t tx_ff_mutex
Definition: midi_device.c:71
tu_fifo_t rx_ff
Definition: midi_device.c:64
CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_MIDI_EP_BUFSIZE]
Definition: midi_device.c:75
CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_MIDI_EP_BUFSIZE]
Definition: midi_device.c:76
midid_stream_t stream_write
Definition: midi_device.c:59
osal_mutex_def_t rx_ff_mutex
Definition: midi_device.c:70
tu_fifo_t tx_ff
Definition: midi_device.c:65
midid_stream_t stream_read
Definition: midi_device.c:60
uint8_t rx_ff_buf[CFG_TUD_MIDI_RX_BUFSIZE]
Definition: midi_device.c:66
uint8_t tx_ff_buf[CFG_TUD_MIDI_TX_BUFSIZE]
Definition: midi_device.c:67
uint8_t total
Definition: midi_device.c:47
uint8_t index
Definition: midi_device.c:46
uint8_t buffer[4]
Definition: midi_device.c:45
osal_mutex_t mutex_wr
Definition: tusb_fifo.h:119
osal_mutex_t mutex_rd
Definition: tusb_fifo.h:120
static TU_ATTR_ALWAYS_INLINE uint32_t tu_min32(uint32_t x, uint32_t y)
Definition: tusb_common.h:156
static TU_ATTR_ALWAYS_INLINE int tu_memcpy_s(void *dest, size_t destsz, const void *src, size_t count)
Definition: tusb_common.h:114
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
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
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
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_DIR_IN
Definition: tusb_types.h:67
@ TUSB_CLASS_AUDIO
Definition: tusb_types.h:160
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
TU_ATTR_PACKED_END TU_ATTR_BIT_FIELD_ORDER_END static TU_ATTR_ALWAYS_INLINE tusb_dir_t tu_edpt_dir(uint8_t addr)
Definition: tusb_types.h:502
static TU_ATTR_ALWAYS_INLINE uint8_t tu_desc_type(void const *desc)
Definition: tusb_types.h:537
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
CFG_TUH_MEM_ALIGN tusb_control_request_t request
Definition: usbh.c:259
volatile uint8_t stage
Definition: usbh.c:265