From 3b239cb6de22b7bb8c2d87defb3205294653be7a Mon Sep 17 00:00:00 2001 From: James Munns Date: Sat, 29 Nov 2025 16:07:30 +0100 Subject: Remove Drive/Slew settings for Input pin (#57) * Don't set slew+strength for inputs * Update example --- examples/src/bin/button.rs | 6 ++++-- examples/src/bin/button_async.rs | 5 +++-- examples/src/bin/i2c-scan-blocking.rs | 4 ++-- src/gpio.rs | 12 ++++++++---- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/examples/src/bin/button.rs b/examples/src/bin/button.rs index 2abfe0a9f..943edbb15 100644 --- a/examples/src/bin/button.rs +++ b/examples/src/bin/button.rs @@ -3,7 +3,7 @@ use embassy_executor::Spawner; use embassy_time::Timer; -use hal::gpio::{DriveStrength, Input, Pull, SlewRate}; +use hal::gpio::{Input, Pull}; use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; #[embassy_executor::main] @@ -12,7 +12,9 @@ async fn main(_spawner: Spawner) { defmt::info!("Button example"); - let monitor = Input::new(p.P1_7, Pull::Disabled, DriveStrength::Normal, SlewRate::Slow); + // This button is labeled "WAKEUP" on the FRDM-MCXA276 + // The board already has a 10K pullup + let monitor = Input::new(p.P1_7, Pull::Disabled); loop { defmt::info!("Pin level is {:?}", monitor.get_level()); diff --git a/examples/src/bin/button_async.rs b/examples/src/bin/button_async.rs index 1ecec2e48..6cc7b62cd 100644 --- a/examples/src/bin/button_async.rs +++ b/examples/src/bin/button_async.rs @@ -3,7 +3,7 @@ use embassy_executor::Spawner; use embassy_time::Timer; -use hal::gpio::{DriveStrength, Input, Pull, SlewRate}; +use hal::gpio::{Input, Pull}; use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; #[embassy_executor::main] @@ -13,7 +13,8 @@ async fn main(_spawner: Spawner) { defmt::info!("GPIO interrupt example"); // This button is labeled "WAKEUP" on the FRDM-MCXA276 - let mut pin = Input::new(p.P1_7, Pull::Up, DriveStrength::Normal, SlewRate::Fast); + // The board already has a 10K pullup + let mut pin = Input::new(p.P1_7, Pull::Disabled); let mut press_count = 0u32; diff --git a/examples/src/bin/i2c-scan-blocking.rs b/examples/src/bin/i2c-scan-blocking.rs index 72f9d09e0..4e203597b 100644 --- a/examples/src/bin/i2c-scan-blocking.rs +++ b/examples/src/bin/i2c-scan-blocking.rs @@ -2,7 +2,7 @@ #![no_main] use embassy_executor::Spawner; -use embassy_mcxa::gpio::{DriveStrength, Pull, SlewRate}; +use embassy_mcxa::gpio::Pull; use embassy_mcxa::Input; use embassy_time::Timer; use hal::clocks::config::Div8; @@ -25,7 +25,7 @@ async fn main(_spawner: Spawner) { // Note: P0_2 is connected to P1_8 on the FRDM_MCXA276 via a resistor, and // defaults to SWO on the debug peripheral. Explicitly make it a high-z // input. - let _pin = Input::new(p.P0_2, Pull::Disabled, DriveStrength::Normal, SlewRate::Slow); + let _pin = Input::new(p.P0_2, Pull::Disabled); let mut i2c = I2c::new_blocking(p.LPI2C2, p.P1_9, p.P1_8, config).unwrap(); for addr in 0x01..=0x7f { diff --git a/src/gpio.rs b/src/gpio.rs index 332c4c8b2..65f8df985 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -818,11 +818,10 @@ pub struct Input<'d> { impl<'d> Input<'d> { /// Create a GPIO input driver for a [GpioPin]. - pub fn new(pin: Peri<'d, impl GpioPin>, pull_select: Pull, strength: DriveStrength, slew_rate: SlewRate) -> Self { + /// + pub fn new(pin: Peri<'d, impl GpioPin>, pull_select: Pull) -> Self { let mut flex = Flex::new(pin); flex.set_as_input(); - flex.set_drive_strength(strength); - flex.set_slew_rate(slew_rate); flex.set_pull(pull_select); Self { flex } } @@ -840,8 +839,13 @@ impl<'d> Input<'d> { } /// Expose the inner `Flex` if callers need to reconfigure the pin. + /// + /// Since Drive Strength and Slew Rate are not set when creating the Input + /// pin, they need to be set when converting #[inline] - pub fn into_flex(self) -> Flex<'d> { + pub fn into_flex(mut self, strength: DriveStrength, slew_rate: SlewRate) -> Flex<'d> { + self.flex.set_drive_strength(strength); + self.flex.set_slew_rate(slew_rate); self.flex } -- cgit