use bitflags::bitflags;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MCIHostCmdType {
Normal = 0,
Suspend = 1,
Resume = 2,
Abort = 3,
Empty = 4,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MCIHostResponseType {
None = 0,
R1 = 1,
R1b = 2,
R2 = 3,
R3 = 4,
R4 = 5,
R5 = 6,
R5b = 7,
R6 = 8,
R7 = 9,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MCIHostDataPacketFormat {
MSBFirst = 0,
LSBFirst = 1,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MCIHostBusWdith {
Bit1 = 1,
Bit4 = 4,
Bit8 = 8,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MCIHostCommonCmd {
GoIdleState = 0,
AllSendCid = 2,
SetDsr = 4,
SelectCard = 7,
SendCsd = 9,
SendCid = 10,
StopTransmission = 12,
SendStatus = 13,
GoInactiveState = 15,
SetBlockLength = 16,
ReadSingleBlock = 17,
ReadMultipleBlock = 18,
SetBlockCount = 23,
WriteSingleBlock = 24,
WriteMultipleBlock = 25,
ProgramCsd = 27,
SetWriteProtect = 28,
ClearWriteProtect = 29,
SendWriteProtect = 30,
Erase = 38,
LockUnlock = 42,
ApplicationCommand = 55,
GeneralCommand = 56,
ReadOcr = 58,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MCISDIOCommand {
SendRelativeAddress = 3,
SendOperationCondition = 5,
SendInterfaceCondition = 8,
RWIODirect = 52,
RWIODirectExtended = 53,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MCISDIOCCCRAddr {
SDIOVer = 0x00,
SDVersion = 0x01,
IOEnable = 0x02,
IOReady = 0x03,
IOIntEnable = 0x04,
IOIntPending = 0x05,
IOAbort = 0x06,
BusInterface = 0x07,
CardCapability = 0x08,
CommonCISPointer = 0x09,
BusSuspend = 0x0C,
FunctionSelect = 0x0D,
ExecutionFlag = 0x0E,
ReadyFlag = 0x0F,
FN0BlockSizeLow = 0x10,
FN0BlockSizeHigh = 0x11,
PowerControl = 0x12,
BusSpeed = 0x13,
UHSITimingSupport = 0x14,
DriverStrength = 0x15,
InterruptExtension = 0x16,
}
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MCIHostCardStatusFlag: u32 {
const OUT_OF_RANGE = 1 << 31;
const ADDRESS_ERROR = 1 << 30;
const BLOCK_LENGTH_ERROR = 1 << 29;
const ERASE_SEQUENCE_ERROR = 1 << 28;
const ERASE_PARAMETER_ERROR = 1 << 27;
const WRITE_PROTECT_VIOLATION = 1 << 26;
const CARD_IS_LOCKED = 1 << 25;
const LOCK_UNLOCK_FAILED = 1 << 24;
const COMMAND_CRC_ERROR = 1 << 23;
const ILLEGAL_COMMAND = 1 << 22;
const CARD_ECC_FAILED = 1 << 21;
const CARD_CONTROLLER_ERROR = 1 << 20;
const ERROR = 1 << 19;
const CID_CSD_OVERWRITE = 1 << 16;
const WRITE_PROTECT_ERASE_SKIP = 1 << 15;
const CARD_ECC_DISABLED = 1 << 14;
const ERASE_RESET = 1 << 13;
const READY_FOR_DATA = 1 << 8;
const SWITCH_ERROR = 1 << 7;
const APPLICATION_COMMAND = 1 << 5;
const AUTHENTICATION_SEQUENCE_ERROR = 1 << 3;
const ALL_ERROR_FLAG = 0xFFF90008;
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum MCIHostCurrentState {
Idle = 0,
Ready = 1,
Identification = 2,
Standby = 3,
Transfer = 4,
Data = 5,
Receive = 6,
Programming = 7,
Disconnect = 8,
}
impl MCIHostCurrentState {
pub(crate) fn current_state(state: u32) -> Self {
let state = (state & 0x00001E00) >> 9;
match state {
0 => MCIHostCurrentState::Idle,
1 => MCIHostCurrentState::Ready,
2 => MCIHostCurrentState::Identification,
3 => MCIHostCurrentState::Standby,
4 => MCIHostCurrentState::Transfer,
5 => MCIHostCurrentState::Data,
6 => MCIHostCurrentState::Receive,
7 => MCIHostCurrentState::Programming,
8 => MCIHostCurrentState::Disconnect,
_ => MCIHostCurrentState::Idle,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum MCIHostOperationVoltage {
None = 0,
Voltage330V = 1,
Voltage300V = 2,
Voltage180V = 3,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum MCIHostDetectCardType {
ByGpioCD,
ByHostCD,
ByHostDATA3,
}
pub(crate) const MCI_HOST_CLOCK_400KHZ: u32 = 400_000;
pub(crate) const MCI_HOST_MAX_CMD_RETRIES: u32 = 10;
pub(crate) const MCI_HOST_DEFAULT_BLOCK_SIZE: u32 = 512;
pub(crate) const MCI_HOST_MAX_BLOCK_LENGTH: u32 = 4096;
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct MCIHostOCR: u32 {
const POWER_UP_BUSY_FLAG = 1 << 31;
const HOST_CAPACITY_SUPPORT_FLAG = 1 << 30;
const CARD_CAPACITY_SUPPORT_FLAG = 1 << 30;
const SWITCH_18_REQUEST_FLAG = 1 << 24;
const SWITCH_18_ACCEPT_FLAG = 1 << 24;
const VDD_27_28 = 1 << 15;
const VDD_28_29 = 1 << 16;
const VDD_29_30 = 1 << 17;
const VDD_30_31 = 1 << 18;
const VDD_31_32 = 1 << 19;
const VDD_32_33 = 1 << 20;
const VDD_33_34 = 1 << 21;
const VDD_34_35 = 1 << 22;
const VDD_35_36 = 1 << 23;
}
}
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct MCIHostCapability: u32 {
const HIGH_SPEED = 1 << 0;
const SUSPEND_RESUME = 1 << 1;
const VOLTAGE_3V3 = 1 << 2;
const VOLTAGE_3V0 = 1 << 3;
const VOLTAGE_1V8 = 1 << 4;
const VOLTAGE_1V2 = 1 << 5;
const BIT4_DATA_WIDTH = 1 << 6;
const BIT8_DATA_WIDTH = 1 << 7;
const DDR_MODE = 1 << 8;
const DETECT_CARD_BY_DATA3 = 1 << 9;
const DETECT_CARD_BY_CD = 1 << 10;
const AUTO_CMD12 = 1 << 11;
const SDR104 = 1 << 12;
const SDR50 = 1 << 13;
const HS200 = 1 << 14;
const HS400 = 1 << 15;
const DRIVER_TYPE_C = 1 << 16;
const SET_CURRENT = 1 << 17;
}
}
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct MCIHostCapabilityExt: u32 {
const BIT8_WIDTH = 1;
}
}
pub const SZ_1: u64 = 0x00000001;
pub const SZ_2: u64 = 0x00000002;
pub const SZ_4: u64 = 0x00000004;
pub const SZ_8: u64 = 0x00000008;
pub const SZ_16: u64 = 0x00000010;
pub const SZ_32: u64 = 0x00000020;
pub const SZ_64: u64 = 0x00000040;
pub const SZ_128: u64 = 0x00000080;
pub const SZ_256: u64 = 0x00000100;
pub const SZ_512: u64 = 0x00000200;
pub const SZ_1K: u64 = 0x00000400;
pub const SZ_2K: u64 = 0x00000800;
pub const SZ_4K: u64 = 0x00001000;
pub const SZ_8K: u64 = 0x00002000;
pub const SZ_16K: u64 = 0x00004000;
pub const SZ_32K: u64 = 0x00008000;
pub const SZ_64K: u64 = 0x00010000;
pub const SZ_128K: u64 = 0x00020000;
pub const SZ_256K: u64 = 0x00040000;
pub const SZ_512K: u64 = 0x00080000;
pub const SZ_1M: u64 = 0x00100000;
pub const SZ_2M: u64 = 0x00200000;
pub const SZ_4M: u64 = 0x00400000;
pub const SZ_8M: u64 = 0x00800000;
pub const SZ_16M: u64 = 0x01000000;
pub const SZ_32M: u64 = 0x02000000;
pub const SZ_64M: u64 = 0x04000000;
pub const SZ_128M: u64 = 0x08000000;
pub const SZ_256M: u64 = 0x10000000;
pub const SZ_512M: u64 = 0x20000000;
pub const SZ_1G: u64 = 0x40000000;
pub const SZ_2G: u64 = 0x80000000;
pub const SZ_3G: u64 = 0xC0000000;
pub const SZ_4G: u64 = 0x100000000;
pub const SZ_8G: u64 = 0x200000000;