Skip to content

Commit b9d7961

Browse files
committed
start adding argument and response module
1 parent 4311956 commit b9d7961

3 files changed

Lines changed: 424 additions & 0 deletions

File tree

src/sdcard/argument.rs

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

src/sdcard/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
pub mod cid;
3333
pub mod csd;
3434
pub mod spi;
35+
pub mod argument;
36+
pub mod response;
3537

3638
/// The different types of card we support.
3739
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]

0 commit comments

Comments
 (0)