embassy-usb

Crates

git

Versions

default

Flavors

Skip to main content

MtpClass

Struct MtpClass 

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

USB Media Transfer Protocol (MTP) device class.

Implementations§

Source§

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

Source

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

Creates a new MtpClass and registers its USB Still Image / MTP interface.

Source

pub fn max_packet_size(&self) -> u16

Returns the Bulk endpoint max packet size in bytes.

Source

pub const fn interface(&self) -> InterfaceNumber

Returns the USB interface number assigned to this class instance.

Source

pub const fn shared(&self) -> &'d ControlShared

Returns a reference to the shared control state.

Source

pub fn set_device_status(&self, status: u16)

Sets the status code returned to the host by REQ_GET_DEVICE_STATUS (0x67).

Source

pub fn take_cancel(&self) -> Option<u32>

Returns and clears the cancelled transaction ID if the host sent REQ_CANCEL (0x64).

Source

pub fn take_reset(&self) -> bool

Returns and clears whether the host sent REQ_RESET (0x66).

Source

pub async fn wait_connection(&mut self)

Waits until the USB host configures and enables the MTP interface endpoints.

Source

pub async fn read_command( &mut self, buf: &mut [u8], ) -> Result<CommandBlock, MtpError>

Reads the next MTP Command container from the Bulk-OUT endpoint.

buf must be at least max_packet_size() bytes long. Any leading zero-length packet (for example, a trailing ZLP from a prior Bulk-OUT data container whose length was a multiple of max_packet_size) is skipped automatically.

Source

pub async fn start_data_out<'a>( &'a mut self, buf: &'a mut [u8], ) -> Result<DataOutReader<'a, 'd, D>, MtpError>

Starts reading an MTP Data-OUT container from the Bulk-OUT endpoint.

buf is used as a packet staging buffer and must be at least max_packet_size() bytes long. Returns a DataOutReader to stream the payload in arbitrary chunk sizes.

Source

pub async fn read_data_all( &mut self, pkt_buf: &mut [u8], payload_buf: &mut [u8], ) -> Result<(ContainerHeader, usize), MtpError>

Reads an entire bounded MTP Data-OUT container into payload_buf.

pkt_buf must be at least max_packet_size() bytes long. Returns the parsed ContainerHeader and the number of payload bytes written into payload_buf.

Source

pub fn start_data_in<'a>( &'a mut self, code: u16, transaction_id: u32, payload_len: Option<u32>, buf: &'a mut [u8], ) -> Result<DataInWriter<'a, 'd, D>, MtpError>

Starts writing an MTP Data-IN container to the Bulk-IN endpoint.

Pass payload_len = Some(len) when the total payload size is known (normal case), or None to write STREAMING_CONTAINER_LEN (0xFFFF_FFFF).

buf is used as a transfer staging buffer and must be at least max_packet_size() bytes long. Larger multiples of max_packet_size() allow multi-packet USB transfers.

Source

pub async fn write_data( &mut self, code: u16, transaction_id: u32, payload: &[u8], buf: &mut [u8], ) -> Result<(), MtpError>

Sends a complete MTP Data-IN container for an in-memory payload.

buf must be at least max_packet_size() bytes long. Automatically appends a ZLP when (12 + payload.len()) is an exact multiple of max_packet_size().

Source

pub async fn write_response( &mut self, response: &ResponseBlock, ) -> Result<(), MtpError>

Sends an MTP Response container on the Bulk-IN endpoint.

Source

pub async fn write_event(&mut self, event: &EventBlock) -> Result<(), MtpError>

Sends an asynchronous MTP Event container on the Interrupt-IN endpoint.

Auto Trait Implementations§

§

impl<'d, D> !RefUnwindSafe for MtpClass<'d, D>

§

impl<'d, D> !UnwindSafe for MtpClass<'d, D>

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<'d, D> UnsafeUnpin for MtpClass<'d, D>
where <D as Driver<'d>>::EndpointOut: UnsafeUnpin, <D as Driver<'d>>::EndpointIn: UnsafeUnpin,

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.