embassy-usb

Crates

git

Versions

default

Flavors

Skip to main content

MscDevice

Struct MscDevice 

Source
pub struct MscDevice<'d, A, M = NoopRawMutex>
where A: UsbHostAllocator<'d>, M: RawMutex,
{ /* private fields */ }
Expand description

USB Mass Storage Class host device.

Owns the control and bulk pipes for one BBB/SCSI interface and serializes all command traffic through an internal async mutex. Open per-LUN handles with MscDevice::lun.

Use MscDevice::new for the common single-task case; the transport mutex is a NoopRawMutex with no runtime cost. To share LUNs across tasks, construct with MscDevice::new_with_raw_mutex and pick a Sync raw mutex.

Implementations§

Source§

impl<'d, A> MscDevice<'d, A, NoopRawMutex>
where A: UsbHostAllocator<'d>,

Source

pub async fn new( alloc: &A, enum_info: &EnumerationInfo, config_desc: &[u8], ) -> Result<Self, MscError>

Allocate the control and bulk pipes for the first BBB/SCSI interface in config_desc, probe GET_MAX_LUN, and wrap the transport in a NoopRawMutex.

The resulting device is !Sync. Use this constructor when all LUNs stay in one task. For multi-task sharing, use MscDevice::new_with_raw_mutex instead.

Source§

impl<'d, A, M> MscDevice<'d, A, M>
where A: UsbHostAllocator<'d>, M: RawMutex,

Source

pub async fn new_with_raw_mutex( alloc: &A, enum_info: &EnumerationInfo, config_desc: &[u8], ) -> Result<Self, MscError>

Allocate the control and bulk pipes for the first BBB/SCSI interface in config_desc, probe GET_MAX_LUN, and wrap the transport in the caller-chosen raw mutex M.

Pick a Sync raw mutex (e.g. CriticalSectionRawMutex) to drive LUNs from multiple tasks. For single-task use, prefer MscDevice::new.

Source

pub fn interface(&self) -> u8

USB interface number this device is bound to.

Source

pub fn max_lun(&self) -> u8

Highest valid LUN index (as returned by GET_MAX_LUN).

Source

pub fn num_luns(&self) -> u8

Number of LUNs exposed by the device (max_lun() + 1).

Source

pub fn lun(&self, lun: u8) -> Result<MscLun<'_, 'd, A, M>, MscError>

Handle to the given LUN.

LUN handles are cheap and do not reserve any transport resource; issuing more than one for the same LUN is permitted but only useful if the caller manages the split state between them.

Source

pub async fn command( &self, lun: u8, cdb: &[u8], data: DataDir<'_>, ) -> Result<CommandOutcome, MscError>

Run one Bulk-Only command cycle and return the outcome.

cdb must be 1..=16 bytes. The length of data is reported as dCBWDataTransferLength and drives the data phase.

Recovers from endpoint stalls (via CLEAR_FEATURE(ENDPOINT_HALT) plus data-toggle reset) and from CSW signature/tag mismatches (via Bulk-Only Mass Storage Reset). A CSW status of 0x02 (phase error) triggers a reset and returns MscError::PhaseError.

§Cancellation

Not cancel-safe: dropping the future mid-cycle leaves the device in an undefined state. The transport marks itself dirty and issues a Mass Storage Reset before the next command.

Source

pub async fn reset(&self) -> Result<(), MscError>

Issue a Bulk-Only Mass Storage Reset followed by CLEAR_FEATURE(ENDPOINT_HALT) on both bulk endpoints.

Trait Implementations§

Source§

impl<'d, A: UsbHostAllocator<'d>> HostClass<'d, A> for MscDevice<'d, A>

Source§

const NAME: &'static str = "MSC"

Human-readable class name, used for logging.
Source§

type Info = MscInfo

Cheap, owned description of the interface(s) and endpoints to use. Read more
Source§

fn probe(_enum_info: &EnumerationInfo, cfg: &[u8]) -> Option<Self::Info>

Find the class in an enumerated device. Returns None when the class is not present. This must not allocate pipes or issue control requests. Read more
Source§

async fn open( alloc: &A, cfg: &[u8], _info: Self::Info, enum_info: &EnumerationInfo, ) -> Result<Self, ClassError>

Allocate pipes and perform any class-specific setup.
Source§

fn is_present(enum_info: &EnumerationInfo, cfg: &[u8]) -> bool

Convenience wrapper around probe.

Auto Trait Implementations§

§

impl<'d, A, M = NoopRawMutex> !Freeze for MscDevice<'d, A, M>

§

impl<'d, A, M = NoopRawMutex> !RefUnwindSafe for MscDevice<'d, A, M>

§

impl<'d, A, M> Forget for MscDevice<'d, A, M>

§

impl<'d, A, M> Move for MscDevice<'d, A, M>

§

impl<'d, A, M> Send for MscDevice<'d, A, M>
where Mutex<M, Transport<'d, A>>: Send,

§

impl<'d, A, M> Sync for MscDevice<'d, A, M>
where Mutex<M, Transport<'d, A>>: Sync,

§

impl<'d, A, M> Unpin for MscDevice<'d, A, M>
where Mutex<M, Transport<'d, A>>: Unpin,

§

impl<'d, A, M> UnsafeUnpin for MscDevice<'d, A, M>
where Mutex<M, Transport<'d, A>>: UnsafeUnpin,

§

impl<'d, A, M> UnwindSafe for MscDevice<'d, A, M>
where Mutex<M, Transport<'d, A>>: UnwindSafe,

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.