diff options
| author | alexmoon <[email protected]> | 2022-04-05 22:04:11 -0400 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-04-09 01:48:17 +0200 |
| commit | e867364d42477ecf3dc48e6fd787dff96cb6fadf (patch) | |
| tree | 9bd64f21d1343b60186ce437f576c6a0fbbfdda6 /embassy-nrf/src | |
| parent | b2cdaa56c1dca5ce293dad3b1e450f97bcf85251 (diff) | |
Unify ReadError and WriteError into EndpointError
Diffstat (limited to 'embassy-nrf/src')
| -rw-r--r-- | embassy-nrf/src/usb.rs | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index 9f483d96e..5e2f585f2 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs | |||
| @@ -10,7 +10,7 @@ use embassy::util::Unborrow; | |||
| 10 | use embassy::waitqueue::AtomicWaker; | 10 | use embassy::waitqueue::AtomicWaker; |
| 11 | use embassy_hal_common::unborrow; | 11 | use embassy_hal_common::unborrow; |
| 12 | use embassy_usb::control::Request; | 12 | use embassy_usb::control::Request; |
| 13 | use embassy_usb::driver::{self, Event, ReadError, WriteError}; | 13 | use embassy_usb::driver::{self, EndpointError, Event}; |
| 14 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; | 14 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; |
| 15 | use futures::future::poll_fn; | 15 | use futures::future::poll_fn; |
| 16 | use futures::Future; | 16 | use futures::Future; |
| @@ -472,13 +472,13 @@ impl<'d, T: Instance, Dir> Endpoint<'d, T, Dir> { | |||
| 472 | } | 472 | } |
| 473 | } | 473 | } |
| 474 | 474 | ||
| 475 | unsafe fn read_dma<T: Instance>(i: usize, buf: &mut [u8]) -> Result<usize, ReadError> { | 475 | unsafe fn read_dma<T: Instance>(i: usize, buf: &mut [u8]) -> Result<usize, EndpointError> { |
| 476 | let regs = T::regs(); | 476 | let regs = T::regs(); |
| 477 | 477 | ||
| 478 | // Check that the packet fits into the buffer | 478 | // Check that the packet fits into the buffer |
| 479 | let size = regs.size.epout[i].read().bits() as usize; | 479 | let size = regs.size.epout[i].read().bits() as usize; |
| 480 | if size > buf.len() { | 480 | if size > buf.len() { |
| 481 | return Err(ReadError::BufferOverflow); | 481 | return Err(EndpointError::BufferOverflow); |
| 482 | } | 482 | } |
| 483 | 483 | ||
| 484 | if i == 0 { | 484 | if i == 0 { |
| @@ -554,7 +554,7 @@ unsafe fn write_dma<T: Instance>(i: usize, buf: &[u8]) { | |||
| 554 | } | 554 | } |
| 555 | 555 | ||
| 556 | impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> { | 556 | impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> { |
| 557 | type ReadFuture<'a> = impl Future<Output = Result<usize, ReadError>> + 'a where Self: 'a; | 557 | type ReadFuture<'a> = impl Future<Output = Result<usize, EndpointError>> + 'a where Self: 'a; |
| 558 | 558 | ||
| 559 | fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> { | 559 | fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> { |
| 560 | async move { | 560 | async move { |
| @@ -563,7 +563,7 @@ impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> { | |||
| 563 | 563 | ||
| 564 | self.wait_data_ready() | 564 | self.wait_data_ready() |
| 565 | .await | 565 | .await |
| 566 | .map_err(|_| ReadError::Disabled)?; | 566 | .map_err(|_| EndpointError::Disabled)?; |
| 567 | 567 | ||
| 568 | unsafe { read_dma::<T>(i, buf) } | 568 | unsafe { read_dma::<T>(i, buf) } |
| 569 | } | 569 | } |
| @@ -571,7 +571,7 @@ impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> { | |||
| 571 | } | 571 | } |
| 572 | 572 | ||
| 573 | impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> { | 573 | impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> { |
| 574 | type WriteFuture<'a> = impl Future<Output = Result<(), WriteError>> + 'a where Self: 'a; | 574 | type WriteFuture<'a> = impl Future<Output = Result<(), EndpointError>> + 'a where Self: 'a; |
| 575 | 575 | ||
| 576 | fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> { | 576 | fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> { |
| 577 | async move { | 577 | async move { |
| @@ -580,7 +580,7 @@ impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> { | |||
| 580 | 580 | ||
| 581 | self.wait_data_ready() | 581 | self.wait_data_ready() |
| 582 | .await | 582 | .await |
| 583 | .map_err(|_| WriteError::Disabled)?; | 583 | .map_err(|_| EndpointError::Disabled)?; |
| 584 | 584 | ||
| 585 | unsafe { write_dma::<T>(i, buf) } | 585 | unsafe { write_dma::<T>(i, buf) } |
| 586 | 586 | ||
| @@ -596,8 +596,8 @@ pub struct ControlPipe<'d, T: Instance> { | |||
| 596 | 596 | ||
| 597 | impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | 597 | impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { |
| 598 | type SetupFuture<'a> = impl Future<Output = Request> + 'a where Self: 'a; | 598 | type SetupFuture<'a> = impl Future<Output = Request> + 'a where Self: 'a; |
| 599 | type DataOutFuture<'a> = impl Future<Output = Result<usize, ReadError>> + 'a where Self: 'a; | 599 | type DataOutFuture<'a> = impl Future<Output = Result<usize, EndpointError>> + 'a where Self: 'a; |
| 600 | type DataInFuture<'a> = impl Future<Output = Result<(), WriteError>> + 'a where Self: 'a; | 600 | type DataInFuture<'a> = impl Future<Output = Result<(), EndpointError>> + 'a where Self: 'a; |
| 601 | 601 | ||
| 602 | fn max_packet_size(&self) -> usize { | 602 | fn max_packet_size(&self) -> usize { |
| 603 | usize::from(self.max_packet_size) | 603 | usize::from(self.max_packet_size) |
| @@ -666,10 +666,10 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 666 | Poll::Ready(Ok(())) | 666 | Poll::Ready(Ok(())) |
| 667 | } else if regs.events_usbreset.read().bits() != 0 { | 667 | } else if regs.events_usbreset.read().bits() != 0 { |
| 668 | trace!("aborted control data_out: usb reset"); | 668 | trace!("aborted control data_out: usb reset"); |
| 669 | Poll::Ready(Err(ReadError::Disabled)) | 669 | Poll::Ready(Err(EndpointError::Disabled)) |
| 670 | } else if regs.events_ep0setup.read().bits() != 0 { | 670 | } else if regs.events_ep0setup.read().bits() != 0 { |
| 671 | trace!("aborted control data_out: received another SETUP"); | 671 | trace!("aborted control data_out: received another SETUP"); |
| 672 | Poll::Ready(Err(ReadError::Disabled)) | 672 | Poll::Ready(Err(EndpointError::Disabled)) |
| 673 | } else { | 673 | } else { |
| 674 | Poll::Pending | 674 | Poll::Pending |
| 675 | } | 675 | } |
| @@ -705,10 +705,10 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 705 | Poll::Ready(Ok(())) | 705 | Poll::Ready(Ok(())) |
| 706 | } else if regs.events_usbreset.read().bits() != 0 { | 706 | } else if regs.events_usbreset.read().bits() != 0 { |
| 707 | trace!("aborted control data_in: usb reset"); | 707 | trace!("aborted control data_in: usb reset"); |
| 708 | Poll::Ready(Err(WriteError::Disabled)) | 708 | Poll::Ready(Err(EndpointError::Disabled)) |
| 709 | } else if regs.events_ep0setup.read().bits() != 0 { | 709 | } else if regs.events_ep0setup.read().bits() != 0 { |
| 710 | trace!("aborted control data_in: received another SETUP"); | 710 | trace!("aborted control data_in: received another SETUP"); |
| 711 | Poll::Ready(Err(WriteError::Disabled)) | 711 | Poll::Ready(Err(EndpointError::Disabled)) |
| 712 | } else { | 712 | } else { |
| 713 | Poll::Pending | 713 | Poll::Pending |
| 714 | } | 714 | } |
