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>
impl<'d, D: Driver<'d>> MtpClass<'d, D>
Sourcepub fn new(
builder: &mut Builder<'d, D>,
state: &'d mut State<'d>,
config: Config<'d>,
) -> Self
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.
Sourcepub fn max_packet_size(&self) -> u16
pub fn max_packet_size(&self) -> u16
Returns the Bulk endpoint max packet size in bytes.
Sourcepub const fn interface(&self) -> InterfaceNumber
pub const fn interface(&self) -> InterfaceNumber
Returns the USB interface number assigned to this class instance.
Returns a reference to the shared control state.
Sourcepub fn set_device_status(&self, status: u16)
pub fn set_device_status(&self, status: u16)
Sets the status code returned to the host by REQ_GET_DEVICE_STATUS (0x67).
Sourcepub fn take_cancel(&self) -> Option<u32>
pub fn take_cancel(&self) -> Option<u32>
Returns and clears the cancelled transaction ID if the host sent REQ_CANCEL (0x64).
Sourcepub fn take_reset(&self) -> bool
pub fn take_reset(&self) -> bool
Returns and clears whether the host sent REQ_RESET (0x66).
Sourcepub async fn wait_connection(&mut self)
pub async fn wait_connection(&mut self)
Waits until the USB host configures and enables the MTP interface endpoints.
Sourcepub async fn read_command(
&mut self,
buf: &mut [u8],
) -> Result<CommandBlock, MtpError>
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.
Sourcepub async fn start_data_out<'a>(
&'a mut self,
buf: &'a mut [u8],
) -> Result<DataOutReader<'a, 'd, D>, MtpError>
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.
Sourcepub async fn read_data_all(
&mut self,
pkt_buf: &mut [u8],
payload_buf: &mut [u8],
) -> Result<(ContainerHeader, usize), MtpError>
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.
Sourcepub 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>
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.
Sourcepub async fn write_data(
&mut self,
code: u16,
transaction_id: u32,
payload: &[u8],
buf: &mut [u8],
) -> Result<(), MtpError>
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().
Sourcepub async fn write_response(
&mut self,
response: &ResponseBlock,
) -> Result<(), MtpError>
pub async fn write_response( &mut self, response: &ResponseBlock, ) -> Result<(), MtpError>
Sends an MTP Response container on the Bulk-IN endpoint.
Sourcepub async fn write_event(&mut self, event: &EventBlock) -> Result<(), MtpError>
pub async fn write_event(&mut self, event: &EventBlock) -> Result<(), MtpError>
Sends an asynchronous MTP Event container on the Interrupt-IN endpoint.