From e867364d42477ecf3dc48e6fd787dff96cb6fadf Mon Sep 17 00:00:00 2001 From: alexmoon Date: Tue, 5 Apr 2022 22:04:11 -0400 Subject: Unify ReadError and WriteError into EndpointError --- embassy-usb/src/control.rs | 4 ++-- embassy-usb/src/driver.rs | 30 +++++++++--------------------- 2 files changed, 11 insertions(+), 23 deletions(-) (limited to 'embassy-usb/src') diff --git a/embassy-usb/src/control.rs b/embassy-usb/src/control.rs index 7c46812bd..a613f1145 100644 --- a/embassy-usb/src/control.rs +++ b/embassy-usb/src/control.rs @@ -1,7 +1,7 @@ use core::mem; use crate::descriptor::DescriptorWriter; -use crate::driver::{self, ReadError}; +use crate::driver::{self, EndpointError}; use crate::DEFAULT_ALTERNATE_SETTING; use super::types::*; @@ -253,7 +253,7 @@ impl ControlPipe { &mut self, buf: &'a mut [u8], stage: DataOutStage, - ) -> Result<(&'a [u8], StatusStage), ReadError> { + ) -> Result<(&'a [u8], StatusStage), EndpointError> { if stage.length == 0 { Ok((&[], StatusStage {})) } else { diff --git a/embassy-usb/src/driver.rs b/embassy-usb/src/driver.rs index 01eb3d577..875ceafcb 100644 --- a/embassy-usb/src/driver.rs +++ b/embassy-usb/src/driver.rs @@ -130,7 +130,7 @@ pub trait Endpoint { } pub trait EndpointOut: Endpoint { - type ReadFuture<'a>: Future> + 'a + type ReadFuture<'a>: Future> + 'a where Self: 'a; @@ -145,10 +145,10 @@ pub trait ControlPipe { type SetupFuture<'a>: Future + 'a where Self: 'a; - type DataOutFuture<'a>: Future> + 'a + type DataOutFuture<'a>: Future> + 'a where Self: 'a; - type DataInFuture<'a>: Future> + 'a + type DataInFuture<'a>: Future> + 'a where Self: 'a; @@ -181,7 +181,7 @@ pub trait ControlPipe { } pub trait EndpointIn: Endpoint { - type WriteFuture<'a>: Future> + 'a + type WriteFuture<'a>: Future> + 'a where Self: 'a; @@ -216,24 +216,12 @@ pub struct Unsupported; #[derive(Copy, Clone, Eq, PartialEq, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -/// Errors returned by [`EndpointIn::write`] -pub enum WriteError { - /// The packet is too long to fit in the - /// transmission buffer. This is generally an error in the class implementation, because the - /// class shouldn't provide more data than the `max_packet_size` it specified when allocating - /// the endpoint. +/// Errors returned by [`EndpointIn::write`] and [`EndpointOut::read`] +pub enum EndpointError { + /// Either the packet to be written is too long to fit in the transmission + /// buffer or the received packet is too long to fit in `buf`. BufferOverflow, - Disabled, -} -#[derive(Copy, Clone, Eq, PartialEq, Debug)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -/// Errors returned by [`EndpointOut::read`] -pub enum ReadError { - /// The received packet is too long to - /// fit in `buf`. This is generally an error in the class implementation, because the class - /// should use a buffer that is large enough for the `max_packet_size` it specified when - /// allocating the endpoint. - BufferOverflow, + /// The endpoint is disabled. Disabled, } -- cgit