From b449f6de9dd504e010154450e4e5f4a39fa5c10b Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 26 May 2021 18:09:18 +0200 Subject: [PATCH] nrf/twim: deconfigure pins on drop --- embassy-nrf/src/gpio.rs | 13 +++++++++++++ embassy-nrf/src/twim.rs | 7 ++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index 3ae160ca..b02e7787 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs @@ -12,6 +12,8 @@ use gpio::pin_cnf::DRIVE_A; use crate::pac; use crate::pac::p0 as gpio; +use self::sealed::Pin as _; + /// A GPIO port with up to 32 pins. #[derive(Debug, Eq, PartialEq)] pub enum Port { @@ -487,6 +489,17 @@ impl OptionalPin for NoPin { // ==================== +pub(crate) fn deconfigure_pin(psel_bits: u32) { + if psel_bits & 0x8000_0000 != 0 { + return; + } + unsafe { + AnyPin::steal(psel_bits as _).conf().reset(); + } +} + +// ==================== + macro_rules! impl_pin { ($type:ident, $port_num:expr, $pin_num:expr) => { impl crate::gpio::Pin for peripherals::$type {} diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs index 05c4c260..4812b353 100644 --- a/embassy-nrf/src/twim.rs +++ b/embassy-nrf/src/twim.rs @@ -13,10 +13,10 @@ use embassy::util::{AtomicWaker, Unborrow}; use embassy_extras::unborrow; use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; -use crate::fmt::*; use crate::gpio::Pin as GpioPin; use crate::pac; use crate::util::{slice_in_ram, slice_in_ram_or}; +use crate::{fmt::*, gpio}; pub enum Frequency { #[doc = "26738688: 100 kbps"] @@ -422,9 +422,10 @@ impl<'a, T: Instance> Drop for Twim<'a, T> { let r = T::regs(); r.enable.write(|w| w.enable().disabled()); - info!("uarte drop: done"); + gpio::deconfigure_pin(r.psel.sda.read().bits()); + gpio::deconfigure_pin(r.psel.scl.read().bits()); - // TODO: disable pins + info!("twim drop: done"); } }