diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-06-12 22:15:44 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-06-12 22:22:31 +0200 |
| commit | a8703b75988e1e700af701116464025679d2feb8 (patch) | |
| tree | f4ec5de70ec05e793a774049e010935ac45853ed /embassy-embedded-hal/src | |
| parent | 6199bdea710cde33e5d5381b6d6abfc8af46df19 (diff) | |
Run rustfmt.
Diffstat (limited to 'embassy-embedded-hal/src')
| -rw-r--r-- | embassy-embedded-hal/src/adapter.rs | 19 | ||||
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/i2c.rs | 12 | ||||
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/spi.rs | 5 |
3 files changed, 13 insertions, 23 deletions
diff --git a/embassy-embedded-hal/src/adapter.rs b/embassy-embedded-hal/src/adapter.rs index 033efb7ef..7d25d89fc 100644 --- a/embassy-embedded-hal/src/adapter.rs +++ b/embassy-embedded-hal/src/adapter.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use core::future::Future; | 1 | use core::future::Future; |
| 2 | use embedded_hal_02::blocking; | 2 | |
| 3 | use embedded_hal_02::serial; | 3 | use embedded_hal_02::{blocking, serial}; |
| 4 | 4 | ||
| 5 | /// BlockingAsync is a wrapper that implements async traits using blocking peripherals. This allows | 5 | /// BlockingAsync is a wrapper that implements async traits using blocking peripherals. This allows |
| 6 | /// driver writers to depend on the async traits while still supporting embedded-hal peripheral implementations. | 6 | /// driver writers to depend on the async traits while still supporting embedded-hal peripheral implementations. |
| @@ -25,9 +25,7 @@ impl<T> BlockingAsync<T> { | |||
| 25 | impl<T, E> embedded_hal_1::i2c::ErrorType for BlockingAsync<T> | 25 | impl<T, E> embedded_hal_1::i2c::ErrorType for BlockingAsync<T> |
| 26 | where | 26 | where |
| 27 | E: embedded_hal_1::i2c::Error + 'static, | 27 | E: embedded_hal_1::i2c::Error + 'static, |
| 28 | T: blocking::i2c::WriteRead<Error = E> | 28 | T: blocking::i2c::WriteRead<Error = E> + blocking::i2c::Read<Error = E> + blocking::i2c::Write<Error = E>, |
| 29 | + blocking::i2c::Read<Error = E> | ||
| 30 | + blocking::i2c::Write<Error = E>, | ||
| 31 | { | 29 | { |
| 32 | type Error = E; | 30 | type Error = E; |
| 33 | } | 31 | } |
| @@ -35,9 +33,7 @@ where | |||
| 35 | impl<T, E> embedded_hal_async::i2c::I2c for BlockingAsync<T> | 33 | impl<T, E> embedded_hal_async::i2c::I2c for BlockingAsync<T> |
| 36 | where | 34 | where |
| 37 | E: embedded_hal_1::i2c::Error + 'static, | 35 | E: embedded_hal_1::i2c::Error + 'static, |
| 38 | T: blocking::i2c::WriteRead<Error = E> | 36 | T: blocking::i2c::WriteRead<Error = E> + blocking::i2c::Read<Error = E> + blocking::i2c::Write<Error = E>, |
| 39 | + blocking::i2c::Read<Error = E> | ||
| 40 | + blocking::i2c::Write<Error = E>, | ||
| 41 | { | 37 | { |
| 42 | type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; | 38 | type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; |
| 43 | type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; | 39 | type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; |
| @@ -51,12 +47,7 @@ where | |||
| 51 | async move { self.wrapped.write(address, bytes) } | 47 | async move { self.wrapped.write(address, bytes) } |
| 52 | } | 48 | } |
| 53 | 49 | ||
| 54 | fn write_read<'a>( | 50 | fn write_read<'a>(&'a mut self, address: u8, bytes: &'a [u8], buffer: &'a mut [u8]) -> Self::WriteReadFuture<'a> { |
| 55 | &'a mut self, | ||
| 56 | address: u8, | ||
| 57 | bytes: &'a [u8], | ||
| 58 | buffer: &'a mut [u8], | ||
| 59 | ) -> Self::WriteReadFuture<'a> { | ||
| 60 | async move { self.wrapped.write_read(address, bytes, buffer) } | 51 | async move { self.wrapped.write_read(address, bytes, buffer) } |
| 61 | } | 52 | } |
| 62 | 53 | ||
diff --git a/embassy-embedded-hal/src/shared_bus/i2c.rs b/embassy-embedded-hal/src/shared_bus/i2c.rs index 5a180e897..e8131288a 100644 --- a/embassy-embedded-hal/src/shared_bus/i2c.rs +++ b/embassy-embedded-hal/src/shared_bus/i2c.rs | |||
| @@ -22,7 +22,9 @@ | |||
| 22 | //! let i2c_dev2 = I2cBusDevice::new(i2c_bus); | 22 | //! let i2c_dev2 = I2cBusDevice::new(i2c_bus); |
| 23 | //! let mpu = Mpu6050::new(i2c_dev2); | 23 | //! let mpu = Mpu6050::new(i2c_dev2); |
| 24 | //! ``` | 24 | //! ``` |
| 25 | use core::{fmt::Debug, future::Future}; | 25 | use core::fmt::Debug; |
| 26 | use core::future::Future; | ||
| 27 | |||
| 26 | use embassy::blocking_mutex::raw::RawMutex; | 28 | use embassy::blocking_mutex::raw::RawMutex; |
| 27 | use embassy::mutex::Mutex; | 29 | use embassy::mutex::Mutex; |
| 28 | use embedded_hal_async::i2c; | 30 | use embedded_hal_async::i2c; |
| @@ -70,9 +72,7 @@ where | |||
| 70 | fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { | 72 | fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { |
| 71 | async move { | 73 | async move { |
| 72 | let mut bus = self.bus.lock().await; | 74 | let mut bus = self.bus.lock().await; |
| 73 | bus.read(address, buffer) | 75 | bus.read(address, buffer).await.map_err(I2cBusDeviceError::I2c)?; |
| 74 | .await | ||
| 75 | .map_err(I2cBusDeviceError::I2c)?; | ||
| 76 | Ok(()) | 76 | Ok(()) |
| 77 | } | 77 | } |
| 78 | } | 78 | } |
| @@ -82,9 +82,7 @@ where | |||
| 82 | fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> { | 82 | fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> { |
| 83 | async move { | 83 | async move { |
| 84 | let mut bus = self.bus.lock().await; | 84 | let mut bus = self.bus.lock().await; |
| 85 | bus.write(address, bytes) | 85 | bus.write(address, bytes).await.map_err(I2cBusDeviceError::I2c)?; |
| 86 | .await | ||
| 87 | .map_err(I2cBusDeviceError::I2c)?; | ||
| 88 | Ok(()) | 86 | Ok(()) |
| 89 | } | 87 | } |
| 90 | } | 88 | } |
diff --git a/embassy-embedded-hal/src/shared_bus/spi.rs b/embassy-embedded-hal/src/shared_bus/spi.rs index 3ec064ba7..fd4b6d565 100644 --- a/embassy-embedded-hal/src/shared_bus/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/spi.rs | |||
| @@ -25,10 +25,11 @@ | |||
| 25 | //! let spi_dev2 = SpiBusDevice::new(spi_bus, cs_pin2); | 25 | //! let spi_dev2 = SpiBusDevice::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::{fmt::Debug, future::Future}; | 28 | use core::fmt::Debug; |
| 29 | use core::future::Future; | ||
| 30 | |||
| 29 | use embassy::blocking_mutex::raw::RawMutex; | 31 | use embassy::blocking_mutex::raw::RawMutex; |
| 30 | use embassy::mutex::Mutex; | 32 | use embassy::mutex::Mutex; |
| 31 | |||
| 32 | use embedded_hal_1::digital::blocking::OutputPin; | 33 | use embedded_hal_1::digital::blocking::OutputPin; |
| 33 | use embedded_hal_1::spi::ErrorType; | 34 | use embedded_hal_1::spi::ErrorType; |
| 34 | use embedded_hal_async::spi; | 35 | use embedded_hal_async::spi; |
