Skip to content

Commit

Permalink
Add Interface::{interface_number, descriptors}
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmehall committed Apr 28, 2024
1 parent 84ddf90 commit 8916126
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{io::ErrorKind, sync::Arc, time::Duration};
use log::error;

use crate::{
descriptors::{ActiveConfigurationError, Configuration},
descriptors::{ActiveConfigurationError, Configuration, InterfaceAltSetting},
platform,
transfer::{
Control, ControlIn, ControlOut, EndpointType, Queue, RequestBuffer, TransferError,
Expand Down Expand Up @@ -535,6 +535,30 @@ impl Interface {
pub fn clear_halt(&self, endpoint: u8) -> Result<(), Error> {
self.backend.clear_halt(endpoint)
}

/// Get the interface number.
pub fn interface_number(&self) -> u8 {
self.backend.interface_number
}

/// Get the interface descriptors for the alternate settings of this interface.
///
/// This returns cached data and does not perform IO.
pub fn descriptors(&self) -> impl Iterator<Item = InterfaceAltSetting> {
let active = self.backend.device.active_configuration_value();

let configuration = self
.backend
.device
.configuration_descriptors()
.map(Configuration::new)
.find(|c| c.configuration_value() == active);

configuration
.into_iter()
.flat_map(|i| i.interface_alt_settings())
.filter(|g| g.interface_number() == self.backend.interface_number)
}
}

#[test]
Expand Down

0 comments on commit 8916126

Please sign in to comment.