Skip to content

Commit a8840e6

Browse files
committed
start work on SD mock
1 parent 6ee4633 commit a8840e6

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

src/sdcard/mock.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//! SD card mock module.
2+
3+
/// SD card mock states.
4+
pub enum State {
5+
/// Idle state.
6+
Idle,
7+
/// Ready state.
8+
Ready,
9+
/// Identification state.
10+
Ident = 2,
11+
/// Standby state.
12+
Stby = 3,
13+
/// Transfer state.
14+
Tran = 4,
15+
/// Data state.
16+
Data = 5,
17+
/// Receive state.
18+
Rcv = 6,
19+
/// Programming state.
20+
Prg = 7,
21+
/// Disconnected state.
22+
Dis = 8,
23+
}
24+
25+
/// SD card mock.
26+
pub struct SdCardMock {
27+
state: State,
28+
}
29+
30+
impl SdCardMock {
31+
/// Create a new SD card mock in the idle state.
32+
pub fn new() -> Self {
33+
Self { state: State::Idle }
34+
}
35+
36+
/// Insert a command into the SD card.
37+
pub fn insert_command(&mut self, cmd_id: super::CmdId, argument: u32) {
38+
match cmd_id {
39+
super::CmdId::CMD0_GoIdleState => self.state = State::Idle,
40+
_ => (),
41+
}
42+
}
43+
}

src/sdcard/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub mod cid;
3434
pub mod csd;
3535
pub mod response;
3636
pub mod spi;
37+
pub mod mock;
3738

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

0 commit comments

Comments
 (0)