embassy-usb-host

Crates

git

Versions

default

Flavors

UacHandler

Struct UacHandler 

Source
pub struct UacHandler<'d, A: UsbHostAllocator<'d>> {
    pub interface_collection: AudioInterfaceCollection,
    pub control_channel: A::Pipe<Control, InOut>,
    pub output_channel: Option<A::Pipe<Isochronous, Out>>,
    pub feedback_channel: Option<A::Pipe<Isochronous, In>>,
    /* private fields */
}
Expand description

Handler for USB Audio Class (UAC) devices, providing control and streaming functionality.

This struct manages the USB pipes and interface descriptors required to interact with a UAC device, including control, output, and feedback pipes.

Fields§

§interface_collection: AudioInterfaceCollection

Collection of audio interface descriptors parsed from the device configuration.

§control_channel: A::Pipe<Control, InOut>

Control pipe for sending standard and class-specific requests.

§output_channel: Option<A::Pipe<Isochronous, Out>>

Output pipe for isochronous audio streaming (if available).

§feedback_channel: Option<A::Pipe<Isochronous, In>>

Feedback pipe for isochronous feedback endpoint (if available).

Implementations§

Source§

impl<'d, A: UsbHostAllocator<'d>> UacHandler<'d, A>

Source

pub async fn try_register( alloc: &A, enum_info: EnumerationInfo, ) -> Result<Self, RegisterError>

Attempts to register a UAC device and allocate necessary pipes.

This method parses the device’s configuration, finds a suitable streaming interface, and allocates output and feedback pipes as needed.

Returns a new UacHandler on success, or a RegisterError if registration fails.

Source

pub async fn output(&mut self) -> Result<UacOut<'d, A>, RequestError>

Returns a UacOut object for audio output streaming.

Returns an error if the output or feedback pipe is not allocated or if the interface is unsupported.

Source

pub fn input_terminal(&self) -> &TerminalDescriptor

Returns a reference to the input terminal descriptor associated with this handler.

Source

pub fn output_interface(&self) -> &AudioStreamingInterface

Returns a reference to the output audio streaming interface descriptor.

Source

pub async fn get_sampling_freq( &mut self, terminal_id: u8, ) -> Result<u32, RequestError>

Retrieves the current sampling frequency from the specified terminal entity.

Returns the sampling frequency in Hz, or an error if the request fails.

Source

pub async fn get_supported_language(&mut self) -> Result<u16, RequestError>

Retrieves the supported language ID from the device.

Returns the language ID as a 16-bit value, or an error if the request fails.

Source

pub async fn get_string( &mut self, index: StringIndex, lang_id: u16, ) -> Result<String<MAX_STRING_LENGTH>, RequestError>

Retrieves a string descriptor from the device.

§Arguments
  • index - The string descriptor index
  • lang_id - The language ID for the string

Returns the string as a UTF-8 encoded string, or an error if the request fails.

Source

pub async fn get_curr_entity1( &mut self, control_selector: u16, channel: u8, entity: u8, interface: u8, ) -> Result<u8, RequestError>

Retrieves a 1-byte current value from a UAC entity.

§Arguments
  • control_selector - The control selector (e.g., volume, mute)
  • channel - The channel number (0 for master control)
  • entity - The entity ID
  • interface - The interface number

Returns the current value as a u8, or an error if the request fails.

Source

pub async fn get_curr_entity2( &mut self, control_selector: u16, channel: u8, entity: u8, interface: u8, ) -> Result<u16, RequestError>

Retrieves a 2-byte current value from a UAC entity.

§Arguments
  • control_selector - The control selector (e.g., volume, mute)
  • channel - The channel number (0 for master control)
  • entity - The entity ID
  • interface - The interface number

Returns the current value as a u16, or an error if the request fails.

Source

pub async fn get_curr_entity3( &mut self, control_selector: u16, channel: u8, entity: u8, interface: u8, ) -> Result<u32, RequestError>

Retrieves a 4-byte current value from a UAC entity.

§Arguments
  • control_selector - The control selector (e.g., sampling frequency)
  • channel - The channel number (0 for master control)
  • entity - The entity ID
  • interface - The interface number

Returns the current value as a u32, or an error if the request fails.

Source

pub async fn get_range_entity1( &mut self, control_selector: u16, channel: u8, entity: u8, interface: u8, ) -> Result<Layout1ParameterBlock, RequestError>

Retrieves the range of supported 1-byte values from a UAC entity.

§Arguments
  • control_selector - The control selector (e.g., volume, mute)
  • channel - The channel number (0 for master control)
  • entity - The entity ID
  • interface - The interface number

Returns a Layout1ParameterBlock containing the supported ranges, or an error if the request fails.

Source

pub async fn get_range_entity2( &mut self, control_selector: u16, channel: u8, entity: u8, interface: u8, ) -> Result<Layout2ParameterBlock, RequestError>

Retrieves the range of supported 2-byte values from a UAC entity.

§Arguments
  • control_selector - The control selector (e.g., volume, mute)
  • channel - The channel number (0 for master control)
  • entity - The entity ID
  • interface - The interface number

Returns a Layout2ParameterBlock containing the supported ranges, or an error if the request fails.

Source

pub async fn get_range_entity3( &mut self, control_selector: u16, channel: u8, entity: u8, interface: u8, ) -> Result<Layout3ParameterBlock, RequestError>

Retrieves the range of supported 4-byte values from a UAC entity.

§Arguments
  • control_selector - The control selector (e.g., sampling frequency)
  • channel - The channel number (0 for master control)
  • entity - The entity ID
  • interface - The interface number

Returns a Layout3ParameterBlock containing the supported ranges, or an error if the request fails.

Auto Trait Implementations§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.