embassy-usb

Crates

git

Versions

default

Flavors

Skip to main content

MidiClass

Struct MidiClass 

Source
pub struct MidiClass<'d, D: Driver<'d>> { /* private fields */ }
Expand description

Packet level implementation of a USB MIDI device supporting MIDI 1.0 and 2.0.

The MIDI 1.0 (Alternate Setting 0) and MIDI 2.0 (Alternate Setting 1) protocols share one pair of bulk endpoints; the host selects which protocol is carried over them with SET_INTERFACE.

This class can be used directly and it has the least overhead due to directly reading and writing USB packets with no intermediate buffers, but it will not act like a stream-like port.

Implementations§

Source§

impl<'d, D: Driver<'d>> MidiClass<'d, D>

Source

pub fn new(builder: &mut Builder<'d, D>, config: MidiClassConfig<'d>) -> Self

Creates a new MidiClass with the provided UsbBuilder and configuration.

The names in config are ignored, use MidiClass::new_with_names if you need to name jacks or configure MIDI 2.0.

Source

pub fn new_with_names( builder: &mut Builder<'d, D>, state: &'d mut MidiClassState<'d>, config: MidiClassConfig<'d>, ) -> Self

Creates a new MidiClass with the provided UsbBuilder that names its interface, jacks, and Group Terminal Blocks.

Source

pub fn new_with_state( builder: &mut Builder<'d, D>, state: &'d mut MidiClassState<'d>, config: MidiClassConfig<'d>, ) -> Self

Creates a new MidiClass with the provided UsbBuilder and state.

Source

pub fn active_alternate_setting(&self) -> u8

Returns the currently active alternate setting (0 for MIDI 1.0, 1 for MIDI 2.0).

The host selects it with SET_INTERFACE (USB MIDI 2.0 §3.1.1).

Source

pub fn is_midi2_active(&self) -> bool

Returns whether MIDI 2.0 (Alternate Setting 1) is currently active.

Source

pub fn max_packet_size(&self) -> u16

Gets the maximum packet size in bytes for the bulk endpoints.

The MIDI 1.0 and MIDI 2.0 alternate settings share the same endpoints, so they have the same maximum packet size.

Source

pub async fn write_packet(&mut self, data: &[u8]) -> Result<(), EndpointError>

Writes a single packet into the MIDI 1.0 IN endpoint.

Source

pub async fn read_packet( &mut self, data: &mut [u8], ) -> Result<usize, EndpointError>

Reads a single packet from the MIDI 1.0 OUT endpoint.

Source

pub async fn write_ump( &mut self, packets: &[UmpPacket], ) -> Result<(), EndpointError>

Writes UMPs to the host, cut between packets at the packet size, with a ZLP after a full last transfer.

Only meaningful while Alternate Setting 1 (MIDI 2.0) is active.

Source

pub async fn write_ump_bytes( &mut self, data: &[u8], ) -> Result<(), EndpointError>

Writes raw UMP bytes to the host as one transfer, with a ZLP after a full last packet.

This is only meaningful while Alternate Setting 1 (MIDI 2.0) is active.

Source

pub async fn read_ump<'a>( &mut self, data: &'a mut [u8], ) -> Result<UmpReader<'a>, EndpointError>

Reads Universal MIDI Packets from the host.

This is only meaningful while Alternate Setting 1 (MIDI 2.0) is active.

Source

pub async fn wait_connection(&mut self)

Waits for the USB host to enable this interface.

Source

pub fn split(self) -> (Option<Sender<'d, D>>, Option<Receiver<'d, D>>)

Split the endpoints into a sender and receiver.

The same endpoints carry both MIDI 1.0 and MIDI 2.0 data, so a single sender/receiver pair serves both alternate settings. This allows concurrently sending and receiving packets from separate tasks.

Auto Trait Implementations§

§

impl<'d, D> Forget for MidiClass<'d, D>

§

impl<'d, D> Freeze for MidiClass<'d, D>
where Option<<D as Driver<'d>>::EndpointOut>: Freeze, Option<<D as Driver<'d>>::EndpointIn>: Freeze,

§

impl<'d, D> Move for MidiClass<'d, D>

§

impl<'d, D> RefUnwindSafe for MidiClass<'d, D>

§

impl<'d, D> Send for MidiClass<'d, D>
where Option<<D as Driver<'d>>::EndpointOut>: Send, Option<<D as Driver<'d>>::EndpointIn>: Send,

§

impl<'d, D> Sync for MidiClass<'d, D>
where Option<<D as Driver<'d>>::EndpointOut>: Sync, Option<<D as Driver<'d>>::EndpointIn>: Sync,

§

impl<'d, D> Unpin for MidiClass<'d, D>
where Option<<D as Driver<'d>>::EndpointOut>: Unpin, Option<<D as Driver<'d>>::EndpointIn>: Unpin,

§

impl<'d, D> UnsafeUnpin for MidiClass<'d, D>

§

impl<'d, D> UnwindSafe for MidiClass<'d, D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.