Skip to content

Commit d713410

Browse files
DirbaioYatekii
authored andcommitted
gpio: add into_disconnected
1 parent 8c91438 commit d713410

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

nrf-hal-common/src/gpio.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,20 @@ impl<MODE> Pin<MODE> {
236236

237237
pin
238238
}
239+
240+
/// Disconnects the pin.
241+
///
242+
/// In disconnected mode the pin cannot be used as input or output.
243+
/// It is primarily useful to reduce power usage.
244+
pub fn into_disconnected(self) -> Pin<Disconnected> {
245+
// Reset value is disconnected.
246+
self.block().pin_cnf[self.pin() as usize].reset();
247+
248+
Pin {
249+
_mode: PhantomData,
250+
pin_port: self.pin_port,
251+
}
252+
}
239253
}
240254

241255
impl<MODE> InputPin for Pin<Input<MODE>> {
@@ -489,6 +503,19 @@ macro_rules! gpio {
489503
pin
490504
}
491505

506+
/// Disconnects the pin.
507+
///
508+
/// In disconnected mode the pin cannot be used as input or output.
509+
/// It is primarily useful to reduce power usage.
510+
pub fn into_disconnected(self) -> $PXi<Disconnected> {
511+
// Reset value is disconnected.
512+
unsafe { &(*$PX::ptr()).pin_cnf[$i] }.reset();
513+
514+
$PXi {
515+
_mode: PhantomData,
516+
}
517+
}
518+
492519
/// Degrade to a generic pin struct, which can be used with peripherals
493520
pub fn degrade(self) -> Pin<MODE> {
494521
Pin::new($port_value, $i)

0 commit comments

Comments
 (0)