Skip to content

Commit

Permalink
Merge pull request #136 from rust-embedded-community/use-spidevice-pr…
Browse files Browse the repository at this point in the history
…operly

Use SpiDevice to control the chip select.
  • Loading branch information
thejpster authored Jul 12, 2024
2 parents 860e072 + 510d50e commit 44a5736
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 165 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ log = {version = "0.4", default-features = false, optional = true}

[dev-dependencies]
chrono = "0.4"
embedded-hal-bus = "0.1.0"
embedded-hal-bus = "0.2.0"
env_logger = "0.10.0"
flate2 = "1.0"
hex-literal = "0.4.1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You will need something that implements the `BlockDevice` trait, which can read

```rust
// Build an SD Card interface out of an SPI device, a chip-select pin and the delay object
let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, sdmmc_cs, delay);
let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, delay);
// Get the card size (this also triggers card initialisation because it's not been done yet)
println!("Card size is {} bytes", sdcard.num_bytes()?);
// Now let's look for volumes (also known as partitions) on our block device.
Expand Down
23 changes: 19 additions & 4 deletions examples/readme_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,23 @@

use core::cell::RefCell;

use embedded_sdmmc::sdcard::DummyCsPin;
pub struct DummyCsPin;

impl embedded_hal::digital::ErrorType for DummyCsPin {
type Error = core::convert::Infallible;
}

impl embedded_hal::digital::OutputPin for DummyCsPin {
#[inline(always)]
fn set_low(&mut self) -> Result<(), Self::Error> {
Ok(())
}

#[inline(always)]
fn set_high(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}

struct FakeSpiBus();

Expand Down Expand Up @@ -99,13 +115,12 @@ fn main() -> Result<(), Error> {
// BEGIN Fake stuff that will be replaced with real peripherals
let spi_bus = RefCell::new(FakeSpiBus());
let delay = FakeDelayer();
let sdmmc_spi = embedded_hal_bus::spi::RefCellDevice::new(&spi_bus, DummyCsPin, delay);
let sdmmc_cs = FakeCs();
let sdmmc_spi = embedded_hal_bus::spi::RefCellDevice::new(&spi_bus, DummyCsPin, delay).unwrap();
let time_source = FakeTimesource();
// END Fake stuff that will be replaced with real peripherals

// Build an SD Card interface out of an SPI device, a chip-select pin and the delay object
let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, sdmmc_cs, delay);
let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, delay);
// Get the card size (this also triggers card initialisation because it's not been done yet)
println!("Card size is {} bytes", sdcard.num_bytes()?);
// Now let's look for volumes (also known as partitions) on our block device.
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
//! ```rust
//! use embedded_sdmmc::{Error, Mode, SdCard, SdCardError, TimeSource, VolumeIdx, VolumeManager};
//!
//! fn example<S, CS, D, T>(spi: S, cs: CS, delay: D, ts: T) -> Result<(), Error<SdCardError>>
//! fn example<S, D, T>(spi: S, delay: D, ts: T) -> Result<(), Error<SdCardError>>
//! where
//! S: embedded_hal::spi::SpiDevice,
//! CS: embedded_hal::digital::OutputPin,
//! D: embedded_hal::delay::DelayNs,
//! T: TimeSource,
//! {
//! let sdcard = SdCard::new(spi, cs, delay);
//! let sdcard = SdCard::new(spi, delay);
//! println!("Card size is {} bytes", sdcard.num_bytes()?);
//! let mut volume_mgr = VolumeManager::new(sdcard, ts);
//! let mut volume0 = volume_mgr.open_volume(VolumeIdx(0))?;
Expand Down
Loading

0 comments on commit 44a5736

Please sign in to comment.