Skip to content

Commit

Permalink
gpio: Add initializer based on pin and port numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Oct 12, 2023
1 parent 76749c8 commit 96fd778
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ impl GPIO {
}
}

// using a generic GPIO_PIN is probably best done by making GPIO_INIT a static inline (given
// it's already fixed to types at tests/periph_gpio/main.c)
// /// Create a GPIO out of thin air
// #[cfg(riot_module_nrf5x_common_periph)]
// pub unsafe fn new(port: u8, pin: u8) -> Self {
// // EXPANDED cpu/nrf5x_common/include/periph_cpu_common.h:50
// GPIO(((port << 5) | pin).into())
// }
/// Create a GPIO from its port and pin numbers
///
/// ```
/// let pin_c8 = GPIO::from_port_and_pin(3, 8);
/// ```
///
/// See [from_c] for safety constraints.
pub fn from_port_and_pin(port: usize, pin: usize) -> Option<Self> {
Self::from_c(unsafe { riot_sys::macro_GPIO_PIN(port, pin) })
}

pub fn configure_as_output(
self,
Expand Down

0 comments on commit 96fd778

Please sign in to comment.