Skip to content

Commit

Permalink
Enforce correct SD state at compilation using a new type
Browse files Browse the repository at this point in the history
The struct `SdMmcSpi` had two separate methods for initialization and deinitialization. It was up to the user not to mess them up at runtime.

A new `BlockSpi` struct takes over `BlockDevice` interface duties, making it impossible to use block procedures while the SD interface is in the wrong state.
  • Loading branch information
dcz-self committed Sep 12, 2021
1 parent 65ba598 commit 7336603
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 145 deletions.
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
//! # let mut sdmmc_spi = DummySpi;
//! # let mut sdmmc_cs = DummyCsPin;
//! # let time_source = DummyTimeSource;
//! let mut cont = embedded_sdmmc::Controller::new(embedded_sdmmc::SdMmcSpi::new(sdmmc_spi, sdmmc_cs), time_source);
//! let mut spi_dev = embedded_sdmmc::SdMmcSpi::new(sdmmc_spi, sdmmc_cs);
//! write!(uart, "Init SD card...").unwrap();
//! match cont.device().init() {
//! Ok(_) => {
//! match spi_dev.acquire() {
//! Ok(block) => {
//! let mut cont = embedded_sdmmc::Controller::new(block, time_source);
//! write!(uart, "OK!\nCard size...").unwrap();
//! match cont.device().card_size_bytes() {
//! Ok(size) => writeln!(uart, "{}", size).unwrap(),
Expand All @@ -51,7 +52,7 @@
//! }
//! }
//! Err(e) => writeln!(uart, "{:?}!", e).unwrap(),
//! }
//! };
//! ```

#![cfg_attr(not(test), no_std)]
Expand Down Expand Up @@ -88,7 +89,7 @@ pub use crate::filesystem::{
Timestamp, MAX_FILE_SIZE,
};
pub use crate::sdmmc::Error as SdMmcError;
pub use crate::sdmmc::SdMmcSpi;
pub use crate::sdmmc::{BlockSpi, SdMmcSpi};

// ****************************************************************************
//
Expand Down
Loading

0 comments on commit 7336603

Please sign in to comment.