From ec4b95579ded58ab3dc441aa1a716c2a2a12cb36 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 19 Oct 2020 21:18:13 +0200 Subject: [PATCH] gpiote: take owned pin but add function to borrow it. --- embassy-nrf/Cargo.toml | 3 --- embassy-nrf/src/gpiote.rs | 16 +++++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index 420d8ced..62df81f4 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml @@ -5,9 +5,6 @@ authors = ["Dario Nieuwenhuis "] edition = "2018" [features] -default = [ - "defmt-default", -] defmt-default = [] defmt-trace = [] defmt-debug = [] diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index 5195f926..ef25109e 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs @@ -85,9 +85,9 @@ impl Gpiote { pub fn new_input_channel<'a, T>( &'a self, - pin: &'a Pin>, + pin: Pin>, trigger_mode: EventPolarity, - ) -> Result, NewChannelError> { + ) -> Result, NewChannelError> { interrupt::free(|_| { unsafe { INSTANCE = self }; let index = self.allocate_channel()?; @@ -113,6 +113,7 @@ impl Gpiote { Ok(InputChannel { gpiote: self, index, + pin, }) }) } @@ -157,21 +158,26 @@ impl Gpiote { } } -pub struct InputChannel<'a> { +pub struct InputChannel<'a, T> { gpiote: &'a Gpiote, + pin: Pin>, index: u8, } -impl<'a> Drop for InputChannel<'a> { +impl<'a, T> Drop for InputChannel<'a, T> { fn drop(&mut self) { self.gpiote.free_channel(self.index); } } -impl<'a> InputChannel<'a> { +impl<'a, T> InputChannel<'a, T> { pub async fn wait(&self) -> () { self.gpiote.signals[self.index as usize].wait().await; } + + pub fn pin(&self) -> &Pin> { + &self.pin + } } pub struct OutputChannel<'a> {