Skip to content

Commit cf6db34

Browse files
committed
Fixing unrelated async feature issues
1 parent 6c0cbad commit cf6db34

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

embedded-hal-bus/src/spi/exclusive.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use embedded_hal::spi::{ErrorType, Operation, SpiBus, SpiDevice};
66
#[cfg(feature = "async")]
77
use embedded_hal_async::{
88
delay::DelayNs as AsyncDelayNs,
9-
spi::{SpiBus as AsyncSpiBus, SpiDevice as AsyncSpiDevice},
9+
spi::{
10+
ErrorType as AsyncErrorType, Operation as AsyncOperation, SpiBus as AsyncSpiBus,
11+
SpiDevice as AsyncSpiDevice,
12+
},
1013
};
1114

1215
use super::shared::transaction;
@@ -89,6 +92,15 @@ where
8992
}
9093
}
9194

95+
#[cfg(feature = "async")]
96+
impl<BUS, CS, D> AsyncErrorType for ExclusiveDevice<BUS, CS, D>
97+
where
98+
BUS: AsyncErrorType,
99+
CS: OutputPin,
100+
{
101+
type Error = DeviceError<BUS::Error, CS::Error>;
102+
}
103+
92104
#[cfg(feature = "async")]
93105
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
94106
impl<Word: Copy + 'static, BUS, CS, D> AsyncSpiDevice<Word> for ExclusiveDevice<BUS, CS, D>
@@ -100,18 +112,18 @@ where
100112
#[inline]
101113
async fn transaction(
102114
&mut self,
103-
operations: &mut [Operation<'_, Word>],
115+
operations: &mut [AsyncOperation<'_, Word>],
104116
) -> Result<(), Self::Error> {
105117
self.cs.set_low().map_err(DeviceError::Cs)?;
106118

107119
let op_res = 'ops: {
108120
for op in operations {
109121
let res = match op {
110-
Operation::Read(buf) => self.bus.read(buf).await,
111-
Operation::Write(buf) => self.bus.write(buf).await,
112-
Operation::Transfer(read, write) => self.bus.transfer(read, write).await,
113-
Operation::TransferInPlace(buf) => self.bus.transfer_in_place(buf).await,
114-
Operation::DelayNs(ns) => match self.bus.flush().await {
122+
AsyncOperation::Read(buf) => self.bus.read(buf).await,
123+
AsyncOperation::Write(buf) => self.bus.write(buf).await,
124+
AsyncOperation::Transfer(read, write) => self.bus.transfer(read, write).await,
125+
AsyncOperation::TransferInPlace(buf) => self.bus.transfer_in_place(buf).await,
126+
AsyncOperation::DelayNs(ns) => match self.bus.flush().await {
115127
Err(e) => Err(e),
116128
Ok(()) => {
117129
self.delay.delay_ns(*ns).await;

embedded-hal-bus/src/spi/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
use core::fmt::{self, Debug, Display, Formatter};
44
use embedded_hal::spi::{Error, ErrorKind};
55

6+
#[cfg(feature = "async")]
7+
use embedded_hal_async::spi::{Error as AsyncError, ErrorKind as AsyncErrorKind};
8+
69
mod exclusive;
710
pub use exclusive::*;
811
mod refcell;
@@ -57,6 +60,21 @@ where
5760
}
5861
}
5962

63+
#[cfg(feature = "async")]
64+
impl<BUS, CS> AsyncError for DeviceError<BUS, CS>
65+
where
66+
BUS: AsyncError + Debug,
67+
CS: Debug,
68+
{
69+
#[inline]
70+
fn kind(&self) -> AsyncErrorKind {
71+
match self {
72+
Self::Spi(e) => e.kind(),
73+
Self::Cs(_) => AsyncErrorKind::ChipSelectFault,
74+
}
75+
}
76+
}
77+
6078
/// Dummy [`DelayNs`](embedded_hal::delay::DelayNs) implementation that panics on use.
6179
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
6280
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]

0 commit comments

Comments
 (0)