diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-01-26 16:53:17 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-01-26 16:53:17 +0000 |
| commit | 845da2ced1424b86f3159f2f89d8700ad97cbea8 (patch) | |
| tree | 0556b80128da554469bb2c828fabb37ca97c4745 /embassy-rp | |
| parent | 7db46771b8ad14467f759c98d604bfaf9e3b5e01 (diff) | |
| parent | 3e5514653fd13a27b3be504513478503e8b9de2d (diff) | |
Merge pull request #3810 from Freax13/enhancement/invalid-i2c-rp
remove checks for reserved I2c addresses
Diffstat (limited to 'embassy-rp')
| -rw-r--r-- | embassy-rp/src/i2c.rs | 13 | ||||
| -rw-r--r-- | embassy-rp/src/i2c_slave.rs | 5 |
2 files changed, 5 insertions, 13 deletions
diff --git a/embassy-rp/src/i2c.rs b/embassy-rp/src/i2c.rs index 32778215f..3a2ee666c 100644 --- a/embassy-rp/src/i2c.rs +++ b/embassy-rp/src/i2c.rs | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | #![cfg_attr(feature = "defmt", allow(deprecated))] // Suppress warnings for defmt::Format using Error::AddressReserved | ||
| 2 | |||
| 1 | //! I2C driver. | 3 | //! I2C driver. |
| 2 | use core::future; | 4 | use core::future; |
| 3 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| @@ -40,6 +42,7 @@ pub enum Error { | |||
| 40 | /// Target i2c address is out of range | 42 | /// Target i2c address is out of range |
| 41 | AddressOutOfRange(u16), | 43 | AddressOutOfRange(u16), |
| 42 | /// Target i2c address is reserved | 44 | /// Target i2c address is reserved |
| 45 | #[deprecated = "embassy_rp no longer prevents accesses to reserved addresses."] | ||
| 43 | AddressReserved(u16), | 46 | AddressReserved(u16), |
| 44 | } | 47 | } |
| 45 | 48 | ||
| @@ -470,10 +473,6 @@ impl<'d, T: Instance + 'd, M: Mode> I2c<'d, T, M> { | |||
| 470 | return Err(Error::AddressOutOfRange(addr)); | 473 | return Err(Error::AddressOutOfRange(addr)); |
| 471 | } | 474 | } |
| 472 | 475 | ||
| 473 | if i2c_reserved_addr(addr) { | ||
| 474 | return Err(Error::AddressReserved(addr)); | ||
| 475 | } | ||
| 476 | |||
| 477 | let p = T::regs(); | 476 | let p = T::regs(); |
| 478 | p.ic_enable().write(|w| w.set_enable(false)); | 477 | p.ic_enable().write(|w| w.set_enable(false)); |
| 479 | p.ic_tar().write(|w| w.set_ic_tar(addr)); | 478 | p.ic_tar().write(|w| w.set_ic_tar(addr)); |
| @@ -680,6 +679,7 @@ impl embedded_hal_1::i2c::Error for Error { | |||
| 680 | Self::InvalidReadBufferLength => embedded_hal_1::i2c::ErrorKind::Other, | 679 | Self::InvalidReadBufferLength => embedded_hal_1::i2c::ErrorKind::Other, |
| 681 | Self::InvalidWriteBufferLength => embedded_hal_1::i2c::ErrorKind::Other, | 680 | Self::InvalidWriteBufferLength => embedded_hal_1::i2c::ErrorKind::Other, |
| 682 | Self::AddressOutOfRange(_) => embedded_hal_1::i2c::ErrorKind::Other, | 681 | Self::AddressOutOfRange(_) => embedded_hal_1::i2c::ErrorKind::Other, |
| 682 | #[allow(deprecated)] | ||
| 683 | Self::AddressReserved(_) => embedded_hal_1::i2c::ErrorKind::Other, | 683 | Self::AddressReserved(_) => embedded_hal_1::i2c::ErrorKind::Other, |
| 684 | } | 684 | } |
| 685 | } | 685 | } |
| @@ -775,11 +775,6 @@ impl<'d, T: Instance, M: Mode> embassy_embedded_hal::SetConfig for I2c<'d, T, M> | |||
| 775 | } | 775 | } |
| 776 | } | 776 | } |
| 777 | 777 | ||
| 778 | /// Check if address is reserved. | ||
| 779 | pub fn i2c_reserved_addr(addr: u16) -> bool { | ||
| 780 | ((addr & 0x78) == 0 || (addr & 0x78) == 0x78) && addr != 0 | ||
| 781 | } | ||
| 782 | |||
| 783 | pub(crate) trait SealedInstance { | 778 | pub(crate) trait SealedInstance { |
| 784 | fn regs() -> crate::pac::i2c::I2c; | 779 | fn regs() -> crate::pac::i2c::I2c; |
| 785 | fn reset() -> crate::pac::resets::regs::Peripherals; | 780 | fn reset() -> crate::pac::resets::regs::Peripherals; |
diff --git a/embassy-rp/src/i2c_slave.rs b/embassy-rp/src/i2c_slave.rs index c46a55d2e..d17b11d14 100644 --- a/embassy-rp/src/i2c_slave.rs +++ b/embassy-rp/src/i2c_slave.rs | |||
| @@ -6,9 +6,7 @@ use core::task::Poll; | |||
| 6 | use embassy_hal_internal::into_ref; | 6 | use embassy_hal_internal::into_ref; |
| 7 | use pac::i2c; | 7 | use pac::i2c; |
| 8 | 8 | ||
| 9 | use crate::i2c::{ | 9 | use crate::i2c::{set_up_i2c_pin, AbortReason, Instance, InterruptHandler, SclPin, SdaPin, FIFO_SIZE}; |
| 10 | i2c_reserved_addr, set_up_i2c_pin, AbortReason, Instance, InterruptHandler, SclPin, SdaPin, FIFO_SIZE, | ||
| 11 | }; | ||
| 12 | use crate::interrupt::typelevel::{Binding, Interrupt}; | 10 | use crate::interrupt::typelevel::{Binding, Interrupt}; |
| 13 | use crate::{pac, Peripheral}; | 11 | use crate::{pac, Peripheral}; |
| 14 | 12 | ||
| @@ -97,7 +95,6 @@ impl<'d, T: Instance> I2cSlave<'d, T> { | |||
| 97 | ) -> Self { | 95 | ) -> Self { |
| 98 | into_ref!(_peri, scl, sda); | 96 | into_ref!(_peri, scl, sda); |
| 99 | 97 | ||
| 100 | assert!(!i2c_reserved_addr(config.addr)); | ||
| 101 | assert!(config.addr != 0); | 98 | assert!(config.addr != 0); |
| 102 | 99 | ||
| 103 | // Configure SCL & SDA pins | 100 | // Configure SCL & SDA pins |
