1use alloc::{boxed::Box, string::String};
2
3#[derive(thiserror::Error, Debug)]
4pub enum TransferError {
5 #[error("Stall")]
6 Stall,
7 #[error("Queue full")]
8 QueueFull,
9 #[error("Invalid endpoint")]
10 InvalidEndpoint,
11 #[error("Endpoint was revoked by an interface reconfiguration")]
12 EndpointRevoked,
13 #[error("Device disconnected")]
14 Disconnected,
15 #[error("No device")]
16 NoDevice,
17 #[error("Not supported")]
18 NotSupported,
19 #[error("Timeout")]
20 Timeout,
21 #[error("Cancelled")]
22 Cancelled,
23 #[error("Other error: {0}")]
24 Other(#[from] anyhow::Error),
25}
26
27impl From<Box<dyn core::error::Error>> for TransferError {
28 fn from(err: Box<dyn core::error::Error>) -> Self {
29 TransferError::Other(anyhow::anyhow!("{}", err))
30 }
31}
32
33#[derive(thiserror::Error, Debug)]
34pub enum USBError {
35 #[error("Timeout")]
36 Timeout,
37 #[error("No memory available")]
38 NoMemory,
39 #[error("Transfer error: {0}")]
40 TransferError(#[from] TransferError),
41 #[error("Not initialized")]
42 NotInitialized,
43 #[error("Not found")]
44 NotFound,
45 #[error("Invalid parameter")]
46 InvalidParameter,
47 #[error("Slot limit reached")]
48 SlotLimitReached,
49 #[error("Configuration not set")]
50 ConfigurationNotSet,
51 #[error("USB interface state could not be recovered")]
52 InterfaceBroken,
53 #[error("Not supported")]
54 NotSupported,
55 #[error("Other error: {0}")]
56 Other(#[from] anyhow::Error),
57}
58
59impl From<&str> for USBError {
60 fn from(value: &str) -> Self {
61 USBError::Other(anyhow::anyhow!("{value}"))
62 }
63}
64
65impl From<String> for USBError {
66 fn from(value: String) -> Self {
67 USBError::Other(anyhow::anyhow!(value))
68 }
69}
70
71