Unify ReadError and WriteError into EndpointError

This commit is contained in:
alexmoon
2022-04-05 22:04:11 -04:00
committed by Dario Nieuwenhuis
parent b2cdaa56c1
commit e867364d42
7 changed files with 44 additions and 74 deletions

View File

@ -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<C: driver::ControlPipe> ControlPipe<C> {
&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 {

View File

@ -130,7 +130,7 @@ pub trait Endpoint {
}
pub trait EndpointOut: Endpoint {
type ReadFuture<'a>: Future<Output = Result<usize, ReadError>> + 'a
type ReadFuture<'a>: Future<Output = Result<usize, EndpointError>> + 'a
where
Self: 'a;
@ -145,10 +145,10 @@ pub trait ControlPipe {
type SetupFuture<'a>: Future<Output = Request> + 'a
where
Self: 'a;
type DataOutFuture<'a>: Future<Output = Result<usize, ReadError>> + 'a
type DataOutFuture<'a>: Future<Output = Result<usize, EndpointError>> + 'a
where
Self: 'a;
type DataInFuture<'a>: Future<Output = Result<(), WriteError>> + 'a
type DataInFuture<'a>: Future<Output = Result<(), EndpointError>> + 'a
where
Self: 'a;
@ -181,7 +181,7 @@ pub trait ControlPipe {
}
pub trait EndpointIn: Endpoint {
type WriteFuture<'a>: Future<Output = Result<(), WriteError>> + 'a
type WriteFuture<'a>: Future<Output = Result<(), EndpointError>> + '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,
}