Skip to content

Commit 7f026ba

Browse files
committed
Use released embedded-sdmmc 0.5
1 parent 05ba0d5 commit 7f026ba

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ shared-bus = "0.2"
5151
# Gets us compare-swap atomic operations
5252
atomic-polyfill = "1.0.2"
5353
# SD Card driver
54-
embedded-sdmmc = { git = "https://github.com/rust-embedded-community/embedded-sdmmc-rs.git", branch="more-api-cleanups", default-features = false, features = ["defmt-log"] }
55-
# embedded-sdmmc = { version = "0.4", default-features = false, features = ["defmt-log"] }
54+
embedded-sdmmc = { version = "0.5", default-features = false, features = ["defmt-log"] }
5655

5756
[[bin]]
5857
name = "neotron-pico-bios"

src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,8 @@ impl Hardware {
12211221
let spi = sdcard::FakeSpi(self, true);
12221222
let cs = sdcard::FakeCs();
12231223
let delayer = sdcard::FakeDelayer();
1224-
let sdcard = embedded_sdmmc::SdCard::new(spi, cs, delayer);
1224+
let options = embedded_sdmmc::sdcard::AcquireOpts { use_crc: true };
1225+
let sdcard = embedded_sdmmc::SdCard::new_with_options(spi, cs, delayer, options);
12251226
// Talk to the card to trigger a scan if its type
12261227
let num_blocks = sdcard.num_blocks();
12271228
let card_type = sdcard.get_card_type();
@@ -1987,7 +1988,8 @@ pub extern "C" fn block_read(
19871988
let spi = sdcard::FakeSpi(hw, false);
19881989
let cs = sdcard::FakeCs();
19891990
let delayer = sdcard::FakeDelayer();
1990-
let sdcard = embedded_sdmmc::SdCard::new(spi, cs, delayer);
1991+
let options = embedded_sdmmc::sdcard::AcquireOpts { use_crc: true };
1992+
let sdcard = embedded_sdmmc::SdCard::new_with_options(spi, cs, delayer, options);
19911993
unsafe {
19921994
sdcard.mark_card_as_init(info.card_type);
19931995
}

src/sdcard.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<'a> embedded_hal::blocking::spi::Transfer<u8> for FakeSpi<'a> {
2222
type Error = core::convert::Infallible;
2323
fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> {
2424
let result = if IS_CS_LOW.load(Ordering::SeqCst) {
25-
defmt::debug!("SD out: {:02x}", words);
25+
defmt::debug!("SD > {:02x}", words);
2626
self.0.with_bus_cs(
2727
1,
2828
if self.1 {
@@ -34,7 +34,7 @@ impl<'a> embedded_hal::blocking::spi::Transfer<u8> for FakeSpi<'a> {
3434
spi.transfer(words).unwrap();
3535
},
3636
);
37-
defmt::debug!("SD: {:02x}", words);
37+
defmt::debug!("SD < {:02x}", words);
3838
words
3939
} else {
4040
// Select a slot we don't use so the SD card won't be activated
@@ -47,6 +47,32 @@ impl<'a> embedded_hal::blocking::spi::Transfer<u8> for FakeSpi<'a> {
4747
}
4848
}
4949

50+
impl<'a> embedded_hal::blocking::spi::Write<u8> for FakeSpi<'a> {
51+
type Error = core::convert::Infallible;
52+
fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> {
53+
if IS_CS_LOW.load(Ordering::SeqCst) {
54+
defmt::debug!("SD > {:02x}", words);
55+
self.0.with_bus_cs(
56+
1,
57+
if self.1 {
58+
CLOCK_SD_CARD_INIT
59+
} else {
60+
CLOCK_SD_CARD
61+
},
62+
|spi, _buffer| {
63+
spi.write(words).unwrap();
64+
},
65+
);
66+
} else {
67+
// Select a slot we don't use so the SD card won't be activated
68+
self.0.with_bus_cs(7, CLOCK_SD_CARD_INIT, |spi, _buffer| {
69+
spi.write(words).unwrap();
70+
});
71+
}
72+
Ok(())
73+
}
74+
}
75+
5076
impl embedded_hal::digital::v2::OutputPin for FakeCs {
5177
type Error = core::convert::Infallible;
5278
fn set_low(&mut self) -> Result<(), Self::Error> {

0 commit comments

Comments
 (0)