aboutsummaryrefslogtreecommitdiff
path: root/embassy-embedded-hal
diff options
context:
space:
mode:
authorHenrik Alsér <[email protected]>2022-07-10 00:05:57 +0200
committerHenrik Alsér <[email protected]>2022-07-10 00:05:57 +0200
commitef24faf2df594d0eca1542ac02834af6aafa3853 (patch)
tree6092b31b84be58e3c54b5bddef12bded57d69e2a /embassy-embedded-hal
parent20f56b856feb3cefde300b76ceab85b6bd29c5a7 (diff)
Add asynch mod to shared_bus
Diffstat (limited to 'embassy-embedded-hal')
-rw-r--r--embassy-embedded-hal/src/lib.rs2
-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.rs3
-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.rs2
-rw-r--r--embassy-embedded-hal/src/shared_bus/blocking/spi.rs2
-rw-r--r--embassy-embedded-hal/src/shared_bus/mod.rs18
7 files changed, 44 insertions, 44 deletions
diff --git a/embassy-embedded-hal/src/lib.rs b/embassy-embedded-hal/src/lib.rs
index 688d0b48d..f57d83b5c 100644
--- a/embassy-embedded-hal/src/lib.rs
+++ b/embassy-embedded-hal/src/lib.rs
@@ -2,7 +2,9 @@
2#![feature(generic_associated_types)] 2#![feature(generic_associated_types)]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5#[cfg(feature = "nightly")]
5pub mod adapter; 6pub mod adapter;
7
6pub mod shared_bus; 8pub mod shared_bus;
7 9
8pub trait SetConfig { 10pub trait SetConfig {
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
28use embassy::blocking_mutex::raw::RawMutex; 28use embassy::blocking_mutex::raw::RawMutex;
29use embassy::mutex::Mutex; 29use embassy::mutex::Mutex;
30#[cfg(feature = "nightly")]
31use embedded_hal_async::i2c; 30use embedded_hal_async::i2c;
32 31
32use crate::shared_bus::I2cBusDeviceError;
33use crate::SetConfig; 33use crate::SetConfig;
34 34
35#[derive(Copy, Clone, Eq, PartialEq, Debug)] 35pub struct I2cBusDevice<'a, M: RawMutex, BUS> {
36pub enum I2cBusDeviceError<BUS> { 36 bus: &'a Mutex<M, BUS>,
37 I2c(BUS), 37}
38
39impl<'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
40impl<BUS> i2c::Error for I2cBusDeviceError<BUS> 45impl<BUS> i2c::Error for I2cBusDeviceError<BUS>
@@ -48,16 +53,6 @@ where
48 } 53 }
49} 54}
50 55
51pub struct I2cBusDevice<'a, M: RawMutex, BUS> {
52 bus: &'a Mutex<M, BUS>,
53}
54
55impl<'a, M: RawMutex, BUS> I2cBusDevice<'a, M, BUS> {
56 pub fn new(bus: &'a Mutex<M, BUS>) -> Self {
57 Self { bus }
58 }
59}
60
61impl<'a, M: RawMutex, BUS> i2c::ErrorType for I2cBusDevice<'a, M, BUS> 56impl<'a, M: RawMutex, BUS> i2c::ErrorType for I2cBusDevice<'a, M, BUS>
62where 57where
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")]
69impl<M, BUS> i2c::I2c for I2cBusDevice<'_, M, BUS> 63impl<M, BUS> i2c::I2c for I2cBusDevice<'_, M, BUS>
70where 64where
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")]
145impl<M, BUS> i2c::I2c for I2cBusDeviceWithConfig<'_, M, BUS> 138impl<M, BUS> i2c::I2c for I2cBusDeviceWithConfig<'_, M, BUS>
146where 139where
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
2pub mod i2c;
3pub 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;
32use embassy::mutex::Mutex; 32use embassy::mutex::Mutex;
33use embedded_hal_1::digital::blocking::OutputPin; 33use embedded_hal_1::digital::blocking::OutputPin;
34use embedded_hal_1::spi::ErrorType; 34use embedded_hal_1::spi::ErrorType;
35#[cfg(feature = "nightly")]
36use embedded_hal_async::spi; 35use embedded_hal_async::spi;
37 36
37use crate::shared_bus::SpiBusDeviceError;
38use crate::SetConfig; 38use crate::SetConfig;
39 39
40#[derive(Copy, Clone, Eq, PartialEq, Debug)]
41pub enum SpiBusDeviceError<BUS, CS> {
42 Spi(BUS),
43 Cs(CS),
44}
45
46impl<BUS, CS> spi::Error for SpiBusDeviceError<BUS, CS>
47where
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
59pub struct SpiBusDevice<'a, M: RawMutex, BUS, CS> { 40pub 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")] 59impl<BUS, CS> spi::Error for SpiBusDeviceError<BUS, CS>
60where
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
79impl<M, BUS, CS> spi::SpiDevice for SpiBusDevice<'_, M, BUS, CS> 72impl<M, BUS, CS> spi::SpiDevice for SpiBusDevice<'_, M, BUS, CS>
80where 73where
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")]
139impl<M, BUS, CS> spi::SpiDevice for SpiBusDeviceWithConfig<'_, M, BUS, CS> 131impl<M, BUS, CS> spi::SpiDevice for SpiBusDeviceWithConfig<'_, M, BUS, CS>
140where 132where
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;
23use embedded_hal_1::i2c::blocking::{I2c, Operation}; 23use embedded_hal_1::i2c::blocking::{I2c, Operation};
24use embedded_hal_1::i2c::ErrorType; 24use embedded_hal_1::i2c::ErrorType;
25 25
26use crate::shared_bus::i2c::I2cBusDeviceError; 26use crate::shared_bus::I2cBusDeviceError;
27use crate::SetConfig; 27use crate::SetConfig;
28 28
29pub struct I2cBusDevice<'a, M: RawMutex, BUS> { 29pub 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;
26use embedded_hal_1::spi; 26use embedded_hal_1::spi;
27use embedded_hal_1::spi::blocking::{SpiBusFlush, SpiDevice}; 27use embedded_hal_1::spi::blocking::{SpiBusFlush, SpiDevice};
28 28
29use crate::shared_bus::spi::SpiBusDeviceError; 29use crate::shared_bus::SpiBusDeviceError;
30use crate::SetConfig; 30use crate::SetConfig;
31 31
32pub struct SpiBusDevice<'a, M: RawMutex, BUS, CS> { 32pub 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")]
3pub mod asynch;
4
2pub mod blocking; 5pub mod blocking;
3/// Shared i2c bus implementation for embedded-hal-async 6
4pub mod i2c; 7#[derive(Copy, Clone, Eq, PartialEq, Debug)]
5/// Shared SPI bus implementation for embedded-hal-async 8pub enum I2cBusDeviceError<BUS> {
6pub mod spi; 9 I2c(BUS),
10}
11
12#[derive(Copy, Clone, Eq, PartialEq, Debug)]
13pub enum SpiBusDeviceError<BUS, CS> {
14 Spi(BUS),
15 Cs(CS),
16}