Skip to main content

AudioClass

Struct AudioClass 

Source
pub struct AudioClass<'a, B: UsbBus> { /* private fields */ }
Expand description

USB Audio Class 1.0 device class.

Supports one streaming input (microphone / line-in) and/or one streaming output (speaker / headphones). Built via AudioClassBuilder.

The host activates a stream by selecting alternate setting 1 (via SET_INTERFACE), and deactivates it by selecting alternate setting 0.

Implementations§

Source§

impl<'a, B: UsbBus> AudioClass<'a, B>

Source

pub fn read(&self, buf: &mut [u8]) -> UsbResult<usize>

Read audio data from the host (output / speaker stream).

Returns the number of bytes read into buf, or UsbError::WouldBlock when no isochronous packet is available. Also returns UsbError::InvalidState if the stream is not configured or not active (alt setting 0).

Source

pub fn write(&self, buf: &[u8]) -> UsbResult<usize>

Write audio data to the host (input / microphone stream).

Returns the number of bytes written, or UsbError::WouldBlock when the previous packet has not yet been sent. Also returns UsbError::InvalidState if the stream is not configured or not active (alt setting 0).

Source

pub fn input_alt_setting(&self) -> Option<u8>

Current alternate setting of the input (microphone) stream. Returns None if no input stream was configured.

Source

pub fn output_alt_setting(&self) -> Option<u8>

Current alternate setting of the output (speaker) stream. Returns None if no output stream was configured.

Source

pub fn is_configured(&self) -> bool

true when the device has been fully configured by the host.

Source

pub fn output_active(&self) -> bool

true when the output (speaker) stream is active (alt setting ≠ 0).

Source

pub fn input_active(&self) -> bool

true when the input (microphone) stream is active (alt setting ≠ 0).

Trait Implementations§

Source§

impl<B: UsbBus> UsbClass<B> for AudioClass<'_, B>

Source§

fn configuration_descriptors( &self, w: &mut DescriptorWriter<'_>, ) -> UsbResult<()>

Append this class’s interface and endpoint descriptors.
Source§

fn control_in(&mut self, xfer: ControlIn<'_, B>)

Handle a control IN transfer. Accept, reject, or pass (drop without acting).
Source§

fn control_out(&mut self, xfer: ControlOut<'_, B>)

Handle a control OUT transfer. Accept, reject, or pass (drop without acting).
Source§

fn configure(&mut self)

Called when the host sends SET_CONFIGURATION(1).
Source§

fn deconfigure(&mut self)

Called when the host sends SET_CONFIGURATION(0) or on reset.
Source§

fn reset(&mut self)

Called after a USB bus reset.
Source§

fn alt_setting(&mut self, iface: InterfaceNumber) -> Option<u8>

Return the current alternate setting for interface, or None.
Source§

fn set_alt_setting(&mut self, iface: InterfaceNumber, alt: u8) -> bool

Set the alternate setting for interface. Return true if handled.
Source§

fn string(&self, index: StringIndex, lang_id: u16) -> Option<&str>

Return the string for a previously allocated StringIndex, or None.
Source§

fn endpoint_out(&mut self, addr: EndpointAddress)

Called when endpoint addr received an OUT packet.
Source§

fn endpoint_in_complete(&mut self, addr: EndpointAddress)

Called when endpoint addr completed an IN transfer.
Source§

fn endpoint_setup(&mut self, addr: EndpointAddress)

Called when endpoint addr received a SETUP packet (non-EP0 control).
Source§

fn poll(&mut self)

Called unconditionally on every UsbDevice::poll.

Auto Trait Implementations§

§

impl<'a, B> Forget for AudioClass<'a, B>

§

impl<'a, B> Freeze for AudioClass<'a, B>
where Option<Endpoint<'a, B, In>>: Freeze, Option<Endpoint<'a, B, Out>>: Freeze,

§

impl<'a, B> Move for AudioClass<'a, B>

§

impl<'a, B> RefUnwindSafe for AudioClass<'a, B>

§

impl<'a, B> Send for AudioClass<'a, B>
where Option<Endpoint<'a, B, In>>: Send, Option<Endpoint<'a, B, Out>>: Send,

§

impl<'a, B> Sync for AudioClass<'a, B>
where Option<Endpoint<'a, B, In>>: Sync, Option<Endpoint<'a, B, Out>>: Sync,

§

impl<'a, B> Unpin for AudioClass<'a, B>
where Option<Endpoint<'a, B, In>>: Unpin, Option<Endpoint<'a, B, Out>>: Unpin,

§

impl<'a, B> UnsafeUnpin for AudioClass<'a, B>

§

impl<'a, B> UnwindSafe for AudioClass<'a, B>

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.