diff options
Diffstat (limited to 'embassy-embedded-hal/src/adapter/blocking_async.rs')
| -rw-r--r-- | embassy-embedded-hal/src/adapter/blocking_async.rs | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/embassy-embedded-hal/src/adapter/blocking_async.rs b/embassy-embedded-hal/src/adapter/blocking_async.rs index bafc31583..3b6e0ec00 100644 --- a/embassy-embedded-hal/src/adapter/blocking_async.rs +++ b/embassy-embedded-hal/src/adapter/blocking_async.rs | |||
| @@ -1,5 +1,3 @@ | |||
| 1 | use embedded_hal_02::blocking; | ||
| 2 | |||
| 3 | /// Wrapper that implements async traits using blocking implementations. | 1 | /// Wrapper that implements async traits using blocking implementations. |
| 4 | /// | 2 | /// |
| 5 | /// This allows driver writers to depend on the async traits while still supporting embedded-hal peripheral implementations. | 3 | /// This allows driver writers to depend on the async traits while still supporting embedded-hal peripheral implementations. |
| @@ -24,7 +22,7 @@ impl<T> BlockingAsync<T> { | |||
| 24 | impl<T, E> embedded_hal_1::i2c::ErrorType for BlockingAsync<T> | 22 | impl<T, E> embedded_hal_1::i2c::ErrorType for BlockingAsync<T> |
| 25 | where | 23 | where |
| 26 | E: embedded_hal_1::i2c::Error + 'static, | 24 | E: embedded_hal_1::i2c::Error + 'static, |
| 27 | T: blocking::i2c::WriteRead<Error = E> + blocking::i2c::Read<Error = E> + blocking::i2c::Write<Error = E>, | 25 | T: embedded_hal_1::i2c::I2c<Error = E>, |
| 28 | { | 26 | { |
| 29 | type Error = E; | 27 | type Error = E; |
| 30 | } | 28 | } |
| @@ -32,7 +30,7 @@ where | |||
| 32 | impl<T, E> embedded_hal_async::i2c::I2c for BlockingAsync<T> | 30 | impl<T, E> embedded_hal_async::i2c::I2c for BlockingAsync<T> |
| 33 | where | 31 | where |
| 34 | E: embedded_hal_1::i2c::Error + 'static, | 32 | E: embedded_hal_1::i2c::Error + 'static, |
| 35 | T: blocking::i2c::WriteRead<Error = E> + blocking::i2c::Read<Error = E> + blocking::i2c::Write<Error = E>, | 33 | T: embedded_hal_1::i2c::I2c<Error = E>, |
| 36 | { | 34 | { |
| 37 | async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { | 35 | async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { |
| 38 | self.wrapped.read(address, read) | 36 | self.wrapped.read(address, read) |
| @@ -51,9 +49,7 @@ where | |||
| 51 | address: u8, | 49 | address: u8, |
| 52 | operations: &mut [embedded_hal_1::i2c::Operation<'_>], | 50 | operations: &mut [embedded_hal_1::i2c::Operation<'_>], |
| 53 | ) -> Result<(), Self::Error> { | 51 | ) -> Result<(), Self::Error> { |
| 54 | let _ = address; | 52 | self.wrapped.transaction(address, operations) |
| 55 | let _ = operations; | ||
| 56 | todo!() | ||
| 57 | } | 53 | } |
| 58 | } | 54 | } |
| 59 | 55 | ||
| @@ -63,16 +59,16 @@ where | |||
| 63 | 59 | ||
| 64 | impl<T, E> embedded_hal_async::spi::ErrorType for BlockingAsync<T> | 60 | impl<T, E> embedded_hal_async::spi::ErrorType for BlockingAsync<T> |
| 65 | where | 61 | where |
| 66 | E: embedded_hal_1::spi::Error, | 62 | E: embedded_hal_async::spi::Error, |
| 67 | T: blocking::spi::Transfer<u8, Error = E> + blocking::spi::Write<u8, Error = E>, | 63 | T: embedded_hal_1::spi::SpiBus<Error = E>, |
| 68 | { | 64 | { |
| 69 | type Error = E; | 65 | type Error = E; |
| 70 | } | 66 | } |
| 71 | 67 | ||
| 72 | impl<T, E> embedded_hal_async::spi::SpiBus<u8> for BlockingAsync<T> | 68 | impl<T, E> embedded_hal_async::spi::SpiBus<u8> for BlockingAsync<T> |
| 73 | where | 69 | where |
| 74 | E: embedded_hal_1::spi::Error + 'static, | 70 | E: embedded_hal_async::spi::Error, |
| 75 | T: blocking::spi::Transfer<u8, Error = E> + blocking::spi::Write<u8, Error = E>, | 71 | T: embedded_hal_1::spi::SpiBus<Error = E>, |
| 76 | { | 72 | { |
| 77 | async fn flush(&mut self) -> Result<(), Self::Error> { | 73 | async fn flush(&mut self) -> Result<(), Self::Error> { |
| 78 | Ok(()) | 74 | Ok(()) |
| @@ -84,21 +80,17 @@ where | |||
| 84 | } | 80 | } |
| 85 | 81 | ||
| 86 | async fn read(&mut self, data: &mut [u8]) -> Result<(), Self::Error> { | 82 | async fn read(&mut self, data: &mut [u8]) -> Result<(), Self::Error> { |
| 87 | self.wrapped.transfer(data)?; | 83 | self.wrapped.read(data)?; |
| 88 | Ok(()) | 84 | Ok(()) |
| 89 | } | 85 | } |
| 90 | 86 | ||
| 91 | async fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Self::Error> { | 87 | async fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Self::Error> { |
| 92 | // Ensure we write the expected bytes | 88 | self.wrapped.transfer(read, write)?; |
| 93 | for i in 0..core::cmp::min(read.len(), write.len()) { | ||
| 94 | read[i] = write[i].clone(); | ||
| 95 | } | ||
| 96 | self.wrapped.transfer(read)?; | ||
| 97 | Ok(()) | 89 | Ok(()) |
| 98 | } | 90 | } |
| 99 | 91 | ||
| 100 | async fn transfer_in_place(&mut self, data: &mut [u8]) -> Result<(), Self::Error> { | 92 | async fn transfer_in_place(&mut self, data: &mut [u8]) -> Result<(), Self::Error> { |
| 101 | self.wrapped.transfer(data)?; | 93 | self.wrapped.transfer_in_place(data)?; |
| 102 | Ok(()) | 94 | Ok(()) |
| 103 | } | 95 | } |
| 104 | } | 96 | } |
