diff options
Diffstat (limited to 'embassy-usb-driver/src')
| -rw-r--r-- | embassy-usb-driver/src/lib.rs | 69 |
1 files changed, 14 insertions, 55 deletions
diff --git a/embassy-usb-driver/src/lib.rs b/embassy-usb-driver/src/lib.rs index 931e9c318..85e9267d3 100644 --- a/embassy-usb-driver/src/lib.rs +++ b/embassy-usb-driver/src/lib.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | 2 | #![feature(async_fn_in_trait)] | |
| 3 | use core::future::Future; | 3 | #![allow(incomplete_features)] |
| 4 | 4 | ||
| 5 | /// Direction of USB traffic. Note that in the USB standard the direction is always indicated from | 5 | /// Direction of USB traffic. Note that in the USB standard the direction is always indicated from |
| 6 | /// the perspective of the host, which is backward for devices, but the standard directions are used | 6 | /// the perspective of the host, which is backward for devices, but the standard directions are used |
| @@ -155,27 +155,14 @@ pub trait Driver<'a> { | |||
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | pub trait Bus { | 157 | pub trait Bus { |
| 158 | type EnableFuture<'a>: Future<Output = ()> + 'a | ||
| 159 | where | ||
| 160 | Self: 'a; | ||
| 161 | type DisableFuture<'a>: Future<Output = ()> + 'a | ||
| 162 | where | ||
| 163 | Self: 'a; | ||
| 164 | type PollFuture<'a>: Future<Output = Event> + 'a | ||
| 165 | where | ||
| 166 | Self: 'a; | ||
| 167 | type RemoteWakeupFuture<'a>: Future<Output = Result<(), Unsupported>> + 'a | ||
| 168 | where | ||
| 169 | Self: 'a; | ||
| 170 | |||
| 171 | /// Enables the USB peripheral. Soon after enabling the device will be reset, so | 158 | /// Enables the USB peripheral. Soon after enabling the device will be reset, so |
| 172 | /// there is no need to perform a USB reset in this method. | 159 | /// there is no need to perform a USB reset in this method. |
| 173 | fn enable(&mut self) -> Self::EnableFuture<'_>; | 160 | async fn enable(&mut self); |
| 174 | 161 | ||
| 175 | /// Disables and powers down the USB peripheral. | 162 | /// Disables and powers down the USB peripheral. |
| 176 | fn disable(&mut self) -> Self::DisableFuture<'_>; | 163 | async fn disable(&mut self); |
| 177 | 164 | ||
| 178 | fn poll<'a>(&'a mut self) -> Self::PollFuture<'a>; | 165 | async fn poll(&mut self) -> Event; |
| 179 | 166 | ||
| 180 | /// Sets the device USB address to `addr`. | 167 | /// Sets the device USB address to `addr`. |
| 181 | fn set_address(&mut self, addr: u8); | 168 | fn set_address(&mut self, addr: u8); |
| @@ -209,85 +196,57 @@ pub trait Bus { | |||
| 209 | /// | 196 | /// |
| 210 | /// * [`Unsupported`](crate::driver::Unsupported) - This UsbBus implementation doesn't support | 197 | /// * [`Unsupported`](crate::driver::Unsupported) - This UsbBus implementation doesn't support |
| 211 | /// remote wakeup or it has not been enabled at creation time. | 198 | /// remote wakeup or it has not been enabled at creation time. |
| 212 | fn remote_wakeup(&mut self) -> Self::RemoteWakeupFuture<'_>; | 199 | async fn remote_wakeup(&mut self) -> Result<(), Unsupported>; |
| 213 | } | 200 | } |
| 214 | 201 | ||
| 215 | pub trait Endpoint { | 202 | pub trait Endpoint { |
| 216 | type WaitEnabledFuture<'a>: Future<Output = ()> + 'a | ||
| 217 | where | ||
| 218 | Self: 'a; | ||
| 219 | |||
| 220 | /// Get the endpoint address | 203 | /// Get the endpoint address |
| 221 | fn info(&self) -> &EndpointInfo; | 204 | fn info(&self) -> &EndpointInfo; |
| 222 | 205 | ||
| 223 | /// Waits for the endpoint to be enabled. | 206 | /// Waits for the endpoint to be enabled. |
| 224 | fn wait_enabled(&mut self) -> Self::WaitEnabledFuture<'_>; | 207 | async fn wait_enabled(&mut self); |
| 225 | } | 208 | } |
| 226 | 209 | ||
| 227 | pub trait EndpointOut: Endpoint { | 210 | pub trait EndpointOut: Endpoint { |
| 228 | type ReadFuture<'a>: Future<Output = Result<usize, EndpointError>> + 'a | ||
| 229 | where | ||
| 230 | Self: 'a; | ||
| 231 | |||
| 232 | /// Reads a single packet of data from the endpoint, and returns the actual length of | 211 | /// Reads a single packet of data from the endpoint, and returns the actual length of |
| 233 | /// the packet. | 212 | /// the packet. |
| 234 | /// | 213 | /// |
| 235 | /// This should also clear any NAK flags and prepare the endpoint to receive the next packet. | 214 | /// This should also clear any NAK flags and prepare the endpoint to receive the next packet. |
| 236 | fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a>; | 215 | async fn read(&mut self, buf: &mut [u8]) -> Result<usize, EndpointError>; |
| 237 | } | 216 | } |
| 238 | 217 | ||
| 239 | pub trait ControlPipe { | 218 | pub trait ControlPipe { |
| 240 | type SetupFuture<'a>: Future<Output = [u8; 8]> + 'a | ||
| 241 | where | ||
| 242 | Self: 'a; | ||
| 243 | type DataOutFuture<'a>: Future<Output = Result<usize, EndpointError>> + 'a | ||
| 244 | where | ||
| 245 | Self: 'a; | ||
| 246 | type DataInFuture<'a>: Future<Output = Result<(), EndpointError>> + 'a | ||
| 247 | where | ||
| 248 | Self: 'a; | ||
| 249 | type AcceptFuture<'a>: Future<Output = ()> + 'a | ||
| 250 | where | ||
| 251 | Self: 'a; | ||
| 252 | type RejectFuture<'a>: Future<Output = ()> + 'a | ||
| 253 | where | ||
| 254 | Self: 'a; | ||
| 255 | |||
| 256 | /// Maximum packet size for the control pipe | 219 | /// Maximum packet size for the control pipe |
| 257 | fn max_packet_size(&self) -> usize; | 220 | fn max_packet_size(&self) -> usize; |
| 258 | 221 | ||
| 259 | /// Reads a single setup packet from the endpoint. | 222 | /// Reads a single setup packet from the endpoint. |
| 260 | fn setup<'a>(&'a mut self) -> Self::SetupFuture<'a>; | 223 | async fn setup<'a>(&'a mut self) -> [u8; 8]; |
| 261 | 224 | ||
| 262 | /// Reads a DATA OUT packet into `buf` in response to a control write request. | 225 | /// Reads a DATA OUT packet into `buf` in response to a control write request. |
| 263 | /// | 226 | /// |
| 264 | /// Must be called after `setup()` for requests with `direction` of `Out` | 227 | /// Must be called after `setup()` for requests with `direction` of `Out` |
| 265 | /// and `length` greater than zero. | 228 | /// and `length` greater than zero. |
| 266 | fn data_out<'a>(&'a mut self, buf: &'a mut [u8], first: bool, last: bool) -> Self::DataOutFuture<'a>; | 229 | async fn data_out(&mut self, buf: &mut [u8], first: bool, last: bool) -> Result<usize, EndpointError>; |
| 267 | 230 | ||
| 268 | /// Sends a DATA IN packet with `data` in response to a control read request. | 231 | /// Sends a DATA IN packet with `data` in response to a control read request. |
| 269 | /// | 232 | /// |
| 270 | /// If `last_packet` is true, the STATUS packet will be ACKed following the transfer of `data`. | 233 | /// If `last_packet` is true, the STATUS packet will be ACKed following the transfer of `data`. |
| 271 | fn data_in<'a>(&'a mut self, data: &'a [u8], first: bool, last: bool) -> Self::DataInFuture<'a>; | 234 | async fn data_in(&mut self, data: &[u8], first: bool, last: bool) -> Result<(), EndpointError>; |
| 272 | 235 | ||
| 273 | /// Accepts a control request. | 236 | /// Accepts a control request. |
| 274 | /// | 237 | /// |
| 275 | /// Causes the STATUS packet for the current request to be ACKed. | 238 | /// Causes the STATUS packet for the current request to be ACKed. |
| 276 | fn accept<'a>(&'a mut self) -> Self::AcceptFuture<'a>; | 239 | async fn accept(&mut self); |
| 277 | 240 | ||
| 278 | /// Rejects a control request. | 241 | /// Rejects a control request. |
| 279 | /// | 242 | /// |
| 280 | /// Sets a STALL condition on the pipe to indicate an error. | 243 | /// Sets a STALL condition on the pipe to indicate an error. |
| 281 | fn reject<'a>(&'a mut self) -> Self::RejectFuture<'a>; | 244 | async fn reject(&mut self); |
| 282 | } | 245 | } |
| 283 | 246 | ||
| 284 | pub trait EndpointIn: Endpoint { | 247 | pub trait EndpointIn: Endpoint { |
| 285 | type WriteFuture<'a>: Future<Output = Result<(), EndpointError>> + 'a | ||
| 286 | where | ||
| 287 | Self: 'a; | ||
| 288 | |||
| 289 | /// Writes a single packet of data to the endpoint. | 248 | /// Writes a single packet of data to the endpoint. |
| 290 | fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a>; | 249 | async fn write(&mut self, buf: &[u8]) -> Result<(), EndpointError>; |
| 291 | } | 250 | } |
| 292 | 251 | ||
| 293 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | 252 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] |
