# MIOS32_USB_MIDI

## Defines
#define | RX_BUFFER_MAX_ANALYSIS 0
#define | EP2IDX(bEP) ((((bEP)&0xF)<<1)|(((bEP)&0x80)>>7))
#define | IDX2EP(idx) ((((idx)<<7)&0x80)|(((idx)>>1)&0xF))
## Enumerations
enum | USBH_MIDI_transfer_state_t { USBH_MIDI_IDLE, USBH_MIDI_RX, USBH_MIDI_TX }
## Functions
s32 | MIOS32_USB_MIDI_Init (u32 mode)
s32 | MIOS32_USB_MIDI_ChangeConnectionState (u8 connected)
s32 | MIOS32_USB_MIDI_CheckAvailable (u8 cable)
s32 | MIOS32_USB_MIDI_PackageSend_NonBlocking (mios32_midi_package_t package)
s32 | MIOS32_USB_MIDI_PackageSend (mios32_midi_package_t package)
s32 | MIOS32_USB_MIDI_PackageReceive (mios32_midi_package_t *package)
s32 | MIOS32_USB_MIDI_Periodic_mS (void)
void | MIOS32_USB_MIDI_EP1_IN_Callback (u8 bEP, u8 bEPStatus)
void | MIOS32_USB_MIDI_EP2_OUT_Callback (u8 bEP, u8 bEPStatus)
## Variables
USB_OTG_CORE_HANDLE | USB_OTG_dev
uint32_t | USB_rx_buffer [MIOS32_USB_MIDI_DATA_OUT_SIZE/4]
USBH_HOST | USB_Host
const USBH_Class_cb_TypeDef | MIOS32_MIDI_USBH_Callbacks

## Detailed Description

USB MIDI layer for MIOS32

USB MIDI layer for MIOS32

Applications shouldn't call these functions directly, instead please use MIOS32_MIDI layer functions

## Define Documentation

#define EP2IDX | ( | bEP |  | ) | ((((bEP)&0xF)<<1)|(((bEP)&0x80)>>7))

convert from endpoint address to endpoint index

#define IDX2EP | ( | idx |  | ) | ((((idx)<<7)&0x80)|(((idx)>>1)&0xF))

convert from endpoint index to endpoint address

#define RX_BUFFER_MAX_ANALYSIS 0

## Enumeration Type Documentation

enum USBH_MIDI_transfer_state_t

Enumerator:

  USBH_MIDI_IDLE |
  USBH_MIDI_RX |
  USBH_MIDI_TX |

## Function Documentation

s32 MIOS32_USB_MIDI_ChangeConnectionState | ( | u8 | connected | ) |

This function is called by the USB driver on cable connection/disconnection

Parameters:

  `[in]` | connected | status (1 if connected)

Returns:
  < 0 on errors

Note:
  Applications shouldn't call this function directly, instead please use MIOS32_MIDI layer functions

s32 MIOS32_USB_MIDI_CheckAvailable | ( | u8 | cable | ) |

This function returns the connection status of the USB MIDI interface

Parameters:

  `[in]` | cable | number

Returns:
  1: interface available
  0: interface not available

Note:
  Applications shouldn't call this function directly, instead please use MIOS32_MIDI layer functions

Here is the call graph for this function:

void MIOS32_USB_MIDI_EP1_IN_Callback | ( | u8 | bEP,
|  | u8 | bEPStatus |
| ) |  |  |

Called by USB driver to check for IN streams

Note:
  Applications shouldn't call this function directly, instead please use MIOS32_MIDI layer functions

Called by STM32 USB driver to check for IN streams

Note:
  Applications shouldn't call this function directly, instead please use MIOS32_MIDI layer functions
  also: bEP, bEPStatus only relevant for LPC17xx port

Called by STM32 USB Device driver to check for IN streams

Note:
  Applications shouldn't call this function directly, instead please use MIOS32_MIDI layer functions
  also: bEP, bEPStatus only relevant for LPC17xx port

void MIOS32_USB_MIDI_EP2_OUT_Callback | ( | u8 | bEP,
|  | u8 | bEPStatus |
| ) |  |  |

Called by USB driver to check for OUT streams

Note:
  Applications shouldn't call this function directly, instead please use MIOS32_MIDI layer functions

Called by STM32 USB driver to check for OUT streams

Note:
  Applications shouldn't call this function directly, instead please use MIOS32_MIDI layer functions
  also: bEP, bEPStatus only relevant for LPC17xx port

Called by STM32 USB Device driver to check for OUT streams

Note:
  Applications shouldn't call this function directly, instead please use MIOS32_MIDI layer functions
  also: bEP, bEPStatus only relevant for LPC17xx port

s32 MIOS32_USB_MIDI_Init | ( | u32 | mode | ) |

Initializes USB MIDI layer

Parameters:

  `[in]` | mode | currently only mode 0 supported

Returns:
  < 0 if initialisation failed

Note:
  Applications shouldn't call this function directly, instead please use MIOS32_MIDI layer functions

s32 MIOS32_USB_MIDI_PackageReceive | ( | mios32_midi_package_t * | package | ) |

This function checks for a new package

Parameters:

  `[out]` | package | pointer to MIDI package (received package will be put into the given variable)

Returns:
  -1 if no package in buffer
  >= 0: number of packages which are still in the buffer

Note:
  Applications shouldn't call this function directly, instead please use MIOS32_MIDI layer functions

Here is the call graph for this function:

s32 MIOS32_USB_MIDI_PackageSend | ( | mios32_midi_package_t | package | ) |

This function puts a new MIDI package into the Tx buffer (blocking function)

Parameters:

  `[in]` | package | MIDI package

Returns:
  0: no error
  -1: USB not connected

Note:
  Applications shouldn't call this function directly, instead please use MIOS32_MIDI layer functions

Here is the call graph for this function:

s32 MIOS32_USB_MIDI_PackageSend_NonBlocking | ( | mios32_midi_package_t | package | ) |

This function puts a new MIDI package into the Tx buffer

Parameters:

  `[in]` | package | MIDI package

Returns:
  0: no error
  -1: USB not connected
  -2: buffer is full caller should retry until buffer is free again

Note:
  Applications shouldn't call this function directly, instead please use MIOS32_MIDI layer functions

Here is the call graph for this function:

s32 MIOS32_USB_MIDI_Periodic_mS | ( | void |  | ) |

This function should be called periodically each mS to handle timeout and expire counters.

For USB MIDI it also checks for incoming/outgoing USB packages!

Not for use in an application - this function is called from MIOS32_MIDI_Periodic_mS(), which is called by a task in the programming model!

Returns:
  < 0 on errors

## Variable Documentation

const USBH_Class_cb_TypeDef MIOS32_MIDI_USBH_Callbacks

Initial value:

     {
      USBH_InterfaceInit,
      USBH_InterfaceDeInit,
      USBH_ClassRequest,
      USBH_Handle
    }

USBH_HOST USB_Host

USB_OTG_CORE_HANDLE USB_OTG_dev

uint32_t USB_rx_buffer[MIOS32_USB_MIDI_DATA_OUT_SIZE/4]