Skip to content

Commit b301ac8

Browse files
committed
Use blocking SPI traits
1 parent bbcb245 commit b301ac8

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Changes
11+
- [breaking-change] Use SPI blocking traits instead to ease SPI peripheral sharing.
12+
See: https://github.com/rust-embedded-community/embedded-sdmmc-rs/issues/28
13+
14+
15+
[Unreleased]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.3.0...develop

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ edition = "2018"
1111
readme = "README.md"
1212

1313
[dependencies]
14-
embedded-hal = "^0.2.2"
14+
embedded-hal = "0.2.3"
1515
byteorder = { version = "1", default-features = false }
16-
nb = "0.1"
1716
log = "0.4"
1817

1918
[dev-dependencies]

src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
//! # struct DummyCsPin;
1818
//! # struct DummyUart;
1919
//! # struct DummyTimeSource;
20-
//! # impl embedded_hal::spi::FullDuplex<u8> for DummySpi {
20+
//! # impl embedded_hal::blocking::spi::Transfer<u8> for DummySpi {
2121
//! # type Error = ();
22-
//! # fn read(&mut self) -> nb::Result<u8, ()> { Ok(0) }
23-
//! # fn send(&mut self, byte: u8) -> nb::Result<(), ()> { Ok(()) }
22+
//! # fn transfer<'w>(&mut self, data: &'w mut [u8]) -> Result<&'w [u8], ()> { Ok(&[0]) }
2423
//! # }
2524
//! # impl embedded_hal::digital::v2::OutputPin for DummyCsPin {
2625
//! # type Error = ();

src/sdmmc.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use super::sdmmc_proto::*;
99
use super::{Block, BlockCount, BlockDevice, BlockIdx};
1010
use core::cell::RefCell;
11-
use nb::block;
1211

1312
const DEFAULT_DELAY_COUNT: u32 = 32_000;
1413

@@ -17,9 +16,9 @@ const DEFAULT_DELAY_COUNT: u32 = 32_000;
1716
/// bytes without Chip Select asserted (which puts the card into SPI mode).
1817
pub struct SdMmcSpi<SPI, CS>
1918
where
20-
SPI: embedded_hal::spi::FullDuplex<u8>,
19+
SPI: embedded_hal::blocking::spi::Transfer<u8>,
2120
CS: embedded_hal::digital::v2::OutputPin,
22-
<SPI as embedded_hal::spi::FullDuplex<u8>>::Error: core::fmt::Debug,
21+
<SPI as embedded_hal::blocking::spi::Transfer<u8>>::Error: core::fmt::Debug,
2322
{
2423
spi: RefCell<SPI>,
2524
cs: RefCell<CS>,
@@ -106,9 +105,9 @@ impl Delay {
106105

107106
impl<SPI, CS> SdMmcSpi<SPI, CS>
108107
where
109-
SPI: embedded_hal::spi::FullDuplex<u8>,
108+
SPI: embedded_hal::blocking::spi::Transfer<u8>,
110109
CS: embedded_hal::digital::v2::OutputPin,
111-
<SPI as embedded_hal::spi::FullDuplex<u8>>::Error: core::fmt::Debug,
110+
<SPI as embedded_hal::blocking::spi::Transfer<u8>>::Error: core::fmt::Debug,
112111
{
113112
/// Create a new SD/MMC controller using a raw SPI interface.
114113
pub fn new(spi: SPI, cs: CS) -> SdMmcSpi<SPI, CS> {
@@ -417,8 +416,9 @@ where
417416
/// Send one byte and receive one byte.
418417
fn transfer(&self, out: u8) -> Result<u8, Error> {
419418
let mut spi = self.spi.borrow_mut();
420-
block!(spi.send(out)).map_err(|_e| Error::Transport)?;
421-
block!(spi.read()).map_err(|_e| Error::Transport)
419+
spi.transfer(&mut [out])
420+
.map(|b| b[0])
421+
.map_err(|_e| Error::Transport)
422422
}
423423

424424
/// Spin until the card returns 0xFF, or we spin too many times and
@@ -438,8 +438,8 @@ where
438438

439439
impl<SPI, CS> BlockDevice for SdMmcSpi<SPI, CS>
440440
where
441-
SPI: embedded_hal::spi::FullDuplex<u8>,
442-
<SPI as embedded_hal::spi::FullDuplex<u8>>::Error: core::fmt::Debug,
441+
SPI: embedded_hal::blocking::spi::Transfer<u8>,
442+
<SPI as embedded_hal::blocking::spi::Transfer<u8>>::Error: core::fmt::Debug,
443443
CS: embedded_hal::digital::v2::OutputPin,
444444
{
445445
type Error = Error;

0 commit comments

Comments
 (0)