aboutsummaryrefslogtreecommitdiff
path: root/embassy-embedded-hal/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-11-29 16:37:07 +0100
committerDario Nieuwenhuis <[email protected]>2023-11-29 17:01:36 +0100
commit4634316749c41dd5d8cc2f316033c9098369ed2f (patch)
tree1992bf003d6afcdeae926db2308f369bccfc42ea /embassy-embedded-hal/src
parent1b9925e3da0ec42b770f736cd22325203c97cb47 (diff)
Update embedded-(hal,io,nal).
Diffstat (limited to 'embassy-embedded-hal/src')
-rw-r--r--embassy-embedded-hal/src/shared_bus/asynch/spi.rs20
-rw-r--r--embassy-embedded-hal/src/shared_bus/blocking/spi.rs20
-rw-r--r--embassy-embedded-hal/src/shared_bus/mod.rs6
3 files changed, 27 insertions, 19 deletions
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
index 17d5f3676..b4f53c623 100644
--- a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
+++ b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
@@ -63,6 +63,10 @@ where
63 CS: OutputPin, 63 CS: OutputPin,
64{ 64{
65 async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { 65 async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> {
66 if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) {
67 return Err(SpiDeviceError::DelayNotSupported);
68 }
69
66 let mut bus = self.bus.lock().await; 70 let mut bus = self.bus.lock().await;
67 self.cs.set_low().map_err(SpiDeviceError::Cs)?; 71 self.cs.set_low().map_err(SpiDeviceError::Cs)?;
68 72
@@ -74,12 +78,12 @@ where
74 Operation::Transfer(read, write) => bus.transfer(read, write).await, 78 Operation::Transfer(read, write) => bus.transfer(read, write).await,
75 Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, 79 Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await,
76 #[cfg(not(feature = "time"))] 80 #[cfg(not(feature = "time"))]
77 Operation::DelayUs(us) => return Err(SpiDeviceError::DelayUsNotSupported), 81 Operation::DelayNs(_) => unreachable!(),
78 #[cfg(feature = "time")] 82 #[cfg(feature = "time")]
79 Operation::DelayUs(us) => match bus.flush().await { 83 Operation::DelayNs(ns) => match bus.flush().await {
80 Err(e) => Err(e), 84 Err(e) => Err(e),
81 Ok(()) => { 85 Ok(()) => {
82 embassy_time::Timer::after_micros(*us as _).await; 86 embassy_time::Timer::after_nanos(*ns as _).await;
83 Ok(()) 87 Ok(())
84 } 88 }
85 }, 89 },
@@ -137,6 +141,10 @@ where
137 CS: OutputPin, 141 CS: OutputPin,
138{ 142{
139 async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { 143 async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> {
144 if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) {
145 return Err(SpiDeviceError::DelayNotSupported);
146 }
147
140 let mut bus = self.bus.lock().await; 148 let mut bus = self.bus.lock().await;
141 bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?; 149 bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?;
142 self.cs.set_low().map_err(SpiDeviceError::Cs)?; 150 self.cs.set_low().map_err(SpiDeviceError::Cs)?;
@@ -149,12 +157,12 @@ where
149 Operation::Transfer(read, write) => bus.transfer(read, write).await, 157 Operation::Transfer(read, write) => bus.transfer(read, write).await,
150 Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, 158 Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await,
151 #[cfg(not(feature = "time"))] 159 #[cfg(not(feature = "time"))]
152 Operation::DelayUs(us) => return Err(SpiDeviceError::DelayUsNotSupported), 160 Operation::DelayNs(_) => unreachable!(),
153 #[cfg(feature = "time")] 161 #[cfg(feature = "time")]
154 Operation::DelayUs(us) => match bus.flush().await { 162 Operation::DelayNs(ns) => match bus.flush().await {
155 Err(e) => Err(e), 163 Err(e) => Err(e),
156 Ok(()) => { 164 Ok(()) => {
157 embassy_time::Timer::after_micros(*us as _).await; 165 embassy_time::Timer::after_nanos(*ns as _).await;
158 Ok(()) 166 Ok(())
159 } 167 }
160 }, 168 },
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs
index 2b67862ea..59b65bfbd 100644
--- a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs
+++ b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs
@@ -55,8 +55,8 @@ where
55 CS: OutputPin, 55 CS: OutputPin,
56{ 56{
57 fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { 57 fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> {
58 if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayUs(_))) { 58 if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) {
59 return Err(SpiDeviceError::DelayUsNotSupported); 59 return Err(SpiDeviceError::DelayNotSupported);
60 } 60 }
61 61
62 self.bus.lock(|bus| { 62 self.bus.lock(|bus| {
@@ -69,10 +69,10 @@ where
69 Operation::Transfer(read, write) => bus.transfer(read, write), 69 Operation::Transfer(read, write) => bus.transfer(read, write),
70 Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), 70 Operation::TransferInPlace(buf) => bus.transfer_in_place(buf),
71 #[cfg(not(feature = "time"))] 71 #[cfg(not(feature = "time"))]
72 Operation::DelayUs(_) => unreachable!(), 72 Operation::DelayNs(_) => unreachable!(),
73 #[cfg(feature = "time")] 73 #[cfg(feature = "time")]
74 Operation::DelayUs(us) => { 74 Operation::DelayNs(ns) => {
75 embassy_time::block_for(embassy_time::Duration::from_micros(*us as _)); 75 embassy_time::block_for(embassy_time::Duration::from_nanos(*ns as _));
76 Ok(()) 76 Ok(())
77 } 77 }
78 }); 78 });
@@ -165,8 +165,8 @@ where
165 CS: OutputPin, 165 CS: OutputPin,
166{ 166{
167 fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { 167 fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> {
168 if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayUs(_))) { 168 if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) {
169 return Err(SpiDeviceError::DelayUsNotSupported); 169 return Err(SpiDeviceError::DelayNotSupported);
170 } 170 }
171 171
172 self.bus.lock(|bus| { 172 self.bus.lock(|bus| {
@@ -180,10 +180,10 @@ where
180 Operation::Transfer(read, write) => bus.transfer(read, write), 180 Operation::Transfer(read, write) => bus.transfer(read, write),
181 Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), 181 Operation::TransferInPlace(buf) => bus.transfer_in_place(buf),
182 #[cfg(not(feature = "time"))] 182 #[cfg(not(feature = "time"))]
183 Operation::DelayUs(_) => unreachable!(), 183 Operation::DelayNs(_) => unreachable!(),
184 #[cfg(feature = "time")] 184 #[cfg(feature = "time")]
185 Operation::DelayUs(us) => { 185 Operation::DelayNs(ns) => {
186 embassy_time::block_for(embassy_time::Duration::from_micros(*us as _)); 186 embassy_time::block_for(embassy_time::Duration::from_nanos(*ns as _));
187 Ok(()) 187 Ok(())
188 } 188 }
189 }); 189 });
diff --git a/embassy-embedded-hal/src/shared_bus/mod.rs b/embassy-embedded-hal/src/shared_bus/mod.rs
index b0159ac09..ab96df134 100644
--- a/embassy-embedded-hal/src/shared_bus/mod.rs
+++ b/embassy-embedded-hal/src/shared_bus/mod.rs
@@ -39,8 +39,8 @@ pub enum SpiDeviceError<BUS, CS> {
39 Spi(BUS), 39 Spi(BUS),
40 /// Setting the value of the Chip Select (CS) pin failed. 40 /// Setting the value of the Chip Select (CS) pin failed.
41 Cs(CS), 41 Cs(CS),
42 /// DelayUs operations are not supported when the `time` Cargo feature is not enabled. 42 /// Delay operations are not supported when the `time` Cargo feature is not enabled.
43 DelayUsNotSupported, 43 DelayNotSupported,
44 /// The SPI bus could not be configured. 44 /// The SPI bus could not be configured.
45 Config, 45 Config,
46} 46}
@@ -54,7 +54,7 @@ where
54 match self { 54 match self {
55 Self::Spi(e) => e.kind(), 55 Self::Spi(e) => e.kind(),
56 Self::Cs(_) => spi::ErrorKind::Other, 56 Self::Cs(_) => spi::ErrorKind::Other,
57 Self::DelayUsNotSupported => spi::ErrorKind::Other, 57 Self::DelayNotSupported => spi::ErrorKind::Other,
58 Self::Config => spi::ErrorKind::Other, 58 Self::Config => spi::ErrorKind::Other,
59 } 59 }
60 } 60 }