Skip to content

Commit 7e4eb98

Browse files
Add associated consts for port and pin number
This allows accessing these values without needing the pin instance, and works in a const context.
1 parent b6247dc commit 7e4eb98

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/gpio.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ macro_rules! gpio {
127127
}
128128

129129
impl<MODE> $PXx<MODE> {
130+
/// The port this pin is part of.
131+
pub const PORT: Port = Port::$PXx;
132+
130133
/// Returns the port this pin is part of.
131134
pub fn port(&self) -> Port {
132135
Port::$PXx
@@ -206,6 +209,12 @@ macro_rules! gpio {
206209
}
207210

208211
impl<MODE> $PXi<MODE> {
212+
/// The port this pin is part of.
213+
pub const PORT: Port = Port::$PXx;
214+
215+
/// The pin's number inside its port.
216+
pub const PIN_NUMBER: u8 = $i;
217+
209218
/// Returns the port this pin is part of.
210219
pub fn port(&self) -> Port {
211220
Port::$PXx

0 commit comments

Comments
 (0)