aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2020-10-19 21:18:13 +0200
committerDario Nieuwenhuis <[email protected]>2020-10-19 21:25:54 +0200
commitec4b95579ded58ab3dc441aa1a716c2a2a12cb36 (patch)
tree0688c4ae295b60e9cd25588f57284b749fb10fd7
parentcd9ecaef57982b33376dcfea3a0406a3df4b09c5 (diff)
gpiote: take owned pin but add function to borrow it.
-rw-r--r--embassy-nrf/Cargo.toml3
-rw-r--r--embassy-nrf/src/gpiote.rs16
2 files changed, 11 insertions, 8 deletions
diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml
index 420d8ced8..62df81f42 100644
--- a/embassy-nrf/Cargo.toml
+++ b/embassy-nrf/Cargo.toml
@@ -5,9 +5,6 @@ authors = ["Dario Nieuwenhuis <[email protected]>"]
5edition = "2018" 5edition = "2018"
6 6
7[features] 7[features]
8default = [
9 "defmt-default",
10]
11defmt-default = [] 8defmt-default = []
12defmt-trace = [] 9defmt-trace = []
13defmt-debug = [] 10defmt-debug = []
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index 5195f926a..ef25109ee 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -85,9 +85,9 @@ impl Gpiote {
85 85
86 pub fn new_input_channel<'a, T>( 86 pub fn new_input_channel<'a, T>(
87 &'a self, 87 &'a self,
88 pin: &'a Pin<Input<T>>, 88 pin: Pin<Input<T>>,
89 trigger_mode: EventPolarity, 89 trigger_mode: EventPolarity,
90 ) -> Result<InputChannel<'a>, NewChannelError> { 90 ) -> Result<InputChannel<'a, T>, NewChannelError> {
91 interrupt::free(|_| { 91 interrupt::free(|_| {
92 unsafe { INSTANCE = self }; 92 unsafe { INSTANCE = self };
93 let index = self.allocate_channel()?; 93 let index = self.allocate_channel()?;
@@ -113,6 +113,7 @@ impl Gpiote {
113 Ok(InputChannel { 113 Ok(InputChannel {
114 gpiote: self, 114 gpiote: self,
115 index, 115 index,
116 pin,
116 }) 117 })
117 }) 118 })
118 } 119 }
@@ -157,21 +158,26 @@ impl Gpiote {
157 } 158 }
158} 159}
159 160
160pub struct InputChannel<'a> { 161pub struct InputChannel<'a, T> {
161 gpiote: &'a Gpiote, 162 gpiote: &'a Gpiote,
163 pin: Pin<Input<T>>,
162 index: u8, 164 index: u8,
163} 165}
164 166
165impl<'a> Drop for InputChannel<'a> { 167impl<'a, T> Drop for InputChannel<'a, T> {
166 fn drop(&mut self) { 168 fn drop(&mut self) {
167 self.gpiote.free_channel(self.index); 169 self.gpiote.free_channel(self.index);
168 } 170 }
169} 171}
170 172
171impl<'a> InputChannel<'a> { 173impl<'a, T> InputChannel<'a, T> {
172 pub async fn wait(&self) -> () { 174 pub async fn wait(&self) -> () {
173 self.gpiote.signals[self.index as usize].wait().await; 175 self.gpiote.signals[self.index as usize].wait().await;
174 } 176 }
177
178 pub fn pin(&self) -> &Pin<Input<T>> {
179 &self.pin
180 }
175} 181}
176 182
177pub struct OutputChannel<'a> { 183pub struct OutputChannel<'a> {