Skip to content

Commit

Permalink
Disable input enable for ADC pins after bringing pads out of reset
Browse files Browse the repository at this point in the history
  • Loading branch information
jannic committed Jan 13, 2024
1 parent 0819378 commit bd1dc23
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions rp2040-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,19 @@ pub trait DefaultTypeState: crate::typelevel::Sealed {
type PullType: PullType;
}

// Clear input enable for pins 26-29 of bank0, as these pins are ADC pins.
// If the pins are connected to an analoug input, the signal level may not
// be valid for a digital input.
macro_rules! reset_ie {
( Bank0, $pads:ident ) => {
(*$pads).gpio[26].modify(|_, w| w.ie().clear_bit());
(*$pads).gpio[27].modify(|_, w| w.ie().clear_bit());
(*$pads).gpio[28].modify(|_, w| w.ie().clear_bit());
(*$pads).gpio[29].modify(|_, w| w.ie().clear_bit());
};
( Qspi, $pads:ident ) => {};
}

macro_rules! gpio {
( $bank:ident:$prefix:ident, [ $(($id:expr, $pull_type:ident, $func:ident)),* ] ) => {
paste::paste!{
Expand All @@ -988,12 +1001,12 @@ macro_rules! gpio {
impl Pins {
/// Take ownership of the PAC peripherals and SIO slice and split it into discrete [`Pin`]s
pub fn new(io : [<IO_ $bank:upper>], pads: [<PADS_ $bank:upper>], sio: [<SioGpio $bank>], reset : &mut $crate::pac::RESETS) -> Self {
use crate::resets::SubsystemReset;
use $crate::gpio::pin::DynBankId;
use $crate::resets::SubsystemReset;
pads.reset_bring_down(reset);
io.reset_bring_down(reset);

{
use $crate::gpio::pin::DynBankId;
// SAFETY: this function owns the whole bank that will be affected.
let sio = unsafe { &*$crate::pac::SIO::PTR };
if DynBankId::$bank == DynBankId::Bank0 {
Expand All @@ -1007,6 +1020,7 @@ macro_rules! gpio {

io.reset_bring_up(reset);
pads.reset_bring_up(reset);
reset_ie!($bank, pads);
gpio!(members: io, pads, sio, $(([<$prefix $id>], $func, $pull_type)),+)
}
}
Expand Down
4 changes: 2 additions & 2 deletions rp2040-hal/src/gpio/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ pub(crate) fn set_function<P: PinId>(pin: &P, function: DynFunction) {
DynFunction::Null => FUNCSEL_A::NULL,
};
if funcsel != FUNCSEL_A::NULL {
pin.pad_ctrl().modify(|_, w| w.ie().set_bit() );
pin.pad_ctrl().modify(|_, w| w.ie().set_bit());
} else {
pin.pad_ctrl().modify(|_, w| w.ie().clear_bit() );
pin.pad_ctrl().modify(|_, w| w.ie().clear_bit());
}

pin.io_ctrl().modify(|_, w| w.funcsel().variant(funcsel));
Expand Down

0 comments on commit bd1dc23

Please sign in to comment.