Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove checks for reserved I2c addresses #3810

Merged
merged 1 commit into from
Jan 26, 2025
Merged
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
13 changes: 4 additions & 9 deletions embassy-rp/src/i2c.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(feature = "defmt", allow(deprecated))] // Suppress warnings for defmt::Format using Error::AddressReserved

//! I2C driver.
use core::future;
use core::marker::PhantomData;
Expand Down Expand Up @@ -40,6 +42,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 +473,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 +679,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 +775,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
Loading