Skip to main content

usb_if/
err.rs

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("No device")]
12    NoDevice,
13    #[error("Not supported")]
14    NotSupported,
15    #[error("Timeout")]
16    Timeout,
17    #[error("Cancelled")]
18    Cancelled,
19    #[error("Other error: {0}")]
20    Other(#[from] anyhow::Error),
21}
22
23impl From<Box<dyn core::error::Error>> for TransferError {
24    fn from(err: Box<dyn core::error::Error>) -> Self {
25        TransferError::Other(anyhow::anyhow!("{}", err))
26    }
27}
28
29#[derive(thiserror::Error, Debug)]
30pub enum USBError {
31    #[error("Timeout")]
32    Timeout,
33    #[error("No memory available")]
34    NoMemory,
35    #[error("Transfer error: {0}")]
36    TransferError(#[from] TransferError),
37    #[error("Not initialized")]
38    NotInitialized,
39    #[error("Not found")]
40    NotFound,
41    #[error("Invalid parameter")]
42    InvalidParameter,
43    #[error("Slot limit reached")]
44    SlotLimitReached,
45    #[error("Configuration not set")]
46    ConfigurationNotSet,
47    #[error("Not supported")]
48    NotSupported,
49    #[error("Other error: {0}")]
50    Other(#[from] anyhow::Error),
51}
52
53impl From<&str> for USBError {
54    fn from(value: &str) -> Self {
55        USBError::Other(anyhow::anyhow!("{value}"))
56    }
57}
58
59impl From<String> for USBError {
60    fn from(value: String) -> Self {
61        USBError::Other(anyhow::anyhow!(value))
62    }
63}
64
65// LIBUSB_SUCCESS
66// Success (no error)
67//
68// LIBUSB_ERROR_IO
69// Input/output error.
70//
71// LIBUSB_ERROR_INVALID_PARAM
72// Invalid parameter.
73//
74// LIBUSB_ERROR_ACCESS
75// Access denied (insufficient permissions)
76//
77// LIBUSB_ERROR_NO_DEVICE
78// No such device (it may have been disconnected)
79//
80// LIBUSB_ERROR_NOT_FOUND
81// Entity not found.
82//
83// LIBUSB_ERROR_BUSY
84// Resource busy.
85//
86// LIBUSB_ERROR_TIMEOUT
87// Operation timed out.
88//
89// LIBUSB_ERROR_OVERFLOW
90// Overflow.
91//
92// LIBUSB_ERROR_PIPE
93// Pipe error.
94//
95// LIBUSB_ERROR_INTERRUPTED
96// System call interrupted (perhaps due to signal)
97//
98// LIBUSB_ERROR_NO_MEM
99// Insufficient memory.
100//
101// LIBUSB_ERROR_NOT_SUPPORTED
102// Operation not supported or unimplemented on this platform.
103//
104// LIBUSB_ERROR_OTHER
105// Other error.