Add asynch mod to shared_bus
This commit is contained in:
parent
20f56b856f
commit
ef24faf2df
7 changed files with 44 additions and 44 deletions
|
@ -2,7 +2,9 @@
|
||||||
#![feature(generic_associated_types)]
|
#![feature(generic_associated_types)]
|
||||||
#![feature(type_alias_impl_trait)]
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
pub mod adapter;
|
pub mod adapter;
|
||||||
|
|
||||||
pub mod shared_bus;
|
pub mod shared_bus;
|
||||||
|
|
||||||
pub trait SetConfig {
|
pub trait SetConfig {
|
||||||
|
|
|
@ -27,14 +27,19 @@ use core::future::Future;
|
||||||
|
|
||||||
use embassy::blocking_mutex::raw::RawMutex;
|
use embassy::blocking_mutex::raw::RawMutex;
|
||||||
use embassy::mutex::Mutex;
|
use embassy::mutex::Mutex;
|
||||||
#[cfg(feature = "nightly")]
|
|
||||||
use embedded_hal_async::i2c;
|
use embedded_hal_async::i2c;
|
||||||
|
|
||||||
|
use crate::shared_bus::I2cBusDeviceError;
|
||||||
use crate::SetConfig;
|
use crate::SetConfig;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
pub struct I2cBusDevice<'a, M: RawMutex, BUS> {
|
||||||
pub enum I2cBusDeviceError<BUS> {
|
bus: &'a Mutex<M, BUS>,
|
||||||
I2c(BUS),
|
}
|
||||||
|
|
||||||
|
impl<'a, M: RawMutex, BUS> I2cBusDevice<'a, M, BUS> {
|
||||||
|
pub fn new(bus: &'a Mutex<M, BUS>) -> Self {
|
||||||
|
Self { bus }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BUS> i2c::Error for I2cBusDeviceError<BUS>
|
impl<BUS> i2c::Error for I2cBusDeviceError<BUS>
|
||||||
|
@ -48,16 +53,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct I2cBusDevice<'a, M: RawMutex, BUS> {
|
|
||||||
bus: &'a Mutex<M, BUS>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, M: RawMutex, BUS> I2cBusDevice<'a, M, BUS> {
|
|
||||||
pub fn new(bus: &'a Mutex<M, BUS>) -> Self {
|
|
||||||
Self { bus }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, M: RawMutex, BUS> i2c::ErrorType for I2cBusDevice<'a, M, BUS>
|
impl<'a, M: RawMutex, BUS> i2c::ErrorType for I2cBusDevice<'a, M, BUS>
|
||||||
where
|
where
|
||||||
BUS: i2c::ErrorType,
|
BUS: i2c::ErrorType,
|
||||||
|
@ -65,7 +60,6 @@ where
|
||||||
type Error = I2cBusDeviceError<BUS::Error>;
|
type Error = I2cBusDeviceError<BUS::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "nightly")]
|
|
||||||
impl<M, BUS> i2c::I2c for I2cBusDevice<'_, M, BUS>
|
impl<M, BUS> i2c::I2c for I2cBusDevice<'_, M, BUS>
|
||||||
where
|
where
|
||||||
M: RawMutex + 'static,
|
M: RawMutex + 'static,
|
||||||
|
@ -141,7 +135,6 @@ where
|
||||||
type Error = I2cBusDeviceError<BUS::Error>;
|
type Error = I2cBusDeviceError<BUS::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "nightly")]
|
|
||||||
impl<M, BUS> i2c::I2c for I2cBusDeviceWithConfig<'_, M, BUS>
|
impl<M, BUS> i2c::I2c for I2cBusDeviceWithConfig<'_, M, BUS>
|
||||||
where
|
where
|
||||||
M: RawMutex + 'static,
|
M: RawMutex + 'static,
|
3
embassy-embedded-hal/src/shared_bus/asynch/mod.rs
Normal file
3
embassy-embedded-hal/src/shared_bus/asynch/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
//! Asynchronous shared bus implementations for embedded-hal-async
|
||||||
|
pub mod i2c;
|
||||||
|
pub mod spi;
|
|
@ -32,30 +32,11 @@ use embassy::blocking_mutex::raw::RawMutex;
|
||||||
use embassy::mutex::Mutex;
|
use embassy::mutex::Mutex;
|
||||||
use embedded_hal_1::digital::blocking::OutputPin;
|
use embedded_hal_1::digital::blocking::OutputPin;
|
||||||
use embedded_hal_1::spi::ErrorType;
|
use embedded_hal_1::spi::ErrorType;
|
||||||
#[cfg(feature = "nightly")]
|
|
||||||
use embedded_hal_async::spi;
|
use embedded_hal_async::spi;
|
||||||
|
|
||||||
|
use crate::shared_bus::SpiBusDeviceError;
|
||||||
use crate::SetConfig;
|
use crate::SetConfig;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
|
||||||
pub enum SpiBusDeviceError<BUS, CS> {
|
|
||||||
Spi(BUS),
|
|
||||||
Cs(CS),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<BUS, CS> spi::Error for SpiBusDeviceError<BUS, CS>
|
|
||||||
where
|
|
||||||
BUS: spi::Error + Debug,
|
|
||||||
CS: Debug,
|
|
||||||
{
|
|
||||||
fn kind(&self) -> spi::ErrorKind {
|
|
||||||
match self {
|
|
||||||
Self::Spi(e) => e.kind(),
|
|
||||||
Self::Cs(_) => spi::ErrorKind::Other,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct SpiBusDevice<'a, M: RawMutex, BUS, CS> {
|
pub struct SpiBusDevice<'a, M: RawMutex, BUS, CS> {
|
||||||
bus: &'a Mutex<M, BUS>,
|
bus: &'a Mutex<M, BUS>,
|
||||||
cs: CS,
|
cs: CS,
|
||||||
|
@ -75,7 +56,19 @@ where
|
||||||
type Error = SpiBusDeviceError<BUS::Error, CS::Error>;
|
type Error = SpiBusDeviceError<BUS::Error, CS::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "nightly")]
|
impl<BUS, CS> spi::Error for SpiBusDeviceError<BUS, CS>
|
||||||
|
where
|
||||||
|
BUS: spi::Error + Debug,
|
||||||
|
CS: Debug,
|
||||||
|
{
|
||||||
|
fn kind(&self) -> spi::ErrorKind {
|
||||||
|
match self {
|
||||||
|
Self::Spi(e) => e.kind(),
|
||||||
|
Self::Cs(_) => spi::ErrorKind::Other,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<M, BUS, CS> spi::SpiDevice for SpiBusDevice<'_, M, BUS, CS>
|
impl<M, BUS, CS> spi::SpiDevice for SpiBusDevice<'_, M, BUS, CS>
|
||||||
where
|
where
|
||||||
M: RawMutex + 'static,
|
M: RawMutex + 'static,
|
||||||
|
@ -135,7 +128,6 @@ where
|
||||||
type Error = SpiBusDeviceError<BUS::Error, CS::Error>;
|
type Error = SpiBusDeviceError<BUS::Error, CS::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "nightly")]
|
|
||||||
impl<M, BUS, CS> spi::SpiDevice for SpiBusDeviceWithConfig<'_, M, BUS, CS>
|
impl<M, BUS, CS> spi::SpiDevice for SpiBusDeviceWithConfig<'_, M, BUS, CS>
|
||||||
where
|
where
|
||||||
M: RawMutex + 'static,
|
M: RawMutex + 'static,
|
|
@ -23,7 +23,7 @@ use embassy::blocking_mutex::Mutex;
|
||||||
use embedded_hal_1::i2c::blocking::{I2c, Operation};
|
use embedded_hal_1::i2c::blocking::{I2c, Operation};
|
||||||
use embedded_hal_1::i2c::ErrorType;
|
use embedded_hal_1::i2c::ErrorType;
|
||||||
|
|
||||||
use crate::shared_bus::i2c::I2cBusDeviceError;
|
use crate::shared_bus::I2cBusDeviceError;
|
||||||
use crate::SetConfig;
|
use crate::SetConfig;
|
||||||
|
|
||||||
pub struct I2cBusDevice<'a, M: RawMutex, BUS> {
|
pub struct I2cBusDevice<'a, M: RawMutex, BUS> {
|
||||||
|
|
|
@ -26,7 +26,7 @@ use embedded_hal_1::digital::blocking::OutputPin;
|
||||||
use embedded_hal_1::spi;
|
use embedded_hal_1::spi;
|
||||||
use embedded_hal_1::spi::blocking::{SpiBusFlush, SpiDevice};
|
use embedded_hal_1::spi::blocking::{SpiBusFlush, SpiDevice};
|
||||||
|
|
||||||
use crate::shared_bus::spi::SpiBusDeviceError;
|
use crate::shared_bus::SpiBusDeviceError;
|
||||||
use crate::SetConfig;
|
use crate::SetConfig;
|
||||||
|
|
||||||
pub struct SpiBusDevice<'a, M: RawMutex, BUS, CS> {
|
pub struct SpiBusDevice<'a, M: RawMutex, BUS, CS> {
|
||||||
|
|
|
@ -1,6 +1,16 @@
|
||||||
//! Shared bus implementations
|
//! Shared bus implementations
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
|
pub mod asynch;
|
||||||
|
|
||||||
pub mod blocking;
|
pub mod blocking;
|
||||||
/// Shared i2c bus implementation for embedded-hal-async
|
|
||||||
pub mod i2c;
|
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||||
/// Shared SPI bus implementation for embedded-hal-async
|
pub enum I2cBusDeviceError<BUS> {
|
||||||
pub mod spi;
|
I2c(BUS),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||||
|
pub enum SpiBusDeviceError<BUS, CS> {
|
||||||
|
Spi(BUS),
|
||||||
|
Cs(CS),
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue