mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-29 01:20:19 +00:00
Merge pull request #85 from hathach/develop
midi only use audio 1.0 without IAD
This commit is contained in:
commit
2d7e61e671
@ -250,15 +250,13 @@ bool midid_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc,
|
|||||||
(*p_length) = sizeof(tusb_desc_interface_t);
|
(*p_length) = sizeof(tusb_desc_interface_t);
|
||||||
|
|
||||||
// Skip over the class specific descriptor.
|
// Skip over the class specific descriptor.
|
||||||
(*p_length) += p_desc[DESC_OFFSET_LEN];
|
(*p_length) += tu_desc_len(p_desc);
|
||||||
p_desc = tu_desc_next(p_desc);
|
p_desc = tu_desc_next(p_desc);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( AUDIO_SUBCLASS_MIDI_STREAMING != p_interface_desc->bInterfaceSubClass ||
|
TU_VERIFY(AUDIO_SUBCLASS_MIDI_STREAMING == p_interface_desc->bInterfaceSubClass &&
|
||||||
p_interface_desc->bInterfaceProtocol != AUDIO_PROTOCOL_V1 ) {
|
AUDIO_PROTOCOL_V1 == p_interface_desc->bInterfaceProtocol );
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find available interface
|
// Find available interface
|
||||||
midid_interface_t * p_midi = NULL;
|
midid_interface_t * p_midi = NULL;
|
||||||
|
@ -174,14 +174,12 @@ TU_ATTR_WEAK void tud_resume_cb(void);
|
|||||||
//------------- MIDI -------------//
|
//------------- MIDI -------------//
|
||||||
|
|
||||||
// Length of template descriptor (96 bytes)
|
// Length of template descriptor (96 bytes)
|
||||||
#define TUD_MIDI_DESC_LEN (8 + 9 + 9 + 9 + 7 + 6 + 6 + 9 + 9 + 7 + 5 + 7 + 5)
|
#define TUD_MIDI_DESC_LEN (9 + 9 + 9 + 7 + 6 + 6 + 9 + 9 + 7 + 5 + 7 + 5)
|
||||||
|
|
||||||
// MIDI simple descriptor
|
// MIDI simple descriptor
|
||||||
// - 1 Embedded Jack In connected to 1 External Jack Out
|
// - 1 Embedded Jack In connected to 1 External Jack Out
|
||||||
// - 1 Embedded Jack out connected to 1 External Jack In
|
// - 1 Embedded Jack out connected to 1 External Jack In
|
||||||
#define TUD_MIDI_DESCRIPTOR(_itfnum, _stridx, _epin, _epout, _epsize) \
|
#define TUD_MIDI_DESCRIPTOR(_itfnum, _stridx, _epin, _epout, _epsize) \
|
||||||
/* Interface Associate */\
|
|
||||||
8, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 2, TUSB_CLASS_AUDIO, 0x00, AUDIO_PROTOCOL_V1, 0,\
|
|
||||||
/* Audio Control (AC) Interface */\
|
/* Audio Control (AC) Interface */\
|
||||||
9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_CONTROL, AUDIO_PROTOCOL_V1, _stridx,\
|
9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_CONTROL, AUDIO_PROTOCOL_V1, _stridx,\
|
||||||
/* AC Header */\
|
/* AC Header */\
|
||||||
|
@ -232,60 +232,63 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
|
|||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
static bool maybe_handle_setup_packet(void) {
|
static bool maybe_handle_setup_packet(void) {
|
||||||
if (USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.RXSTP)
|
if (USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.RXSTP)
|
||||||
{
|
{
|
||||||
USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_RXSTP;
|
USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_RXSTP;
|
||||||
|
|
||||||
// This copies the data elsewhere so we can reuse the buffer.
|
// This copies the data elsewhere so we can reuse the buffer.
|
||||||
dcd_event_setup_received(0, (uint8_t*) sram_registers[0][0].ADDR.reg, true);
|
dcd_event_setup_received(0, (uint8_t*) sram_registers[0][0].ADDR.reg, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void maybe_transfer_complete(void) {
|
void maybe_transfer_complete(void) {
|
||||||
uint32_t epints = USB->DEVICE.EPINTSMRY.reg;
|
uint32_t epints = USB->DEVICE.EPINTSMRY.reg;
|
||||||
for (uint8_t epnum = 0; epnum < USB_EPT_NUM; epnum++) {
|
|
||||||
if ((epints & (1 << epnum)) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (maybe_handle_setup_packet()) {
|
for (uint8_t epnum = 0; epnum < USB_EPT_NUM; epnum++) {
|
||||||
continue;
|
if ((epints & (1 << epnum)) == 0) {
|
||||||
}
|
continue;
|
||||||
UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
|
|
||||||
|
|
||||||
uint32_t epintflag = ep->EPINTFLAG.reg;
|
|
||||||
|
|
||||||
uint16_t total_transfer_size = 0;
|
|
||||||
|
|
||||||
// Handle IN completions
|
|
||||||
if ((epintflag & USB_DEVICE_EPINTFLAG_TRCPT1) != 0) {
|
|
||||||
ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT1;
|
|
||||||
|
|
||||||
UsbDeviceDescBank* bank = &sram_registers[epnum][TUSB_DIR_IN];
|
|
||||||
total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
|
|
||||||
|
|
||||||
uint8_t ep_addr = epnum | TUSB_DIR_IN_MASK;
|
|
||||||
dcd_event_xfer_complete(0, ep_addr, total_transfer_size, XFER_RESULT_SUCCESS, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle OUT completions
|
|
||||||
if ((epintflag & USB_DEVICE_EPINTFLAG_TRCPT0) != 0) {
|
|
||||||
ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT0;
|
|
||||||
|
|
||||||
UsbDeviceDescBank* bank = &sram_registers[epnum][TUSB_DIR_OUT];
|
|
||||||
total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
|
|
||||||
|
|
||||||
uint8_t ep_addr = epnum;
|
|
||||||
dcd_event_xfer_complete(0, ep_addr, total_transfer_size, XFER_RESULT_SUCCESS, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// just finished status stage (total size = 0), prepare for next setup packet
|
|
||||||
if (epnum == 0 && total_transfer_size == 0) {
|
|
||||||
dcd_edpt_xfer(0, 0, _setup_packet, sizeof(_setup_packet));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (maybe_handle_setup_packet()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
|
||||||
|
|
||||||
|
uint32_t epintflag = ep->EPINTFLAG.reg;
|
||||||
|
|
||||||
|
uint16_t total_transfer_size = 0;
|
||||||
|
|
||||||
|
// Handle IN completions
|
||||||
|
if ((epintflag & USB_DEVICE_EPINTFLAG_TRCPT1) != 0) {
|
||||||
|
ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT1;
|
||||||
|
|
||||||
|
UsbDeviceDescBank* bank = &sram_registers[epnum][TUSB_DIR_IN];
|
||||||
|
total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
|
||||||
|
|
||||||
|
uint8_t ep_addr = epnum | TUSB_DIR_IN_MASK;
|
||||||
|
dcd_event_xfer_complete(0, ep_addr, total_transfer_size, XFER_RESULT_SUCCESS, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle OUT completions
|
||||||
|
if ((epintflag & USB_DEVICE_EPINTFLAG_TRCPT0) != 0) {
|
||||||
|
ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT0;
|
||||||
|
|
||||||
|
UsbDeviceDescBank* bank = &sram_registers[epnum][TUSB_DIR_OUT];
|
||||||
|
total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
|
||||||
|
|
||||||
|
uint8_t ep_addr = epnum;
|
||||||
|
dcd_event_xfer_complete(0, ep_addr, total_transfer_size, XFER_RESULT_SUCCESS, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Just finished status stage (total size = 0), prepare for next setup packet
|
||||||
|
// TODO could cause issue with actual zero length data used by class such as DFU
|
||||||
|
if (epnum == 0 && total_transfer_size == 0) {
|
||||||
|
dcd_edpt_xfer(0, 0, _setup_packet, sizeof(_setup_packet));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void USB_Handler(void)
|
void USB_Handler(void)
|
||||||
|
@ -213,9 +213,9 @@ void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
|||||||
UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
|
UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
|
||||||
|
|
||||||
if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) {
|
if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) {
|
||||||
ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
|
ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
|
||||||
} else {
|
} else {
|
||||||
ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
|
ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,15 +236,15 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
|
|||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
static bool maybe_handle_setup_packet(void) {
|
static bool maybe_handle_setup_packet(void) {
|
||||||
if (USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.RXSTP)
|
if (USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.RXSTP)
|
||||||
{
|
{
|
||||||
USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_RXSTP;
|
USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_RXSTP;
|
||||||
|
|
||||||
// This copies the data elsewhere so we can reuse the buffer.
|
// This copies the data elsewhere so we can reuse the buffer.
|
||||||
dcd_event_setup_received(0, (uint8_t*) sram_registers[0][0].ADDR.reg, true);
|
dcd_event_setup_received(0, (uint8_t*) sram_registers[0][0].ADDR.reg, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
@ -309,42 +309,42 @@ void USB_0_Handler(void) {
|
|||||||
|
|
||||||
/* USB_SOF_HSOF */
|
/* USB_SOF_HSOF */
|
||||||
void USB_1_Handler(void) {
|
void USB_1_Handler(void) {
|
||||||
USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_SOF;
|
USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_SOF;
|
||||||
dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
|
dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void transfer_complete(uint8_t direction) {
|
void transfer_complete(uint8_t direction) {
|
||||||
uint32_t epints = USB->DEVICE.EPINTSMRY.reg;
|
uint32_t epints = USB->DEVICE.EPINTSMRY.reg;
|
||||||
for (uint8_t epnum = 0; epnum < USB_EPT_NUM; epnum++) {
|
for (uint8_t epnum = 0; epnum < USB_EPT_NUM; epnum++) {
|
||||||
if ((epints & (1 << epnum)) == 0) {
|
if ((epints & (1 << epnum)) == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (direction == TUSB_DIR_OUT && maybe_handle_setup_packet()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
|
|
||||||
|
|
||||||
UsbDeviceDescBank* bank = &sram_registers[epnum][direction];
|
|
||||||
uint16_t total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
|
|
||||||
|
|
||||||
uint8_t ep_addr = epnum;
|
|
||||||
if (direction == TUSB_DIR_IN) {
|
|
||||||
ep_addr |= TUSB_DIR_IN_MASK;
|
|
||||||
}
|
|
||||||
dcd_event_xfer_complete(0, ep_addr, total_transfer_size, XFER_RESULT_SUCCESS, true);
|
|
||||||
|
|
||||||
// just finished status stage (total size = 0), prepare for next setup packet
|
|
||||||
if (epnum == 0 && total_transfer_size == 0) {
|
|
||||||
dcd_edpt_xfer(0, 0, _setup_packet, sizeof(_setup_packet));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (direction == TUSB_DIR_IN) {
|
|
||||||
ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT1;
|
|
||||||
} else {
|
|
||||||
ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (direction == TUSB_DIR_OUT && maybe_handle_setup_packet()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
|
||||||
|
|
||||||
|
UsbDeviceDescBank* bank = &sram_registers[epnum][direction];
|
||||||
|
uint16_t total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
|
||||||
|
|
||||||
|
uint8_t ep_addr = epnum;
|
||||||
|
if (direction == TUSB_DIR_IN) {
|
||||||
|
ep_addr |= TUSB_DIR_IN_MASK;
|
||||||
|
}
|
||||||
|
dcd_event_xfer_complete(0, ep_addr, total_transfer_size, XFER_RESULT_SUCCESS, true);
|
||||||
|
|
||||||
|
// just finished status stage (total size = 0), prepare for next setup packet
|
||||||
|
if (epnum == 0 && total_transfer_size == 0) {
|
||||||
|
dcd_edpt_xfer(0, 0, _setup_packet, sizeof(_setup_packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (direction == TUSB_DIR_IN) {
|
||||||
|
ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT1;
|
||||||
|
} else {
|
||||||
|
ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bank zero is for OUT and SETUP transactions.
|
// Bank zero is for OUT and SETUP transactions.
|
||||||
@ -352,7 +352,7 @@ void transfer_complete(uint8_t direction) {
|
|||||||
USB_TRCPT0_3, USB_TRCPT0_4, USB_TRCPT0_5,
|
USB_TRCPT0_3, USB_TRCPT0_4, USB_TRCPT0_5,
|
||||||
USB_TRCPT0_6, USB_TRCPT0_7 */
|
USB_TRCPT0_6, USB_TRCPT0_7 */
|
||||||
void USB_2_Handler(void) {
|
void USB_2_Handler(void) {
|
||||||
transfer_complete(TUSB_DIR_OUT);
|
transfer_complete(TUSB_DIR_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bank one is used for IN transactions.
|
// Bank one is used for IN transactions.
|
||||||
@ -360,7 +360,7 @@ void USB_2_Handler(void) {
|
|||||||
USB_TRCPT1_3, USB_TRCPT1_4, USB_TRCPT1_5,
|
USB_TRCPT1_3, USB_TRCPT1_4, USB_TRCPT1_5,
|
||||||
USB_TRCPT1_6, USB_TRCPT1_7 */
|
USB_TRCPT1_6, USB_TRCPT1_7 */
|
||||||
void USB_3_Handler(void) {
|
void USB_3_Handler(void) {
|
||||||
transfer_complete(TUSB_DIR_IN);
|
transfer_complete(TUSB_DIR_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user