Skip to content

Commit

Permalink
rp: Fix indexing for pins >31 on rp235xb (#3330)
Browse files Browse the repository at this point in the history
* Fix indexing for pins >31 on rp235xb

* fixup knowing that 1<<7 is 128 not 64
  • Loading branch information
CBJamo authored Sep 11, 2024
1 parent 7648d42 commit 3d6a270
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions embassy-rp/src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,12 +846,12 @@ pub(crate) trait SealedPin: Sized {

#[inline]
fn _pin(&self) -> u8 {
self.pin_bank() & 0x1f
self.pin_bank() & 0x7f
}

#[inline]
fn _bank(&self) -> Bank {
match self.pin_bank() >> 5 {
match self.pin_bank() >> 7 {
#[cfg(feature = "qspi-as-gpio")]
1 => Bank::Qspi,
_ => Bank::Bank0,
Expand Down Expand Up @@ -880,15 +880,27 @@ pub(crate) trait SealedPin: Sized {
}

fn sio_out(&self) -> pac::sio::Gpio {
SIO.gpio_out(self._bank() as _)
if cfg!(feature = "rp2040") {
SIO.gpio_out(self._bank() as _)
} else {
SIO.gpio_out((self._pin() / 32) as _)
}
}

fn sio_oe(&self) -> pac::sio::Gpio {
SIO.gpio_oe(self._bank() as _)
if cfg!(feature = "rp2040") {
SIO.gpio_oe(self._bank() as _)
} else {
SIO.gpio_oe((self._pin() / 32) as _)
}
}

fn sio_in(&self) -> Reg<u32, RW> {
SIO.gpio_in(self._bank() as _)
if cfg!(feature = "rp2040") {
SIO.gpio_in(self._bank() as _)
} else {
SIO.gpio_in((self._pin() / 32) as _)
}
}

fn int_proc(&self) -> pac::io::Int {
Expand Down Expand Up @@ -953,7 +965,7 @@ macro_rules! impl_pin {
impl SealedPin for peripherals::$name {
#[inline]
fn pin_bank(&self) -> u8 {
($bank as u8) * 32 + $pin_num
($bank as u8) * 128 + $pin_num
}
}

Expand Down

0 comments on commit 3d6a270

Please sign in to comment.