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("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// LIBUSB_SUCCESS
72// Success (no error)
73//
74// LIBUSB_ERROR_IO
75// Input/output error.
76//
77// LIBUSB_ERROR_INVALID_PARAM
78// Invalid parameter.
79//
80// LIBUSB_ERROR_ACCESS
81// Access denied (insufficient permissions)
82//
83// LIBUSB_ERROR_NO_DEVICE
84// No such device (it may have been disconnected)
85//
86// LIBUSB_ERROR_NOT_FOUND
87// Entity not found.
88//
89// LIBUSB_ERROR_BUSY
90// Resource busy.
91//
92// LIBUSB_ERROR_TIMEOUT
93// Operation timed out.
94//
95// LIBUSB_ERROR_OVERFLOW
96// Overflow.
97//
98// LIBUSB_ERROR_PIPE
99// Pipe error.
100//
101// LIBUSB_ERROR_INTERRUPTED
102// System call interrupted (perhaps due to signal)
103//
104// LIBUSB_ERROR_NO_MEM
105// Insufficient memory.
106//
107// LIBUSB_ERROR_NOT_SUPPORTED
108// Operation not supported or unimplemented on this platform.
109//
110// LIBUSB_ERROR_OTHER
111// Other error.