# MIOS32_USB

## Data Structures
struct | TLineCoding
## Defines
#define | DSCR_DEVICE 1
#define | DSCR_CONFIG 2
#define | DSCR_STRING 3
#define | DSCR_INTRFC 4
#define | DSCR_ENDPNT 5
#define | CS_INTERFACE 0x24
#define | CS_ENDPOINT 0x25
#define | LE_WORD(x) ((x)&0xFF),((x)>>8)
#define | SET_LINE_CODING 0x20
#define | GET_LINE_CODING 0x21
#define | SET_CONTROL_LINE_STATE 0x22
#define | MIOS32_USB_MIDI_NUM_INTERFACES 2
#define | MIOS32_USB_MIDI_AC_INTERFACE_IX 0x00
#define | MIOS32_USB_MIDI_AS_INTERFACE_IX 0x01
#define | MIOS32_USB_MIDI_INTERFACE_OFFSET 2
#define | MIOS32_USB_MIDI_SIZ_CLASS_DESC (7+MIOS32_USB_MIDI_NUM_PORTS*(6+6+9+9)+9+(4+MIOS32_USB_MIDI_NUM_PORTS)+9+(4+MIOS32_USB_MIDI_NUM_PORTS))
#define | MIOS32_USB_MIDI_SIZ_CONFIG_DESC (9+MIOS32_USB_MIDI_USE_AC_INTERFACE*(9+9)+MIOS32_USB_MIDI_SIZ_CLASS_DESC)
#define | MIOS32_USB_MIDI_SIZ_CLASS_DESC_SINGLE_USB (7+1*(6+6+9+9)+9+(4+1)+9+(4+1))
#define | MIOS32_USB_MIDI_SIZ_CONFIG_DESC_SINGLE_USB (9+MIOS32_USB_MIDI_USE_AC_INTERFACE*(9+9)+MIOS32_USB_MIDI_SIZ_CLASS_DESC_SINGLE_USB)
#define | MIOS32_USB_COM_NUM_INTERFACES 2
#define | MIOS32_USB_COM_SIZ_CONFIG_DESC 58
#define | MIOS32_USB_COM_CC_INTERFACE_IX (MIOS32_USB_MIDI_INTERFACE_OFFSET + 0x00)
#define | MIOS32_USB_COM_CD_INTERFACE_IX (MIOS32_USB_MIDI_INTERFACE_OFFSET + 0x01)
#define | MIOS32_USB_COM_INTERFACE_OFFSET (MIOS32_USB_MIDI_INTERFACE_OFFSET + 2)
#define | MIOS32_USB_NUM_INTERFACES (MIOS32_USB_MIDI_NUM_INTERFACES + MIOS32_USB_COM_NUM_INTERFACES)
#define | MIOS32_USB_SIZ_CONFIG_DESC (9 + MIOS32_USB_MIDI_SIZ_CONFIG_DESC + MIOS32_USB_COM_SIZ_CONFIG_DESC)
#define | MIOS32_USB_SIZ_CONFIG_DESC_SINGLE_USB (9 + MIOS32_USB_MIDI_SIZ_CONFIG_DESC_SINGLE_USB)
#define | MIOS32_USB_SIZ_DEVICE_DESC 18
#define | BUFFER_SIZE 100
#define | DSCR_DEVICE 1
#define | DSCR_CONFIG 2
#define | DSCR_STRING 3
#define | DSCR_INTRFC 4
#define | DSCR_ENDPNT 5
#define | CS_INTERFACE 0x24
#define | CS_ENDPOINT 0x25
#define | IMR_MSK (CNTR_CTRM | CNTR_RESETM)
#define | MIOS32_USB_MIDI_NUM_INTERFACES 2
#define | MIOS32_USB_MIDI_AC_INTERFACE_IX 0x00
#define | MIOS32_USB_MIDI_AS_INTERFACE_IX 0x01
#define | MIOS32_USB_MIDI_INTERFACE_OFFSET 2
#define | MIOS32_USB_MIDI_SIZ_CLASS_DESC (7+MIOS32_USB_MIDI_NUM_PORTS*(6+6+9+9)+9+(4+MIOS32_USB_MIDI_NUM_PORTS)+9+(4+MIOS32_USB_MIDI_NUM_PORTS))
#define | MIOS32_USB_MIDI_SIZ_CONFIG_DESC (9+MIOS32_USB_MIDI_USE_AC_INTERFACE*(9+9)+MIOS32_USB_MIDI_SIZ_CLASS_DESC)
#define | MIOS32_USB_MIDI_SIZ_CLASS_DESC_SINGLE_USB (7+1*(6+6+9+9)+9+(4+1)+9+(4+1))
#define | MIOS32_USB_MIDI_SIZ_CONFIG_DESC_SINGLE_USB (9+MIOS32_USB_MIDI_USE_AC_INTERFACE*(9+9)+MIOS32_USB_MIDI_SIZ_CLASS_DESC)
#define | MIOS32_USB_COM_NUM_INTERFACES 2
#define | MIOS32_USB_COM_SIZ_CONFIG_DESC 58
#define | MIOS32_USB_COM_CC_INTERFACE_IX (MIOS32_USB_MIDI_INTERFACE_OFFSET + 0x00)
#define | MIOS32_USB_COM_CD_INTERFACE_IX (MIOS32_USB_MIDI_INTERFACE_OFFSET + 0x01)
#define | MIOS32_USB_COM_INTERFACE_OFFSET (MIOS32_USB_MIDI_INTERFACE_OFFSET + 2)
#define | MIOS32_USB_NUM_INTERFACES (MIOS32_USB_MIDI_NUM_INTERFACES + MIOS32_USB_COM_NUM_INTERFACES)
#define | MIOS32_USB_SIZ_CONFIG_DESC (9 + MIOS32_USB_MIDI_SIZ_CONFIG_DESC + MIOS32_USB_COM_SIZ_CONFIG_DESC)
#define | MIOS32_USB_SIZ_CONFIG_DESC_SINGLE_USB (9 + MIOS32_USB_MIDI_SIZ_CONFIG_DESC_SINGLE_USB)
#define | MIOS32_USB_SIZ_DEVICE_DESC 18
#define | DSCR_DEVICE 1
#define | DSCR_CONFIG 2
#define | DSCR_STRING 3
#define | DSCR_INTRFC 4
#define | DSCR_ENDPNT 5
#define | CS_INTERFACE 0x24
#define | CS_ENDPOINT 0x25
#define | MIOS32_USB_MIDI_NUM_INTERFACES 2
#define | MIOS32_USB_MIDI_AC_INTERFACE_IX 0x00
#define | MIOS32_USB_MIDI_AS_INTERFACE_IX 0x01
#define | MIOS32_USB_MIDI_INTERFACE_OFFSET 2
#define | MIOS32_USB_MIDI_SIZ_CLASS_DESC (7+MIOS32_USB_MIDI_NUM_PORTS*(6+6+9+9)+9+(4+MIOS32_USB_MIDI_NUM_PORTS)+9+(4+MIOS32_USB_MIDI_NUM_PORTS))
#define | MIOS32_USB_MIDI_SIZ_CONFIG_DESC (9+MIOS32_USB_MIDI_USE_AC_INTERFACE*(9+9)+MIOS32_USB_MIDI_SIZ_CLASS_DESC)
#define | MIOS32_USB_MIDI_SIZ_CLASS_DESC_SINGLE_USB (7+1*(6+6+9+9)+9+(4+1)+9+(4+1))
#define | MIOS32_USB_MIDI_SIZ_CONFIG_DESC_SINGLE_USB (9+MIOS32_USB_MIDI_USE_AC_INTERFACE*(9+9)+MIOS32_USB_MIDI_SIZ_CLASS_DESC)
#define | MIOS32_USB_COM_NUM_INTERFACES 2
#define | MIOS32_USB_COM_SIZ_CONFIG_DESC 58
#define | MIOS32_USB_COM_CC_INTERFACE_IX (MIOS32_USB_MIDI_INTERFACE_OFFSET + 0x00)
#define | MIOS32_USB_COM_CD_INTERFACE_IX (MIOS32_USB_MIDI_INTERFACE_OFFSET + 0x01)
#define | MIOS32_USB_COM_INTERFACE_OFFSET (MIOS32_USB_MIDI_INTERFACE_OFFSET + 2)
#define | MIOS32_USB_NUM_INTERFACES (MIOS32_USB_MIDI_NUM_INTERFACES + MIOS32_USB_COM_NUM_INTERFACES)
#define | MIOS32_USB_SIZ_CONFIG_DESC (9 + MIOS32_USB_MIDI_SIZ_CONFIG_DESC + MIOS32_USB_COM_SIZ_CONFIG_DESC)
#define | MIOS32_USB_SIZ_CONFIG_DESC_SINGLE_USB (9 + MIOS32_USB_MIDI_SIZ_CONFIG_DESC_SINGLE_USB)
#define | MIOS32_USB_SIZ_DEVICE_DESC 18
## Typedefs
typedef enum _DEVICE_STATE | DEVICE_STATE
## Enumerations
enum | _DEVICE_STATE { UNCONNECTED, ATTACHED, POWERED, SUSPENDED, ADDRESSED, CONFIGURED }
## Functions
s32 | MIOS32_USB_Init (u32 mode)
void | USB_IRQHandler (void)
s32 | MIOS32_USB_IsInitialized (void)
s32 | MIOS32_USB_ForceSingleUSB (void)
void | USB_LP_CAN1_RX0_IRQHandler (void)
void | USB_OTG_BSP_Init (USB_OTG_CORE_HANDLE *pdev)
| USB_OTG_BSP_Init Initilizes BSP configurations.
void | USB_OTG_BSP_EnableInterrupt (USB_OTG_CORE_HANDLE *pdev)
| USB_OTG_BSP_EnableInterrupt Enabele USB Global interrupt.
void | OTG_FS_IRQHandler (void)
| This function handles OTG_FS Handler.
void | USB_OTG_BSP_uDelay (const uint32_t usec)
| USB_OTG_BSP_uDelay This function provides delay time in micro sec.
void | USB_OTG_BSP_mDelay (const uint32_t msec)
| USB_OTG_BSP_mDelay This function provides delay time in milli sec.
void | USB_OTG_BSP_ConfigVBUS (USB_OTG_CORE_HANDLE *pdev)
| USB_OTG_BSP_ConfigVBUS Configures the IO for the Vbus and OverCurrent.
void | USB_OTG_BSP_DriveVBUS (USB_OTG_CORE_HANDLE *pdev, uint8_t state)
| BSP_Drive_VBUS Drives the Vbus signal through IO.
s32 | MIOS32_USB_ForceDeviceMode (void)
## Variables
DEVICE_INFO * | pInformation
DEVICE | Device_Table
DEVICE_PROP * | pProperty
USER_STANDARD_REQUESTS * | pUser_Standard_Requests
void(* | pEpInt_IN [7])(void)
void(* | pEpInt_OUT [7])(void)
__ALIGN_BEGIN USB_OTG_CORE_HANDLE USB_OTG_dev | __ALIGN_END
uint32_t | USB_rx_buffer [MIOS32_USB_MIDI_DATA_OUT_SIZE/4]
const USBH_Class_cb_TypeDef | MIOS32_MIDI_USBH_Callbacks

## Detailed Description

USB driver for MIOS32

Uses LPCUSB driver from Bertrik Sikken (bertrik@sikken.nl) which is installed under $MIOS32_PATH/drivers/LPC17xx/usbstack -> http://sourceforge.net/projects/lpcusb

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

USB driver for MIOS32

Based on driver included in STM32 USB library Some code copied and modified from Virtual_COM_Port demo

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

## Define Documentation

#define BUFFER_SIZE 100

#define CS_ENDPOINT 0x25

#define CS_INTERFACE 0x24

#define DSCR_CONFIG 2

#define DSCR_DEVICE 1

#define DSCR_ENDPNT 5

#define DSCR_INTRFC 4

#define DSCR_STRING 3

#define GET_LINE_CODING 0x21

#define IMR_MSK (CNTR_CTRM | CNTR_RESETM)

#define LE_WORD | ( | x |  | ) | ((x)&0xFF),((x)>>8)

#define MIOS32_USB_COM_CC_INTERFACE_IX (MIOS32_USB_MIDI_INTERFACE_OFFSET + 0x00)

#define MIOS32_USB_COM_CD_INTERFACE_IX (MIOS32_USB_MIDI_INTERFACE_OFFSET + 0x01)

#define MIOS32_USB_COM_INTERFACE_OFFSET (MIOS32_USB_MIDI_INTERFACE_OFFSET + 2)

#define MIOS32_USB_COM_NUM_INTERFACES 2

#define MIOS32_USB_COM_SIZ_CONFIG_DESC 58

#define MIOS32_USB_MIDI_AC_INTERFACE_IX 0x00

#define MIOS32_USB_MIDI_AS_INTERFACE_IX 0x01

#define MIOS32_USB_MIDI_INTERFACE_OFFSET 2

#define MIOS32_USB_MIDI_NUM_INTERFACES 2

#define MIOS32_USB_MIDI_SIZ_CLASS_DESC (7+MIOS32_USB_MIDI_NUM_PORTS*(6+6+9+9)+9+(4+MIOS32_USB_MIDI_NUM_PORTS)+9+(4+MIOS32_USB_MIDI_NUM_PORTS))

#define MIOS32_USB_MIDI_SIZ_CLASS_DESC_SINGLE_USB (7+1*(6+6+9+9)+9+(4+1)+9+(4+1))

#define MIOS32_USB_MIDI_SIZ_CONFIG_DESC (9+MIOS32_USB_MIDI_USE_AC_INTERFACE*(9+9)+MIOS32_USB_MIDI_SIZ_CLASS_DESC)

#define MIOS32_USB_MIDI_SIZ_CONFIG_DESC_SINGLE_USB (9+MIOS32_USB_MIDI_USE_AC_INTERFACE*(9+9)+MIOS32_USB_MIDI_SIZ_CLASS_DESC)

#define MIOS32_USB_MIDI_SIZ_CONFIG_DESC_SINGLE_USB (9+MIOS32_USB_MIDI_USE_AC_INTERFACE*(9+9)+MIOS32_USB_MIDI_SIZ_CLASS_DESC_SINGLE_USB)

#define MIOS32_USB_NUM_INTERFACES (MIOS32_USB_MIDI_NUM_INTERFACES + MIOS32_USB_COM_NUM_INTERFACES)

#define MIOS32_USB_SIZ_CONFIG_DESC (9 + MIOS32_USB_MIDI_SIZ_CONFIG_DESC + MIOS32_USB_COM_SIZ_CONFIG_DESC)

#define MIOS32_USB_SIZ_CONFIG_DESC_SINGLE_USB (9 + MIOS32_USB_MIDI_SIZ_CONFIG_DESC_SINGLE_USB)

#define MIOS32_USB_SIZ_DEVICE_DESC 18

#define SET_CONTROL_LINE_STATE 0x22

#define SET_LINE_CODING 0x20

## Typedef Documentation

typedef enum _DEVICE_STATE DEVICE_STATE

## Enumeration Type Documentation

enum _DEVICE_STATE

Enumerator:

  UNCONNECTED |
  ATTACHED |
  POWERED |
  SUSPENDED |
  ADDRESSED |
  CONFIGURED |

## Function Documentation

s32 MIOS32_USB_ForceDeviceMode | ( | void |  | ) |

Returns:
  != 0 if device mode is enforced in the bootloader config section

s32 MIOS32_USB_ForceSingleUSB | ( | void |  | ) |

Returns:
  != 0 if a single USB port has been forced in the bootloader config section

s32 MIOS32_USB_Init | ( | u32 | mode | ) |

Initializes USB interface

Parameters:

  `[in]` | mode | if 0, USB peripheral won't be initialized if this has already been done before if 1, USB peripheral re-initialisation will be forced if 2, USB peripheral re-initialisation will be forced, STM32 driver hooks won't be overwritten. This mode can be used for a local USB driver which installs it's own hooks during runtime. The application can switch back to MIOS32 drivers (e.g. MIOS32_USB_MIDI) by calling MIOS32_USB_Init(1)

Returns:
  < 0 if initialisation failed

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

Here is the call graph for this function:

s32 MIOS32_USB_IsInitialized | ( | void |  | ) |

Allows to query, if the USB interface has already been initialized.
This function is used by the bootloader to avoid a reconnection, it isn't relevant for typical applications!

Returns:
  1 if USB already initialized, 0 if not initialized

void OTG_FS_IRQHandler | ( | void |  | ) |

This function handles OTG_FS Handler.

Parameters:

  | None |

Return values:

  | None |

void USB_IRQHandler | ( | void |  | ) |

Interrupt handler for USB

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

void USB_LP_CAN1_RX0_IRQHandler | ( | void |  | ) |

Interrupt handler for USB

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

void USB_OTG_BSP_ConfigVBUS | ( | USB_OTG_CORE_HANDLE * | pdev | ) |

USB_OTG_BSP_ConfigVBUS Configures the IO for the Vbus and OverCurrent.

Parameters:

  | None |

Return values:

  | None |

Here is the call graph for this function:

void USB_OTG_BSP_DriveVBUS | ( | USB_OTG_CORE_HANDLE * | pdev,
|  | uint8_t | state |
| ) |  |  |

BSP_Drive_VBUS Drives the Vbus signal through IO.

Parameters:

  | state | : VBUS states

Return values:

  | None |

void USB_OTG_BSP_EnableInterrupt | ( | USB_OTG_CORE_HANDLE * | pdev | ) |

USB_OTG_BSP_EnableInterrupt Enabele USB Global interrupt.

Parameters:

  | None |

Return values:

  | None |

Here is the call graph for this function:

void USB_OTG_BSP_Init | ( | USB_OTG_CORE_HANDLE * | pdev | ) |

USB_OTG_BSP_Init Initilizes BSP configurations.

Parameters:

  | None |

Return values:

  | None |

void USB_OTG_BSP_mDelay | ( | const uint32_t | msec | ) |

USB_OTG_BSP_mDelay This function provides delay time in milli sec.

Parameters:

  | msec | : Value of delay required in milli sec

Return values:

  | None |

Here is the call graph for this function:

void USB_OTG_BSP_uDelay | ( | const uint32_t | usec | ) |

USB_OTG_BSP_uDelay This function provides delay time in micro sec.

Parameters:

  | usec | : Value of delay required in micro sec

Return values:

  | None |

Here is the call graph for this function:

## Variable Documentation

const __ALIGN_BEGIN u8 USBD_LangIDDesc [4] __ALIGN_END

Initial value:

    {
         4,
         USB_DESC_TYPE_STRING,
         0x09,
         0x04,
    }

DEVICE Device_Table

const USBH_Class_cb_TypeDef MIOS32_MIDI_USBH_Callbacks

void(* pEpInt_IN[7])(void)

Initial value:

     {
      NOP_Process, NOP_Process, NOP_Process, NOP_Process, NOP_Process, NOP_Process, NOP_Process
    }

void(* pEpInt_OUT[7])(void)

Initial value:

     {
      NOP_Process, NOP_Process, NOP_Process, NOP_Process, NOP_Process, NOP_Process, NOP_Process
    }

DEVICE_INFO* pInformation

DEVICE_PROP* pProperty

USER_STANDARD_REQUESTS* pUser_Standard_Requests

uint32_t USB_rx_buffer[MIOS32_USB_MIDI_DATA_OUT_SIZE/4]