From 5cb0c8cc01583137ccb8b6a64a452b52316b626f Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Tue, 28 Feb 2023 09:22:38 +0200 Subject: [PATCH] fix: rp - disable Pull-down/up resistors for ADC read Signed-off-by: Lachezar Lechev --- embassy-rp/src/adc.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/embassy-rp/src/adc.rs b/embassy-rp/src/adc.rs index 025c6f91..145ba9c5 100644 --- a/embassy-rp/src/adc.rs +++ b/embassy-rp/src/adc.rs @@ -7,6 +7,7 @@ use embassy_hal_common::into_ref; use embassy_sync::waitqueue::AtomicWaker; use embedded_hal_02::adc::{Channel, OneShot}; +use crate::gpio::Pin; use crate::interrupt::{self, InterruptExt}; use crate::peripherals::ADC; use crate::{pac, peripherals, Peripheral}; @@ -90,9 +91,17 @@ impl<'d> Adc<'d> { } } - pub async fn read, ID = u8>>(&mut self, _pin: &mut PIN) -> u16 { + pub async fn read, ID = u8> + Pin>(&mut self, pin: &mut PIN) -> u16 { let r = Self::regs(); unsafe { + // disable pull-down and pull-up resistors + // pull-down resistors are enabled by default + pin.pad_ctrl().modify(|w| { + w.set_ie(true); + let (pu, pd) = (false, false); + w.set_pue(pu); + w.set_pde(pd); + }); r.cs().modify(|w| { w.set_ainsel(PIN::channel()); w.set_start_once(true)