Skip to content

Commit 44a5736

Browse files
authored
Merge pull request #136 from rust-embedded-community/use-spidevice-properly
Use SpiDevice to control the chip select.
2 parents 860e072 + 510d50e commit 44a5736

File tree

6 files changed

+102
-165
lines changed

6 files changed

+102
-165
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ log = {version = "0.4", default-features = false, optional = true}
1919

2020
[dev-dependencies]
2121
chrono = "0.4"
22-
embedded-hal-bus = "0.1.0"
22+
embedded-hal-bus = "0.2.0"
2323
env_logger = "0.10.0"
2424
flate2 = "1.0"
2525
hex-literal = "0.4.1"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ 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, a chip-select pin and the delay object
15-
let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, sdmmc_cs, delay);
15+
let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, delay);
1616
// Get the card size (this also triggers card initialisation because it's not been done yet)
1717
println!("Card size is {} bytes", sdcard.num_bytes()?);
1818
// Now let's look for volumes (also known as partitions) on our block device.

examples/readme_test.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,23 @@
77

88
use core::cell::RefCell;
99

10-
use embedded_sdmmc::sdcard::DummyCsPin;
10+
pub struct DummyCsPin;
11+
12+
impl embedded_hal::digital::ErrorType for DummyCsPin {
13+
type Error = core::convert::Infallible;
14+
}
15+
16+
impl embedded_hal::digital::OutputPin for DummyCsPin {
17+
#[inline(always)]
18+
fn set_low(&mut self) -> Result<(), Self::Error> {
19+
Ok(())
20+
}
21+
22+
#[inline(always)]
23+
fn set_high(&mut self) -> Result<(), Self::Error> {
24+
Ok(())
25+
}
26+
}
1127

1228
struct FakeSpiBus();
1329

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

107122
// Build an SD Card interface out of an SPI device, a chip-select pin and the delay object
108-
let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, sdmmc_cs, delay);
123+
let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, delay);
109124
// Get the card size (this also triggers card initialisation because it's not been done yet)
110125
println!("Card size is {} bytes", sdcard.num_bytes()?);
111126
// Now let's look for volumes (also known as partitions) on our block device.

src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
//! ```rust
2020
//! use embedded_sdmmc::{Error, Mode, SdCard, SdCardError, TimeSource, VolumeIdx, VolumeManager};
2121
//!
22-
//! fn example<S, CS, D, T>(spi: S, cs: CS, delay: D, ts: T) -> Result<(), Error<SdCardError>>
22+
//! fn example<S, D, T>(spi: S, delay: D, ts: T) -> Result<(), Error<SdCardError>>
2323
//! where
2424
//! S: embedded_hal::spi::SpiDevice,
25-
//! CS: embedded_hal::digital::OutputPin,
2625
//! D: embedded_hal::delay::DelayNs,
2726
//! T: TimeSource,
2827
//! {
29-
//! let sdcard = SdCard::new(spi, cs, delay);
28+
//! let sdcard = SdCard::new(spi, delay);
3029
//! println!("Card size is {} bytes", sdcard.num_bytes()?);
3130
//! let mut volume_mgr = VolumeManager::new(sdcard, ts);
3231
//! let mut volume0 = volume_mgr.open_volume(VolumeIdx(0))?;

0 commit comments

Comments
 (0)