Skip to content

File syn_usb_midi.h

FileList > drivers > syn_usb_midi.h

Go to the source code of this file

Zero-Heap USB 2.0 MIDI Class Device Driver. More...

  • #include "syntropic/common/syn_defs.h"
  • #include "syntropic/drivers/syn_usb.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_USB_MIDI
struct SYN_USB_MIDI_Packet

Public Functions

Type Name
SYN_Status syn_usb_midi_init (SYN_USB_MIDI * midi)
Initialize USB MIDI Class Instance.
SYN_Status syn_usb_midi_parse_packet (const uint8_t raw_bytes, SYN_USB_MIDI_Packet * packet)
Parse a 4-byte raw USB MIDI packet into structured event packet.
SYN_Status syn_usb_midi_register (SYN_USB_Device * dev, SYN_USB_MIDI * midi)
Register USB MIDI class driver with USB device core.
SYN_Status syn_usb_midi_send_cc (SYN_USB_MIDI * midi, uint8_t channel, uint8_t controller, uint8_t value)
Encode and queue a Control Change (CC) MIDI message.
SYN_Status syn_usb_midi_send_note_off (SYN_USB_MIDI * midi, uint8_t channel, uint8_t note, uint8_t velocity)
Encode and queue a Note Off MIDI message.
SYN_Status syn_usb_midi_send_note_on (SYN_USB_MIDI * midi, uint8_t channel, uint8_t note, uint8_t velocity)
Encode and queue a Note On MIDI message.
SYN_Status syn_usb_midi_send_pitch_bend (SYN_USB_MIDI * midi, uint8_t channel, int16_t value)
Encode and queue a Pitch Bend MIDI message.

Macros

Type Name
define SYN_USB_MIDI_CIN_CABLE_EVENT 0x1U
define SYN_USB_MIDI_CIN_CHANNEL_PRESSURE 0xDU
define SYN_USB_MIDI_CIN_CONTROL_CHANGE 0xBU
define SYN_USB_MIDI_CIN_MISC 0x0U
define SYN_USB_MIDI_CIN_NOTE_OFF 0x8U
define SYN_USB_MIDI_CIN_NOTE_ON 0x9U
define SYN_USB_MIDI_CIN_PITCH_BEND 0xEU
define SYN_USB_MIDI_CIN_POLY_KEYPRESS 0xAU
define SYN_USB_MIDI_CIN_PROGRAM_CHANGE 0xCU
define SYN_USB_MIDI_CIN_SINGLE_BYTE 0xFU
define SYN_USB_MIDI_CIN_SYSEX_ENDS_1 0x5U
define SYN_USB_MIDI_CIN_SYSEX_ENDS_2 0x6U
define SYN_USB_MIDI_CIN_SYSEX_ENDS_3 0x7U
define SYN_USB_MIDI_CIN_SYSEX_START 0x4U
define SYN_USB_MIDI_CIN_SYSTEM_COMMON_2 0x2U
define SYN_USB_MIDI_CIN_SYSTEM_COMMON_3 0x3U
define SYN_USB_MIDI_MAX_PACKET_SIZE 64U

Detailed Description

Implements USB Class Definition for MIDI Devices v1.0 (Audio Streaming subclass). Provides 4-byte USB MIDI Event Packet encoding and decoding for Note On/Off, Control Change, Pitch Bend, and Program Change messages.

Public Functions Documentation

function syn_usb_midi_init

Initialize USB MIDI Class Instance.

SYN_Status syn_usb_midi_init (
    SYN_USB_MIDI * midi
) 

Parameters:

  • midi Pointer to USB MIDI instance.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if NULL.


function syn_usb_midi_parse_packet

Parse a 4-byte raw USB MIDI packet into structured event packet.

SYN_Status syn_usb_midi_parse_packet (
    const uint8_t raw_bytes,
    SYN_USB_MIDI_Packet * packet
) 

Parameters:

  • raw_bytes 4-byte raw buffer.
  • packet Output structured packet pointer.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if NULL.


function syn_usb_midi_register

Register USB MIDI class driver with USB device core.

SYN_Status syn_usb_midi_register (
    SYN_USB_Device * dev,
    SYN_USB_MIDI * midi
) 

Parameters:

  • dev Pointer to USB device core context.
  • midi Pointer to USB MIDI instance.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if NULL.


function syn_usb_midi_send_cc

Encode and queue a Control Change (CC) MIDI message.

SYN_Status syn_usb_midi_send_cc (
    SYN_USB_MIDI * midi,
    uint8_t channel,
    uint8_t controller,
    uint8_t value
) 

Parameters:

  • midi Pointer to USB MIDI instance.
  • channel MIDI Channel (0..15).
  • controller Controller Number (0..127).
  • value Controller Value (0..127).

Returns:

SYN_OK on success, SYN_INVALID_PARAM if invalid.


function syn_usb_midi_send_note_off

Encode and queue a Note Off MIDI message.

SYN_Status syn_usb_midi_send_note_off (
    SYN_USB_MIDI * midi,
    uint8_t channel,
    uint8_t note,
    uint8_t velocity
) 

Parameters:

  • midi Pointer to USB MIDI instance.
  • channel MIDI Channel (0..15).
  • note MIDI Note Number (0..127).
  • velocity Release Velocity (0..127).

Returns:

SYN_OK on success, SYN_INVALID_PARAM if invalid.


function syn_usb_midi_send_note_on

Encode and queue a Note On MIDI message.

SYN_Status syn_usb_midi_send_note_on (
    SYN_USB_MIDI * midi,
    uint8_t channel,
    uint8_t note,
    uint8_t velocity
) 

Parameters:

  • midi Pointer to USB MIDI instance.
  • channel MIDI Channel (0..15).
  • note MIDI Note Number (0..127).
  • velocity Note Velocity (0..127).

Returns:

SYN_OK on success, SYN_INVALID_PARAM if invalid.


function syn_usb_midi_send_pitch_bend

Encode and queue a Pitch Bend MIDI message.

SYN_Status syn_usb_midi_send_pitch_bend (
    SYN_USB_MIDI * midi,
    uint8_t channel,
    int16_t value
) 

Parameters:

  • midi Pointer to USB MIDI instance.
  • channel MIDI Channel (0..15).
  • value Pitch Bend value (-8192..+8191, center 0).

Returns:

SYN_OK on success, SYN_INVALID_PARAM if invalid.


Macro Definition Documentation

define SYN_USB_MIDI_CIN_CABLE_EVENT

#define SYN_USB_MIDI_CIN_CABLE_EVENT `0x1U`

Cable events


define SYN_USB_MIDI_CIN_CHANNEL_PRESSURE

#define SYN_USB_MIDI_CIN_CHANNEL_PRESSURE `0xDU`

Channel Pressure message (0xD0)


define SYN_USB_MIDI_CIN_CONTROL_CHANGE

#define SYN_USB_MIDI_CIN_CONTROL_CHANGE `0xBU`

Control Change message (0xB0)


define SYN_USB_MIDI_CIN_MISC

#define SYN_USB_MIDI_CIN_MISC `0x0U`

USB MIDI Code Index Number (CIN) definitions per USB MIDI Spec Table 4-1 Miscellaneous function codes


define SYN_USB_MIDI_CIN_NOTE_OFF

#define SYN_USB_MIDI_CIN_NOTE_OFF `0x8U`

Note Off message (0x80)


define SYN_USB_MIDI_CIN_NOTE_ON

#define SYN_USB_MIDI_CIN_NOTE_ON `0x9U`

Note On message (0x90)


define SYN_USB_MIDI_CIN_PITCH_BEND

#define SYN_USB_MIDI_CIN_PITCH_BEND `0xEU`

Pitch Bend message (0xE0)


define SYN_USB_MIDI_CIN_POLY_KEYPRESS

#define SYN_USB_MIDI_CIN_POLY_KEYPRESS `0xAU`

Poly KeyPress message (0xA0)


define SYN_USB_MIDI_CIN_PROGRAM_CHANGE

#define SYN_USB_MIDI_CIN_PROGRAM_CHANGE `0xCU`

Program Change message (0xC0)


define SYN_USB_MIDI_CIN_SINGLE_BYTE

#define SYN_USB_MIDI_CIN_SINGLE_BYTE `0xFU`

Single Byte message


define SYN_USB_MIDI_CIN_SYSEX_ENDS_1

#define SYN_USB_MIDI_CIN_SYSEX_ENDS_1 `0x5U`

Single-byte SysEx ends


define SYN_USB_MIDI_CIN_SYSEX_ENDS_2

#define SYN_USB_MIDI_CIN_SYSEX_ENDS_2 `0x6U`

2-byte SysEx ends


define SYN_USB_MIDI_CIN_SYSEX_ENDS_3

#define SYN_USB_MIDI_CIN_SYSEX_ENDS_3 `0x7U`

3-byte SysEx ends


define SYN_USB_MIDI_CIN_SYSEX_START

#define SYN_USB_MIDI_CIN_SYSEX_START `0x4U`

SysEx starts or continues


define SYN_USB_MIDI_CIN_SYSTEM_COMMON_2

#define SYN_USB_MIDI_CIN_SYSTEM_COMMON_2 `0x2U`

2-byte System Common messages


define SYN_USB_MIDI_CIN_SYSTEM_COMMON_3

#define SYN_USB_MIDI_CIN_SYSTEM_COMMON_3 `0x3U`

3-byte System Common messages


define SYN_USB_MIDI_MAX_PACKET_SIZE

#define SYN_USB_MIDI_MAX_PACKET_SIZE `64U`

Maximum USB MIDI packet size in bytes



The documentation for this class was generated from the following file src/syntropic/drivers/syn_usb_midi.h