Skip to content
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

Use SpiDevice to control the chip select. #136

Merged
merged 1 commit into from
Jul 12, 2024
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 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