Skip to content

Commit bac1603

Browse files
committed
Remove futures::i2c::Transactional and remove required min_type_alias_impl_trait feature as a result
1 parent 6298952 commit bac1603

File tree

2 files changed

+8
-73
lines changed

2 files changed

+8
-73
lines changed

src/futures/i2c.rs

Lines changed: 7 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
//! Since 7-bit addressing is the mode of the majority of I2C devices,
1717
//! `SevenBitAddress` has been set as default mode and thus can be omitted if desired.
1818
19-
use core::future::Future;
20-
pub use crate::blocking::i2c::{AddressMode, SevenBitAddress, TenBitAddress, Operation};
19+
use core::{future::Future, mem::MaybeUninit};
20+
pub use crate::blocking::i2c::{AddressMode, SevenBitAddress, TenBitAddress};
2121

2222
/// Async read
2323
pub trait Read<A: AddressMode = SevenBitAddress> {
@@ -46,7 +46,7 @@ pub trait Read<A: AddressMode = SevenBitAddress> {
4646
/// - `MAK` = master acknowledge
4747
/// - `NMAK` = master no acknowledge
4848
/// - `SP` = stop condition
49-
fn read<'a>(&'a mut self, address: A, buffer: &'a mut [u8]) -> Self::ReadFuture<'a>;
49+
fn read<'a>(&'a mut self, address: A, read: &'a mut [MaybeUninit<u8>]) -> Self::ReadFuture<'a>;
5050
}
5151

5252
/// Async write
@@ -74,7 +74,7 @@ pub trait Write<A: AddressMode = SevenBitAddress> {
7474
/// - `SAK` = slave acknowledge
7575
/// - `Bi` = ith byte of data
7676
/// - `SP` = stop condition
77-
fn write<'a>(&'a mut self, address: A, bytes: &'a [u8]) -> Self::WriteFuture<'a>;
77+
fn write<'a>(&'a mut self, address: A, write: &'a [u8]) -> Self::WriteFuture<'a>;
7878
}
7979

8080
/// Async write + read
@@ -86,7 +86,7 @@ pub trait WriteRead<A: AddressMode = SevenBitAddress> {
8686
where
8787
Self: 'a;
8888

89-
/// Writes bytes to slave with address `address` and then reads enough bytes to fill `buffer` *in a
89+
/// Writes bytes to slave with address `address` and then reads enough bytes to fill `read` *in a
9090
/// single transaction*
9191
///
9292
/// # I2C Events (contract)
@@ -111,72 +111,7 @@ pub trait WriteRead<A: AddressMode = SevenBitAddress> {
111111
fn write_read<'a>(
112112
&'a mut self,
113113
address: A,
114-
bytes: &'a [u8],
115-
buffer: &'a mut [u8],
114+
write: &'a [u8],
115+
read: &'a mut [MaybeUninit<u8>],
116116
) -> Self::WriteReadFuture<'a>;
117117
}
118-
119-
/// Transactional I2C interface.
120-
///
121-
/// This allows combining operations within an I2C transaction.
122-
pub trait Transactional<A: AddressMode = SevenBitAddress> {
123-
/// Error type
124-
type Error;
125-
/// The future associated with the `exec` method.
126-
type ExecFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
127-
where
128-
Self: 'a;
129-
130-
/// Execute the provided operations on the I2C bus.
131-
///
132-
/// Transaction contract:
133-
/// - Before executing the first operation an ST is sent automatically. This is followed by SAD+R/W as appropriate.
134-
/// - Data from adjacent operations of the same type are sent after each other without an SP or SR.
135-
/// - Between adjacent operations of a different type an SR and SAD+R/W is sent.
136-
/// - After executing the last operation an SP is sent automatically.
137-
/// - If the last operation is a `Read` the master does not send an acknowledge for the last byte.
138-
///
139-
/// - `ST` = start condition
140-
/// - `SAD+R/W` = slave address followed by bit 1 to indicate reading or 0 to indicate writing
141-
/// - `SR` = repeated start condition
142-
/// - `SP` = stop condition
143-
fn exec<'a>(&'a mut self, address: A, operations: &'a mut [Operation<'a>])
144-
-> Self::ExecFuture<'a>;
145-
}
146-
147-
/// Default implementation of `futures::i2c::Transactional` for `futures::i2c::{Read, Write}` implementers.
148-
///
149-
/// If you implement `futures::i2c::Read` and `futures::i2c::Write` for your I2C peripheral,
150-
/// you can use this default implementation so to automatically implement
151-
/// `futures::i2c::Transactional` as well.
152-
pub mod transactional {
153-
use super::{Future, AddressMode, Operation, Read, Transactional, Write};
154-
155-
/// Default implementation of `futures::i2c::Write`, `futures::i2c::Read` and
156-
/// `futures::i2c::WriteRead` traits for `futures::i2c::Transactional` implementers.
157-
pub trait Default<A: AddressMode>: Read<A> + Write<A> {}
158-
159-
impl<A, E, S> Transactional<A> for S
160-
where
161-
A: AddressMode + Copy + 'static,
162-
S: Default<A> + Read<A, Error = E> + Write<A, Error = E>,
163-
E: 'static,
164-
{
165-
type Error = E;
166-
167-
type ExecFuture<'a> where Self: 'a = impl Future<Output = Result<(), Self::Error>> + 'a;
168-
169-
fn exec<'a>(&'a mut self, address: A, operations: &'a mut [Operation<'a>]) -> Self::ExecFuture<'a> {
170-
async move {
171-
for op in operations {
172-
match op {
173-
Operation::Read(buffer) => self.read(address, buffer).await?,
174-
Operation::Write(buffer) => self.write(address, buffer).await?,
175-
}
176-
}
177-
178-
Ok(())
179-
}
180-
}
181-
}
182-
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@
407407
#![doc(html_root_url = "https://docs.rs/embedded-hal/1.0.0-alpha.4")]
408408
#![deny(missing_docs)]
409409
#![no_std]
410-
#![cfg_attr(feature = "unstable-futures", feature(generic_associated_types, min_type_alias_impl_trait))]
410+
#![cfg_attr(feature = "unstable-futures", feature(generic_associated_types))]
411411

412412
pub mod blocking;
413413
pub mod fmt;

0 commit comments

Comments
 (0)