Skip to content

Enforce correct SD state at compilation using a new type #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- [breaking-change] Use SPI blocking traits instead to ease SPI peripheral sharing.
See: https://github.com/rust-embedded-community/embedded-sdmmc-rs/issues/28
- Added `Controller::has_open_handles` and `Controller::free` methods.

- [breaking-change] Changed interface to enforce correct SD state at compile time.

[Unreleased]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.3.0...develop

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ designed for readability and simplicity over performance.
You will need something that implements the `BlockDevice` trait, which can read and write the 512-byte blocks (or sectors) from your card. If you were to implement this over USB Mass Storage, there's no reason this crate couldn't work with a USB Thumb Drive, but we only supply a `BlockDevice` suitable for reading SD and SDHC cards over SPI.

```rust
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(embedded_sdmmc::SdMmcSpi::new(sdmmc_spi, sdmmc_cs), time_source);
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 Down
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