Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added
- Implement `PartialOrd`, `Ord`, `Hash` for `can::StandardId`, `can::ExtendedId` and `can::Id` according to CAN bus arbitration rules
- `I2c::software_reset` for resetting all (supported) devices connected to the bus.

### Fixed
- Fixed documentation for `wait_for_rising_edge`.
Expand Down
4 changes: 4 additions & 0 deletions embedded-hal-async/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [v0.1.0-alpha.1] - 2022-05-24

### Added

- `I2c::software_reset` for resetting all (supported) devices connected to the bus.

Comment on lines +12 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be added to the unreleased section

### Changed

- spi: device helper methods (`read`, `write`, `transfer`...) are now default methods in `SpiDevice` instead of an `SpiDeviceExt` extension trait.
Expand Down
10 changes: 10 additions & 0 deletions embedded-hal-async/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
address: A,
operations: &'a mut [Operation<'b>],
) -> Self::TransactionFuture<'a, 'b>;

/// Request a software reset for all devices connected to the I2C bus.
///
/// # Note
///
/// This I2C feature is optional. It depends on each individual device whether or not it responds to this command.
#[inline]
fn software_reset<'a>(&'a mut self) -> Self::WriteFuture<'a> {
self.write(A::GENERAL_CALL_ADDR, &[0x06])
}
}

impl<A: AddressMode, T: I2c<A>> I2c<A> for &mut T {
Expand Down
32 changes: 26 additions & 6 deletions src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@
//! }
//! ```

use crate::private;

/// I2C error
pub trait Error: core::fmt::Debug {
/// Convert error to a generic I2C error kind
Expand Down Expand Up @@ -241,24 +239,36 @@ impl<T: ErrorType> ErrorType for &mut T {
type Error = T::Error;
}

mod private {
pub trait Sealed {}
}

/// Address mode (7-bit / 10-bit)
///
/// Note: This trait is sealed and should not be implemented outside of this crate.
pub trait AddressMode: private::Sealed + 'static {}
pub trait AddressMode: private::Sealed + 'static {
#[doc(hidden)]
const GENERAL_CALL_ADDR: Self;
}

/// 7-bit address mode type
pub type SevenBitAddress = u8;

/// 10-bit address mode type
pub type TenBitAddress = u16;

impl AddressMode for SevenBitAddress {}
impl private::Sealed for SevenBitAddress {}
impl AddressMode for SevenBitAddress {
const GENERAL_CALL_ADDR: Self = 0;
}

impl AddressMode for TenBitAddress {}
impl private::Sealed for TenBitAddress {}
impl AddressMode for TenBitAddress {
const GENERAL_CALL_ADDR: Self = 0;
}

/// Blocking I2C traits
pub mod blocking {

use super::{AddressMode, ErrorType, SevenBitAddress};

/// Transactional I2C operation.
Expand Down Expand Up @@ -400,6 +410,16 @@ pub mod blocking {
fn transaction_iter<'a, O>(&mut self, address: A, operations: O) -> Result<(), Self::Error>
where
O: IntoIterator<Item = Operation<'a>>;

/// Request a software reset for all devices connected to the I2C bus.
///
/// # Note
///
/// This I2C feature is optional. It depends on each individual device whether or not it responds to this command.
#[inline]
fn software_reset(&mut self) -> Result<(), Self::Error> {
self.write(A::GENERAL_CALL_ADDR, &[0x06])
}
}

impl<A: AddressMode, T: I2c<A>> I2c<A> for &mut T {
Expand Down
8 changes: 0 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,3 @@ pub mod digital;
pub mod i2c;
pub mod serial;
pub mod spi;

mod private {
use crate::i2c::{SevenBitAddress, TenBitAddress};
pub trait Sealed {}

impl Sealed for SevenBitAddress {}
impl Sealed for TenBitAddress {}
}