use rusb::constants::{LIBUSB_ENDPOINT_IN, LIBUSB_ENDPOINT_OUT};
use serde::{Deserialize, Serialize};
use std::time::Duration;
pub const PICO1541_VID: u16 = 0x1209;
pub const PICO1541_PID: u16 = 0x0f0f;
pub const XUM1541_VID: u16 = 0x16d0;
pub const XUM1541_PID: u16 = 0x0504;
pub const PRODUCT_STRINGS: [&str; 3] = ["xum1541", "pico1541", "tinyusb vendor example"];
pub const CUR_FW_VERSION: u8 = 8;
pub const MIN_FW_VERSION: u8 = 7;
pub const PROTO_WRITE_TALK: u8 = 1 << 0;
pub const PROTO_WRITE_ATN: u8 = 1 << 1;
pub const PROTO_MASK: u8 = 0xf0;
pub const PROTO_CBM: u8 = 1 << 4;
pub const PROTO_S1: u8 = 2 << 4;
pub const PROTO_S2: u8 = 3 << 4;
pub const PROTO_PP: u8 = 4 << 4;
pub const PROTO_P2: u8 = 5 << 4;
pub const PROTO_NIB: u8 = 6 << 4;
pub const PROTO_NIB_COMMAND: u8 = 7 << 4;
pub const PROTO_NIB_SRQ: u8 = 8 << 4;
pub const PROTO_NIB_SRQ_COMMAND: u8 = 9 << 4;
pub const DEFAULT_READ_TIMEOUT: Duration = Duration::from_secs(5);
pub const DEFAULT_WRITE_TIMEOUT: Duration = Duration::from_secs(5);
pub const DEFAULT_CONTROL_TIMEOUT: Duration = Duration::from_secs(5);
pub const DEFAULT_USB_LOOP_SLEEP: Duration = Duration::from_millis(10);
pub const DEFAULT_USB_RESET_SLEEP: Duration = Duration::from_millis(100);
pub const BULK_IN_ENDPOINT: u8 = 3 | LIBUSB_ENDPOINT_IN;
pub const BULK_OUT_ENDPOINT: u8 = 4 | LIBUSB_ENDPOINT_OUT;
pub const STATUS_BUF_SIZE: usize = 3;
pub const DEV_INFO_SIZE: usize = 8;
pub const MAX_XFER_SIZE: usize = 32768;
pub const IO_BUSY: u8 = 1;
pub const IO_READY: u8 = 2;
pub const IO_ERROR: u8 = 3;
pub const READ: u8 = 8;
pub const WRITE: u8 = 9;
pub const CTRL_ECHO: u8 = 0;
pub const CTRL_INIT: u8 = 1;
pub const CTRL_RESET: u8 = 2;
pub const CTRL_SHUTDOWN: u8 = 3;
pub const CTRL_ENTER_BOOTLOADER: u8 = 4;
pub const CTRL_TAP_BREAK: u8 = 5;
pub const CTRL_GITREV: u8 = 6;
pub const CTRL_GCCVER: u8 = 7;
pub const CTRL_LIBCVER: u8 = 8;
pub const STATUS_DOING_RESET: u8 = 0x01;
pub const STATUS_IEEE488_PRESENT: u8 = 0x10;
pub const STATUS_TAPE_PRESENT: u8 = 0x20;
pub const CAP_CBM: u8 = 0x01;
pub const CAP_NIB: u8 = 0x02;
pub const CAP_NIB_SRQ: u8 = 0x04;
pub const CAP_IEEE488: u8 = 0x08;
pub const CAP_TAP: u8 = 0x10;
pub const DEVICE_MIN_NUM: u8 = 8;
pub const DEVICE_MAX_NUM: u8 = 30;
pub const DRIVE_MIN_CHANNEL: u8 = 0;
pub const DRIVE_MAX_CHANNEL: u8 = 15;
pub const DRIVE_LOAD_CHANNEL: u8 = 0;
pub const DRIVE_SAVE_CHANNEL: u8 = 1;
pub const DRIVE_MIN_FREE_CHANNEL: u8 = 2;
pub const DRIVE_MAX_FREE_CHANNEL: u8 = 14;
pub const DRIVE_COMMAND_CHANNEL: u8 = 15;
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub enum Ioctl {
GetEoi = 23,
ClearEoi = 24,
PpRead = 25,
PpWrite = 26,
IecPoll = 27,
IecWait = 28,
IecSetRelease = 29,
ParburstRead = 30,
ParburstWrite = 31,
SrqburstRead = 32,
SrqburstWrite = 33,
TapMotorOn = 66,
TapGetVer = 67,
TapPrepareCapture = 68,
TapPrepareWrite = 69,
TapGetSense = 70,
TapWaitForStopSense = 71,
TapWaitForPlaySense = 72,
TapMotorOff = 73,
Unknown = 255,
}
impl Ioctl {
#[must_use]
pub fn is_async(&self) -> bool {
*self == Self::IecWait
}
#[must_use]
pub fn is_sync(&self) -> bool {
!self.is_async()
}
}
impl From<u8> for Ioctl {
fn from(value: u8) -> Self {
match value {
23 => Self::GetEoi,
24 => Self::ClearEoi,
25 => Self::PpRead,
26 => Self::PpWrite,
27 => Self::IecPoll,
28 => Self::IecWait,
29 => Self::IecSetRelease,
30 => Self::ParburstRead,
31 => Self::ParburstWrite,
32 => Self::SrqburstRead,
33 => Self::SrqburstWrite,
66 => Self::TapMotorOn,
67 => Self::TapGetVer,
68 => Self::TapPrepareCapture,
69 => Self::TapPrepareWrite,
70 => Self::TapGetSense,
71 => Self::TapWaitForStopSense,
72 => Self::TapWaitForPlaySense,
73 => Self::TapMotorOff,
_ => Self::Unknown,
}
}
}
impl std::fmt::Display for Ioctl {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::GetEoi => write!(f, "GetEoi"),
Self::ClearEoi => write!(f, "ClearEoi"),
Self::PpRead => write!(f, "PpRead"),
Self::PpWrite => write!(f, "PpWrite"),
Self::IecPoll => write!(f, "IecPoll"),
Self::IecWait => write!(f, "IecWait"),
Self::IecSetRelease => write!(f, "IecSetRelease"),
Self::ParburstRead => write!(f, "ParburstRead"),
Self::ParburstWrite => write!(f, "ParburstWrite"),
Self::SrqburstRead => write!(f, "SrqburstRead"),
Self::SrqburstWrite => write!(f, "SrqburstWrite"),
Self::TapMotorOn => write!(f, "TapMotorOn"),
Self::TapGetVer => write!(f, "TapGetVer"),
Self::TapPrepareCapture => write!(f, "TapPrepareCapture"),
Self::TapPrepareWrite => write!(f, "TapPrepareWrite"),
Self::TapGetSense => write!(f, "TapGetSense"),
Self::TapWaitForStopSense => write!(f, "TapWaitForStopSense"),
Self::TapWaitForPlaySense => write!(f, "TapWaitForPlaySense"),
Self::TapMotorOff => write!(f, "TapMotorOff"),
Self::Unknown => write!(f, "Unknown"),
}
}
}