Skip to content

Commit d18fefa

Browse files
author
Simon Struck
committed
Update embedded hal
1 parent 6c3fa0a commit d18fefa

File tree

4 files changed

+33
-42
lines changed

4 files changed

+33
-42
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ version = "0.6.0"
1313
[dependencies]
1414
byteorder = {version = "1", default-features = false}
1515
defmt = {version = "0.3", optional = true}
16-
embedded-hal = "0.2.3"
16+
embedded-hal = "1.0.0-rc.1"
1717
heapless = "0.7"
1818
log = {version = "0.4", default-features = false, optional = true}
1919

2020
[dev-dependencies]
21-
env_logger = "0.9"
22-
hex-literal = "0.3"
21+
env_logger = "0.10.0"
22+
hex-literal = "0.4.1"
2323
flate2 = "1.0"
2424
sha2 = "0.10"
2525
chrono = "0.4"

examples/readme_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
66
struct FakeSpi();
77

8-
impl embedded_hal::blocking::spi::Transfer<u8> for FakeSpi {
8+
impl embedded_hal::spi::SpiDevice<u8> for FakeSpi {
99
type Error = core::convert::Infallible;
1010
fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> {
1111
Ok(words)
1212
}
1313
}
1414

15-
impl embedded_hal::blocking::spi::Write<u8> for FakeSpi {
15+
impl embedded_hal::spi::SpiDevice<u8> for FakeSpi {
1616
type Error = core::convert::Infallible;
1717
fn write(&mut self, _words: &[u8]) -> Result<(), Self::Error> {
1818
Ok(())
@@ -21,7 +21,7 @@ impl embedded_hal::blocking::spi::Write<u8> for FakeSpi {
2121

2222
struct FakeCs();
2323

24-
impl embedded_hal::digital::v2::OutputPin for FakeCs {
24+
impl embedded_hal::digital::OutputPin for FakeCs {
2525
type Error = core::convert::Infallible;
2626
fn set_low(&mut self) -> Result<(), Self::Error> {
2727
Ok(())
@@ -34,7 +34,7 @@ impl embedded_hal::digital::v2::OutputPin for FakeCs {
3434

3535
struct FakeDelayer();
3636

37-
impl embedded_hal::blocking::delay::DelayUs<u8> for FakeDelayer {
37+
impl embedded_hal::delay::DelayUs for FakeDelayer {
3838
fn delay_us(&mut self, us: u8) {
3939
std::thread::sleep(std::time::Duration::from_micros(u64::from(us)));
4040
}

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@
2222
//! # struct DummyUart;
2323
//! # struct DummyTimeSource;
2424
//! # struct DummyDelayer;
25-
//! # impl embedded_hal::blocking::spi::Transfer<u8> for DummySpi {
25+
//! # impl embedded_hal::spi::SpiDevice<u8> for DummySpi {
2626
//! # type Error = ();
2727
//! # fn transfer<'w>(&mut self, data: &'w mut [u8]) -> Result<&'w [u8], Self::Error> { Ok(&[0]) }
2828
//! # }
29-
//! # impl embedded_hal::blocking::spi::Write<u8> for DummySpi {
29+
//! # impl embedded_hal::spi::SpiDevice<u8> for DummySpi {
3030
//! # type Error = ();
3131
//! # fn write(&mut self, data: &[u8]) -> Result<(), Self::Error> { Ok(()) }
3232
//! # }
33-
//! # impl embedded_hal::digital::v2::OutputPin for DummyCsPin {
33+
//! # impl embedded_hal::digital::OutputPin for DummyCsPin {
3434
//! # type Error = ();
3535
//! # fn set_low(&mut self) -> Result<(), ()> { Ok(()) }
3636
//! # fn set_high(&mut self) -> Result<(), ()> { Ok(()) }
3737
//! # }
3838
//! # impl embedded_sdmmc::TimeSource for DummyTimeSource {
3939
//! # fn get_timestamp(&self) -> embedded_sdmmc::Timestamp { embedded_sdmmc::Timestamp::from_fat(0, 0) }
4040
//! # }
41-
//! # impl embedded_hal::blocking::delay::DelayUs<u8> for DummyDelayer {
41+
//! # impl embedded_hal::delay::DelayUs for DummyDelayer {
4242
//! # fn delay_us(&mut self, us: u8) {}
4343
//! # }
4444
//! # impl std::fmt::Write for DummyUart { fn write_str(&mut self, s: &str) -> std::fmt::Result { Ok(()) } }

src/sdcard/mod.rs

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,18 @@ use crate::{debug, warn};
3030
/// All the APIs take `&self` - mutability is handled using an inner `RefCell`.
3131
pub struct SdCard<SPI, CS, DELAYER>
3232
where
33-
SPI: embedded_hal::blocking::spi::Transfer<u8> + embedded_hal::blocking::spi::Write<u8>,
34-
CS: embedded_hal::digital::v2::OutputPin,
35-
<SPI as embedded_hal::blocking::spi::Transfer<u8>>::Error: core::fmt::Debug,
36-
<SPI as embedded_hal::blocking::spi::Write<u8>>::Error: core::fmt::Debug,
37-
DELAYER: embedded_hal::blocking::delay::DelayUs<u8>,
33+
SPI: embedded_hal::spi::SpiDevice<u8>,
34+
CS: embedded_hal::digital::OutputPin,
35+
DELAYER: embedded_hal::delay::DelayUs,
3836
{
3937
inner: RefCell<SdCardInner<SPI, CS, DELAYER>>,
4038
}
4139

4240
impl<SPI, CS, DELAYER> SdCard<SPI, CS, DELAYER>
4341
where
44-
SPI: embedded_hal::blocking::spi::Transfer<u8> + embedded_hal::blocking::spi::Write<u8>,
45-
CS: embedded_hal::digital::v2::OutputPin,
46-
<SPI as embedded_hal::blocking::spi::Transfer<u8>>::Error: core::fmt::Debug,
47-
<SPI as embedded_hal::blocking::spi::Write<u8>>::Error: core::fmt::Debug,
48-
DELAYER: embedded_hal::blocking::delay::DelayUs<u8>,
42+
SPI: embedded_hal::spi::SpiDevice<u8> + embedded_hal::spi::SpiDevice<u8>,
43+
CS: embedded_hal::digital::OutputPin,
44+
DELAYER: embedded_hal::delay::DelayUs,
4945
{
5046
/// Create a new SD/MMC Card driver using a raw SPI interface.
5147
///
@@ -152,11 +148,9 @@ where
152148

153149
impl<SPI, CS, DELAYER> BlockDevice for SdCard<SPI, CS, DELAYER>
154150
where
155-
SPI: embedded_hal::blocking::spi::Transfer<u8> + embedded_hal::blocking::spi::Write<u8>,
156-
CS: embedded_hal::digital::v2::OutputPin,
157-
<SPI as embedded_hal::blocking::spi::Transfer<u8>>::Error: core::fmt::Debug,
158-
<SPI as embedded_hal::blocking::spi::Write<u8>>::Error: core::fmt::Debug,
159-
DELAYER: embedded_hal::blocking::delay::DelayUs<u8>,
151+
SPI: embedded_hal::spi::SpiDevice<u8> + embedded_hal::spi::SpiDevice<u8>,
152+
CS: embedded_hal::digital::OutputPin,
153+
DELAYER: embedded_hal::delay::DelayUs,
160154
{
161155
type Error = Error;
162156

@@ -205,11 +199,9 @@ where
205199
/// All the APIs required `&mut self`.
206200
struct SdCardInner<SPI, CS, DELAYER>
207201
where
208-
SPI: embedded_hal::blocking::spi::Transfer<u8> + embedded_hal::blocking::spi::Write<u8>,
209-
CS: embedded_hal::digital::v2::OutputPin,
210-
<SPI as embedded_hal::blocking::spi::Transfer<u8>>::Error: core::fmt::Debug,
211-
<SPI as embedded_hal::blocking::spi::Write<u8>>::Error: core::fmt::Debug,
212-
DELAYER: embedded_hal::blocking::delay::DelayUs<u8>,
202+
SPI: embedded_hal::spi::SpiDevice<u8> + embedded_hal::spi::SpiDevice<u8>,
203+
CS: embedded_hal::digital::OutputPin,
204+
DELAYER: embedded_hal::delay::DelayUs,
213205
{
214206
spi: SPI,
215207
cs: CS,
@@ -220,11 +212,9 @@ where
220212

221213
impl<SPI, CS, DELAYER> SdCardInner<SPI, CS, DELAYER>
222214
where
223-
SPI: embedded_hal::blocking::spi::Transfer<u8> + embedded_hal::blocking::spi::Write<u8>,
224-
CS: embedded_hal::digital::v2::OutputPin,
225-
<SPI as embedded_hal::blocking::spi::Transfer<u8>>::Error: core::fmt::Debug,
226-
<SPI as embedded_hal::blocking::spi::Write<u8>>::Error: core::fmt::Debug,
227-
DELAYER: embedded_hal::blocking::delay::DelayUs<u8>,
215+
SPI: embedded_hal::spi::SpiDevice<u8> + embedded_hal::spi::SpiDevice<u8>,
216+
CS: embedded_hal::digital::OutputPin,
217+
DELAYER: embedded_hal::delay::DelayUs,
228218
{
229219
/// Read one or more blocks, starting at the given block index.
230220
fn read(&mut self, blocks: &mut [Block], start_block_idx: BlockIdx) -> Result<(), Error> {
@@ -583,21 +573,22 @@ where
583573

584574
/// Send one byte and receive one byte over the SPI bus.
585575
fn transfer_byte(&mut self, out: u8) -> Result<u8, Error> {
576+
let mut read_buf = [0u8;1];
586577
self.spi
587-
.transfer(&mut [out])
588-
.map(|b| b[0])
589-
.map_err(|_e| Error::Transport)
578+
.transfer(&mut read_buf,&[out])
579+
.map_err(|_| Error::Transport)?;
580+
Ok(read_buf[0])
590581
}
591582

592-
/// Send mutiple bytes and ignore what comes back over the SPI bus.
583+
/// Send multiple bytes and ignore what comes back over the SPI bus.
593584
fn write_bytes(&mut self, out: &[u8]) -> Result<(), Error> {
594585
self.spi.write(out).map_err(|_e| Error::Transport)?;
595586
Ok(())
596587
}
597588

598589
/// Send multiple bytes and replace them with what comes back over the SPI bus.
599590
fn transfer_bytes(&mut self, in_out: &mut [u8]) -> Result<(), Error> {
600-
self.spi.transfer(in_out).map_err(|_e| Error::Transport)?;
591+
self.spi.transfer_in_place(in_out).map_err(|_e| Error::Transport)?;
601592
Ok(())
602593
}
603594

@@ -753,7 +744,7 @@ impl Delay {
753744
/// `Ok(())`.
754745
fn delay<T>(&mut self, delayer: &mut T, err: Error) -> Result<(), Error>
755746
where
756-
T: embedded_hal::blocking::delay::DelayUs<u8>,
747+
T: embedded_hal::delay::DelayUs,
757748
{
758749
if self.retries_left == 0 {
759750
Err(err)

0 commit comments

Comments
 (0)