1use alloc::string::String;
2
3use crate::{
4 err::TransferError,
5 transfer::{Recipient, Request, RequestType},
6};
7
8#[derive(thiserror::Error, Debug)]
9pub enum USBError {
10 #[error("Timeout")]
11 Timeout,
12 #[error("No memory available")]
13 NoMemory,
14 #[error("Transfer error: {0}")]
15 TransferError(#[from] TransferError),
16 #[error("Not initialized")]
17 NotInitialized,
18 #[error("Not found")]
19 NotFound,
20 #[error("Slot limit reached")]
21 SlotLimitReached,
22 #[error("Configuration not set")]
23 ConfigurationNotSet,
24 #[error("Other error: {0}")]
25 Other(#[from] anyhow::Error),
26}
27
28impl From<&str> for USBError {
29 fn from(value: &str) -> Self {
30 USBError::Other(anyhow::anyhow!("{value}"))
31 }
32}
33
34impl From<String> for USBError {
35 fn from(value: String) -> Self {
36 USBError::Other(anyhow::anyhow!(value))
37 }
38}
39
40#[derive(Debug, Clone)]
41pub struct ControlSetup {
42 pub request_type: RequestType,
43 pub recipient: Recipient,
44 pub request: Request,
45 pub value: u16,
46 pub index: u16,
47}