From 42abeca4934afcdd85a09f1c8e74c30569046de7 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 26 May 2021 18:22:44 +0200 Subject: [PATCH] nrf/spim: disable and deconfigure pins on drop. --- embassy-nrf/src/spim.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index bb43b7c7c..a29c1a3ee 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs @@ -14,6 +14,7 @@ use traits::spi::FullDuplex; use crate::gpio::sealed::Pin as _; use crate::gpio::{OptionalPin, Pin as GpioPin}; use crate::interrupt::Interrupt; +use crate::{fmt::*, gpio}; use crate::{pac, util::slice_in_ram_or}; pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; @@ -153,6 +154,24 @@ impl<'d, T: Instance> Spim<'d, T> { } } +impl<'d, T: Instance> Drop for Spim<'d, T> { + fn drop(&mut self) { + info!("spim drop"); + + // TODO check for abort, wait for xxxstopped + + // disable! + let r = T::regs(); + r.enable.write(|w| w.enable().disabled()); + + gpio::deconfigure_pin(r.psel.sck.read().bits()); + gpio::deconfigure_pin(r.psel.miso.read().bits()); + gpio::deconfigure_pin(r.psel.mosi.read().bits()); + + info!("spim drop: done"); + } +} + impl<'d, T: Instance> FullDuplex for Spim<'d, T> { type Error = Error;