mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
update midi open()
This commit is contained in:
parent
89a3d1f6d1
commit
8f560bf275
@ -290,31 +290,30 @@ void midid_reset(uint8_t rhport)
|
||||
}
|
||||
}
|
||||
|
||||
bool midid_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t *p_length)
|
||||
uint16_t midid_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t max_len)
|
||||
{
|
||||
|
||||
// 1st Interface is Audio Control v1
|
||||
TU_VERIFY(TUSB_CLASS_AUDIO == desc_itf->bInterfaceClass &&
|
||||
AUDIO_SUBCLASS_CONTROL == desc_itf->bInterfaceSubClass &&
|
||||
AUDIO_PROTOCOL_V1 == desc_itf->bInterfaceProtocol);
|
||||
AUDIO_PROTOCOL_V1 == desc_itf->bInterfaceProtocol, 0);
|
||||
|
||||
uint16_t drv_len = tu_desc_len(desc_itf);
|
||||
uint8_t const * p_desc = tu_desc_next(desc_itf);
|
||||
|
||||
// Skip Class Specific descriptors
|
||||
while ( TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) )
|
||||
while ( TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) && drv_len <= max_len )
|
||||
{
|
||||
drv_len += tu_desc_len(p_desc);
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
|
||||
// 2nd Interface is MIDI Streaming
|
||||
TU_VERIFY(TUSB_DESC_INTERFACE == tu_desc_type(p_desc));
|
||||
TU_VERIFY(TUSB_DESC_INTERFACE == tu_desc_type(p_desc), 0);
|
||||
tusb_desc_interface_t const * desc_midi = (tusb_desc_interface_t const *) p_desc;
|
||||
|
||||
TU_VERIFY(TUSB_CLASS_AUDIO == desc_midi->bInterfaceClass &&
|
||||
AUDIO_SUBCLASS_MIDI_STREAMING == desc_midi->bInterfaceSubClass &&
|
||||
AUDIO_PROTOCOL_V1 == desc_midi->bInterfaceProtocol );
|
||||
AUDIO_PROTOCOL_V1 == desc_midi->bInterfaceProtocol, 0);
|
||||
|
||||
// Find available interface
|
||||
midid_interface_t * p_midi = NULL;
|
||||
@ -335,32 +334,34 @@ bool midid_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t
|
||||
|
||||
// Find and open endpoint descriptors
|
||||
uint8_t found_endpoints = 0;
|
||||
while (found_endpoints < desc_midi->bNumEndpoints)
|
||||
while ( (found_endpoints < desc_midi->bNumEndpoints) && (drv_len <= max_len) )
|
||||
{
|
||||
if ( TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE])
|
||||
if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) )
|
||||
{
|
||||
TU_ASSERT( usbd_edpt_open(rhport, (tusb_desc_endpoint_t const *) p_desc), false);
|
||||
TU_ASSERT(usbd_edpt_open(rhport, (tusb_desc_endpoint_t const *) p_desc), 0);
|
||||
uint8_t ep_addr = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress;
|
||||
if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) {
|
||||
|
||||
if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN)
|
||||
{
|
||||
p_midi->ep_in = ep_addr;
|
||||
} else {
|
||||
p_midi->ep_out = ep_addr;
|
||||
}
|
||||
|
||||
drv_len += p_desc[DESC_OFFSET_LEN];
|
||||
drv_len += tu_desc_len(p_desc);
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
|
||||
found_endpoints += 1;
|
||||
}
|
||||
drv_len += p_desc[DESC_OFFSET_LEN];
|
||||
|
||||
drv_len += tu_desc_len(p_desc);
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
|
||||
*p_length = drv_len;
|
||||
|
||||
// Prepare for incoming data
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_midi->ep_out, p_midi->epout_buf, CFG_TUD_MIDI_EPSIZE), false);
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_midi->ep_out, p_midi->epout_buf, CFG_TUD_MIDI_EPSIZE), 0 );
|
||||
|
||||
return true;
|
||||
return drv_len;
|
||||
}
|
||||
|
||||
bool midid_control_complete(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
|
@ -138,7 +138,7 @@ static inline bool tud_midi_send (uint8_t const packet[4])
|
||||
//--------------------------------------------------------------------+
|
||||
void midid_init (void);
|
||||
void midid_reset (uint8_t rhport);
|
||||
bool midid_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length);
|
||||
uint16_t midid_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
|
||||
bool midid_control_request (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool midid_control_complete (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool midid_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes);
|
||||
|
Loading…
x
Reference in New Issue
Block a user