From 62c71c7c1758dfd73eec330fb29b57be2b2008f5 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Thu, 19 Nov 2020 09:39:39 +0100 Subject: [PATCH 1/2] Update dev dependency --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index afa981e..273e211 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,5 +17,5 @@ nb = "0.1" log = "0.4" [dev-dependencies] -env_logger = "0.7" hex-literal = "0.3" +env_logger = "0.8" From 4c7345aa7b20b94a149e15677418d9c238081245 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Thu, 19 Nov 2020 09:50:32 +0100 Subject: [PATCH 2/2] Use blocking SPI traits --- CHANGELOG.md | 15 +++++++++++++++ Cargo.toml | 3 +-- src/lib.rs | 5 ++--- src/sdmmc.rs | 18 +++++++++--------- 4 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6b4c3c1 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Changes +- [breaking-change] Use SPI blocking traits instead to ease SPI peripheral sharing. + See: https://github.com/rust-embedded-community/embedded-sdmmc-rs/issues/28 + + +[Unreleased]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.3.0...develop diff --git a/Cargo.toml b/Cargo.toml index 273e211..2d292c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,9 +11,8 @@ edition = "2018" readme = "README.md" [dependencies] -embedded-hal = "^0.2.2" +embedded-hal = "0.2.3" byteorder = { version = "1", default-features = false } -nb = "0.1" log = "0.4" [dev-dependencies] diff --git a/src/lib.rs b/src/lib.rs index e276371..073f491 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,10 +17,9 @@ //! # struct DummyCsPin; //! # struct DummyUart; //! # struct DummyTimeSource; -//! # impl embedded_hal::spi::FullDuplex for DummySpi { +//! # impl embedded_hal::blocking::spi::Transfer for DummySpi { //! # type Error = (); -//! # fn read(&mut self) -> nb::Result { Ok(0) } -//! # fn send(&mut self, byte: u8) -> nb::Result<(), ()> { Ok(()) } +//! # fn transfer<'w>(&mut self, data: &'w mut [u8]) -> Result<&'w [u8], ()> { Ok(&[0]) } //! # } //! # impl embedded_hal::digital::v2::OutputPin for DummyCsPin { //! # type Error = (); diff --git a/src/sdmmc.rs b/src/sdmmc.rs index f273d53..21f346b 100644 --- a/src/sdmmc.rs +++ b/src/sdmmc.rs @@ -8,7 +8,6 @@ use super::sdmmc_proto::*; use super::{Block, BlockCount, BlockDevice, BlockIdx}; use core::cell::RefCell; -use nb::block; const DEFAULT_DELAY_COUNT: u32 = 32_000; @@ -17,9 +16,9 @@ const DEFAULT_DELAY_COUNT: u32 = 32_000; /// bytes without Chip Select asserted (which puts the card into SPI mode). pub struct SdMmcSpi where - SPI: embedded_hal::spi::FullDuplex, + SPI: embedded_hal::blocking::spi::Transfer, CS: embedded_hal::digital::v2::OutputPin, - >::Error: core::fmt::Debug, + >::Error: core::fmt::Debug, { spi: RefCell, cs: RefCell, @@ -106,9 +105,9 @@ impl Delay { impl SdMmcSpi where - SPI: embedded_hal::spi::FullDuplex, + SPI: embedded_hal::blocking::spi::Transfer, CS: embedded_hal::digital::v2::OutputPin, - >::Error: core::fmt::Debug, + >::Error: core::fmt::Debug, { /// Create a new SD/MMC controller using a raw SPI interface. pub fn new(spi: SPI, cs: CS) -> SdMmcSpi { @@ -417,8 +416,9 @@ where /// Send one byte and receive one byte. fn transfer(&self, out: u8) -> Result { let mut spi = self.spi.borrow_mut(); - block!(spi.send(out)).map_err(|_e| Error::Transport)?; - block!(spi.read()).map_err(|_e| Error::Transport) + spi.transfer(&mut [out]) + .map(|b| b[0]) + .map_err(|_e| Error::Transport) } /// Spin until the card returns 0xFF, or we spin too many times and @@ -438,8 +438,8 @@ where impl BlockDevice for SdMmcSpi where - SPI: embedded_hal::spi::FullDuplex, - >::Error: core::fmt::Debug, + SPI: embedded_hal::blocking::spi::Transfer, + >::Error: core::fmt::Debug, CS: embedded_hal::digital::v2::OutputPin, { type Error = Error;