From bd1dc238dee0adb14654142d6a618668e98e3cf0 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sat, 13 Jan 2024 17:58:45 +0000 Subject: [PATCH] Disable input enable for ADC pins after bringing pads out of reset --- rp2040-hal/src/gpio/mod.rs | 18 ++++++++++++++++-- rp2040-hal/src/gpio/pin.rs | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/rp2040-hal/src/gpio/mod.rs b/rp2040-hal/src/gpio/mod.rs index e5b017578..b82e959e3 100644 --- a/rp2040-hal/src/gpio/mod.rs +++ b/rp2040-hal/src/gpio/mod.rs @@ -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!{ @@ -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 : [], pads: [], sio: [], 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 { @@ -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)),+) } } diff --git a/rp2040-hal/src/gpio/pin.rs b/rp2040-hal/src/gpio/pin.rs index b9eab289c..1f3689555 100644 --- a/rp2040-hal/src/gpio/pin.rs +++ b/rp2040-hal/src/gpio/pin.rs @@ -154,9 +154,9 @@ pub(crate) fn set_function(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));