Skip to content

Commit aba3449

Browse files
Reworked the API.
Now there is only "SdCard" in the public API. Any attempt to use the SD card when the card type is unknown will force a re-initialisation of the SD card. You no longer need to acquire.
1 parent 261c52e commit aba3449

File tree

3 files changed

+383
-392
lines changed

3 files changed

+383
-392
lines changed

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@ You will need something that implements the `BlockDevice` trait, which can read
1212

1313
```rust
1414
// Build an SD Card interface out of an SPI device
15-
let mut spi_dev = embedded_sdmmc::SdCard::new(sdmmc_spi, sdmmc_cs);
16-
// Try and initialise the SD card
17-
let block_dev = spi_dev.acquire()?;
18-
// The SD Card was initialised, and we have a `AcquiredSdCard` object
19-
// representing the initialised card.
20-
write!(uart, "Card size is {} bytes", block_dev.card_size_bytes()?)?;
15+
let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, sdmmc_cs);
16+
write!(uart, "Card size is {} bytes", sdcard.card_size_bytes()?)?;
2117
// Now let's look for volumes (also known as partitions) on our block device.
22-
let mut cont = embedded_sdmmc::VolumeManager::new(block_dev, time_source);
18+
let mut cont = embedded_sdmmc::VolumeManager::new(sdcard, time_source);
2319
// Try and access Volume 0 (i.e. the first partition)
2420
let mut volume = cont.get_volume(embedded_sdmmc::VolumeIdx(0))?;
2521
writeln!(uart, "Volume 0: {:?}", v)?;

src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@
4040
//! # let mut sdmmc_spi = DummySpi;
4141
//! # let mut sdmmc_cs = DummyCsPin;
4242
//! # let time_source = DummyTimeSource;
43-
//! let mut spi_dev = embedded_sdmmc::SdCard::new(sdmmc_spi, sdmmc_cs);
44-
//! let block = spi_dev.acquire()?;
45-
//! println!("Card size {} bytes", block.card_size_bytes()?);
46-
//! let mut volume_mgr = VolumeManager::new(block, time_source);
43+
//! let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, sdmmc_cs);
44+
//! println!("Card size {} bytes", sdcard.card_size_bytes()?);
45+
//! let mut volume_mgr = VolumeManager::new(sdcard, time_source);
4746
//! println!("Card size is still {} bytes", volume_mgr.device().card_size_bytes()?);
4847
//! let mut volume0 = volume_mgr.get_volume(embedded_sdmmc::VolumeIdx(0))?;
4948
//! println!("Volume 0: {:?}", volume0);
@@ -101,7 +100,7 @@ pub use crate::filesystem::{
101100
Timestamp, MAX_FILE_SIZE,
102101
};
103102
pub use crate::sdmmc::Error as SdMmcError;
104-
pub use crate::sdmmc::{AcquiredSdCard, SdCard};
103+
pub use crate::sdmmc::SdCard;
105104

106105
mod volume_mgr;
107106
pub use volume_mgr::VolumeManager;

0 commit comments

Comments
 (0)