diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-04-06 22:25:24 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-04-06 22:41:50 +0200 |
| commit | be37eee13dbd7833e0d74ea57d31d3e5c58cd47f (patch) | |
| tree | 3e1d5a59409ea06fe34d97fdaf45642683332638 | |
| parent | f3ec6080bf9a39d9819195861e7b41e8a2081600 (diff) | |
Update embedded-hal crates.
28 files changed, 536 insertions, 607 deletions
diff --git a/embassy-embedded-hal/Cargo.toml b/embassy-embedded-hal/Cargo.toml index 45eb0d43d..c509d6ee5 100644 --- a/embassy-embedded-hal/Cargo.toml +++ b/embassy-embedded-hal/Cargo.toml | |||
| @@ -19,8 +19,8 @@ nightly = ["embedded-hal-async", "embedded-storage-async"] | |||
| 19 | [dependencies] | 19 | [dependencies] |
| 20 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } | 20 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } |
| 21 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } | 21 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } |
| 22 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } | 22 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" } |
| 23 | embedded-hal-async = { version = "=0.2.0-alpha.0", optional = true } | 23 | embedded-hal-async = { version = "=0.2.0-alpha.1", optional = true } |
| 24 | embedded-storage = "0.3.0" | 24 | embedded-storage = "0.3.0" |
| 25 | embedded-storage-async = { version = "0.4.0", optional = true } | 25 | embedded-storage-async = { version = "0.4.0", optional = true } |
| 26 | nb = "1.0.0" | 26 | nb = "1.0.0" |
diff --git a/embassy-embedded-hal/src/adapter.rs b/embassy-embedded-hal/src/adapter.rs index a49f8df4b..ee919bd84 100644 --- a/embassy-embedded-hal/src/adapter.rs +++ b/embassy-embedded-hal/src/adapter.rs | |||
| @@ -36,27 +36,22 @@ where | |||
| 36 | E: embedded_hal_1::i2c::Error + 'static, | 36 | E: embedded_hal_1::i2c::Error + 'static, |
| 37 | T: blocking::i2c::WriteRead<Error = E> + blocking::i2c::Read<Error = E> + blocking::i2c::Write<Error = E>, | 37 | T: blocking::i2c::WriteRead<Error = E> + blocking::i2c::Read<Error = E> + blocking::i2c::Write<Error = E>, |
| 38 | { | 38 | { |
| 39 | async fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Result<(), Self::Error> { | 39 | async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { |
| 40 | self.wrapped.read(address, buffer) | 40 | self.wrapped.read(address, read) |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | async fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Result<(), Self::Error> { | 43 | async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 44 | self.wrapped.write(address, bytes) | 44 | self.wrapped.write(address, write) |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | async fn write_read<'a>( | 47 | async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 48 | &'a mut self, | 48 | self.wrapped.write_read(address, write, read) |
| 49 | address: u8, | ||
| 50 | bytes: &'a [u8], | ||
| 51 | buffer: &'a mut [u8], | ||
| 52 | ) -> Result<(), Self::Error> { | ||
| 53 | self.wrapped.write_read(address, bytes, buffer) | ||
| 54 | } | 49 | } |
| 55 | 50 | ||
| 56 | async fn transaction<'a, 'b>( | 51 | async fn transaction( |
| 57 | &'a mut self, | 52 | &mut self, |
| 58 | address: u8, | 53 | address: u8, |
| 59 | operations: &'a mut [embedded_hal_async::i2c::Operation<'b>], | 54 | operations: &mut [embedded_hal_1::i2c::Operation<'_>], |
| 60 | ) -> Result<(), Self::Error> { | 55 | ) -> Result<(), Self::Error> { |
| 61 | let _ = address; | 56 | let _ = address; |
| 62 | let _ = operations; | 57 | let _ = operations; |
diff --git a/embassy-embedded-hal/src/lib.rs b/embassy-embedded-hal/src/lib.rs index 8da042228..a23fbdc41 100644 --- a/embassy-embedded-hal/src/lib.rs +++ b/embassy-embedded-hal/src/lib.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #![cfg_attr(not(feature = "std"), no_std)] | 1 | #![cfg_attr(not(feature = "std"), no_std)] |
| 2 | #![cfg_attr( | 2 | #![cfg_attr( |
| 3 | feature = "nightly", | 3 | feature = "nightly", |
| 4 | feature(type_alias_impl_trait, async_fn_in_trait, impl_trait_projections) | 4 | feature(type_alias_impl_trait, async_fn_in_trait, impl_trait_projections, try_blocks) |
| 5 | )] | 5 | )] |
| 6 | #![cfg_attr(feature = "nightly", allow(incomplete_features))] | 6 | #![cfg_attr(feature = "nightly", allow(incomplete_features))] |
| 7 | #![warn(missing_docs)] | 7 | #![warn(missing_docs)] |
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs index c5e1fd415..829554045 100644 --- a/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs +++ b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs | |||
| @@ -54,35 +54,35 @@ where | |||
| 54 | M: RawMutex + 'static, | 54 | M: RawMutex + 'static, |
| 55 | BUS: i2c::I2c + 'static, | 55 | BUS: i2c::I2c + 'static, |
| 56 | { | 56 | { |
| 57 | async fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Result<(), I2cDeviceError<BUS::Error>> { | 57 | async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), I2cDeviceError<BUS::Error>> { |
| 58 | let mut bus = self.bus.lock().await; | 58 | let mut bus = self.bus.lock().await; |
| 59 | bus.read(address, buffer).await.map_err(I2cDeviceError::I2c)?; | 59 | bus.read(address, read).await.map_err(I2cDeviceError::I2c)?; |
| 60 | Ok(()) | 60 | Ok(()) |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | async fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Result<(), I2cDeviceError<BUS::Error>> { | 63 | async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), I2cDeviceError<BUS::Error>> { |
| 64 | let mut bus = self.bus.lock().await; | 64 | let mut bus = self.bus.lock().await; |
| 65 | bus.write(address, bytes).await.map_err(I2cDeviceError::I2c)?; | 65 | bus.write(address, write).await.map_err(I2cDeviceError::I2c)?; |
| 66 | Ok(()) | 66 | Ok(()) |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | async fn write_read<'a>( | 69 | async fn write_read( |
| 70 | &'a mut self, | 70 | &mut self, |
| 71 | address: u8, | 71 | address: u8, |
| 72 | wr_buffer: &'a [u8], | 72 | write: &[u8], |
| 73 | rd_buffer: &'a mut [u8], | 73 | read: &mut [u8], |
| 74 | ) -> Result<(), I2cDeviceError<BUS::Error>> { | 74 | ) -> Result<(), I2cDeviceError<BUS::Error>> { |
| 75 | let mut bus = self.bus.lock().await; | 75 | let mut bus = self.bus.lock().await; |
| 76 | bus.write_read(address, wr_buffer, rd_buffer) | 76 | bus.write_read(address, write, read) |
| 77 | .await | 77 | .await |
| 78 | .map_err(I2cDeviceError::I2c)?; | 78 | .map_err(I2cDeviceError::I2c)?; |
| 79 | Ok(()) | 79 | Ok(()) |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | async fn transaction<'a, 'b>( | 82 | async fn transaction( |
| 83 | &'a mut self, | 83 | &mut self, |
| 84 | address: u8, | 84 | address: u8, |
| 85 | operations: &'a mut [embedded_hal_async::i2c::Operation<'b>], | 85 | operations: &mut [embedded_hal_async::i2c::Operation<'_>], |
| 86 | ) -> Result<(), I2cDeviceError<BUS::Error>> { | 86 | ) -> Result<(), I2cDeviceError<BUS::Error>> { |
| 87 | let _ = address; | 87 | let _ = address; |
| 88 | let _ = operations; | 88 | let _ = operations; |
| @@ -121,25 +121,25 @@ where | |||
| 121 | M: RawMutex + 'static, | 121 | M: RawMutex + 'static, |
| 122 | BUS: i2c::I2c + SetConfig + 'static, | 122 | BUS: i2c::I2c + SetConfig + 'static, |
| 123 | { | 123 | { |
| 124 | async fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Result<(), I2cDeviceError<BUS::Error>> { | 124 | async fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), I2cDeviceError<BUS::Error>> { |
| 125 | let mut bus = self.bus.lock().await; | 125 | let mut bus = self.bus.lock().await; |
| 126 | bus.set_config(&self.config); | 126 | bus.set_config(&self.config); |
| 127 | bus.read(address, buffer).await.map_err(I2cDeviceError::I2c)?; | 127 | bus.read(address, buffer).await.map_err(I2cDeviceError::I2c)?; |
| 128 | Ok(()) | 128 | Ok(()) |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | async fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Result<(), I2cDeviceError<BUS::Error>> { | 131 | async fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), I2cDeviceError<BUS::Error>> { |
| 132 | let mut bus = self.bus.lock().await; | 132 | let mut bus = self.bus.lock().await; |
| 133 | bus.set_config(&self.config); | 133 | bus.set_config(&self.config); |
| 134 | bus.write(address, bytes).await.map_err(I2cDeviceError::I2c)?; | 134 | bus.write(address, bytes).await.map_err(I2cDeviceError::I2c)?; |
| 135 | Ok(()) | 135 | Ok(()) |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | async fn write_read<'a>( | 138 | async fn write_read( |
| 139 | &'a mut self, | 139 | &mut self, |
| 140 | address: u8, | 140 | address: u8, |
| 141 | wr_buffer: &'a [u8], | 141 | wr_buffer: &[u8], |
| 142 | rd_buffer: &'a mut [u8], | 142 | rd_buffer: &mut [u8], |
| 143 | ) -> Result<(), I2cDeviceError<BUS::Error>> { | 143 | ) -> Result<(), I2cDeviceError<BUS::Error>> { |
| 144 | let mut bus = self.bus.lock().await; | 144 | let mut bus = self.bus.lock().await; |
| 145 | bus.set_config(&self.config); | 145 | bus.set_config(&self.config); |
| @@ -149,11 +149,7 @@ where | |||
| 149 | Ok(()) | 149 | Ok(()) |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | async fn transaction<'a, 'b>( | 152 | async fn transaction(&mut self, address: u8, operations: &mut [i2c::Operation<'_>]) -> Result<(), Self::Error> { |
| 153 | &'a mut self, | ||
| 154 | address: u8, | ||
| 155 | operations: &'a mut [embedded_hal_async::i2c::Operation<'b>], | ||
| 156 | ) -> Result<(), I2cDeviceError<BUS::Error>> { | ||
| 157 | let _ = address; | 153 | let _ = address; |
| 158 | let _ = operations; | 154 | let _ = operations; |
| 159 | todo!() | 155 | todo!() |
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs index d25716655..b5549a6cd 100644 --- a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs | |||
| @@ -25,12 +25,11 @@ | |||
| 25 | //! let spi_dev2 = SpiDevice::new(spi_bus, cs_pin2); | 25 | //! let spi_dev2 = SpiDevice::new(spi_bus, cs_pin2); |
| 26 | //! let display2 = ST7735::new(spi_dev2, dc2, rst2, Default::default(), 160, 128); | 26 | //! let display2 = ST7735::new(spi_dev2, dc2, rst2, Default::default(), 160, 128); |
| 27 | //! ``` | 27 | //! ``` |
| 28 | use core::future::Future; | ||
| 29 | 28 | ||
| 30 | use embassy_sync::blocking_mutex::raw::RawMutex; | 29 | use embassy_sync::blocking_mutex::raw::RawMutex; |
| 31 | use embassy_sync::mutex::Mutex; | 30 | use embassy_sync::mutex::Mutex; |
| 32 | use embedded_hal_1::digital::OutputPin; | 31 | use embedded_hal_1::digital::OutputPin; |
| 33 | use embedded_hal_1::spi::ErrorType; | 32 | use embedded_hal_1::spi::Operation; |
| 34 | use embedded_hal_async::spi; | 33 | use embedded_hal_async::spi; |
| 35 | 34 | ||
| 36 | use crate::shared_bus::SpiDeviceError; | 35 | use crate::shared_bus::SpiDeviceError; |
| @@ -57,33 +56,92 @@ where | |||
| 57 | type Error = SpiDeviceError<BUS::Error, CS::Error>; | 56 | type Error = SpiDeviceError<BUS::Error, CS::Error>; |
| 58 | } | 57 | } |
| 59 | 58 | ||
| 60 | unsafe impl<M, BUS, CS> spi::SpiDevice for SpiDevice<'_, M, BUS, CS> | 59 | impl<M, BUS, CS> spi::SpiDeviceRead for SpiDevice<'_, M, BUS, CS> |
| 61 | where | 60 | where |
| 62 | M: RawMutex + 'static, | 61 | M: RawMutex, |
| 63 | BUS: spi::SpiBusFlush + 'static, | 62 | BUS: spi::SpiBusRead, |
| 64 | CS: OutputPin, | 63 | CS: OutputPin, |
| 65 | { | 64 | { |
| 66 | type Bus = BUS; | 65 | async fn read_transaction(&mut self, operations: &mut [&mut [u8]]) -> Result<(), Self::Error> { |
| 66 | let mut bus = self.bus.lock().await; | ||
| 67 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | ||
| 68 | |||
| 69 | let op_res: Result<(), BUS::Error> = try { | ||
| 70 | for buf in operations { | ||
| 71 | bus.read(buf).await?; | ||
| 72 | } | ||
| 73 | }; | ||
| 74 | |||
| 75 | // On failure, it's important to still flush and deassert CS. | ||
| 76 | let flush_res = bus.flush().await; | ||
| 77 | let cs_res = self.cs.set_high(); | ||
| 67 | 78 | ||
| 68 | async fn transaction<R, F, Fut>(&mut self, f: F) -> Result<R, Self::Error> | 79 | let op_res = op_res.map_err(SpiDeviceError::Spi)?; |
| 69 | where | 80 | flush_res.map_err(SpiDeviceError::Spi)?; |
| 70 | F: FnOnce(*mut Self::Bus) -> Fut, | 81 | cs_res.map_err(SpiDeviceError::Cs)?; |
| 71 | Fut: Future<Output = Result<R, <Self::Bus as ErrorType>::Error>>, | 82 | |
| 72 | { | 83 | Ok(op_res) |
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | impl<M, BUS, CS> spi::SpiDeviceWrite for SpiDevice<'_, M, BUS, CS> | ||
| 88 | where | ||
| 89 | M: RawMutex, | ||
| 90 | BUS: spi::SpiBusWrite, | ||
| 91 | CS: OutputPin, | ||
| 92 | { | ||
| 93 | async fn write_transaction(&mut self, operations: &[&[u8]]) -> Result<(), Self::Error> { | ||
| 73 | let mut bus = self.bus.lock().await; | 94 | let mut bus = self.bus.lock().await; |
| 74 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | 95 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; |
| 75 | 96 | ||
| 76 | let f_res = f(&mut *bus).await; | 97 | let op_res: Result<(), BUS::Error> = try { |
| 98 | for buf in operations { | ||
| 99 | bus.write(buf).await?; | ||
| 100 | } | ||
| 101 | }; | ||
| 77 | 102 | ||
| 78 | // On failure, it's important to still flush and deassert CS. | 103 | // On failure, it's important to still flush and deassert CS. |
| 79 | let flush_res = bus.flush().await; | 104 | let flush_res = bus.flush().await; |
| 80 | let cs_res = self.cs.set_high(); | 105 | let cs_res = self.cs.set_high(); |
| 81 | 106 | ||
| 82 | let f_res = f_res.map_err(SpiDeviceError::Spi)?; | 107 | let op_res = op_res.map_err(SpiDeviceError::Spi)?; |
| 83 | flush_res.map_err(SpiDeviceError::Spi)?; | 108 | flush_res.map_err(SpiDeviceError::Spi)?; |
| 84 | cs_res.map_err(SpiDeviceError::Cs)?; | 109 | cs_res.map_err(SpiDeviceError::Cs)?; |
| 85 | 110 | ||
| 86 | Ok(f_res) | 111 | Ok(op_res) |
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | impl<M, BUS, CS> spi::SpiDevice for SpiDevice<'_, M, BUS, CS> | ||
| 116 | where | ||
| 117 | M: RawMutex, | ||
| 118 | BUS: spi::SpiBus, | ||
| 119 | CS: OutputPin, | ||
| 120 | { | ||
| 121 | async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { | ||
| 122 | let mut bus = self.bus.lock().await; | ||
| 123 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | ||
| 124 | |||
| 125 | let op_res: Result<(), BUS::Error> = try { | ||
| 126 | for op in operations { | ||
| 127 | match op { | ||
| 128 | Operation::Read(buf) => bus.read(buf).await?, | ||
| 129 | Operation::Write(buf) => bus.write(buf).await?, | ||
| 130 | Operation::Transfer(read, write) => bus.transfer(read, write).await?, | ||
| 131 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await?, | ||
| 132 | } | ||
| 133 | } | ||
| 134 | }; | ||
| 135 | |||
| 136 | // On failure, it's important to still flush and deassert CS. | ||
| 137 | let flush_res = bus.flush().await; | ||
| 138 | let cs_res = self.cs.set_high(); | ||
| 139 | |||
| 140 | let op_res = op_res.map_err(SpiDeviceError::Spi)?; | ||
| 141 | flush_res.map_err(SpiDeviceError::Spi)?; | ||
| 142 | cs_res.map_err(SpiDeviceError::Cs)?; | ||
| 143 | |||
| 144 | Ok(op_res) | ||
| 87 | } | 145 | } |
| 88 | } | 146 | } |
| 89 | 147 | ||
| @@ -114,33 +172,94 @@ where | |||
| 114 | type Error = SpiDeviceError<BUS::Error, CS::Error>; | 172 | type Error = SpiDeviceError<BUS::Error, CS::Error>; |
| 115 | } | 173 | } |
| 116 | 174 | ||
| 117 | unsafe impl<M, BUS, CS> spi::SpiDevice for SpiDeviceWithConfig<'_, M, BUS, CS> | 175 | impl<M, BUS, CS> spi::SpiDeviceWrite for SpiDeviceWithConfig<'_, M, BUS, CS> |
| 176 | where | ||
| 177 | M: RawMutex, | ||
| 178 | BUS: spi::SpiBusWrite + SetConfig, | ||
| 179 | CS: OutputPin, | ||
| 180 | { | ||
| 181 | async fn write_transaction(&mut self, operations: &[&[u8]]) -> Result<(), Self::Error> { | ||
| 182 | let mut bus = self.bus.lock().await; | ||
| 183 | bus.set_config(&self.config); | ||
| 184 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | ||
| 185 | |||
| 186 | let op_res: Result<(), BUS::Error> = try { | ||
| 187 | for buf in operations { | ||
| 188 | bus.write(buf).await?; | ||
| 189 | } | ||
| 190 | }; | ||
| 191 | |||
| 192 | // On failure, it's important to still flush and deassert CS. | ||
| 193 | let flush_res = bus.flush().await; | ||
| 194 | let cs_res = self.cs.set_high(); | ||
| 195 | |||
| 196 | let op_res = op_res.map_err(SpiDeviceError::Spi)?; | ||
| 197 | flush_res.map_err(SpiDeviceError::Spi)?; | ||
| 198 | cs_res.map_err(SpiDeviceError::Cs)?; | ||
| 199 | |||
| 200 | Ok(op_res) | ||
| 201 | } | ||
| 202 | } | ||
| 203 | |||
| 204 | impl<M, BUS, CS> spi::SpiDeviceRead for SpiDeviceWithConfig<'_, M, BUS, CS> | ||
| 118 | where | 205 | where |
| 119 | M: RawMutex + 'static, | 206 | M: RawMutex, |
| 120 | BUS: spi::SpiBusFlush + SetConfig + 'static, | 207 | BUS: spi::SpiBusRead + SetConfig, |
| 121 | CS: OutputPin, | 208 | CS: OutputPin, |
| 122 | { | 209 | { |
| 123 | type Bus = BUS; | 210 | async fn read_transaction(&mut self, operations: &mut [&mut [u8]]) -> Result<(), Self::Error> { |
| 211 | let mut bus = self.bus.lock().await; | ||
| 212 | bus.set_config(&self.config); | ||
| 213 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | ||
| 214 | |||
| 215 | let op_res: Result<(), BUS::Error> = try { | ||
| 216 | for buf in operations { | ||
| 217 | bus.read(buf).await?; | ||
| 218 | } | ||
| 219 | }; | ||
| 220 | |||
| 221 | // On failure, it's important to still flush and deassert CS. | ||
| 222 | let flush_res = bus.flush().await; | ||
| 223 | let cs_res = self.cs.set_high(); | ||
| 224 | |||
| 225 | let op_res = op_res.map_err(SpiDeviceError::Spi)?; | ||
| 226 | flush_res.map_err(SpiDeviceError::Spi)?; | ||
| 227 | cs_res.map_err(SpiDeviceError::Cs)?; | ||
| 228 | |||
| 229 | Ok(op_res) | ||
| 230 | } | ||
| 231 | } | ||
| 124 | 232 | ||
| 125 | async fn transaction<R, F, Fut>(&mut self, f: F) -> Result<R, Self::Error> | 233 | impl<M, BUS, CS> spi::SpiDevice for SpiDeviceWithConfig<'_, M, BUS, CS> |
| 126 | where | 234 | where |
| 127 | F: FnOnce(*mut Self::Bus) -> Fut, | 235 | M: RawMutex, |
| 128 | Fut: Future<Output = Result<R, <Self::Bus as ErrorType>::Error>>, | 236 | BUS: spi::SpiBus + SetConfig, |
| 129 | { | 237 | CS: OutputPin, |
| 238 | { | ||
| 239 | async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { | ||
| 130 | let mut bus = self.bus.lock().await; | 240 | let mut bus = self.bus.lock().await; |
| 131 | bus.set_config(&self.config); | 241 | bus.set_config(&self.config); |
| 132 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | 242 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; |
| 133 | 243 | ||
| 134 | let f_res = f(&mut *bus).await; | 244 | let op_res: Result<(), BUS::Error> = try { |
| 245 | for op in operations { | ||
| 246 | match op { | ||
| 247 | Operation::Read(buf) => bus.read(buf).await?, | ||
| 248 | Operation::Write(buf) => bus.write(buf).await?, | ||
| 249 | Operation::Transfer(read, write) => bus.transfer(read, write).await?, | ||
| 250 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await?, | ||
| 251 | } | ||
| 252 | } | ||
| 253 | }; | ||
| 135 | 254 | ||
| 136 | // On failure, it's important to still flush and deassert CS. | 255 | // On failure, it's important to still flush and deassert CS. |
| 137 | let flush_res = bus.flush().await; | 256 | let flush_res = bus.flush().await; |
| 138 | let cs_res = self.cs.set_high(); | 257 | let cs_res = self.cs.set_high(); |
| 139 | 258 | ||
| 140 | let f_res = f_res.map_err(SpiDeviceError::Spi)?; | 259 | let op_res = op_res.map_err(SpiDeviceError::Spi)?; |
| 141 | flush_res.map_err(SpiDeviceError::Spi)?; | 260 | flush_res.map_err(SpiDeviceError::Spi)?; |
| 142 | cs_res.map_err(SpiDeviceError::Cs)?; | 261 | cs_res.map_err(SpiDeviceError::Cs)?; |
| 143 | 262 | ||
| 144 | Ok(f_res) | 263 | Ok(op_res) |
| 145 | } | 264 | } |
| 146 | } | 265 | } |
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs index 892000b26..1fe520e6c 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs | |||
| @@ -72,34 +72,6 @@ where | |||
| 72 | let _ = operations; | 72 | let _ = operations; |
| 73 | todo!() | 73 | todo!() |
| 74 | } | 74 | } |
| 75 | |||
| 76 | fn write_iter<B: IntoIterator<Item = u8>>(&mut self, addr: u8, bytes: B) -> Result<(), Self::Error> { | ||
| 77 | let _ = addr; | ||
| 78 | let _ = bytes; | ||
| 79 | todo!() | ||
| 80 | } | ||
| 81 | |||
| 82 | fn write_iter_read<B: IntoIterator<Item = u8>>( | ||
| 83 | &mut self, | ||
| 84 | addr: u8, | ||
| 85 | bytes: B, | ||
| 86 | buffer: &mut [u8], | ||
| 87 | ) -> Result<(), Self::Error> { | ||
| 88 | let _ = addr; | ||
| 89 | let _ = bytes; | ||
| 90 | let _ = buffer; | ||
| 91 | todo!() | ||
| 92 | } | ||
| 93 | |||
| 94 | fn transaction_iter<'a, O: IntoIterator<Item = Operation<'a>>>( | ||
| 95 | &mut self, | ||
| 96 | address: u8, | ||
| 97 | operations: O, | ||
| 98 | ) -> Result<(), Self::Error> { | ||
| 99 | let _ = address; | ||
| 100 | let _ = operations; | ||
| 101 | todo!() | ||
| 102 | } | ||
| 103 | } | 75 | } |
| 104 | 76 | ||
| 105 | impl<'a, M, BUS, E> embedded_hal_02::blocking::i2c::Write for I2cDevice<'_, M, BUS> | 77 | impl<'a, M, BUS, E> embedded_hal_02::blocking::i2c::Write for I2cDevice<'_, M, BUS> |
| @@ -204,32 +176,4 @@ where | |||
| 204 | let _ = operations; | 176 | let _ = operations; |
| 205 | todo!() | 177 | todo!() |
| 206 | } | 178 | } |
| 207 | |||
| 208 | fn write_iter<B: IntoIterator<Item = u8>>(&mut self, addr: u8, bytes: B) -> Result<(), Self::Error> { | ||
| 209 | let _ = addr; | ||
| 210 | let _ = bytes; | ||
| 211 | todo!() | ||
| 212 | } | ||
| 213 | |||
| 214 | fn write_iter_read<B: IntoIterator<Item = u8>>( | ||
| 215 | &mut self, | ||
| 216 | addr: u8, | ||
| 217 | bytes: B, | ||
| 218 | buffer: &mut [u8], | ||
| 219 | ) -> Result<(), Self::Error> { | ||
| 220 | let _ = addr; | ||
| 221 | let _ = bytes; | ||
| 222 | let _ = buffer; | ||
| 223 | todo!() | ||
| 224 | } | ||
| 225 | |||
| 226 | fn transaction_iter<'a, O: IntoIterator<Item = Operation<'a>>>( | ||
| 227 | &mut self, | ||
| 228 | address: u8, | ||
| 229 | operations: O, | ||
| 230 | ) -> Result<(), Self::Error> { | ||
| 231 | let _ = address; | ||
| 232 | let _ = operations; | ||
| 233 | todo!() | ||
| 234 | } | ||
| 235 | } | 179 | } |
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs index 4a08dc36e..7982ffb6e 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs | |||
| @@ -23,8 +23,7 @@ use core::cell::RefCell; | |||
| 23 | use embassy_sync::blocking_mutex::raw::RawMutex; | 23 | use embassy_sync::blocking_mutex::raw::RawMutex; |
| 24 | use embassy_sync::blocking_mutex::Mutex; | 24 | use embassy_sync::blocking_mutex::Mutex; |
| 25 | use embedded_hal_1::digital::OutputPin; | 25 | use embedded_hal_1::digital::OutputPin; |
| 26 | use embedded_hal_1::spi; | 26 | use embedded_hal_1::spi::{self, Operation, SpiBus, SpiBusRead, SpiBusWrite}; |
| 27 | use embedded_hal_1::spi::SpiBusFlush; | ||
| 28 | 27 | ||
| 29 | use crate::shared_bus::SpiDeviceError; | 28 | use crate::shared_bus::SpiDeviceError; |
| 30 | use crate::SetConfig; | 29 | use crate::SetConfig; |
| @@ -50,30 +49,85 @@ where | |||
| 50 | type Error = SpiDeviceError<BUS::Error, CS::Error>; | 49 | type Error = SpiDeviceError<BUS::Error, CS::Error>; |
| 51 | } | 50 | } |
| 52 | 51 | ||
| 53 | impl<BUS, M, CS> embedded_hal_1::spi::SpiDevice for SpiDevice<'_, M, BUS, CS> | 52 | impl<BUS, M, CS> embedded_hal_1::spi::SpiDeviceRead for SpiDevice<'_, M, BUS, CS> |
| 54 | where | 53 | where |
| 55 | M: RawMutex, | 54 | M: RawMutex, |
| 56 | BUS: SpiBusFlush, | 55 | BUS: SpiBusRead, |
| 57 | CS: OutputPin, | 56 | CS: OutputPin, |
| 58 | { | 57 | { |
| 59 | type Bus = BUS; | 58 | fn read_transaction(&mut self, operations: &mut [&mut [u8]]) -> Result<(), Self::Error> { |
| 59 | self.bus.lock(|bus| { | ||
| 60 | let mut bus = bus.borrow_mut(); | ||
| 61 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | ||
| 62 | |||
| 63 | let op_res = operations.iter_mut().try_for_each(|buf| bus.read(buf)); | ||
| 60 | 64 | ||
| 61 | fn transaction<R>(&mut self, f: impl FnOnce(&mut Self::Bus) -> Result<R, BUS::Error>) -> Result<R, Self::Error> { | 65 | // On failure, it's important to still flush and deassert CS. |
| 66 | let flush_res = bus.flush(); | ||
| 67 | let cs_res = self.cs.set_high(); | ||
| 68 | |||
| 69 | let op_res = op_res.map_err(SpiDeviceError::Spi)?; | ||
| 70 | flush_res.map_err(SpiDeviceError::Spi)?; | ||
| 71 | cs_res.map_err(SpiDeviceError::Cs)?; | ||
| 72 | |||
| 73 | Ok(op_res) | ||
| 74 | }) | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | impl<BUS, M, CS> embedded_hal_1::spi::SpiDeviceWrite for SpiDevice<'_, M, BUS, CS> | ||
| 79 | where | ||
| 80 | M: RawMutex, | ||
| 81 | BUS: SpiBusWrite, | ||
| 82 | CS: OutputPin, | ||
| 83 | { | ||
| 84 | fn write_transaction(&mut self, operations: &[&[u8]]) -> Result<(), Self::Error> { | ||
| 85 | self.bus.lock(|bus| { | ||
| 86 | let mut bus = bus.borrow_mut(); | ||
| 87 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | ||
| 88 | |||
| 89 | let op_res = operations.iter().try_for_each(|buf| bus.write(buf)); | ||
| 90 | |||
| 91 | // On failure, it's important to still flush and deassert CS. | ||
| 92 | let flush_res = bus.flush(); | ||
| 93 | let cs_res = self.cs.set_high(); | ||
| 94 | |||
| 95 | let op_res = op_res.map_err(SpiDeviceError::Spi)?; | ||
| 96 | flush_res.map_err(SpiDeviceError::Spi)?; | ||
| 97 | cs_res.map_err(SpiDeviceError::Cs)?; | ||
| 98 | |||
| 99 | Ok(op_res) | ||
| 100 | }) | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | impl<BUS, M, CS> embedded_hal_1::spi::SpiDevice for SpiDevice<'_, M, BUS, CS> | ||
| 105 | where | ||
| 106 | M: RawMutex, | ||
| 107 | BUS: SpiBus, | ||
| 108 | CS: OutputPin, | ||
| 109 | { | ||
| 110 | fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { | ||
| 62 | self.bus.lock(|bus| { | 111 | self.bus.lock(|bus| { |
| 63 | let mut bus = bus.borrow_mut(); | 112 | let mut bus = bus.borrow_mut(); |
| 64 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | 113 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; |
| 65 | 114 | ||
| 66 | let f_res = f(&mut bus); | 115 | let op_res = operations.iter_mut().try_for_each(|op| match op { |
| 116 | Operation::Read(buf) => bus.read(buf), | ||
| 117 | Operation::Write(buf) => bus.write(buf), | ||
| 118 | Operation::Transfer(read, write) => bus.transfer(read, write), | ||
| 119 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), | ||
| 120 | }); | ||
| 67 | 121 | ||
| 68 | // On failure, it's important to still flush and deassert CS. | 122 | // On failure, it's important to still flush and deassert CS. |
| 69 | let flush_res = bus.flush(); | 123 | let flush_res = bus.flush(); |
| 70 | let cs_res = self.cs.set_high(); | 124 | let cs_res = self.cs.set_high(); |
| 71 | 125 | ||
| 72 | let f_res = f_res.map_err(SpiDeviceError::Spi)?; | 126 | let op_res = op_res.map_err(SpiDeviceError::Spi)?; |
| 73 | flush_res.map_err(SpiDeviceError::Spi)?; | 127 | flush_res.map_err(SpiDeviceError::Spi)?; |
| 74 | cs_res.map_err(SpiDeviceError::Cs)?; | 128 | cs_res.map_err(SpiDeviceError::Cs)?; |
| 75 | 129 | ||
| 76 | Ok(f_res) | 130 | Ok(op_res) |
| 77 | }) | 131 | }) |
| 78 | } | 132 | } |
| 79 | } | 133 | } |
| @@ -89,11 +143,11 @@ where | |||
| 89 | self.bus.lock(|bus| { | 143 | self.bus.lock(|bus| { |
| 90 | let mut bus = bus.borrow_mut(); | 144 | let mut bus = bus.borrow_mut(); |
| 91 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | 145 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; |
| 92 | let f_res = bus.transfer(words); | 146 | let op_res = bus.transfer(words); |
| 93 | let cs_res = self.cs.set_high(); | 147 | let cs_res = self.cs.set_high(); |
| 94 | let f_res = f_res.map_err(SpiDeviceError::Spi)?; | 148 | let op_res = op_res.map_err(SpiDeviceError::Spi)?; |
| 95 | cs_res.map_err(SpiDeviceError::Cs)?; | 149 | cs_res.map_err(SpiDeviceError::Cs)?; |
| 96 | Ok(f_res) | 150 | Ok(op_res) |
| 97 | }) | 151 | }) |
| 98 | } | 152 | } |
| 99 | } | 153 | } |
| @@ -110,11 +164,11 @@ where | |||
| 110 | self.bus.lock(|bus| { | 164 | self.bus.lock(|bus| { |
| 111 | let mut bus = bus.borrow_mut(); | 165 | let mut bus = bus.borrow_mut(); |
| 112 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | 166 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; |
| 113 | let f_res = bus.write(words); | 167 | let op_res = bus.write(words); |
| 114 | let cs_res = self.cs.set_high(); | 168 | let cs_res = self.cs.set_high(); |
| 115 | let f_res = f_res.map_err(SpiDeviceError::Spi)?; | 169 | let op_res = op_res.map_err(SpiDeviceError::Spi)?; |
| 116 | cs_res.map_err(SpiDeviceError::Cs)?; | 170 | cs_res.map_err(SpiDeviceError::Cs)?; |
| 117 | Ok(f_res) | 171 | Ok(op_res) |
| 118 | }) | 172 | }) |
| 119 | } | 173 | } |
| 120 | } | 174 | } |
| @@ -146,30 +200,85 @@ where | |||
| 146 | type Error = SpiDeviceError<BUS::Error, CS::Error>; | 200 | type Error = SpiDeviceError<BUS::Error, CS::Error>; |
| 147 | } | 201 | } |
| 148 | 202 | ||
| 149 | impl<BUS, M, CS> embedded_hal_1::spi::SpiDevice for SpiDeviceWithConfig<'_, M, BUS, CS> | 203 | impl<BUS, M, CS> embedded_hal_1::spi::SpiDeviceRead for SpiDeviceWithConfig<'_, M, BUS, CS> |
| 150 | where | 204 | where |
| 151 | M: RawMutex, | 205 | M: RawMutex, |
| 152 | BUS: SpiBusFlush + SetConfig, | 206 | BUS: SpiBusRead + SetConfig, |
| 153 | CS: OutputPin, | 207 | CS: OutputPin, |
| 154 | { | 208 | { |
| 155 | type Bus = BUS; | 209 | fn read_transaction(&mut self, operations: &mut [&mut [u8]]) -> Result<(), Self::Error> { |
| 210 | self.bus.lock(|bus| { | ||
| 211 | let mut bus = bus.borrow_mut(); | ||
| 212 | bus.set_config(&self.config); | ||
| 213 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | ||
| 214 | |||
| 215 | let op_res = operations.iter_mut().try_for_each(|buf| bus.read(buf)); | ||
| 156 | 216 | ||
| 157 | fn transaction<R>(&mut self, f: impl FnOnce(&mut Self::Bus) -> Result<R, BUS::Error>) -> Result<R, Self::Error> { | 217 | // On failure, it's important to still flush and deassert CS. |
| 218 | let flush_res = bus.flush(); | ||
| 219 | let cs_res = self.cs.set_high(); | ||
| 220 | |||
| 221 | let op_res = op_res.map_err(SpiDeviceError::Spi)?; | ||
| 222 | flush_res.map_err(SpiDeviceError::Spi)?; | ||
| 223 | cs_res.map_err(SpiDeviceError::Cs)?; | ||
| 224 | Ok(op_res) | ||
| 225 | }) | ||
| 226 | } | ||
| 227 | } | ||
| 228 | |||
| 229 | impl<BUS, M, CS> embedded_hal_1::spi::SpiDeviceWrite for SpiDeviceWithConfig<'_, M, BUS, CS> | ||
| 230 | where | ||
| 231 | M: RawMutex, | ||
| 232 | BUS: SpiBusWrite + SetConfig, | ||
| 233 | CS: OutputPin, | ||
| 234 | { | ||
| 235 | fn write_transaction(&mut self, operations: &[&[u8]]) -> Result<(), Self::Error> { | ||
| 236 | self.bus.lock(|bus| { | ||
| 237 | let mut bus = bus.borrow_mut(); | ||
| 238 | bus.set_config(&self.config); | ||
| 239 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | ||
| 240 | |||
| 241 | let op_res = operations.iter().try_for_each(|buf| bus.write(buf)); | ||
| 242 | |||
| 243 | // On failure, it's important to still flush and deassert CS. | ||
| 244 | let flush_res = bus.flush(); | ||
| 245 | let cs_res = self.cs.set_high(); | ||
| 246 | |||
| 247 | let op_res = op_res.map_err(SpiDeviceError::Spi)?; | ||
| 248 | flush_res.map_err(SpiDeviceError::Spi)?; | ||
| 249 | cs_res.map_err(SpiDeviceError::Cs)?; | ||
| 250 | Ok(op_res) | ||
| 251 | }) | ||
| 252 | } | ||
| 253 | } | ||
| 254 | |||
| 255 | impl<BUS, M, CS> embedded_hal_1::spi::SpiDevice for SpiDeviceWithConfig<'_, M, BUS, CS> | ||
| 256 | where | ||
| 257 | M: RawMutex, | ||
| 258 | BUS: SpiBus + SetConfig, | ||
| 259 | CS: OutputPin, | ||
| 260 | { | ||
| 261 | fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { | ||
| 158 | self.bus.lock(|bus| { | 262 | self.bus.lock(|bus| { |
| 159 | let mut bus = bus.borrow_mut(); | 263 | let mut bus = bus.borrow_mut(); |
| 160 | bus.set_config(&self.config); | 264 | bus.set_config(&self.config); |
| 161 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | 265 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; |
| 162 | 266 | ||
| 163 | let f_res = f(&mut bus); | 267 | let op_res = operations.iter_mut().try_for_each(|op| match op { |
| 268 | Operation::Read(buf) => bus.read(buf), | ||
| 269 | Operation::Write(buf) => bus.write(buf), | ||
| 270 | Operation::Transfer(read, write) => bus.transfer(read, write), | ||
| 271 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), | ||
| 272 | }); | ||
| 164 | 273 | ||
| 165 | // On failure, it's important to still flush and deassert CS. | 274 | // On failure, it's important to still flush and deassert CS. |
| 166 | let flush_res = bus.flush(); | 275 | let flush_res = bus.flush(); |
| 167 | let cs_res = self.cs.set_high(); | 276 | let cs_res = self.cs.set_high(); |
| 168 | 277 | ||
| 169 | let f_res = f_res.map_err(SpiDeviceError::Spi)?; | 278 | let op_res = op_res.map_err(SpiDeviceError::Spi)?; |
| 170 | flush_res.map_err(SpiDeviceError::Spi)?; | 279 | flush_res.map_err(SpiDeviceError::Spi)?; |
| 171 | cs_res.map_err(SpiDeviceError::Cs)?; | 280 | cs_res.map_err(SpiDeviceError::Cs)?; |
| 172 | Ok(f_res) | 281 | Ok(op_res) |
| 173 | }) | 282 | }) |
| 174 | } | 283 | } |
| 175 | } | 284 | } |
diff --git a/embassy-lora/Cargo.toml b/embassy-lora/Cargo.toml index cbe78e592..c9174ea82 100644 --- a/embassy-lora/Cargo.toml +++ b/embassy-lora/Cargo.toml | |||
| @@ -31,8 +31,8 @@ log = { version = "0.4.14", optional = true } | |||
| 31 | embassy-time = { version = "0.1.0", path = "../embassy-time" } | 31 | embassy-time = { version = "0.1.0", path = "../embassy-time" } |
| 32 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } | 32 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } |
| 33 | embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true } | 33 | embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true } |
| 34 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } | 34 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" } |
| 35 | embedded-hal-async = { version = "=0.2.0-alpha.0" } | 35 | embedded-hal-async = { version = "=0.2.0-alpha.1" } |
| 36 | embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common", default-features = false } | 36 | embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common", default-features = false } |
| 37 | futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } | 37 | futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } |
| 38 | embedded-hal = { version = "0.2", features = ["unproven"] } | 38 | embedded-hal = { version = "0.2", features = ["unproven"] } |
diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index 4e62ca89e..4a4e7c9f9 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml | |||
| @@ -87,8 +87,8 @@ embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } | |||
| 87 | embassy-usb-driver = {version = "0.1.0", path = "../embassy-usb-driver", optional=true } | 87 | embassy-usb-driver = {version = "0.1.0", path = "../embassy-usb-driver", optional=true } |
| 88 | 88 | ||
| 89 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } | 89 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } |
| 90 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9", optional = true} | 90 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10", optional = true} |
| 91 | embedded-hal-async = { version = "=0.2.0-alpha.0", optional = true} | 91 | embedded-hal-async = { version = "=0.2.0-alpha.1", optional = true} |
| 92 | embedded-io = { version = "0.4.0", features = ["async"], optional = true } | 92 | embedded-io = { version = "0.4.0", features = ["async"], optional = true } |
| 93 | 93 | ||
| 94 | defmt = { version = "0.3", optional = true } | 94 | defmt = { version = "0.3", optional = true } |
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs index ef4c929a3..9ae569609 100644 --- a/embassy-nrf/src/twim.rs +++ b/embassy-nrf/src/twim.rs | |||
| @@ -846,20 +846,6 @@ mod eh1 { | |||
| 846 | self.blocking_write(address, buffer) | 846 | self.blocking_write(address, buffer) |
| 847 | } | 847 | } |
| 848 | 848 | ||
| 849 | fn write_iter<B>(&mut self, _address: u8, _bytes: B) -> Result<(), Self::Error> | ||
| 850 | where | ||
| 851 | B: IntoIterator<Item = u8>, | ||
| 852 | { | ||
| 853 | todo!(); | ||
| 854 | } | ||
| 855 | |||
| 856 | fn write_iter_read<B>(&mut self, _address: u8, _bytes: B, _buffer: &mut [u8]) -> Result<(), Self::Error> | ||
| 857 | where | ||
| 858 | B: IntoIterator<Item = u8>, | ||
| 859 | { | ||
| 860 | todo!(); | ||
| 861 | } | ||
| 862 | |||
| 863 | fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Self::Error> { | 849 | fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Self::Error> { |
| 864 | self.blocking_write_read(address, wr_buffer, rd_buffer) | 850 | self.blocking_write_read(address, wr_buffer, rd_buffer) |
| 865 | } | 851 | } |
| @@ -871,13 +857,6 @@ mod eh1 { | |||
| 871 | ) -> Result<(), Self::Error> { | 857 | ) -> Result<(), Self::Error> { |
| 872 | todo!(); | 858 | todo!(); |
| 873 | } | 859 | } |
| 874 | |||
| 875 | fn transaction_iter<'a, O>(&mut self, _address: u8, _operations: O) -> Result<(), Self::Error> | ||
| 876 | where | ||
| 877 | O: IntoIterator<Item = embedded_hal_1::i2c::Operation<'a>>, | ||
| 878 | { | ||
| 879 | todo!(); | ||
| 880 | } | ||
| 881 | } | 860 | } |
| 882 | } | 861 | } |
| 883 | 862 | ||
| @@ -885,28 +864,22 @@ mod eh1 { | |||
| 885 | mod eha { | 864 | mod eha { |
| 886 | use super::*; | 865 | use super::*; |
| 887 | impl<'d, T: Instance> embedded_hal_async::i2c::I2c for Twim<'d, T> { | 866 | impl<'d, T: Instance> embedded_hal_async::i2c::I2c for Twim<'d, T> { |
| 888 | async fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Result<(), Error> { | 867 | async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { |
| 889 | self.read(address, buffer).await | 868 | self.read(address, read).await |
| 890 | } | 869 | } |
| 891 | 870 | ||
| 892 | async fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Result<(), Error> { | 871 | async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 893 | self.write(address, bytes).await | 872 | self.write(address, write).await |
| 894 | } | 873 | } |
| 895 | 874 | async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { | |
| 896 | async fn write_read<'a>( | 875 | self.write_read(address, write, read).await |
| 897 | &'a mut self, | ||
| 898 | address: u8, | ||
| 899 | wr_buffer: &'a [u8], | ||
| 900 | rd_buffer: &'a mut [u8], | ||
| 901 | ) -> Result<(), Error> { | ||
| 902 | self.write_read(address, wr_buffer, rd_buffer).await | ||
| 903 | } | 876 | } |
| 904 | 877 | ||
| 905 | async fn transaction<'a, 'b>( | 878 | async fn transaction( |
| 906 | &'a mut self, | 879 | &mut self, |
| 907 | address: u8, | 880 | address: u8, |
| 908 | operations: &'a mut [embedded_hal_async::i2c::Operation<'b>], | 881 | operations: &mut [embedded_hal_1::i2c::Operation<'_>], |
| 909 | ) -> Result<(), Error> { | 882 | ) -> Result<(), Self::Error> { |
| 910 | let _ = address; | 883 | let _ = address; |
| 911 | let _ = operations; | 884 | let _ = operations; |
| 912 | todo!() | 885 | todo!() |
diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml index 209c665b0..cb9c7be77 100644 --- a/embassy-rp/Cargo.toml +++ b/embassy-rp/Cargo.toml | |||
| @@ -65,9 +65,9 @@ rp2040-pac2 = { git = "https://github.com/embassy-rs/rp2040-pac2", rev="017e3c90 | |||
| 65 | #rp2040-pac2 = { path = "../../rp2040-pac2", features = ["rt"] } | 65 | #rp2040-pac2 = { path = "../../rp2040-pac2", features = ["rt"] } |
| 66 | 66 | ||
| 67 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } | 67 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } |
| 68 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9", optional = true} | 68 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10", optional = true} |
| 69 | embedded-hal-async = { version = "=0.2.0-alpha.0", optional = true} | 69 | embedded-hal-async = { version = "=0.2.0-alpha.1", optional = true} |
| 70 | embedded-hal-nb = { version = "=1.0.0-alpha.1", optional = true} | 70 | embedded-hal-nb = { version = "=1.0.0-alpha.2", optional = true} |
| 71 | 71 | ||
| 72 | paste = "1.0" | 72 | paste = "1.0" |
| 73 | pio-proc = {version= "0.2", optional = true} | 73 | pio-proc = {version= "0.2", optional = true} |
diff --git a/embassy-rp/src/i2c.rs b/embassy-rp/src/i2c.rs index e48e16d81..40e85c66f 100644 --- a/embassy-rp/src/i2c.rs +++ b/embassy-rp/src/i2c.rs | |||
| @@ -490,14 +490,14 @@ impl<'d, T: Instance + 'd, M: Mode> I2c<'d, T, M> { | |||
| 490 | } | 490 | } |
| 491 | } | 491 | } |
| 492 | 492 | ||
| 493 | fn read_blocking_internal(&mut self, buffer: &mut [u8], restart: bool, send_stop: bool) -> Result<(), Error> { | 493 | fn read_blocking_internal(&mut self, read: &mut [u8], restart: bool, send_stop: bool) -> Result<(), Error> { |
| 494 | if buffer.is_empty() { | 494 | if read.is_empty() { |
| 495 | return Err(Error::InvalidReadBufferLength); | 495 | return Err(Error::InvalidReadBufferLength); |
| 496 | } | 496 | } |
| 497 | 497 | ||
| 498 | let p = T::regs(); | 498 | let p = T::regs(); |
| 499 | let lastindex = buffer.len() - 1; | 499 | let lastindex = read.len() - 1; |
| 500 | for (i, byte) in buffer.iter_mut().enumerate() { | 500 | for (i, byte) in read.iter_mut().enumerate() { |
| 501 | let first = i == 0; | 501 | let first = i == 0; |
| 502 | let last = i == lastindex; | 502 | let last = i == lastindex; |
| 503 | 503 | ||
| @@ -524,15 +524,15 @@ impl<'d, T: Instance + 'd, M: Mode> I2c<'d, T, M> { | |||
| 524 | Ok(()) | 524 | Ok(()) |
| 525 | } | 525 | } |
| 526 | 526 | ||
| 527 | fn write_blocking_internal(&mut self, bytes: &[u8], send_stop: bool) -> Result<(), Error> { | 527 | fn write_blocking_internal(&mut self, write: &[u8], send_stop: bool) -> Result<(), Error> { |
| 528 | if bytes.is_empty() { | 528 | if write.is_empty() { |
| 529 | return Err(Error::InvalidWriteBufferLength); | 529 | return Err(Error::InvalidWriteBufferLength); |
| 530 | } | 530 | } |
| 531 | 531 | ||
| 532 | let p = T::regs(); | 532 | let p = T::regs(); |
| 533 | 533 | ||
| 534 | for (i, byte) in bytes.iter().enumerate() { | 534 | for (i, byte) in write.iter().enumerate() { |
| 535 | let last = i == bytes.len() - 1; | 535 | let last = i == write.len() - 1; |
| 536 | 536 | ||
| 537 | // NOTE(unsafe) We have &mut self | 537 | // NOTE(unsafe) We have &mut self |
| 538 | unsafe { | 538 | unsafe { |
| @@ -572,21 +572,21 @@ impl<'d, T: Instance + 'd, M: Mode> I2c<'d, T, M> { | |||
| 572 | // Blocking public API | 572 | // Blocking public API |
| 573 | // ========================= | 573 | // ========================= |
| 574 | 574 | ||
| 575 | pub fn blocking_read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error> { | 575 | pub fn blocking_read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Error> { |
| 576 | Self::setup(address.into())?; | 576 | Self::setup(address.into())?; |
| 577 | self.read_blocking_internal(buffer, true, true) | 577 | self.read_blocking_internal(read, true, true) |
| 578 | // Automatic Stop | 578 | // Automatic Stop |
| 579 | } | 579 | } |
| 580 | 580 | ||
| 581 | pub fn blocking_write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Error> { | 581 | pub fn blocking_write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> { |
| 582 | Self::setup(address.into())?; | 582 | Self::setup(address.into())?; |
| 583 | self.write_blocking_internal(bytes, true) | 583 | self.write_blocking_internal(write, true) |
| 584 | } | 584 | } |
| 585 | 585 | ||
| 586 | pub fn blocking_write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> { | 586 | pub fn blocking_write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { |
| 587 | Self::setup(address.into())?; | 587 | Self::setup(address.into())?; |
| 588 | self.write_blocking_internal(bytes, false)?; | 588 | self.write_blocking_internal(write, false)?; |
| 589 | self.read_blocking_internal(buffer, true, true) | 589 | self.read_blocking_internal(read, true, true) |
| 590 | // Automatic Stop | 590 | // Automatic Stop |
| 591 | } | 591 | } |
| 592 | } | 592 | } |
| @@ -644,48 +644,22 @@ mod eh1 { | |||
| 644 | } | 644 | } |
| 645 | 645 | ||
| 646 | impl<'d, T: Instance, M: Mode> embedded_hal_1::i2c::I2c for I2c<'d, T, M> { | 646 | impl<'d, T: Instance, M: Mode> embedded_hal_1::i2c::I2c for I2c<'d, T, M> { |
| 647 | fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { | 647 | fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { |
| 648 | self.blocking_read(address, buffer) | 648 | self.blocking_read(address, read) |
| 649 | } | 649 | } |
| 650 | 650 | ||
| 651 | fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Self::Error> { | 651 | fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 652 | self.blocking_write(address, buffer) | 652 | self.blocking_write(address, write) |
| 653 | } | ||
| 654 | |||
| 655 | fn write_iter<B>(&mut self, address: u8, bytes: B) -> Result<(), Self::Error> | ||
| 656 | where | ||
| 657 | B: IntoIterator<Item = u8>, | ||
| 658 | { | ||
| 659 | let mut peekable = bytes.into_iter().peekable(); | ||
| 660 | Self::setup(address.into())?; | ||
| 661 | |||
| 662 | while let Some(tx) = peekable.next() { | ||
| 663 | self.write_blocking_internal(&[tx], peekable.peek().is_none())?; | ||
| 664 | } | ||
| 665 | Ok(()) | ||
| 666 | } | ||
| 667 | |||
| 668 | fn write_iter_read<B>(&mut self, address: u8, bytes: B, buffer: &mut [u8]) -> Result<(), Self::Error> | ||
| 669 | where | ||
| 670 | B: IntoIterator<Item = u8>, | ||
| 671 | { | ||
| 672 | let peekable = bytes.into_iter().peekable(); | ||
| 673 | Self::setup(address.into())?; | ||
| 674 | |||
| 675 | for tx in peekable { | ||
| 676 | self.write_blocking_internal(&[tx], false)? | ||
| 677 | } | ||
| 678 | self.read_blocking_internal(buffer, true, true) | ||
| 679 | } | 653 | } |
| 680 | 654 | ||
| 681 | fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Self::Error> { | 655 | fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 682 | self.blocking_write_read(address, wr_buffer, rd_buffer) | 656 | self.blocking_write_read(address, write, read) |
| 683 | } | 657 | } |
| 684 | 658 | ||
| 685 | fn transaction<'a>( | 659 | fn transaction( |
| 686 | &mut self, | 660 | &mut self, |
| 687 | address: u8, | 661 | address: u8, |
| 688 | operations: &mut [embedded_hal_1::i2c::Operation<'a>], | 662 | operations: &mut [embedded_hal_1::i2c::Operation<'_>], |
| 689 | ) -> Result<(), Self::Error> { | 663 | ) -> Result<(), Self::Error> { |
| 690 | Self::setup(address.into())?; | 664 | Self::setup(address.into())?; |
| 691 | for i in 0..operations.len() { | 665 | for i in 0..operations.len() { |
| @@ -697,22 +671,6 @@ mod eh1 { | |||
| 697 | } | 671 | } |
| 698 | Ok(()) | 672 | Ok(()) |
| 699 | } | 673 | } |
| 700 | |||
| 701 | fn transaction_iter<'a, O>(&mut self, address: u8, operations: O) -> Result<(), Self::Error> | ||
| 702 | where | ||
| 703 | O: IntoIterator<Item = embedded_hal_1::i2c::Operation<'a>>, | ||
| 704 | { | ||
| 705 | Self::setup(address.into())?; | ||
| 706 | let mut peekable = operations.into_iter().peekable(); | ||
| 707 | while let Some(operation) = peekable.next() { | ||
| 708 | let last = peekable.peek().is_none(); | ||
| 709 | match operation { | ||
| 710 | embedded_hal_1::i2c::Operation::Read(buf) => self.read_blocking_internal(buf, false, last)?, | ||
| 711 | embedded_hal_1::i2c::Operation::Write(buf) => self.write_blocking_internal(buf, last)?, | ||
| 712 | } | ||
| 713 | } | ||
| 714 | Ok(()) | ||
| 715 | } | ||
| 716 | } | 674 | } |
| 717 | } | 675 | } |
| 718 | #[cfg(all(feature = "unstable-traits", feature = "nightly"))] | 676 | #[cfg(all(feature = "unstable-traits", feature = "nightly"))] |
| @@ -727,36 +685,29 @@ mod nightly { | |||
| 727 | A: AddressMode + Into<u16> + 'static, | 685 | A: AddressMode + Into<u16> + 'static, |
| 728 | T: Instance + 'd, | 686 | T: Instance + 'd, |
| 729 | { | 687 | { |
| 730 | async fn read<'a>(&'a mut self, address: A, read: &'a mut [u8]) -> Result<(), Self::Error> { | 688 | async fn read(&mut self, address: A, read: &mut [u8]) -> Result<(), Self::Error> { |
| 731 | let addr: u16 = address.into(); | 689 | let addr: u16 = address.into(); |
| 732 | 690 | ||
| 733 | Self::setup(addr)?; | 691 | Self::setup(addr)?; |
| 734 | self.read_async_internal(read, false, true).await | 692 | self.read_async_internal(read, false, true).await |
| 735 | } | 693 | } |
| 736 | 694 | ||
| 737 | async fn write<'a>(&'a mut self, address: A, write: &'a [u8]) -> Result<(), Self::Error> { | 695 | async fn write(&mut self, address: A, write: &[u8]) -> Result<(), Self::Error> { |
| 738 | let addr: u16 = address.into(); | 696 | let addr: u16 = address.into(); |
| 739 | 697 | ||
| 740 | Self::setup(addr)?; | 698 | Self::setup(addr)?; |
| 741 | self.write_async_internal(write.iter().copied(), true).await | 699 | self.write_async_internal(write.iter().copied(), true).await |
| 742 | } | 700 | } |
| 743 | async fn write_read<'a>( | 701 | |
| 744 | &'a mut self, | 702 | async fn write_read(&mut self, address: A, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 745 | address: A, | ||
| 746 | write: &'a [u8], | ||
| 747 | read: &'a mut [u8], | ||
| 748 | ) -> Result<(), Self::Error> { | ||
| 749 | let addr: u16 = address.into(); | 703 | let addr: u16 = address.into(); |
| 750 | 704 | ||
| 751 | Self::setup(addr)?; | 705 | Self::setup(addr)?; |
| 752 | self.write_async_internal(write.iter().cloned(), false).await?; | 706 | self.write_async_internal(write.iter().cloned(), false).await?; |
| 753 | self.read_async_internal(read, false, true).await | 707 | self.read_async_internal(read, false, true).await |
| 754 | } | 708 | } |
| 755 | async fn transaction<'a, 'b>( | 709 | |
| 756 | &'a mut self, | 710 | async fn transaction(&mut self, address: A, operations: &mut [Operation<'_>]) -> Result<(), Self::Error> { |
| 757 | address: A, | ||
| 758 | operations: &'a mut [Operation<'b>], | ||
| 759 | ) -> Result<(), Self::Error> { | ||
| 760 | let addr: u16 = address.into(); | 711 | let addr: u16 = address.into(); |
| 761 | 712 | ||
| 762 | let mut iterator = operations.iter_mut(); | 713 | let mut iterator = operations.iter_mut(); |
diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs index ebd621ecf..742a35d49 100644 --- a/embassy-rp/src/spi.rs +++ b/embassy-rp/src/spi.rs | |||
| @@ -19,6 +19,7 @@ pub enum Error { | |||
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | #[non_exhaustive] | 21 | #[non_exhaustive] |
| 22 | #[derive(Clone)] | ||
| 22 | pub struct Config { | 23 | pub struct Config { |
| 23 | pub frequency: u32, | 24 | pub frequency: u32, |
| 24 | pub phase: Phase, | 25 | pub phase: Phase, |
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 3fd1e4b4e..6710ff2d0 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -44,9 +44,9 @@ embassy-net-driver = { version = "0.1.0", path = "../embassy-net-driver" } | |||
| 44 | embassy-usb-driver = {version = "0.1.0", path = "../embassy-usb-driver", optional = true } | 44 | embassy-usb-driver = {version = "0.1.0", path = "../embassy-usb-driver", optional = true } |
| 45 | 45 | ||
| 46 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } | 46 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } |
| 47 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9", optional = true} | 47 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10", optional = true} |
| 48 | embedded-hal-async = { version = "=0.2.0-alpha.0", optional = true} | 48 | embedded-hal-async = { version = "=0.2.0-alpha.1", optional = true} |
| 49 | embedded-hal-nb = { version = "=1.0.0-alpha.1", optional = true} | 49 | embedded-hal-nb = { version = "=1.0.0-alpha.2", optional = true} |
| 50 | 50 | ||
| 51 | embedded-storage = "0.3.0" | 51 | embedded-storage = "0.3.0" |
| 52 | 52 | ||
diff --git a/embassy-stm32/src/i2c/timeout.rs b/embassy-stm32/src/i2c/timeout.rs index 4fca1ca2b..939e2750e 100644 --- a/embassy-stm32/src/i2c/timeout.rs +++ b/embassy-stm32/src/i2c/timeout.rs | |||
| @@ -28,64 +28,64 @@ impl<'d, T: Instance, TXDMA, RXDMA> TimeoutI2c<'d, T, TXDMA, RXDMA> { | |||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | /// Blocking read with a custom timeout | 30 | /// Blocking read with a custom timeout |
| 31 | pub fn blocking_read_timeout(&mut self, addr: u8, buffer: &mut [u8], timeout: Duration) -> Result<(), Error> { | 31 | pub fn blocking_read_timeout(&mut self, addr: u8, read: &mut [u8], timeout: Duration) -> Result<(), Error> { |
| 32 | self.i2c.blocking_read_timeout(addr, buffer, timeout_fn(timeout)) | 32 | self.i2c.blocking_read_timeout(addr, read, timeout_fn(timeout)) |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | /// Blocking read with default timeout, provided in [`TimeoutI2c::new()`] | 35 | /// Blocking read with default timeout, provided in [`TimeoutI2c::new()`] |
| 36 | pub fn blocking_read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Error> { | 36 | pub fn blocking_read(&mut self, addr: u8, read: &mut [u8]) -> Result<(), Error> { |
| 37 | self.blocking_read_timeout(addr, buffer, self.timeout) | 37 | self.blocking_read_timeout(addr, read, self.timeout) |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | /// Blocking write with a custom timeout | 40 | /// Blocking write with a custom timeout |
| 41 | pub fn blocking_write_timeout(&mut self, addr: u8, bytes: &[u8], timeout: Duration) -> Result<(), Error> { | 41 | pub fn blocking_write_timeout(&mut self, addr: u8, write: &[u8], timeout: Duration) -> Result<(), Error> { |
| 42 | self.i2c.blocking_write_timeout(addr, bytes, timeout_fn(timeout)) | 42 | self.i2c.blocking_write_timeout(addr, write, timeout_fn(timeout)) |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | /// Blocking write with default timeout, provided in [`TimeoutI2c::new()`] | 45 | /// Blocking write with default timeout, provided in [`TimeoutI2c::new()`] |
| 46 | pub fn blocking_write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Error> { | 46 | pub fn blocking_write(&mut self, addr: u8, write: &[u8]) -> Result<(), Error> { |
| 47 | self.blocking_write_timeout(addr, bytes, self.timeout) | 47 | self.blocking_write_timeout(addr, write, self.timeout) |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | /// Blocking write-read with a custom timeout | 50 | /// Blocking write-read with a custom timeout |
| 51 | pub fn blocking_write_read_timeout( | 51 | pub fn blocking_write_read_timeout( |
| 52 | &mut self, | 52 | &mut self, |
| 53 | addr: u8, | 53 | addr: u8, |
| 54 | bytes: &[u8], | 54 | write: &[u8], |
| 55 | buffer: &mut [u8], | 55 | read: &mut [u8], |
| 56 | timeout: Duration, | 56 | timeout: Duration, |
| 57 | ) -> Result<(), Error> { | 57 | ) -> Result<(), Error> { |
| 58 | self.i2c | 58 | self.i2c |
| 59 | .blocking_write_read_timeout(addr, bytes, buffer, timeout_fn(timeout)) | 59 | .blocking_write_read_timeout(addr, write, read, timeout_fn(timeout)) |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | /// Blocking write-read with default timeout, provided in [`TimeoutI2c::new()`] | 62 | /// Blocking write-read with default timeout, provided in [`TimeoutI2c::new()`] |
| 63 | pub fn blocking_write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> { | 63 | pub fn blocking_write_read(&mut self, addr: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { |
| 64 | self.blocking_write_read_timeout(addr, bytes, buffer, self.timeout) | 64 | self.blocking_write_read_timeout(addr, write, read, self.timeout) |
| 65 | } | 65 | } |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_02::blocking::i2c::Read for TimeoutI2c<'d, T, TXDMA, RXDMA> { | 68 | impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_02::blocking::i2c::Read for TimeoutI2c<'d, T, TXDMA, RXDMA> { |
| 69 | type Error = Error; | 69 | type Error = Error; |
| 70 | 70 | ||
| 71 | fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { | 71 | fn read(&mut self, addr: u8, read: &mut [u8]) -> Result<(), Self::Error> { |
| 72 | self.blocking_read(addr, buffer) | 72 | self.blocking_read(addr, read) |
| 73 | } | 73 | } |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_02::blocking::i2c::Write for TimeoutI2c<'d, T, TXDMA, RXDMA> { | 76 | impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_02::blocking::i2c::Write for TimeoutI2c<'d, T, TXDMA, RXDMA> { |
| 77 | type Error = Error; | 77 | type Error = Error; |
| 78 | 78 | ||
| 79 | fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> { | 79 | fn write(&mut self, addr: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 80 | self.blocking_write(addr, bytes) | 80 | self.blocking_write(addr, write) |
| 81 | } | 81 | } |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_02::blocking::i2c::WriteRead for TimeoutI2c<'d, T, TXDMA, RXDMA> { | 84 | impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_02::blocking::i2c::WriteRead for TimeoutI2c<'d, T, TXDMA, RXDMA> { |
| 85 | type Error = Error; | 85 | type Error = Error; |
| 86 | 86 | ||
| 87 | fn write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Self::Error> { | 87 | fn write_read(&mut self, addr: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 88 | self.blocking_write_read(addr, bytes, buffer) | 88 | self.blocking_write_read(addr, write, read) |
| 89 | } | 89 | } |
| 90 | } | 90 | } |
| 91 | 91 | ||
| @@ -98,45 +98,24 @@ mod eh1 { | |||
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_1::i2c::I2c for TimeoutI2c<'d, T, TXDMA, RXDMA> { | 100 | impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_1::i2c::I2c for TimeoutI2c<'d, T, TXDMA, RXDMA> { |
| 101 | fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { | 101 | fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { |
| 102 | self.blocking_read(address, buffer) | 102 | self.blocking_read(address, read) |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Self::Error> { | 105 | fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 106 | self.blocking_write(address, buffer) | 106 | self.blocking_write(address, write) |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | fn write_iter<B>(&mut self, _address: u8, _bytes: B) -> Result<(), Self::Error> | 109 | fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 110 | where | 110 | self.blocking_write_read(address, write, read) |
| 111 | B: IntoIterator<Item = u8>, | ||
| 112 | { | ||
| 113 | todo!(); | ||
| 114 | } | 111 | } |
| 115 | 112 | ||
| 116 | fn write_iter_read<B>(&mut self, _address: u8, _bytes: B, _buffer: &mut [u8]) -> Result<(), Self::Error> | 113 | fn transaction( |
| 117 | where | ||
| 118 | B: IntoIterator<Item = u8>, | ||
| 119 | { | ||
| 120 | todo!(); | ||
| 121 | } | ||
| 122 | |||
| 123 | fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Self::Error> { | ||
| 124 | self.blocking_write_read(address, wr_buffer, rd_buffer) | ||
| 125 | } | ||
| 126 | |||
| 127 | fn transaction<'a>( | ||
| 128 | &mut self, | 114 | &mut self, |
| 129 | _address: u8, | 115 | _address: u8, |
| 130 | _operations: &mut [embedded_hal_1::i2c::Operation<'a>], | 116 | _operations: &mut [embedded_hal_1::i2c::Operation<'_>], |
| 131 | ) -> Result<(), Self::Error> { | 117 | ) -> Result<(), Self::Error> { |
| 132 | todo!(); | 118 | todo!(); |
| 133 | } | 119 | } |
| 134 | |||
| 135 | fn transaction_iter<'a, O>(&mut self, _address: u8, _operations: O) -> Result<(), Self::Error> | ||
| 136 | where | ||
| 137 | O: IntoIterator<Item = embedded_hal_1::i2c::Operation<'a>>, | ||
| 138 | { | ||
| 139 | todo!(); | ||
| 140 | } | ||
| 141 | } | 120 | } |
| 142 | } | 121 | } |
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index f140e2b0d..4b47f0eb1 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs | |||
| @@ -307,18 +307,18 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 307 | } | 307 | } |
| 308 | } | 308 | } |
| 309 | 309 | ||
| 310 | pub fn blocking_read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Error> { | 310 | pub fn blocking_read(&mut self, addr: u8, read: &mut [u8]) -> Result<(), Error> { |
| 311 | self.blocking_read_timeout(addr, buffer, || Ok(())) | 311 | self.blocking_read_timeout(addr, read, || Ok(())) |
| 312 | } | 312 | } |
| 313 | 313 | ||
| 314 | pub fn blocking_write_timeout( | 314 | pub fn blocking_write_timeout( |
| 315 | &mut self, | 315 | &mut self, |
| 316 | addr: u8, | 316 | addr: u8, |
| 317 | bytes: &[u8], | 317 | write: &[u8], |
| 318 | check_timeout: impl Fn() -> Result<(), Error>, | 318 | check_timeout: impl Fn() -> Result<(), Error>, |
| 319 | ) -> Result<(), Error> { | 319 | ) -> Result<(), Error> { |
| 320 | unsafe { | 320 | unsafe { |
| 321 | self.write_bytes(addr, bytes, &check_timeout)?; | 321 | self.write_bytes(addr, write, &check_timeout)?; |
| 322 | // Send a STOP condition | 322 | // Send a STOP condition |
| 323 | T::regs().cr1().modify(|reg| reg.set_stop(true)); | 323 | T::regs().cr1().modify(|reg| reg.set_stop(true)); |
| 324 | // Wait for STOP condition to transmit. | 324 | // Wait for STOP condition to transmit. |
| @@ -331,49 +331,49 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 331 | Ok(()) | 331 | Ok(()) |
| 332 | } | 332 | } |
| 333 | 333 | ||
| 334 | pub fn blocking_write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Error> { | 334 | pub fn blocking_write(&mut self, addr: u8, write: &[u8]) -> Result<(), Error> { |
| 335 | self.blocking_write_timeout(addr, bytes, || Ok(())) | 335 | self.blocking_write_timeout(addr, write, || Ok(())) |
| 336 | } | 336 | } |
| 337 | 337 | ||
| 338 | pub fn blocking_write_read_timeout( | 338 | pub fn blocking_write_read_timeout( |
| 339 | &mut self, | 339 | &mut self, |
| 340 | addr: u8, | 340 | addr: u8, |
| 341 | bytes: &[u8], | 341 | write: &[u8], |
| 342 | buffer: &mut [u8], | 342 | read: &mut [u8], |
| 343 | check_timeout: impl Fn() -> Result<(), Error>, | 343 | check_timeout: impl Fn() -> Result<(), Error>, |
| 344 | ) -> Result<(), Error> { | 344 | ) -> Result<(), Error> { |
| 345 | unsafe { self.write_bytes(addr, bytes, &check_timeout)? }; | 345 | unsafe { self.write_bytes(addr, write, &check_timeout)? }; |
| 346 | self.blocking_read_timeout(addr, buffer, &check_timeout)?; | 346 | self.blocking_read_timeout(addr, read, &check_timeout)?; |
| 347 | 347 | ||
| 348 | Ok(()) | 348 | Ok(()) |
| 349 | } | 349 | } |
| 350 | 350 | ||
| 351 | pub fn blocking_write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> { | 351 | pub fn blocking_write_read(&mut self, addr: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { |
| 352 | self.blocking_write_read_timeout(addr, bytes, buffer, || Ok(())) | 352 | self.blocking_write_read_timeout(addr, write, read, || Ok(())) |
| 353 | } | 353 | } |
| 354 | } | 354 | } |
| 355 | 355 | ||
| 356 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Read for I2c<'d, T> { | 356 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Read for I2c<'d, T> { |
| 357 | type Error = Error; | 357 | type Error = Error; |
| 358 | 358 | ||
| 359 | fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { | 359 | fn read(&mut self, addr: u8, read: &mut [u8]) -> Result<(), Self::Error> { |
| 360 | self.blocking_read(addr, buffer) | 360 | self.blocking_read(addr, read) |
| 361 | } | 361 | } |
| 362 | } | 362 | } |
| 363 | 363 | ||
| 364 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Write for I2c<'d, T> { | 364 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Write for I2c<'d, T> { |
| 365 | type Error = Error; | 365 | type Error = Error; |
| 366 | 366 | ||
| 367 | fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> { | 367 | fn write(&mut self, addr: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 368 | self.blocking_write(addr, bytes) | 368 | self.blocking_write(addr, write) |
| 369 | } | 369 | } |
| 370 | } | 370 | } |
| 371 | 371 | ||
| 372 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for I2c<'d, T> { | 372 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for I2c<'d, T> { |
| 373 | type Error = Error; | 373 | type Error = Error; |
| 374 | 374 | ||
| 375 | fn write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Self::Error> { | 375 | fn write_read(&mut self, addr: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 376 | self.blocking_write_read(addr, bytes, buffer) | 376 | self.blocking_write_read(addr, write, read) |
| 377 | } | 377 | } |
| 378 | } | 378 | } |
| 379 | 379 | ||
| @@ -402,46 +402,25 @@ mod eh1 { | |||
| 402 | } | 402 | } |
| 403 | 403 | ||
| 404 | impl<'d, T: Instance> embedded_hal_1::i2c::I2c for I2c<'d, T> { | 404 | impl<'d, T: Instance> embedded_hal_1::i2c::I2c for I2c<'d, T> { |
| 405 | fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { | 405 | fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { |
| 406 | self.blocking_read(address, buffer) | 406 | self.blocking_read(address, read) |
| 407 | } | ||
| 408 | |||
| 409 | fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Self::Error> { | ||
| 410 | self.blocking_write(address, buffer) | ||
| 411 | } | ||
| 412 | |||
| 413 | fn write_iter<B>(&mut self, _address: u8, _bytes: B) -> Result<(), Self::Error> | ||
| 414 | where | ||
| 415 | B: IntoIterator<Item = u8>, | ||
| 416 | { | ||
| 417 | todo!(); | ||
| 418 | } | 407 | } |
| 419 | 408 | ||
| 420 | fn write_iter_read<B>(&mut self, _address: u8, _bytes: B, _buffer: &mut [u8]) -> Result<(), Self::Error> | 409 | fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 421 | where | 410 | self.blocking_write(address, write) |
| 422 | B: IntoIterator<Item = u8>, | ||
| 423 | { | ||
| 424 | todo!(); | ||
| 425 | } | 411 | } |
| 426 | 412 | ||
| 427 | fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Self::Error> { | 413 | fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 428 | self.blocking_write_read(address, wr_buffer, rd_buffer) | 414 | self.blocking_write_read(address, write, read) |
| 429 | } | 415 | } |
| 430 | 416 | ||
| 431 | fn transaction<'a>( | 417 | fn transaction( |
| 432 | &mut self, | 418 | &mut self, |
| 433 | _address: u8, | 419 | _address: u8, |
| 434 | _operations: &mut [embedded_hal_1::i2c::Operation<'a>], | 420 | _operations: &mut [embedded_hal_1::i2c::Operation<'_>], |
| 435 | ) -> Result<(), Self::Error> { | 421 | ) -> Result<(), Self::Error> { |
| 436 | todo!(); | 422 | todo!(); |
| 437 | } | 423 | } |
| 438 | |||
| 439 | fn transaction_iter<'a, O>(&mut self, _address: u8, _operations: O) -> Result<(), Self::Error> | ||
| 440 | where | ||
| 441 | O: IntoIterator<Item = embedded_hal_1::i2c::Operation<'a>>, | ||
| 442 | { | ||
| 443 | todo!(); | ||
| 444 | } | ||
| 445 | } | 424 | } |
| 446 | } | 425 | } |
| 447 | 426 | ||
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index 06ff07b21..28663fb36 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs | |||
| @@ -345,12 +345,12 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 345 | fn read_internal( | 345 | fn read_internal( |
| 346 | &mut self, | 346 | &mut self, |
| 347 | address: u8, | 347 | address: u8, |
| 348 | buffer: &mut [u8], | 348 | read: &mut [u8], |
| 349 | restart: bool, | 349 | restart: bool, |
| 350 | check_timeout: impl Fn() -> Result<(), Error>, | 350 | check_timeout: impl Fn() -> Result<(), Error>, |
| 351 | ) -> Result<(), Error> { | 351 | ) -> Result<(), Error> { |
| 352 | let completed_chunks = buffer.len() / 255; | 352 | let completed_chunks = read.len() / 255; |
| 353 | let total_chunks = if completed_chunks * 255 == buffer.len() { | 353 | let total_chunks = if completed_chunks * 255 == read.len() { |
| 354 | completed_chunks | 354 | completed_chunks |
| 355 | } else { | 355 | } else { |
| 356 | completed_chunks + 1 | 356 | completed_chunks + 1 |
| @@ -360,7 +360,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 360 | unsafe { | 360 | unsafe { |
| 361 | Self::master_read( | 361 | Self::master_read( |
| 362 | address, | 362 | address, |
| 363 | buffer.len().min(255), | 363 | read.len().min(255), |
| 364 | Stop::Automatic, | 364 | Stop::Automatic, |
| 365 | last_chunk_idx != 0, | 365 | last_chunk_idx != 0, |
| 366 | restart, | 366 | restart, |
| @@ -368,7 +368,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 368 | )?; | 368 | )?; |
| 369 | } | 369 | } |
| 370 | 370 | ||
| 371 | for (number, chunk) in buffer.chunks_mut(255).enumerate() { | 371 | for (number, chunk) in read.chunks_mut(255).enumerate() { |
| 372 | if number != 0 { | 372 | if number != 0 { |
| 373 | // NOTE(unsafe) We have &mut self | 373 | // NOTE(unsafe) We have &mut self |
| 374 | unsafe { | 374 | unsafe { |
| @@ -391,12 +391,12 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 391 | fn write_internal( | 391 | fn write_internal( |
| 392 | &mut self, | 392 | &mut self, |
| 393 | address: u8, | 393 | address: u8, |
| 394 | bytes: &[u8], | 394 | write: &[u8], |
| 395 | send_stop: bool, | 395 | send_stop: bool, |
| 396 | check_timeout: impl Fn() -> Result<(), Error>, | 396 | check_timeout: impl Fn() -> Result<(), Error>, |
| 397 | ) -> Result<(), Error> { | 397 | ) -> Result<(), Error> { |
| 398 | let completed_chunks = bytes.len() / 255; | 398 | let completed_chunks = write.len() / 255; |
| 399 | let total_chunks = if completed_chunks * 255 == bytes.len() { | 399 | let total_chunks = if completed_chunks * 255 == write.len() { |
| 400 | completed_chunks | 400 | completed_chunks |
| 401 | } else { | 401 | } else { |
| 402 | completed_chunks + 1 | 402 | completed_chunks + 1 |
| @@ -410,14 +410,14 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 410 | unsafe { | 410 | unsafe { |
| 411 | Self::master_write( | 411 | Self::master_write( |
| 412 | address, | 412 | address, |
| 413 | bytes.len().min(255), | 413 | write.len().min(255), |
| 414 | Stop::Software, | 414 | Stop::Software, |
| 415 | last_chunk_idx != 0, | 415 | last_chunk_idx != 0, |
| 416 | &check_timeout, | 416 | &check_timeout, |
| 417 | )?; | 417 | )?; |
| 418 | } | 418 | } |
| 419 | 419 | ||
| 420 | for (number, chunk) in bytes.chunks(255).enumerate() { | 420 | for (number, chunk) in write.chunks(255).enumerate() { |
| 421 | if number != 0 { | 421 | if number != 0 { |
| 422 | // NOTE(unsafe) We have &mut self | 422 | // NOTE(unsafe) We have &mut self |
| 423 | unsafe { | 423 | unsafe { |
| @@ -448,7 +448,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 448 | async fn write_dma_internal( | 448 | async fn write_dma_internal( |
| 449 | &mut self, | 449 | &mut self, |
| 450 | address: u8, | 450 | address: u8, |
| 451 | bytes: &[u8], | 451 | write: &[u8], |
| 452 | first_slice: bool, | 452 | first_slice: bool, |
| 453 | last_slice: bool, | 453 | last_slice: bool, |
| 454 | check_timeout: impl Fn() -> Result<(), Error>, | 454 | check_timeout: impl Fn() -> Result<(), Error>, |
| @@ -456,7 +456,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 456 | where | 456 | where |
| 457 | TXDMA: crate::i2c::TxDma<T>, | 457 | TXDMA: crate::i2c::TxDma<T>, |
| 458 | { | 458 | { |
| 459 | let total_len = bytes.len(); | 459 | let total_len = write.len(); |
| 460 | let completed_chunks = total_len / 255; | 460 | let completed_chunks = total_len / 255; |
| 461 | let total_chunks = if completed_chunks * 255 == total_len { | 461 | let total_chunks = if completed_chunks * 255 == total_len { |
| 462 | completed_chunks | 462 | completed_chunks |
| @@ -476,7 +476,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 476 | 476 | ||
| 477 | let ch = &mut self.tx_dma; | 477 | let ch = &mut self.tx_dma; |
| 478 | let request = ch.request(); | 478 | let request = ch.request(); |
| 479 | crate::dma::write(ch, request, bytes, dst) | 479 | crate::dma::write(ch, request, write, dst) |
| 480 | }; | 480 | }; |
| 481 | 481 | ||
| 482 | let state = T::state(); | 482 | let state = T::state(); |
| @@ -641,25 +641,25 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 641 | // ========================= | 641 | // ========================= |
| 642 | // Async public API | 642 | // Async public API |
| 643 | 643 | ||
| 644 | pub async fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Error> | 644 | pub async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> |
| 645 | where | 645 | where |
| 646 | TXDMA: crate::i2c::TxDma<T>, | 646 | TXDMA: crate::i2c::TxDma<T>, |
| 647 | { | 647 | { |
| 648 | if bytes.is_empty() { | 648 | if write.is_empty() { |
| 649 | self.write_internal(address, bytes, true, || Ok(())) | 649 | self.write_internal(address, write, true, || Ok(())) |
| 650 | } else { | 650 | } else { |
| 651 | self.write_dma_internal(address, bytes, true, true, || Ok(())).await | 651 | self.write_dma_internal(address, write, true, true, || Ok(())).await |
| 652 | } | 652 | } |
| 653 | } | 653 | } |
| 654 | 654 | ||
| 655 | pub async fn write_vectored(&mut self, address: u8, bytes: &[&[u8]]) -> Result<(), Error> | 655 | pub async fn write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error> |
| 656 | where | 656 | where |
| 657 | TXDMA: crate::i2c::TxDma<T>, | 657 | TXDMA: crate::i2c::TxDma<T>, |
| 658 | { | 658 | { |
| 659 | if bytes.is_empty() { | 659 | if write.is_empty() { |
| 660 | return Err(Error::ZeroLengthTransfer); | 660 | return Err(Error::ZeroLengthTransfer); |
| 661 | } | 661 | } |
| 662 | let mut iter = bytes.iter(); | 662 | let mut iter = write.iter(); |
| 663 | 663 | ||
| 664 | let mut first = true; | 664 | let mut first = true; |
| 665 | let mut current = iter.next(); | 665 | let mut current = iter.next(); |
| @@ -685,21 +685,21 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 685 | } | 685 | } |
| 686 | } | 686 | } |
| 687 | 687 | ||
| 688 | pub async fn write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> | 688 | pub async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> |
| 689 | where | 689 | where |
| 690 | TXDMA: super::TxDma<T>, | 690 | TXDMA: super::TxDma<T>, |
| 691 | RXDMA: super::RxDma<T>, | 691 | RXDMA: super::RxDma<T>, |
| 692 | { | 692 | { |
| 693 | if bytes.is_empty() { | 693 | if write.is_empty() { |
| 694 | self.write_internal(address, bytes, false, || Ok(()))?; | 694 | self.write_internal(address, write, false, || Ok(()))?; |
| 695 | } else { | 695 | } else { |
| 696 | self.write_dma_internal(address, bytes, true, true, || Ok(())).await?; | 696 | self.write_dma_internal(address, write, true, true, || Ok(())).await?; |
| 697 | } | 697 | } |
| 698 | 698 | ||
| 699 | if buffer.is_empty() { | 699 | if read.is_empty() { |
| 700 | self.read_internal(address, buffer, true, || Ok(()))?; | 700 | self.read_internal(address, read, true, || Ok(()))?; |
| 701 | } else { | 701 | } else { |
| 702 | self.read_dma_internal(address, buffer, true, || Ok(())).await?; | 702 | self.read_dma_internal(address, read, true, || Ok(())).await?; |
| 703 | } | 703 | } |
| 704 | 704 | ||
| 705 | Ok(()) | 705 | Ok(()) |
| @@ -711,57 +711,57 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 711 | pub fn blocking_read_timeout( | 711 | pub fn blocking_read_timeout( |
| 712 | &mut self, | 712 | &mut self, |
| 713 | address: u8, | 713 | address: u8, |
| 714 | buffer: &mut [u8], | 714 | read: &mut [u8], |
| 715 | check_timeout: impl Fn() -> Result<(), Error>, | 715 | check_timeout: impl Fn() -> Result<(), Error>, |
| 716 | ) -> Result<(), Error> { | 716 | ) -> Result<(), Error> { |
| 717 | self.read_internal(address, buffer, false, &check_timeout) | 717 | self.read_internal(address, read, false, &check_timeout) |
| 718 | // Automatic Stop | 718 | // Automatic Stop |
| 719 | } | 719 | } |
| 720 | 720 | ||
| 721 | pub fn blocking_read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error> { | 721 | pub fn blocking_read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Error> { |
| 722 | self.blocking_read_timeout(address, buffer, || Ok(())) | 722 | self.blocking_read_timeout(address, read, || Ok(())) |
| 723 | } | 723 | } |
| 724 | 724 | ||
| 725 | pub fn blocking_write_timeout( | 725 | pub fn blocking_write_timeout( |
| 726 | &mut self, | 726 | &mut self, |
| 727 | address: u8, | 727 | address: u8, |
| 728 | bytes: &[u8], | 728 | write: &[u8], |
| 729 | check_timeout: impl Fn() -> Result<(), Error>, | 729 | check_timeout: impl Fn() -> Result<(), Error>, |
| 730 | ) -> Result<(), Error> { | 730 | ) -> Result<(), Error> { |
| 731 | self.write_internal(address, bytes, true, &check_timeout) | 731 | self.write_internal(address, write, true, &check_timeout) |
| 732 | } | 732 | } |
| 733 | 733 | ||
| 734 | pub fn blocking_write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Error> { | 734 | pub fn blocking_write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> { |
| 735 | self.blocking_write_timeout(address, bytes, || Ok(())) | 735 | self.blocking_write_timeout(address, write, || Ok(())) |
| 736 | } | 736 | } |
| 737 | 737 | ||
| 738 | pub fn blocking_write_read_timeout( | 738 | pub fn blocking_write_read_timeout( |
| 739 | &mut self, | 739 | &mut self, |
| 740 | address: u8, | 740 | address: u8, |
| 741 | bytes: &[u8], | 741 | write: &[u8], |
| 742 | buffer: &mut [u8], | 742 | read: &mut [u8], |
| 743 | check_timeout: impl Fn() -> Result<(), Error>, | 743 | check_timeout: impl Fn() -> Result<(), Error>, |
| 744 | ) -> Result<(), Error> { | 744 | ) -> Result<(), Error> { |
| 745 | self.write_internal(address, bytes, false, &check_timeout)?; | 745 | self.write_internal(address, write, false, &check_timeout)?; |
| 746 | self.read_internal(address, buffer, true, &check_timeout) | 746 | self.read_internal(address, read, true, &check_timeout) |
| 747 | // Automatic Stop | 747 | // Automatic Stop |
| 748 | } | 748 | } |
| 749 | 749 | ||
| 750 | pub fn blocking_write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> { | 750 | pub fn blocking_write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { |
| 751 | self.blocking_write_read_timeout(address, bytes, buffer, || Ok(())) | 751 | self.blocking_write_read_timeout(address, write, read, || Ok(())) |
| 752 | } | 752 | } |
| 753 | 753 | ||
| 754 | pub fn blocking_write_vectored_timeout( | 754 | pub fn blocking_write_vectored_timeout( |
| 755 | &mut self, | 755 | &mut self, |
| 756 | address: u8, | 756 | address: u8, |
| 757 | bytes: &[&[u8]], | 757 | write: &[&[u8]], |
| 758 | check_timeout: impl Fn() -> Result<(), Error>, | 758 | check_timeout: impl Fn() -> Result<(), Error>, |
| 759 | ) -> Result<(), Error> { | 759 | ) -> Result<(), Error> { |
| 760 | if bytes.is_empty() { | 760 | if write.is_empty() { |
| 761 | return Err(Error::ZeroLengthTransfer); | 761 | return Err(Error::ZeroLengthTransfer); |
| 762 | } | 762 | } |
| 763 | let first_length = bytes[0].len(); | 763 | let first_length = write[0].len(); |
| 764 | let last_slice_index = bytes.len() - 1; | 764 | let last_slice_index = write.len() - 1; |
| 765 | 765 | ||
| 766 | // NOTE(unsafe) We have &mut self | 766 | // NOTE(unsafe) We have &mut self |
| 767 | unsafe { | 767 | unsafe { |
| @@ -774,7 +774,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 774 | )?; | 774 | )?; |
| 775 | } | 775 | } |
| 776 | 776 | ||
| 777 | for (idx, slice) in bytes.iter().enumerate() { | 777 | for (idx, slice) in write.iter().enumerate() { |
| 778 | let slice_len = slice.len(); | 778 | let slice_len = slice.len(); |
| 779 | let completed_chunks = slice_len / 255; | 779 | let completed_chunks = slice_len / 255; |
| 780 | let total_chunks = if completed_chunks * 255 == slice_len { | 780 | let total_chunks = if completed_chunks * 255 == slice_len { |
| @@ -828,8 +828,8 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 828 | Ok(()) | 828 | Ok(()) |
| 829 | } | 829 | } |
| 830 | 830 | ||
| 831 | pub fn blocking_write_vectored(&mut self, address: u8, bytes: &[&[u8]]) -> Result<(), Error> { | 831 | pub fn blocking_write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error> { |
| 832 | self.blocking_write_vectored_timeout(address, bytes, || Ok(())) | 832 | self.blocking_write_vectored_timeout(address, write, || Ok(())) |
| 833 | } | 833 | } |
| 834 | } | 834 | } |
| 835 | 835 | ||
| @@ -847,16 +847,16 @@ mod eh02 { | |||
| 847 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Write for I2c<'d, T> { | 847 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Write for I2c<'d, T> { |
| 848 | type Error = Error; | 848 | type Error = Error; |
| 849 | 849 | ||
| 850 | fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Self::Error> { | 850 | fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 851 | self.blocking_write(address, bytes) | 851 | self.blocking_write(address, write) |
| 852 | } | 852 | } |
| 853 | } | 853 | } |
| 854 | 854 | ||
| 855 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for I2c<'d, T> { | 855 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for I2c<'d, T> { |
| 856 | type Error = Error; | 856 | type Error = Error; |
| 857 | 857 | ||
| 858 | fn write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Self::Error> { | 858 | fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 859 | self.blocking_write_read(address, bytes, buffer) | 859 | self.blocking_write_read(address, write, read) |
| 860 | } | 860 | } |
| 861 | } | 861 | } |
| 862 | } | 862 | } |
| @@ -1010,46 +1010,25 @@ mod eh1 { | |||
| 1010 | } | 1010 | } |
| 1011 | 1011 | ||
| 1012 | impl<'d, T: Instance> embedded_hal_1::i2c::I2c for I2c<'d, T, NoDma, NoDma> { | 1012 | impl<'d, T: Instance> embedded_hal_1::i2c::I2c for I2c<'d, T, NoDma, NoDma> { |
| 1013 | fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { | 1013 | fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { |
| 1014 | self.blocking_read(address, buffer) | 1014 | self.blocking_read(address, read) |
| 1015 | } | ||
| 1016 | |||
| 1017 | fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Self::Error> { | ||
| 1018 | self.blocking_write(address, buffer) | ||
| 1019 | } | ||
| 1020 | |||
| 1021 | fn write_iter<B>(&mut self, _address: u8, _bytes: B) -> Result<(), Self::Error> | ||
| 1022 | where | ||
| 1023 | B: IntoIterator<Item = u8>, | ||
| 1024 | { | ||
| 1025 | todo!(); | ||
| 1026 | } | 1015 | } |
| 1027 | 1016 | ||
| 1028 | fn write_iter_read<B>(&mut self, _address: u8, _bytes: B, _buffer: &mut [u8]) -> Result<(), Self::Error> | 1017 | fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 1029 | where | 1018 | self.blocking_write(address, write) |
| 1030 | B: IntoIterator<Item = u8>, | ||
| 1031 | { | ||
| 1032 | todo!(); | ||
| 1033 | } | 1019 | } |
| 1034 | 1020 | ||
| 1035 | fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Self::Error> { | 1021 | fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 1036 | self.blocking_write_read(address, wr_buffer, rd_buffer) | 1022 | self.blocking_write_read(address, write, read) |
| 1037 | } | 1023 | } |
| 1038 | 1024 | ||
| 1039 | fn transaction<'a>( | 1025 | fn transaction( |
| 1040 | &mut self, | 1026 | &mut self, |
| 1041 | _address: u8, | 1027 | _address: u8, |
| 1042 | _operations: &mut [embedded_hal_1::i2c::Operation<'a>], | 1028 | _operations: &mut [embedded_hal_1::i2c::Operation<'_>], |
| 1043 | ) -> Result<(), Self::Error> { | 1029 | ) -> Result<(), Self::Error> { |
| 1044 | todo!(); | 1030 | todo!(); |
| 1045 | } | 1031 | } |
| 1046 | |||
| 1047 | fn transaction_iter<'a, O>(&mut self, _address: u8, _operations: O) -> Result<(), Self::Error> | ||
| 1048 | where | ||
| 1049 | O: IntoIterator<Item = embedded_hal_1::i2c::Operation<'a>>, | ||
| 1050 | { | ||
| 1051 | todo!(); | ||
| 1052 | } | ||
| 1053 | } | 1032 | } |
| 1054 | } | 1033 | } |
| 1055 | 1034 | ||
| @@ -1059,27 +1038,22 @@ mod eha { | |||
| 1059 | use super::*; | 1038 | use super::*; |
| 1060 | 1039 | ||
| 1061 | impl<'d, T: Instance, TXDMA: TxDma<T>, RXDMA: RxDma<T>> embedded_hal_async::i2c::I2c for I2c<'d, T, TXDMA, RXDMA> { | 1040 | impl<'d, T: Instance, TXDMA: TxDma<T>, RXDMA: RxDma<T>> embedded_hal_async::i2c::I2c for I2c<'d, T, TXDMA, RXDMA> { |
| 1062 | async fn read<'a>(&'a mut self, address: u8, read: &'a mut [u8]) -> Result<(), Self::Error> { | 1041 | async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { |
| 1063 | self.read(address, read).await | 1042 | self.read(address, read).await |
| 1064 | } | 1043 | } |
| 1065 | 1044 | ||
| 1066 | async fn write<'a>(&'a mut self, address: u8, write: &'a [u8]) -> Result<(), Self::Error> { | 1045 | async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 1067 | self.write(address, write).await | 1046 | self.write(address, write).await |
| 1068 | } | 1047 | } |
| 1069 | 1048 | ||
| 1070 | async fn write_read<'a>( | 1049 | async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 1071 | &'a mut self, | ||
| 1072 | address: u8, | ||
| 1073 | write: &'a [u8], | ||
| 1074 | read: &'a mut [u8], | ||
| 1075 | ) -> Result<(), Self::Error> { | ||
| 1076 | self.write_read(address, write, read).await | 1050 | self.write_read(address, write, read).await |
| 1077 | } | 1051 | } |
| 1078 | 1052 | ||
| 1079 | async fn transaction<'a, 'b>( | 1053 | async fn transaction( |
| 1080 | &'a mut self, | 1054 | &mut self, |
| 1081 | address: u8, | 1055 | address: u8, |
| 1082 | operations: &'a mut [embedded_hal_1::i2c::Operation<'b>], | 1056 | operations: &mut [embedded_hal_1::i2c::Operation<'_>], |
| 1083 | ) -> Result<(), Self::Error> { | 1057 | ) -> Result<(), Self::Error> { |
| 1084 | let _ = address; | 1058 | let _ = address; |
| 1085 | let _ = operations; | 1059 | let _ = operations; |
diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml index 5b14814a1..38d31f1c4 100644 --- a/embassy-time/Cargo.toml +++ b/embassy-time/Cargo.toml | |||
| @@ -152,8 +152,8 @@ defmt = { version = "0.3", optional = true } | |||
| 152 | log = { version = "0.4.14", optional = true } | 152 | log = { version = "0.4.14", optional = true } |
| 153 | 153 | ||
| 154 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } | 154 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } |
| 155 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9", optional = true} | 155 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10", optional = true} |
| 156 | embedded-hal-async = { version = "=0.2.0-alpha.0", optional = true} | 156 | embedded-hal-async = { version = "=0.2.0-alpha.1", optional = true} |
| 157 | 157 | ||
| 158 | futures-util = { version = "0.3.17", default-features = false } | 158 | futures-util = { version = "0.3.17", default-features = false } |
| 159 | embassy-sync = { version = "0.1", path = "../embassy-sync" } | 159 | embassy-sync = { version = "0.1", path = "../embassy-sync" } |
diff --git a/embassy-time/src/delay.rs b/embassy-time/src/delay.rs index 0ca176abd..cf1918724 100644 --- a/embassy-time/src/delay.rs +++ b/embassy-time/src/delay.rs | |||
| @@ -19,14 +19,12 @@ mod eh1 { | |||
| 19 | use super::*; | 19 | use super::*; |
| 20 | 20 | ||
| 21 | impl embedded_hal_1::delay::DelayUs for Delay { | 21 | impl embedded_hal_1::delay::DelayUs for Delay { |
| 22 | type Error = core::convert::Infallible; | 22 | fn delay_us(&mut self, us: u32) { |
| 23 | 23 | block_for(Duration::from_micros(us as u64)) | |
| 24 | fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { | ||
| 25 | Ok(block_for(Duration::from_micros(us as u64))) | ||
| 26 | } | 24 | } |
| 27 | 25 | ||
| 28 | fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> { | 26 | fn delay_ms(&mut self, ms: u32) { |
| 29 | Ok(block_for(Duration::from_millis(ms as u64))) | 27 | block_for(Duration::from_millis(ms as u64)) |
| 30 | } | 28 | } |
| 31 | } | 29 | } |
| 32 | } | 30 | } |
| @@ -37,14 +35,12 @@ mod eha { | |||
| 37 | use crate::Timer; | 35 | use crate::Timer; |
| 38 | 36 | ||
| 39 | impl embedded_hal_async::delay::DelayUs for Delay { | 37 | impl embedded_hal_async::delay::DelayUs for Delay { |
| 40 | type Error = core::convert::Infallible; | 38 | async fn delay_us(&mut self, micros: u32) { |
| 41 | 39 | Timer::after(Duration::from_micros(micros as _)).await | |
| 42 | async fn delay_us(&mut self, micros: u32) -> Result<(), Self::Error> { | ||
| 43 | Ok(Timer::after(Duration::from_micros(micros as _)).await) | ||
| 44 | } | 40 | } |
| 45 | 41 | ||
| 46 | async fn delay_ms(&mut self, millis: u32) -> Result<(), Self::Error> { | 42 | async fn delay_ms(&mut self, millis: u32) { |
| 47 | Ok(Timer::after(Duration::from_millis(millis as _)).await) | 43 | Timer::after(Duration::from_millis(millis as _)).await |
| 48 | } | 44 | } |
| 49 | } | 45 | } |
| 50 | } | 46 | } |
diff --git a/examples/rp/.cargo/config.toml b/examples/rp/.cargo/config.toml index d1c8c1c5a..2ee6fcb00 100644 --- a/examples/rp/.cargo/config.toml +++ b/examples/rp/.cargo/config.toml | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] |
| 2 | runner = "probe-run --chip RP2040" | 2 | runner = "probe-rs-cli run --chip RP2040" |
| 3 | 3 | ||
| 4 | [build] | 4 | [build] |
| 5 | target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ | 5 | target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ |
diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index aea61eec5..63d0ac82a 100644 --- a/examples/rp/Cargo.toml +++ b/examples/rp/Cargo.toml | |||
| @@ -6,6 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | [dependencies] | 8 | [dependencies] |
| 9 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal", features = ["defmt"] } | ||
| 9 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 10 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 11 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } | 12 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } |
| @@ -30,8 +31,8 @@ display-interface = "0.4.1" | |||
| 30 | byte-slice-cast = { version = "1.2.0", default-features = false } | 31 | byte-slice-cast = { version = "1.2.0", default-features = false } |
| 31 | smart-leds = "0.3.0" | 32 | smart-leds = "0.3.0" |
| 32 | 33 | ||
| 33 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } | 34 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" } |
| 34 | embedded-hal-async = "0.2.0-alpha.0" | 35 | embedded-hal-async = "0.2.0-alpha.1" |
| 35 | embedded-io = { version = "0.4.0", features = ["async", "defmt"] } | 36 | embedded-io = { version = "0.4.0", features = ["async", "defmt"] } |
| 36 | embedded-storage = { version = "0.3" } | 37 | embedded-storage = { version = "0.3" } |
| 37 | static_cell = "1.0.0" | 38 | static_cell = "1.0.0" |
diff --git a/examples/rp/src/bin/spi_display.rs b/examples/rp/src/bin/spi_display.rs index 778cad3fa..85a19ce07 100644 --- a/examples/rp/src/bin/spi_display.rs +++ b/examples/rp/src/bin/spi_display.rs | |||
| @@ -5,10 +5,13 @@ | |||
| 5 | use core::cell::RefCell; | 5 | use core::cell::RefCell; |
| 6 | 6 | ||
| 7 | use defmt::*; | 7 | use defmt::*; |
| 8 | use embassy_embedded_hal::shared_bus::blocking::spi::SpiDeviceWithConfig; | ||
| 8 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 9 | use embassy_rp::gpio::{Level, Output}; | 10 | use embassy_rp::gpio::{Level, Output}; |
| 10 | use embassy_rp::spi; | 11 | use embassy_rp::spi; |
| 11 | use embassy_rp::spi::{Blocking, Spi}; | 12 | use embassy_rp::spi::{Blocking, Spi}; |
| 13 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | ||
| 14 | use embassy_sync::blocking_mutex::Mutex; | ||
| 12 | use embassy_time::Delay; | 15 | use embassy_time::Delay; |
| 13 | use embedded_graphics::image::{Image, ImageRawLE}; | 16 | use embedded_graphics::image::{Image, ImageRawLE}; |
| 14 | use embedded_graphics::mono_font::ascii::FONT_10X20; | 17 | use embedded_graphics::mono_font::ascii::FONT_10X20; |
| @@ -21,10 +24,9 @@ use st7789::{Orientation, ST7789}; | |||
| 21 | use {defmt_rtt as _, panic_probe as _}; | 24 | use {defmt_rtt as _, panic_probe as _}; |
| 22 | 25 | ||
| 23 | use crate::my_display_interface::SPIDeviceInterface; | 26 | use crate::my_display_interface::SPIDeviceInterface; |
| 24 | use crate::shared_spi::SpiDeviceWithCs; | ||
| 25 | use crate::touch::Touch; | 27 | use crate::touch::Touch; |
| 26 | 28 | ||
| 27 | //const DISPLAY_FREQ: u32 = 64_000_000; | 29 | const DISPLAY_FREQ: u32 = 64_000_000; |
| 28 | const TOUCH_FREQ: u32 = 200_000; | 30 | const TOUCH_FREQ: u32 = 200_000; |
| 29 | 31 | ||
| 30 | #[embassy_executor::main] | 32 | #[embassy_executor::main] |
| @@ -43,16 +45,20 @@ async fn main(_spawner: Spawner) { | |||
| 43 | //let touch_irq = p.PIN_17; | 45 | //let touch_irq = p.PIN_17; |
| 44 | 46 | ||
| 45 | // create SPI | 47 | // create SPI |
| 46 | let mut config = spi::Config::default(); | 48 | let mut display_config = spi::Config::default(); |
| 47 | config.frequency = TOUCH_FREQ; // use the lowest freq | 49 | display_config.frequency = DISPLAY_FREQ; |
| 48 | config.phase = spi::Phase::CaptureOnSecondTransition; | 50 | display_config.phase = spi::Phase::CaptureOnSecondTransition; |
| 49 | config.polarity = spi::Polarity::IdleHigh; | 51 | display_config.polarity = spi::Polarity::IdleHigh; |
| 52 | let mut touch_config = spi::Config::default(); | ||
| 53 | touch_config.frequency = TOUCH_FREQ; | ||
| 54 | touch_config.phase = spi::Phase::CaptureOnSecondTransition; | ||
| 55 | touch_config.polarity = spi::Polarity::IdleHigh; | ||
| 50 | 56 | ||
| 51 | let spi: Spi<'_, _, Blocking> = Spi::new_blocking(p.SPI1, clk, mosi, miso, config); | 57 | let spi: Spi<'_, _, Blocking> = Spi::new_blocking(p.SPI1, clk, mosi, miso, touch_config.clone()); |
| 52 | let spi_bus = RefCell::new(spi); | 58 | let spi_bus: Mutex<NoopRawMutex, _> = Mutex::new(RefCell::new(spi)); |
| 53 | 59 | ||
| 54 | let display_spi = SpiDeviceWithCs::new(&spi_bus, Output::new(display_cs, Level::High)); | 60 | let display_spi = SpiDeviceWithConfig::new(&spi_bus, Output::new(display_cs, Level::High), display_config); |
| 55 | let touch_spi = SpiDeviceWithCs::new(&spi_bus, Output::new(touch_cs, Level::High)); | 61 | let touch_spi = SpiDeviceWithConfig::new(&spi_bus, Output::new(touch_cs, Level::High), touch_config); |
| 56 | 62 | ||
| 57 | let mut touch = Touch::new(touch_spi); | 63 | let mut touch = Touch::new(touch_spi); |
| 58 | 64 | ||
| @@ -104,85 +110,9 @@ async fn main(_spawner: Spawner) { | |||
| 104 | } | 110 | } |
| 105 | } | 111 | } |
| 106 | 112 | ||
| 107 | mod shared_spi { | ||
| 108 | use core::cell::RefCell; | ||
| 109 | use core::fmt::Debug; | ||
| 110 | |||
| 111 | use embedded_hal_1::digital::OutputPin; | ||
| 112 | use embedded_hal_1::spi; | ||
| 113 | use embedded_hal_1::spi::SpiDevice; | ||
| 114 | |||
| 115 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | ||
| 116 | pub enum SpiDeviceWithCsError<BUS, CS> { | ||
| 117 | #[allow(unused)] // will probably use in the future when adding a flush() to SpiBus | ||
| 118 | Spi(BUS), | ||
| 119 | Cs(CS), | ||
| 120 | } | ||
| 121 | |||
| 122 | impl<BUS, CS> spi::Error for SpiDeviceWithCsError<BUS, CS> | ||
| 123 | where | ||
| 124 | BUS: spi::Error + Debug, | ||
| 125 | CS: Debug, | ||
| 126 | { | ||
| 127 | fn kind(&self) -> spi::ErrorKind { | ||
| 128 | match self { | ||
| 129 | Self::Spi(e) => e.kind(), | ||
| 130 | Self::Cs(_) => spi::ErrorKind::Other, | ||
| 131 | } | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | pub struct SpiDeviceWithCs<'a, BUS, CS> { | ||
| 136 | bus: &'a RefCell<BUS>, | ||
| 137 | cs: CS, | ||
| 138 | } | ||
| 139 | |||
| 140 | impl<'a, BUS, CS> SpiDeviceWithCs<'a, BUS, CS> { | ||
| 141 | pub fn new(bus: &'a RefCell<BUS>, cs: CS) -> Self { | ||
| 142 | Self { bus, cs } | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | impl<'a, BUS, CS> spi::ErrorType for SpiDeviceWithCs<'a, BUS, CS> | ||
| 147 | where | ||
| 148 | BUS: spi::ErrorType, | ||
| 149 | CS: OutputPin, | ||
| 150 | { | ||
| 151 | type Error = SpiDeviceWithCsError<BUS::Error, CS::Error>; | ||
| 152 | } | ||
| 153 | |||
| 154 | impl<'a, BUS, CS> SpiDevice for SpiDeviceWithCs<'a, BUS, CS> | ||
| 155 | where | ||
| 156 | BUS: spi::SpiBusFlush, | ||
| 157 | CS: OutputPin, | ||
| 158 | { | ||
| 159 | type Bus = BUS; | ||
| 160 | |||
| 161 | fn transaction<R>( | ||
| 162 | &mut self, | ||
| 163 | f: impl FnOnce(&mut Self::Bus) -> Result<R, BUS::Error>, | ||
| 164 | ) -> Result<R, Self::Error> { | ||
| 165 | let mut bus = self.bus.borrow_mut(); | ||
| 166 | self.cs.set_low().map_err(SpiDeviceWithCsError::Cs)?; | ||
| 167 | |||
| 168 | let f_res = f(&mut bus); | ||
| 169 | |||
| 170 | // On failure, it's important to still flush and deassert CS. | ||
| 171 | let flush_res = bus.flush(); | ||
| 172 | let cs_res = self.cs.set_high(); | ||
| 173 | |||
| 174 | let f_res = f_res.map_err(SpiDeviceWithCsError::Spi)?; | ||
| 175 | flush_res.map_err(SpiDeviceWithCsError::Spi)?; | ||
| 176 | cs_res.map_err(SpiDeviceWithCsError::Cs)?; | ||
| 177 | |||
| 178 | Ok(f_res) | ||
| 179 | } | ||
| 180 | } | ||
| 181 | } | ||
| 182 | |||
| 183 | /// Driver for the XPT2046 resistive touchscreen sensor | 113 | /// Driver for the XPT2046 resistive touchscreen sensor |
| 184 | mod touch { | 114 | mod touch { |
| 185 | use embedded_hal_1::spi::{SpiBus, SpiBusRead, SpiBusWrite, SpiDevice}; | 115 | use embedded_hal_1::spi::{Operation, SpiDevice}; |
| 186 | 116 | ||
| 187 | struct Calibration { | 117 | struct Calibration { |
| 188 | x1: i32, | 118 | x1: i32, |
| @@ -209,7 +139,6 @@ mod touch { | |||
| 209 | impl<SPI> Touch<SPI> | 139 | impl<SPI> Touch<SPI> |
| 210 | where | 140 | where |
| 211 | SPI: SpiDevice, | 141 | SPI: SpiDevice, |
| 212 | SPI::Bus: SpiBus, | ||
| 213 | { | 142 | { |
| 214 | pub fn new(spi: SPI) -> Self { | 143 | pub fn new(spi: SPI) -> Self { |
| 215 | Self { spi } | 144 | Self { spi } |
| @@ -219,13 +148,12 @@ mod touch { | |||
| 219 | let mut x = [0; 2]; | 148 | let mut x = [0; 2]; |
| 220 | let mut y = [0; 2]; | 149 | let mut y = [0; 2]; |
| 221 | self.spi | 150 | self.spi |
| 222 | .transaction(|bus| { | 151 | .transaction(&mut [ |
| 223 | bus.write(&[0x90])?; | 152 | Operation::Write(&[0x90]), |
| 224 | bus.read(&mut x)?; | 153 | Operation::Read(&mut x), |
| 225 | bus.write(&[0xd0])?; | 154 | Operation::Write(&[0xd0]), |
| 226 | bus.read(&mut y)?; | 155 | Operation::Read(&mut y), |
| 227 | Ok(()) | 156 | ]) |
| 228 | }) | ||
| 229 | .unwrap(); | 157 | .unwrap(); |
| 230 | 158 | ||
| 231 | let x = (u16::from_be_bytes(x) >> 3) as i32; | 159 | let x = (u16::from_be_bytes(x) >> 3) as i32; |
| @@ -247,7 +175,7 @@ mod touch { | |||
| 247 | mod my_display_interface { | 175 | mod my_display_interface { |
| 248 | use display_interface::{DataFormat, DisplayError, WriteOnlyDataCommand}; | 176 | use display_interface::{DataFormat, DisplayError, WriteOnlyDataCommand}; |
| 249 | use embedded_hal_1::digital::OutputPin; | 177 | use embedded_hal_1::digital::OutputPin; |
| 250 | use embedded_hal_1::spi::{SpiBusWrite, SpiDevice}; | 178 | use embedded_hal_1::spi::SpiDeviceWrite; |
| 251 | 179 | ||
| 252 | /// SPI display interface. | 180 | /// SPI display interface. |
| 253 | /// | 181 | /// |
| @@ -259,8 +187,7 @@ mod my_display_interface { | |||
| 259 | 187 | ||
| 260 | impl<SPI, DC> SPIDeviceInterface<SPI, DC> | 188 | impl<SPI, DC> SPIDeviceInterface<SPI, DC> |
| 261 | where | 189 | where |
| 262 | SPI: SpiDevice, | 190 | SPI: SpiDeviceWrite, |
| 263 | SPI::Bus: SpiBusWrite, | ||
| 264 | DC: OutputPin, | 191 | DC: OutputPin, |
| 265 | { | 192 | { |
| 266 | /// Create new SPI interface for communciation with a display driver | 193 | /// Create new SPI interface for communciation with a display driver |
| @@ -271,42 +198,27 @@ mod my_display_interface { | |||
| 271 | 198 | ||
| 272 | impl<SPI, DC> WriteOnlyDataCommand for SPIDeviceInterface<SPI, DC> | 199 | impl<SPI, DC> WriteOnlyDataCommand for SPIDeviceInterface<SPI, DC> |
| 273 | where | 200 | where |
| 274 | SPI: SpiDevice, | 201 | SPI: SpiDeviceWrite, |
| 275 | SPI::Bus: SpiBusWrite, | ||
| 276 | DC: OutputPin, | 202 | DC: OutputPin, |
| 277 | { | 203 | { |
| 278 | fn send_commands(&mut self, cmds: DataFormat<'_>) -> Result<(), DisplayError> { | 204 | fn send_commands(&mut self, cmds: DataFormat<'_>) -> Result<(), DisplayError> { |
| 279 | let r = self.spi.transaction(|bus| { | 205 | // 1 = data, 0 = command |
| 280 | // 1 = data, 0 = command | 206 | self.dc.set_low().map_err(|_| DisplayError::DCError)?; |
| 281 | if let Err(_) = self.dc.set_low() { | ||
| 282 | return Ok(Err(DisplayError::DCError)); | ||
| 283 | } | ||
| 284 | |||
| 285 | // Send words over SPI | ||
| 286 | send_u8(bus, cmds)?; | ||
| 287 | 207 | ||
| 288 | Ok(Ok(())) | 208 | send_u8(&mut self.spi, cmds).map_err(|_| DisplayError::BusWriteError)?; |
| 289 | }); | 209 | Ok(()) |
| 290 | r.map_err(|_| DisplayError::BusWriteError)? | ||
| 291 | } | 210 | } |
| 292 | 211 | ||
| 293 | fn send_data(&mut self, buf: DataFormat<'_>) -> Result<(), DisplayError> { | 212 | fn send_data(&mut self, buf: DataFormat<'_>) -> Result<(), DisplayError> { |
| 294 | let r = self.spi.transaction(|bus| { | 213 | // 1 = data, 0 = command |
| 295 | // 1 = data, 0 = command | 214 | self.dc.set_high().map_err(|_| DisplayError::DCError)?; |
| 296 | if let Err(_) = self.dc.set_high() { | ||
| 297 | return Ok(Err(DisplayError::DCError)); | ||
| 298 | } | ||
| 299 | |||
| 300 | // Send words over SPI | ||
| 301 | send_u8(bus, buf)?; | ||
| 302 | 215 | ||
| 303 | Ok(Ok(())) | 216 | send_u8(&mut self.spi, buf).map_err(|_| DisplayError::BusWriteError)?; |
| 304 | }); | 217 | Ok(()) |
| 305 | r.map_err(|_| DisplayError::BusWriteError)? | ||
| 306 | } | 218 | } |
| 307 | } | 219 | } |
| 308 | 220 | ||
| 309 | fn send_u8<T: SpiBusWrite>(spi: &mut T, words: DataFormat<'_>) -> Result<(), T::Error> { | 221 | fn send_u8<T: SpiDeviceWrite>(spi: &mut T, words: DataFormat<'_>) -> Result<(), T::Error> { |
| 310 | match words { | 222 | match words { |
| 311 | DataFormat::U8(slice) => spi.write(slice), | 223 | DataFormat::U8(slice) => spi.write(slice), |
| 312 | DataFormat::U16(slice) => { | 224 | DataFormat::U16(slice) => { |
diff --git a/examples/stm32f1/Cargo.toml b/examples/stm32f1/Cargo.toml index 387af783a..99f37cdda 100644 --- a/examples/stm32f1/Cargo.toml +++ b/examples/stm32f1/Cargo.toml | |||
| @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" | |||
| 8 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any", "unstable-traits" ] } |
| 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 13 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 13 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 14 | 14 | ||
diff --git a/examples/stm32h5/Cargo.toml b/examples/stm32h5/Cargo.toml index 70702863f..f240c3896 100644 --- a/examples/stm32h5/Cargo.toml +++ b/examples/stm32h5/Cargo.toml | |||
| @@ -19,8 +19,8 @@ defmt-rtt = "0.4" | |||
| 19 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | 19 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } |
| 20 | cortex-m-rt = "0.7.0" | 20 | cortex-m-rt = "0.7.0" |
| 21 | embedded-hal = "0.2.6" | 21 | embedded-hal = "0.2.6" |
| 22 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } | 22 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" } |
| 23 | embedded-hal-async = { version = "=0.2.0-alpha.0" } | 23 | embedded-hal-async = { version = "=0.2.0-alpha.1" } |
| 24 | embedded-nal-async = "0.4.0" | 24 | embedded-nal-async = "0.4.0" |
| 25 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 25 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
| 26 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 26 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml index d0d6a9497..154f5a987 100644 --- a/examples/stm32h7/Cargo.toml +++ b/examples/stm32h7/Cargo.toml | |||
| @@ -19,8 +19,8 @@ defmt-rtt = "0.4" | |||
| 19 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | 19 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } |
| 20 | cortex-m-rt = "0.7.0" | 20 | cortex-m-rt = "0.7.0" |
| 21 | embedded-hal = "0.2.6" | 21 | embedded-hal = "0.2.6" |
| 22 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } | 22 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" } |
| 23 | embedded-hal-async = { version = "=0.2.0-alpha.0" } | 23 | embedded-hal-async = { version = "=0.2.0-alpha.1" } |
| 24 | embedded-nal-async = "0.4.0" | 24 | embedded-nal-async = "0.4.0" |
| 25 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 25 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
| 26 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 26 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index 7c254eba3..fa39df6db 100644 --- a/examples/stm32l4/Cargo.toml +++ b/examples/stm32l4/Cargo.toml | |||
| @@ -18,8 +18,8 @@ defmt-rtt = "0.4" | |||
| 18 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | 18 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } |
| 19 | cortex-m-rt = "0.7.0" | 19 | cortex-m-rt = "0.7.0" |
| 20 | embedded-hal = "0.2.6" | 20 | embedded-hal = "0.2.6" |
| 21 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } | 21 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" } |
| 22 | embedded-hal-async = { version = "=0.2.0-alpha.0" } | 22 | embedded-hal-async = { version = "=0.2.0-alpha.1" } |
| 23 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 23 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
| 24 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 24 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 25 | heapless = { version = "0.7.5", default-features = false } | 25 | heapless = { version = "0.7.5", default-features = false } |
diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml index eb447be35..463a370fe 100644 --- a/tests/rp/Cargo.toml +++ b/tests/rp/Cargo.toml | |||
| @@ -17,8 +17,8 @@ defmt-rtt = "0.4" | |||
| 17 | cortex-m = { version = "0.7.6" } | 17 | cortex-m = { version = "0.7.6" } |
| 18 | cortex-m-rt = "0.7.0" | 18 | cortex-m-rt = "0.7.0" |
| 19 | embedded-hal = "0.2.6" | 19 | embedded-hal = "0.2.6" |
| 20 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } | 20 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" } |
| 21 | embedded-hal-async = { version = "=0.2.0-alpha.0" } | 21 | embedded-hal-async = { version = "=0.2.0-alpha.1" } |
| 22 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | 22 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } |
| 23 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 23 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 24 | embedded-io = { version = "0.4.0", features = ["async"] } | 24 | embedded-io = { version = "0.4.0", features = ["async"] } |
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index 17b640797..6070a5a87 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml | |||
| @@ -25,8 +25,8 @@ defmt-rtt = "0.4" | |||
| 25 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | 25 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } |
| 26 | cortex-m-rt = "0.7.0" | 26 | cortex-m-rt = "0.7.0" |
| 27 | embedded-hal = "0.2.6" | 27 | embedded-hal = "0.2.6" |
| 28 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } | 28 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" } |
| 29 | embedded-hal-async = { version = "=0.2.0-alpha.0" } | 29 | embedded-hal-async = { version = "=0.2.0-alpha.1" } |
| 30 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | 30 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } |
| 31 | 31 | ||
| 32 | [profile.dev] | 32 | [profile.dev] |
