mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-22 14:53:03 +00:00
gpiote: take owned pin but add function to borrow it.
This commit is contained in:
parent
cd9ecaef57
commit
ec4b95579d
@ -5,9 +5,6 @@ authors = ["Dario Nieuwenhuis <dirbaio@dirbaio.net>"]
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [
|
|
||||||
"defmt-default",
|
|
||||||
]
|
|
||||||
defmt-default = []
|
defmt-default = []
|
||||||
defmt-trace = []
|
defmt-trace = []
|
||||||
defmt-debug = []
|
defmt-debug = []
|
||||||
|
@ -85,9 +85,9 @@ impl Gpiote {
|
|||||||
|
|
||||||
pub fn new_input_channel<'a, T>(
|
pub fn new_input_channel<'a, T>(
|
||||||
&'a self,
|
&'a self,
|
||||||
pin: &'a Pin<Input<T>>,
|
pin: Pin<Input<T>>,
|
||||||
trigger_mode: EventPolarity,
|
trigger_mode: EventPolarity,
|
||||||
) -> Result<InputChannel<'a>, NewChannelError> {
|
) -> Result<InputChannel<'a, T>, NewChannelError> {
|
||||||
interrupt::free(|_| {
|
interrupt::free(|_| {
|
||||||
unsafe { INSTANCE = self };
|
unsafe { INSTANCE = self };
|
||||||
let index = self.allocate_channel()?;
|
let index = self.allocate_channel()?;
|
||||||
@ -113,6 +113,7 @@ impl Gpiote {
|
|||||||
Ok(InputChannel {
|
Ok(InputChannel {
|
||||||
gpiote: self,
|
gpiote: self,
|
||||||
index,
|
index,
|
||||||
|
pin,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -157,21 +158,26 @@ impl Gpiote {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct InputChannel<'a> {
|
pub struct InputChannel<'a, T> {
|
||||||
gpiote: &'a Gpiote,
|
gpiote: &'a Gpiote,
|
||||||
|
pin: Pin<Input<T>>,
|
||||||
index: u8,
|
index: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Drop for InputChannel<'a> {
|
impl<'a, T> Drop for InputChannel<'a, T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.gpiote.free_channel(self.index);
|
self.gpiote.free_channel(self.index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> InputChannel<'a> {
|
impl<'a, T> InputChannel<'a, T> {
|
||||||
pub async fn wait(&self) -> () {
|
pub async fn wait(&self) -> () {
|
||||||
self.gpiote.signals[self.index as usize].wait().await;
|
self.gpiote.signals[self.index as usize].wait().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn pin(&self) -> &Pin<Input<T>> {
|
||||||
|
&self.pin
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct OutputChannel<'a> {
|
pub struct OutputChannel<'a> {
|
||||||
|
Loading…
Reference in New Issue
Block a user