diff options
| author | Henrik Alsér <[email protected]> | 2022-07-10 00:05:57 +0200 |
|---|---|---|
| committer | Henrik Alsér <[email protected]> | 2022-07-10 00:05:57 +0200 |
| commit | ef24faf2df594d0eca1542ac02834af6aafa3853 (patch) | |
| tree | 6092b31b84be58e3c54b5bddef12bded57d69e2a /embassy-embedded-hal/src/shared_bus | |
| parent | 20f56b856feb3cefde300b76ceab85b6bd29c5a7 (diff) | |
Add asynch mod to shared_bus
Diffstat (limited to 'embassy-embedded-hal/src/shared_bus')
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/asynch/i2c.rs (renamed from embassy-embedded-hal/src/shared_bus/i2c.rs) | 25 | ||||
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/asynch/mod.rs | 3 | ||||
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/asynch/spi.rs (renamed from embassy-embedded-hal/src/shared_bus/spi.rs) | 36 | ||||
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/blocking/i2c.rs | 2 | ||||
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/blocking/spi.rs | 2 | ||||
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/mod.rs | 18 |
6 files changed, 42 insertions, 44 deletions
diff --git a/embassy-embedded-hal/src/shared_bus/i2c.rs b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs index f63190e6a..408317490 100644 --- a/embassy-embedded-hal/src/shared_bus/i2c.rs +++ b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs | |||
| @@ -27,14 +27,19 @@ use core::future::Future; | |||
| 27 | 27 | ||
| 28 | use embassy::blocking_mutex::raw::RawMutex; | 28 | use embassy::blocking_mutex::raw::RawMutex; |
| 29 | use embassy::mutex::Mutex; | 29 | use embassy::mutex::Mutex; |
| 30 | #[cfg(feature = "nightly")] | ||
| 31 | use embedded_hal_async::i2c; | 30 | use embedded_hal_async::i2c; |
| 32 | 31 | ||
| 32 | use crate::shared_bus::I2cBusDeviceError; | ||
| 33 | use crate::SetConfig; | 33 | use crate::SetConfig; |
| 34 | 34 | ||
| 35 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | 35 | pub struct I2cBusDevice<'a, M: RawMutex, BUS> { |
| 36 | pub enum I2cBusDeviceError<BUS> { | 36 | bus: &'a Mutex<M, BUS>, |
| 37 | I2c(BUS), | 37 | } |
| 38 | |||
| 39 | impl<'a, M: RawMutex, BUS> I2cBusDevice<'a, M, BUS> { | ||
| 40 | pub fn new(bus: &'a Mutex<M, BUS>) -> Self { | ||
| 41 | Self { bus } | ||
| 42 | } | ||
| 38 | } | 43 | } |
| 39 | 44 | ||
| 40 | impl<BUS> i2c::Error for I2cBusDeviceError<BUS> | 45 | impl<BUS> i2c::Error for I2cBusDeviceError<BUS> |
| @@ -48,16 +53,6 @@ where | |||
| 48 | } | 53 | } |
| 49 | } | 54 | } |
| 50 | 55 | ||
| 51 | pub struct I2cBusDevice<'a, M: RawMutex, BUS> { | ||
| 52 | bus: &'a Mutex<M, BUS>, | ||
| 53 | } | ||
| 54 | |||
| 55 | impl<'a, M: RawMutex, BUS> I2cBusDevice<'a, M, BUS> { | ||
| 56 | pub fn new(bus: &'a Mutex<M, BUS>) -> Self { | ||
| 57 | Self { bus } | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | impl<'a, M: RawMutex, BUS> i2c::ErrorType for I2cBusDevice<'a, M, BUS> | 56 | impl<'a, M: RawMutex, BUS> i2c::ErrorType for I2cBusDevice<'a, M, BUS> |
| 62 | where | 57 | where |
| 63 | BUS: i2c::ErrorType, | 58 | BUS: i2c::ErrorType, |
| @@ -65,7 +60,6 @@ where | |||
| 65 | type Error = I2cBusDeviceError<BUS::Error>; | 60 | type Error = I2cBusDeviceError<BUS::Error>; |
| 66 | } | 61 | } |
| 67 | 62 | ||
| 68 | #[cfg(feature = "nightly")] | ||
| 69 | impl<M, BUS> i2c::I2c for I2cBusDevice<'_, M, BUS> | 63 | impl<M, BUS> i2c::I2c for I2cBusDevice<'_, M, BUS> |
| 70 | where | 64 | where |
| 71 | M: RawMutex + 'static, | 65 | M: RawMutex + 'static, |
| @@ -141,7 +135,6 @@ where | |||
| 141 | type Error = I2cBusDeviceError<BUS::Error>; | 135 | type Error = I2cBusDeviceError<BUS::Error>; |
| 142 | } | 136 | } |
| 143 | 137 | ||
| 144 | #[cfg(feature = "nightly")] | ||
| 145 | impl<M, BUS> i2c::I2c for I2cBusDeviceWithConfig<'_, M, BUS> | 138 | impl<M, BUS> i2c::I2c for I2cBusDeviceWithConfig<'_, M, BUS> |
| 146 | where | 139 | where |
| 147 | M: RawMutex + 'static, | 140 | M: RawMutex + 'static, |
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/mod.rs b/embassy-embedded-hal/src/shared_bus/asynch/mod.rs new file mode 100644 index 000000000..2e660b724 --- /dev/null +++ b/embassy-embedded-hal/src/shared_bus/asynch/mod.rs | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | //! Asynchronous shared bus implementations for embedded-hal-async | ||
| 2 | pub mod i2c; | ||
| 3 | pub mod spi; | ||
diff --git a/embassy-embedded-hal/src/shared_bus/spi.rs b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs index 136352e0a..f3795bb19 100644 --- a/embassy-embedded-hal/src/shared_bus/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs | |||
| @@ -32,30 +32,11 @@ use embassy::blocking_mutex::raw::RawMutex; | |||
| 32 | use embassy::mutex::Mutex; | 32 | use embassy::mutex::Mutex; |
| 33 | use embedded_hal_1::digital::blocking::OutputPin; | 33 | use embedded_hal_1::digital::blocking::OutputPin; |
| 34 | use embedded_hal_1::spi::ErrorType; | 34 | use embedded_hal_1::spi::ErrorType; |
| 35 | #[cfg(feature = "nightly")] | ||
| 36 | use embedded_hal_async::spi; | 35 | use embedded_hal_async::spi; |
| 37 | 36 | ||
| 37 | use crate::shared_bus::SpiBusDeviceError; | ||
| 38 | use crate::SetConfig; | 38 | use crate::SetConfig; |
| 39 | 39 | ||
| 40 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | ||
| 41 | pub enum SpiBusDeviceError<BUS, CS> { | ||
| 42 | Spi(BUS), | ||
| 43 | Cs(CS), | ||
| 44 | } | ||
| 45 | |||
| 46 | impl<BUS, CS> spi::Error for SpiBusDeviceError<BUS, CS> | ||
| 47 | where | ||
| 48 | BUS: spi::Error + Debug, | ||
| 49 | CS: Debug, | ||
| 50 | { | ||
| 51 | fn kind(&self) -> spi::ErrorKind { | ||
| 52 | match self { | ||
| 53 | Self::Spi(e) => e.kind(), | ||
| 54 | Self::Cs(_) => spi::ErrorKind::Other, | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | pub struct SpiBusDevice<'a, M: RawMutex, BUS, CS> { | 40 | pub struct SpiBusDevice<'a, M: RawMutex, BUS, CS> { |
| 60 | bus: &'a Mutex<M, BUS>, | 41 | bus: &'a Mutex<M, BUS>, |
| 61 | cs: CS, | 42 | cs: CS, |
| @@ -75,7 +56,19 @@ where | |||
| 75 | type Error = SpiBusDeviceError<BUS::Error, CS::Error>; | 56 | type Error = SpiBusDeviceError<BUS::Error, CS::Error>; |
| 76 | } | 57 | } |
| 77 | 58 | ||
| 78 | #[cfg(feature = "nightly")] | 59 | impl<BUS, CS> spi::Error for SpiBusDeviceError<BUS, CS> |
| 60 | where | ||
| 61 | BUS: spi::Error + Debug, | ||
| 62 | CS: Debug, | ||
| 63 | { | ||
| 64 | fn kind(&self) -> spi::ErrorKind { | ||
| 65 | match self { | ||
| 66 | Self::Spi(e) => e.kind(), | ||
| 67 | Self::Cs(_) => spi::ErrorKind::Other, | ||
| 68 | } | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 79 | impl<M, BUS, CS> spi::SpiDevice for SpiBusDevice<'_, M, BUS, CS> | 72 | impl<M, BUS, CS> spi::SpiDevice for SpiBusDevice<'_, M, BUS, CS> |
| 80 | where | 73 | where |
| 81 | M: RawMutex + 'static, | 74 | M: RawMutex + 'static, |
| @@ -135,7 +128,6 @@ where | |||
| 135 | type Error = SpiBusDeviceError<BUS::Error, CS::Error>; | 128 | type Error = SpiBusDeviceError<BUS::Error, CS::Error>; |
| 136 | } | 129 | } |
| 137 | 130 | ||
| 138 | #[cfg(feature = "nightly")] | ||
| 139 | impl<M, BUS, CS> spi::SpiDevice for SpiBusDeviceWithConfig<'_, M, BUS, CS> | 131 | impl<M, BUS, CS> spi::SpiDevice for SpiBusDeviceWithConfig<'_, M, BUS, CS> |
| 140 | where | 132 | where |
| 141 | M: RawMutex + 'static, | 133 | M: RawMutex + 'static, |
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs index 0c8338c73..ac361a786 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs | |||
| @@ -23,7 +23,7 @@ use embassy::blocking_mutex::Mutex; | |||
| 23 | use embedded_hal_1::i2c::blocking::{I2c, Operation}; | 23 | use embedded_hal_1::i2c::blocking::{I2c, Operation}; |
| 24 | use embedded_hal_1::i2c::ErrorType; | 24 | use embedded_hal_1::i2c::ErrorType; |
| 25 | 25 | ||
| 26 | use crate::shared_bus::i2c::I2cBusDeviceError; | 26 | use crate::shared_bus::I2cBusDeviceError; |
| 27 | use crate::SetConfig; | 27 | use crate::SetConfig; |
| 28 | 28 | ||
| 29 | pub struct I2cBusDevice<'a, M: RawMutex, BUS> { | 29 | pub struct I2cBusDevice<'a, M: RawMutex, BUS> { |
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs index 456da8859..704858cdb 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs | |||
| @@ -26,7 +26,7 @@ use embedded_hal_1::digital::blocking::OutputPin; | |||
| 26 | use embedded_hal_1::spi; | 26 | use embedded_hal_1::spi; |
| 27 | use embedded_hal_1::spi::blocking::{SpiBusFlush, SpiDevice}; | 27 | use embedded_hal_1::spi::blocking::{SpiBusFlush, SpiDevice}; |
| 28 | 28 | ||
| 29 | use crate::shared_bus::spi::SpiBusDeviceError; | 29 | use crate::shared_bus::SpiBusDeviceError; |
| 30 | use crate::SetConfig; | 30 | use crate::SetConfig; |
| 31 | 31 | ||
| 32 | pub struct SpiBusDevice<'a, M: RawMutex, BUS, CS> { | 32 | pub struct SpiBusDevice<'a, M: RawMutex, BUS, CS> { |
diff --git a/embassy-embedded-hal/src/shared_bus/mod.rs b/embassy-embedded-hal/src/shared_bus/mod.rs index cd748cac8..2309a6c35 100644 --- a/embassy-embedded-hal/src/shared_bus/mod.rs +++ b/embassy-embedded-hal/src/shared_bus/mod.rs | |||
| @@ -1,6 +1,16 @@ | |||
| 1 | //! Shared bus implementations | 1 | //! Shared bus implementations |
| 2 | #[cfg(feature = "nightly")] | ||
| 3 | pub mod asynch; | ||
| 4 | |||
| 2 | pub mod blocking; | 5 | pub mod blocking; |
| 3 | /// Shared i2c bus implementation for embedded-hal-async | 6 | |
| 4 | pub mod i2c; | 7 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] |
| 5 | /// Shared SPI bus implementation for embedded-hal-async | 8 | pub enum I2cBusDeviceError<BUS> { |
| 6 | pub mod spi; | 9 | I2c(BUS), |
| 10 | } | ||
| 11 | |||
| 12 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | ||
| 13 | pub enum SpiBusDeviceError<BUS, CS> { | ||
| 14 | Spi(BUS), | ||
| 15 | Cs(CS), | ||
| 16 | } | ||
