29#if (CFG_TUD_ENABLED && CFG_TUD_MIDI)
66 uint8_t rx_ff_buf[CFG_TUD_MIDI_RX_BUFSIZE];
67 uint8_t tx_ff_buf[CFG_TUD_MIDI_TX_BUFSIZE];
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];
80#define ITF_MEM_RESET_SIZE offsetof(midid_interface_t, rx_ff)
95 uint8_t
const rhport = 0;
102 TU_VERIFY(available >=
sizeof(p_midi->
epout_buf), );
110 if ( available >=
sizeof(p_midi->
epout_buf) ) {
138 uint8_t* buf8 = (uint8_t*)
buffer;
143 uint32_t total_read = 0;
147 if ( stream->
total == 0 )
152 uint8_t
const code_index = stream->
buffer[0] & 0x0f;
188 stream->
index += count;
210 return (num_read == 4);
222 uint8_t
const rhport = 0;
244 TU_VERIFY(midi->
ep_in, 0);
254 if ( stream->
index == 0 )
258 uint8_t
const msg =
data >> 4;
276 else if ( (msg >= 0x8 && msg <= 0xB) || msg == 0xE )
279 stream->
buffer[0] = (uint8_t) ((cable_num << 4) | msg);
282 else if ( msg == 0xC || msg == 0xD)
285 stream->
buffer[0] = (uint8_t) ((cable_num << 4) | msg);
288 else if ( msg == 0xf )
311 stream->
buffer[0] |= (uint8_t)(cable_num << 4);
316 stream->
buffer[0] = (uint8_t) (cable_num << 4 | 0xf);
327 TU_ASSERT(stream->
index < 4, i);
343 for(uint8_t idx = stream->
total; idx < 4; idx++) stream->
buffer[idx] = 0;
351 TU_ASSERT(count == 4, i);
363 TU_VERIFY(midi->
ep_in);
379 for (uint8_t i = 0; i < CFG_TUD_MIDI; i++) {
389 TU_ASSERT(mutex_wr != NULL && mutex_wr != NULL, );
399 for(uint8_t i=0; i<CFG_TUD_MIDI; i++) {
423 for(uint8_t i=0; i<CFG_TUD_MIDI; i++)
426 tu_memclr(midi, ITF_MEM_RESET_SIZE);
459 for(uint8_t i=0; i<CFG_TUD_MIDI; i++)
477 uint8_t found_endpoints = 0;
478 while ( (found_endpoints < desc_midi->bNumEndpoints) && (drv_len <= max_len) )
487 p_midi->
ep_in = ep_addr;
496 found_endpoints += 1;
531 for (itf = 0; itf < CFG_TUD_MIDI; itf++)
534 if ( ( ep_addr == p_midi->
ep_out ) || ( ep_addr == p_midi->
ep_in ) )
break;
536 TU_ASSERT(itf < CFG_TUD_MIDI);
539 if ( ep_addr == p_midi->
ep_out )
551 else if ( ep_addr == p_midi->
ep_in )
557 if ( !
tu_fifo_count(&p_midi->
tx_ff) && xferred_bytes && (0 == (xferred_bytes % CFG_TUD_MIDI_EP_BUFSIZE)) )
void tud_midi_rx_cb(uint8_t itf)
@ AUDIO_SUBCLASS_MIDI_STREAMING
MIDI Streaming.
@ AUDIO_SUBCLASS_CONTROL
Audio Control.
@ AUDIO_FUNC_PROTOCOL_CODE_UNDEF
@ MIDI_STATUS_SYSCOM_SONG_SELECT
@ MIDI_STATUS_SYSCOM_SONG_POSITION_POINTER
@ MIDI_STATUS_SYSCOM_TIME_CODE_QUARTER_FRAME
@ MIDI_STATUS_SYSEX_START
@ MIDI_CIN_PROGRAM_CHANGE
@ MIDI_CIN_SYSEX_END_1BYTE
@ MIDI_CIN_CHANNEL_PRESSURE
@ MIDI_CIN_SYSEX_END_2BYTE
bool tud_midi_n_packet_write(uint8_t itf, uint8_t const packet[4])
CFG_TUD_MEM_SECTION midid_interface_t _midid_itf[CFG_TUD_MIDI]
uint32_t tud_midi_n_stream_write(uint8_t itf, uint8_t cable_num, uint8_t const *buffer, uint32_t bufsize)
bool midid_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
uint32_t tud_midi_n_stream_read(uint8_t itf, uint8_t cable_num, void *buffer, uint32_t bufsize)
static uint32_t write_flush(midid_interface_t *midi)
uint16_t midid_open(uint8_t rhport, tusb_desc_interface_t const *desc_itf, uint16_t max_len)
uint32_t tud_midi_n_available(uint8_t itf, uint8_t cable_num)
static void _prep_out_transaction(midid_interface_t *p_midi)
bool tud_midi_n_mounted(uint8_t itf)
bool tud_midi_n_packet_read(uint8_t itf, uint8_t packet[4])
void midid_reset(uint8_t rhport)
bool midid_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request)
StaticSemaphore_t osal_mutex_def_t
static TU_ATTR_ALWAYS_INLINE bool osal_mutex_delete(osal_mutex_t mutex_hdl)
SemaphoreHandle_t osal_mutex_t
static TU_ATTR_ALWAYS_INLINE osal_mutex_t osal_mutex_create(osal_mutex_def_t *mdef)
AUDIO Channel Cluster Descriptor (4.1)
uint8_t bInterfaceClass
Class code (assigned by the USB-IF).
uint8_t bInterfaceSubClass
Subclass code (assigned by the USB-IF). These codes are qualified by the value of the bInterfaceCla...
uint8_t bInterfaceProtocol
Protocol code (assigned by the USB). These codes are qualified by the value of the bInterfaceClass ...
uint8_t bInterfaceNumber
Number of this interface. Zero-based value identifying the index in the array of concurrent interface...
osal_mutex_def_t tx_ff_mutex
CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_MIDI_EP_BUFSIZE]
CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_MIDI_EP_BUFSIZE]
midid_stream_t stream_write
osal_mutex_def_t rx_ff_mutex
midid_stream_t stream_read
uint8_t rx_ff_buf[CFG_TUD_MIDI_RX_BUFSIZE]
uint8_t tx_ff_buf[CFG_TUD_MIDI_TX_BUFSIZE]
static TU_ATTR_ALWAYS_INLINE uint32_t tu_min32(uint32_t x, uint32_t y)
static TU_ATTR_ALWAYS_INLINE int tu_memcpy_s(void *dest, size_t destsz, const void *src, size_t count)
uint16_t tu_fifo_count(tu_fifo_t *f)
Get number of items in FIFO.
bool tu_fifo_config(tu_fifo_t *f, void *buffer, uint16_t depth, uint16_t item_size, bool overwritable)
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...
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...
uint16_t tu_fifo_remaining(tu_fifo_t *f)
Get remaining space in FIFO.
bool tu_fifo_clear(tu_fifo_t *f)
Clear the fifo read and write pointers.
static TU_ATTR_ALWAYS_INLINE void tu_fifo_config_mutex(tu_fifo_t *f, osal_mutex_t wr_mutex, osal_mutex_t rd_mutex)
static TU_ATTR_ALWAYS_INLINE uint8_t tu_desc_len(void const *desc)
TU_ATTR_PACKED_END TU_ATTR_BIT_FIELD_ORDER_END static TU_ATTR_ALWAYS_INLINE tusb_dir_t tu_edpt_dir(uint8_t addr)
static TU_ATTR_ALWAYS_INLINE uint8_t tu_desc_type(void const *desc)
static TU_ATTR_ALWAYS_INLINE uint8_t const * tu_desc_next(void const *desc)
bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes)
bool usbd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_ep)
bool usbd_edpt_claim(uint8_t rhport, uint8_t ep_addr)
bool usbd_edpt_release(uint8_t rhport, uint8_t ep_addr)
CFG_TUH_MEM_ALIGN tusb_control_request_t request