|
| 1 | +//! # Argument module |
| 2 | +//! |
| 3 | +//! Arguments are additional command parameters. |
| 4 | +
|
| 5 | +use arbitrary_int::u24; |
| 6 | + |
| 7 | +/// Voltage settings supplied in CMD8. |
| 8 | +#[bitbybit::bitenum(u4, exhaustive = false)] |
| 9 | +#[derive(Debug, Default, PartialEq, Eq)] |
| 10 | +#[cfg_attr(feature = "defmt-log", derive(defmt::Format))] |
| 11 | +pub enum VoltageSuppliedSelect { |
| 12 | + /// Regular voltage range. |
| 13 | + #[default] |
| 14 | + _2_7To3_6V = 0b0001, |
| 15 | + /// Reserved for low voltage. |
| 16 | + LowVoltageRange = 0b0010, |
| 17 | +} |
| 18 | + |
| 19 | +/// CMD8 argument. |
| 20 | +#[bitbybit::bitfield(u32, default = 0x0, debug, defmt_fields(feature = "defmt-log"))] |
| 21 | +pub struct Cmd8 { |
| 22 | + /// PCIe v1.2 support. |
| 23 | + #[bit(13, rw)] |
| 24 | + pcie_1_2v_support: bool, |
| 25 | + /// PCIe available. |
| 26 | + #[bit(12, rw)] |
| 27 | + pcie_availability: bool, |
| 28 | + /// Voltage settings. |
| 29 | + #[bits(8..=11, rw)] |
| 30 | + voltage_supplied: Option<VoltageSuppliedSelect>, |
| 31 | + /// Check pattern which is echoed. |
| 32 | + #[bits(0..=7, rw)] |
| 33 | + check_pattern: u8, |
| 34 | +} |
| 35 | + |
| 36 | +/// Power control (XPC) settings. |
| 37 | +#[bitbybit::bitenum(u1, exhaustive = true)] |
| 38 | +#[derive(Debug, PartialEq, Eq)] |
| 39 | +#[cfg_attr(feature = "defmt-log", derive(defmt::Format))] |
| 40 | +pub enum PowerControl { |
| 41 | + /// Power saving. |
| 42 | + PowerSaving = 0, |
| 43 | + /// Maximum performance. |
| 44 | + MaximumPerformance = 1, |
| 45 | +} |
| 46 | + |
| 47 | +/// HPC. |
| 48 | +#[bitbybit::bitenum(u1, exhaustive = true)] |
| 49 | +#[derive(Debug, PartialEq, Eq)] |
| 50 | +#[cfg_attr(feature = "defmt-log", derive(defmt::Format))] |
| 51 | +pub enum HostCapacitySupport { |
| 52 | + /// SDSC only. |
| 53 | + SdscOnly = 0, |
| 54 | + /// Extended capacity - SDHC or SDXC. |
| 55 | + SdhcOrSdxc = 1, |
| 56 | +} |
| 57 | + |
| 58 | +/// Lower OCR bits used to negotiate voltage capabilities. |
| 59 | +#[bitbybit::bitfield(u24, default = 0x0, debug, defmt_fields(feature = "defmt-log"))] |
| 60 | +pub struct OcrLower { |
| 61 | + /// 3.5 to 3.6V |
| 62 | + #[bit(23, rw)] |
| 63 | + _3_5_to_3_6v: bool, |
| 64 | + /// 3.4 to 3.5V |
| 65 | + #[bit(22, rw)] |
| 66 | + _3_4_to_3_5v: bool, |
| 67 | + /// 3.3 to 3.4V |
| 68 | + #[bit(21, rw)] |
| 69 | + _3_3_to_3_4v: bool, |
| 70 | + /// 3.2 to 3.3V |
| 71 | + #[bit(20, rw)] |
| 72 | + _3_2_to_3_3v: bool, |
| 73 | + /// 3.1 to 3.2V |
| 74 | + #[bit(19, rw)] |
| 75 | + _3_1_to_3_2v: bool, |
| 76 | + /// 3.0 to 3.1V |
| 77 | + #[bit(18, rw)] |
| 78 | + _3_0_to_3_1v: bool, |
| 79 | + /// 2.9 to 3.0V |
| 80 | + #[bit(17, rw)] |
| 81 | + _2_9_to_3_0v: bool, |
| 82 | + /// 2.8 to 2.9V |
| 83 | + #[bit(16, rw)] |
| 84 | + _2_8_to_2_9v: bool, |
| 85 | + /// 2.7 to 2.8V |
| 86 | + #[bit(15, rw)] |
| 87 | + _2_7_to_2_8v: bool, |
| 88 | + /// Reserved for low voltage |
| 89 | + #[bit(7, rw)] |
| 90 | + reserved_low_voltage: bool, |
| 91 | +} |
| 92 | + |
| 93 | +/// Bus width setting. |
| 94 | +#[bitbybit::bitenum(u2, exhaustive = false)] |
| 95 | +#[derive(Debug, PartialEq, Eq)] |
| 96 | +#[cfg_attr(feature = "defmt-log", derive(defmt::Format))] |
| 97 | +pub enum BusWidth { |
| 98 | + /// 1 bit bus. |
| 99 | + _1bit = 0b00, |
| 100 | + /// 4 bit bus. |
| 101 | + _4bits = 0b10, |
| 102 | +} |
| 103 | + |
| 104 | +/// ACMD6 - Set bus width. |
| 105 | +#[bitbybit::bitfield( |
| 106 | + u32, |
| 107 | + default = 0x0, |
| 108 | + debug, |
| 109 | + defmt_fields(feature = "defmt-log"), |
| 110 | + forbid_overlaps |
| 111 | +)] |
| 112 | +pub struct Acmd6 { |
| 113 | + /// Bus width. |
| 114 | + #[bits(0..=1, rw)] |
| 115 | + bus_width: Option<BusWidth>, |
| 116 | +} |
| 117 | + |
| 118 | +/// ACMD41 argument - Capability negotiation. |
| 119 | +#[bitbybit::bitfield( |
| 120 | + u32, |
| 121 | + default = 0x0, |
| 122 | + debug, |
| 123 | + defmt_fields(feature = "defmt-log"), |
| 124 | + forbid_overlaps |
| 125 | +)] |
| 126 | +pub struct Acmd41 { |
| 127 | + /// HPC. |
| 128 | + #[bit(30, rw)] |
| 129 | + host_capacity_support: HostCapacitySupport, |
| 130 | + /// FB. |
| 131 | + #[bit(29, rw)] |
| 132 | + fast_boot: bool, |
| 133 | + /// XPC. |
| 134 | + #[bit(28, rw)] |
| 135 | + xpc: PowerControl, |
| 136 | + /// Switch to 1.8V signal voltage request. |
| 137 | + #[bit(24, rw)] |
| 138 | + s18r: bool, |
| 139 | + /// If this is set to 0. ACMD41 is called "inquire CMD41" that does not start |
| 140 | + /// initialization and is used for getting OCR. Bits 24 to 31 are ignored. |
| 141 | + #[bits(0..=23, rw)] |
| 142 | + ocr: OcrLower, |
| 143 | +} |
| 144 | + |
| 145 | +/// Relative Card Address (RCA) select. |
| 146 | +#[bitbybit::bitfield( |
| 147 | + u32, |
| 148 | + default = 0x0, |
| 149 | + debug, |
| 150 | + defmt_bitfields(feature = "defmt-log"), |
| 151 | + forbid_overlaps |
| 152 | +)] |
| 153 | +pub struct RcaSelect { |
| 154 | + /// RCA. |
| 155 | + #[bits(16..=31, rw)] |
| 156 | + rca: u16, |
| 157 | +} |
| 158 | + |
| 159 | +/// CMD9 argument. |
| 160 | +pub type Cmd9 = RcaSelect; |
| 161 | +/// CMD7 argument. |
| 162 | +pub type Cmd7 = RcaSelect; |
| 163 | + |
| 164 | +/// CMD13 argument. |
| 165 | +#[bitbybit::bitfield( |
| 166 | + u32, |
| 167 | + default = 0x0, |
| 168 | + debug, |
| 169 | + defmt_bitfields(feature = "defmt-log"), |
| 170 | + forbid_overlaps |
| 171 | +)] |
| 172 | +pub struct Cmd13 { |
| 173 | + /// RCA. |
| 174 | + #[bits(16..=31, rw)] |
| 175 | + rca: u16, |
| 176 | + /// Send task status instead of regular card status. |
| 177 | + #[bit(15, rw)] |
| 178 | + send_task_status: bool, |
| 179 | +} |
0 commit comments