aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-11-23 12:17:02 +0000
committerGitHub <[email protected]>2022-11-23 12:17:02 +0000
commitb76631bebe980a8a04db0f07f0c3efb7edaccf2e (patch)
treede3c8dfe450a02df55e98d5ef6d3463d9d6a1963 /embassy-nrf/src
parent2fa2c1a6fe9c79f11f7382a63ba6a13fe1bae1be (diff)
parenteae67d0be888d12e71bc3340279bab85666c05ae (diff)
Merge #1069
1069: GPIOTE InputChannel with mutable reference. r=Dirbaio a=Ardelean-Calin Adding these changes enables us to define a channel using a mutable reference to `GPIOTE_CH(n)`, similar to how we can do with other drivers. So instead of using: ```rust let p = embassy_nrf::init(config); let freq_in = InputChannel::new( p.GPIOTE_CH0, Input::new(&mut p.P0_19, embassy_nrf::gpio::Pull::Up), embassy_nrf::gpiote::InputChannelPolarity::HiToLo, ); ``` we can use: ```rust let p = embassy_nrf::init(config); let freq_in = InputChannel::new( &mut p.GPIOTE_CH0, Input::new(&mut p.P0_19, embassy_nrf::gpio::Pull::Up), embassy_nrf::gpiote::InputChannelPolarity::HiToLo, ); ``` therefore not giving ownership to GPIOTE_CH0. Co-authored-by: Ardelean Călin Petru <[email protected]> Co-authored-by: Ardelean Calin <[email protected]>
Diffstat (limited to 'embassy-nrf/src')
-rw-r--r--embassy-nrf/src/gpiote.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index 25ad90496..7f7468a20 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -2,7 +2,7 @@ use core::convert::Infallible;
2use core::future::{poll_fn, Future}; 2use core::future::{poll_fn, Future};
3use core::task::{Context, Poll}; 3use core::task::{Context, Poll};
4 4
5use embassy_hal_common::{impl_peripheral, Peripheral, PeripheralRef}; 5use embassy_hal_common::{impl_peripheral, into_ref, Peripheral, PeripheralRef};
6use embassy_sync::waitqueue::AtomicWaker; 6use embassy_sync::waitqueue::AtomicWaker;
7 7
8use crate::gpio::sealed::Pin as _; 8use crate::gpio::sealed::Pin as _;
@@ -148,7 +148,7 @@ impl Iterator for BitIter {
148 148
149/// GPIOTE channel driver in input mode 149/// GPIOTE channel driver in input mode
150pub struct InputChannel<'d, C: Channel, T: GpioPin> { 150pub struct InputChannel<'d, C: Channel, T: GpioPin> {
151 ch: C, 151 ch: PeripheralRef<'d, C>,
152 pin: Input<'d, T>, 152 pin: Input<'d, T>,
153} 153}
154 154
@@ -162,7 +162,9 @@ impl<'d, C: Channel, T: GpioPin> Drop for InputChannel<'d, C, T> {
162} 162}
163 163
164impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> { 164impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> {
165 pub fn new(ch: C, pin: Input<'d, T>, polarity: InputChannelPolarity) -> Self { 165 pub fn new(ch: impl Peripheral<P = C> + 'd, pin: Input<'d, T>, polarity: InputChannelPolarity) -> Self {
166 into_ref!(ch);
167
166 let g = regs(); 168 let g = regs();
167 let num = ch.number(); 169 let num = ch.number();
168 170
@@ -215,7 +217,7 @@ impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> {
215 217
216/// GPIOTE channel driver in output mode 218/// GPIOTE channel driver in output mode
217pub struct OutputChannel<'d, C: Channel, T: GpioPin> { 219pub struct OutputChannel<'d, C: Channel, T: GpioPin> {
218 ch: C, 220 ch: PeripheralRef<'d, C>,
219 _pin: Output<'d, T>, 221 _pin: Output<'d, T>,
220} 222}
221 223
@@ -229,7 +231,8 @@ impl<'d, C: Channel, T: GpioPin> Drop for OutputChannel<'d, C, T> {
229} 231}
230 232
231impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> { 233impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> {
232 pub fn new(ch: C, pin: Output<'d, T>, polarity: OutputChannelPolarity) -> Self { 234 pub fn new(ch: impl Peripheral<P = C> + 'd, pin: Output<'d, T>, polarity: OutputChannelPolarity) -> Self {
235 into_ref!(ch);
233 let g = regs(); 236 let g = regs();
234 let num = ch.number(); 237 let num = ch.number();
235 238