Skip to content

Commit

Permalink
remove checks for reserved I2c addresses
Browse files Browse the repository at this point in the history
There are some non-compliant devices that respond to reserved I2c
addresses. rp2040 behaves sanely for these addresses, so let's just
allow using them.
  • Loading branch information
Freax13 committed Jan 26, 2025
1 parent 51d87c6 commit bb65c7c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
11 changes: 2 additions & 9 deletions embassy-rp/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub enum Error {
/// Target i2c address is out of range
AddressOutOfRange(u16),
/// Target i2c address is reserved
#[deprecated = "embassy_rp no longer prevents accesses to reserved addresses."]
AddressReserved(u16),
}

Expand Down Expand Up @@ -470,10 +471,6 @@ impl<'d, T: Instance + 'd, M: Mode> I2c<'d, T, M> {
return Err(Error::AddressOutOfRange(addr));
}

if i2c_reserved_addr(addr) {
return Err(Error::AddressReserved(addr));
}

let p = T::regs();
p.ic_enable().write(|w| w.set_enable(false));
p.ic_tar().write(|w| w.set_ic_tar(addr));
Expand Down Expand Up @@ -680,6 +677,7 @@ impl embedded_hal_1::i2c::Error for Error {
Self::InvalidReadBufferLength => embedded_hal_1::i2c::ErrorKind::Other,
Self::InvalidWriteBufferLength => embedded_hal_1::i2c::ErrorKind::Other,
Self::AddressOutOfRange(_) => embedded_hal_1::i2c::ErrorKind::Other,
#[allow(deprecated)]
Self::AddressReserved(_) => embedded_hal_1::i2c::ErrorKind::Other,
}
}
Expand Down Expand Up @@ -775,11 +773,6 @@ impl<'d, T: Instance, M: Mode> embassy_embedded_hal::SetConfig for I2c<'d, T, M>
}
}

/// Check if address is reserved.
pub fn i2c_reserved_addr(addr: u16) -> bool {
((addr & 0x78) == 0 || (addr & 0x78) == 0x78) && addr != 0
}

pub(crate) trait SealedInstance {
fn regs() -> crate::pac::i2c::I2c;
fn reset() -> crate::pac::resets::regs::Peripherals;
Expand Down
5 changes: 1 addition & 4 deletions embassy-rp/src/i2c_slave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use core::task::Poll;
use embassy_hal_internal::into_ref;
use pac::i2c;

use crate::i2c::{
i2c_reserved_addr, set_up_i2c_pin, AbortReason, Instance, InterruptHandler, SclPin, SdaPin, FIFO_SIZE,
};
use crate::i2c::{set_up_i2c_pin, AbortReason, Instance, InterruptHandler, SclPin, SdaPin, FIFO_SIZE};
use crate::interrupt::typelevel::{Binding, Interrupt};
use crate::{pac, Peripheral};

Expand Down Expand Up @@ -97,7 +95,6 @@ impl<'d, T: Instance> I2cSlave<'d, T> {
) -> Self {
into_ref!(_peri, scl, sda);

assert!(!i2c_reserved_addr(config.addr));
assert!(config.addr != 0);

// Configure SCL & SDA pins
Expand Down

0 comments on commit bb65c7c

Please sign in to comment.