nrf/twim: deconfigure pins on drop

This commit is contained in:
Dario Nieuwenhuis 2021-05-26 18:09:18 +02:00
parent a126e17fb2
commit b449f6de9d
2 changed files with 17 additions and 3 deletions

View file

@ -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 {}

View file

@ -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");
}
}