# MIOS32_IIC_MIDI

## Functions
s32 | MIOS32_IIC_MIDI_Init (u32 mode)
s32 | MIOS32_IIC_MIDI_ScanInterfaces (void)
s32 | MIOS32_IIC_MIDI_CheckAvailable (u8 iic_port)
s32 | MIOS32_IIC_MIDI_RS_OptimisationSet (u8 iic_port, u8 enable)
s32 | MIOS32_IIC_MIDI_RS_OptimisationGet (u8 iic_port)
s32 | MIOS32_IIC_MIDI_RS_Reset (u8 iic_port)
s32 | MIOS32_IIC_MIDI_Periodic_mS (void)
s32 | MIOS32_IIC_MIDI_PackageSend_NonBlocking (u8 iic_port, mios32_midi_package_t package)
s32 | MIOS32_IIC_MIDI_PackageSend (u8 iic_port, mios32_midi_package_t package)
s32 | MIOS32_IIC_MIDI_PackageReceive_NonBlocking (u8 iic_port, mios32_midi_package_t *package)
s32 | MIOS32_IIC_MIDI_PackageReceive (u8 iic_port, mios32_midi_package_t *package)

## Detailed Description

IIC MIDI layer for MIOS32

Except for MIOS32_IIC_MIDI_ScanInterfaces applications shouldn't call these functions directly, instead please use MIOS32_MIDI layer functions

## Function Documentation

s32 MIOS32_IIC_MIDI_CheckAvailable | ( | u8 | iic_port | ) |

This function checks the availability of the MBHP_IIC_MIDI module taken from the last results of MIOS32_IIC_MIDI_ScanInterface()

Parameters:

  `[in]` | iic_port | module number (0..7)

Returns:
  1: interface available
  0: interface not available

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

s32 MIOS32_IIC_MIDI_Init | ( | u32 | mode | ) |

Initializes IIC 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

Here is the call graph for this function:

s32 MIOS32_IIC_MIDI_PackageReceive | ( | u8 | iic_port,
|  | mios32_midi_package_t * | package |
| ) |  |  |

This function checks for a new package
(blocking function)

Parameters:

  `[in]` | iic_port | IIC_MIDI module number (0..7)
  `[out]` | package | pointer to MIDI package (received package will be put into the given variable)

Returns:
  0: no error
  -1: no package in buffer
  -3: IIC error during transfer
  -10: IIC package timed out

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

s32 MIOS32_IIC_MIDI_PackageReceive_NonBlocking | ( | u8 | iic_port,
|  | mios32_midi_package_t * | package |
| ) |  |  |

This function checks for a new package

Parameters:

  `[in]` | iic_port | IIC_MIDI module number (0..7)
  `[out]` | package | pointer to MIDI package (received package will be put into the given variable)

Returns:
  0: no error
  -1: no package in buffer
  -2: IIC interface allocated - retry (only in Non Blocking mode)
  -3: IIC error during transfer
  -10: IIC package timed out

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

s32 MIOS32_IIC_MIDI_PackageSend | ( | u8 | iic_port,
|  | mios32_midi_package_t | package |
| ) |  |  |

This function sends a new MIDI package to the selected IIC_MIDI port (blocking function)

Parameters:

  `[in]` | iic_port | IIC_MIDI module number (0..7)
  `[in]` | package | MIDI package

Returns:
  0: no error
  -1: IIC_MIDI device not available
  -3: IIC error during transfer
  -4: Error reported by Rx callback function

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

s32 MIOS32_IIC_MIDI_PackageSend_NonBlocking | ( | u8 | iic_port,
|  | mios32_midi_package_t | package |
| ) |  |  |

This function sends a new MIDI package to the selected IIC_MIDI port

Parameters:

  `[in]` | iic_port | IIC_MIDI module number (0..7)
  `[in]` | package | MIDI package

Returns:
  0: no error
  -1: IIC_MIDI device not available
  -2: IIC_MIDI buffer is full caller should retry until buffer is free again
  -3: IIC error during transfer
  -4: Error reported by Rx callback function

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

s32 MIOS32_IIC_MIDI_Periodic_mS | ( | void |  | ) |

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

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

s32 MIOS32_IIC_MIDI_RS_OptimisationGet | ( | u8 | iic_port | ) |

This function returns the running status optimisation enable/disable flag for the given MIDI OUT port.

Parameters:

  `[in]` | iic_port | module number (0..7)

Returns:
  -1 if port not available
  0 if optimisation disabled
  1 if optimisation enabled

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

s32 MIOS32_IIC_MIDI_RS_OptimisationSet | ( | u8 | iic_port,
|  | u8 | enable |
| ) |  |  |

This function enables/disables running status optimisation for a given MIDI OUT port to improve bandwidth if MIDI events with the same status byte are sent back-to-back.
Note that the optimisation is enabled by default.

Parameters:

  `[in]` | iic_port | module number (0..7)
  `[in]` | enable | 0=optimisation disabled, 1=optimisation enabled

Returns:
  -1 if port not available
  0 on success

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

s32 MIOS32_IIC_MIDI_RS_Reset | ( | u8 | iic_port | ) |

This function resets the current running status, so that it will be sent again with the next MIDI Out package.

Parameters:

  `[in]` | iic_port | module number (0..7)

Returns:
  -1 if port not available
  < 0 on errors

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

s32 MIOS32_IIC_MIDI_ScanInterfaces | ( | void |  | ) |

Scans all MBHP_IIC_MIDI modules to check the availablility by sending dummy requests and checking the ACK response.

Per module, this procedure takes at least ca. 25 uS, if no module is connected ca. 75 uS (3 retries), or even more if we have to wait for completion of the previous IIC transfer.

Therefore this function should only be rarely used (e.g. once per second), and the state should be saved somewhere in the application

Returns:
  0 if all IIC interfaces scanned
  -2 if IIC interface blocked by another task (retry the scan!)

Here is the call graph for this function: