diff options
| -rw-r--r-- | examples/src/bin/button.rs | 6 | ||||
| -rw-r--r-- | examples/src/bin/button_async.rs | 5 | ||||
| -rw-r--r-- | examples/src/bin/i2c-scan-blocking.rs | 4 | ||||
| -rw-r--r-- | 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 @@ | |||
| 3 | 3 | ||
| 4 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 5 | use embassy_time::Timer; | 5 | use embassy_time::Timer; |
| 6 | use hal::gpio::{DriveStrength, Input, Pull, SlewRate}; | 6 | use hal::gpio::{Input, Pull}; |
| 7 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | 7 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; |
| 8 | 8 | ||
| 9 | #[embassy_executor::main] | 9 | #[embassy_executor::main] |
| @@ -12,7 +12,9 @@ async fn main(_spawner: Spawner) { | |||
| 12 | 12 | ||
| 13 | defmt::info!("Button example"); | 13 | defmt::info!("Button example"); |
| 14 | 14 | ||
| 15 | let monitor = Input::new(p.P1_7, Pull::Disabled, DriveStrength::Normal, SlewRate::Slow); | 15 | // This button is labeled "WAKEUP" on the FRDM-MCXA276 |
| 16 | // The board already has a 10K pullup | ||
| 17 | let monitor = Input::new(p.P1_7, Pull::Disabled); | ||
| 16 | 18 | ||
| 17 | loop { | 19 | loop { |
| 18 | defmt::info!("Pin level is {:?}", monitor.get_level()); | 20 | 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 @@ | |||
| 3 | 3 | ||
| 4 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 5 | use embassy_time::Timer; | 5 | use embassy_time::Timer; |
| 6 | use hal::gpio::{DriveStrength, Input, Pull, SlewRate}; | 6 | use hal::gpio::{Input, Pull}; |
| 7 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | 7 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; |
| 8 | 8 | ||
| 9 | #[embassy_executor::main] | 9 | #[embassy_executor::main] |
| @@ -13,7 +13,8 @@ async fn main(_spawner: Spawner) { | |||
| 13 | defmt::info!("GPIO interrupt example"); | 13 | defmt::info!("GPIO interrupt example"); |
| 14 | 14 | ||
| 15 | // This button is labeled "WAKEUP" on the FRDM-MCXA276 | 15 | // This button is labeled "WAKEUP" on the FRDM-MCXA276 |
| 16 | let mut pin = Input::new(p.P1_7, Pull::Up, DriveStrength::Normal, SlewRate::Fast); | 16 | // The board already has a 10K pullup |
| 17 | let mut pin = Input::new(p.P1_7, Pull::Disabled); | ||
| 17 | 18 | ||
| 18 | let mut press_count = 0u32; | 19 | let mut press_count = 0u32; |
| 19 | 20 | ||
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 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 5 | use embassy_mcxa::gpio::{DriveStrength, Pull, SlewRate}; | 5 | use embassy_mcxa::gpio::Pull; |
| 6 | use embassy_mcxa::Input; | 6 | use embassy_mcxa::Input; |
| 7 | use embassy_time::Timer; | 7 | use embassy_time::Timer; |
| 8 | use hal::clocks::config::Div8; | 8 | use hal::clocks::config::Div8; |
| @@ -25,7 +25,7 @@ async fn main(_spawner: Spawner) { | |||
| 25 | // Note: P0_2 is connected to P1_8 on the FRDM_MCXA276 via a resistor, and | 25 | // Note: P0_2 is connected to P1_8 on the FRDM_MCXA276 via a resistor, and |
| 26 | // defaults to SWO on the debug peripheral. Explicitly make it a high-z | 26 | // defaults to SWO on the debug peripheral. Explicitly make it a high-z |
| 27 | // input. | 27 | // input. |
| 28 | let _pin = Input::new(p.P0_2, Pull::Disabled, DriveStrength::Normal, SlewRate::Slow); | 28 | let _pin = Input::new(p.P0_2, Pull::Disabled); |
| 29 | let mut i2c = I2c::new_blocking(p.LPI2C2, p.P1_9, p.P1_8, config).unwrap(); | 29 | let mut i2c = I2c::new_blocking(p.LPI2C2, p.P1_9, p.P1_8, config).unwrap(); |
| 30 | 30 | ||
| 31 | for addr in 0x01..=0x7f { | 31 | 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> { | |||
| 818 | 818 | ||
| 819 | impl<'d> Input<'d> { | 819 | impl<'d> Input<'d> { |
| 820 | /// Create a GPIO input driver for a [GpioPin]. | 820 | /// Create a GPIO input driver for a [GpioPin]. |
| 821 | pub fn new(pin: Peri<'d, impl GpioPin>, pull_select: Pull, strength: DriveStrength, slew_rate: SlewRate) -> Self { | 821 | /// |
| 822 | pub fn new(pin: Peri<'d, impl GpioPin>, pull_select: Pull) -> Self { | ||
| 822 | let mut flex = Flex::new(pin); | 823 | let mut flex = Flex::new(pin); |
| 823 | flex.set_as_input(); | 824 | flex.set_as_input(); |
| 824 | flex.set_drive_strength(strength); | ||
| 825 | flex.set_slew_rate(slew_rate); | ||
| 826 | flex.set_pull(pull_select); | 825 | flex.set_pull(pull_select); |
| 827 | Self { flex } | 826 | Self { flex } |
| 828 | } | 827 | } |
| @@ -840,8 +839,13 @@ impl<'d> Input<'d> { | |||
| 840 | } | 839 | } |
| 841 | 840 | ||
| 842 | /// Expose the inner `Flex` if callers need to reconfigure the pin. | 841 | /// Expose the inner `Flex` if callers need to reconfigure the pin. |
| 842 | /// | ||
| 843 | /// Since Drive Strength and Slew Rate are not set when creating the Input | ||
| 844 | /// pin, they need to be set when converting | ||
| 843 | #[inline] | 845 | #[inline] |
| 844 | pub fn into_flex(self) -> Flex<'d> { | 846 | pub fn into_flex(mut self, strength: DriveStrength, slew_rate: SlewRate) -> Flex<'d> { |
| 847 | self.flex.set_drive_strength(strength); | ||
| 848 | self.flex.set_slew_rate(slew_rate); | ||
| 845 | self.flex | 849 | self.flex |
| 846 | } | 850 | } |
| 847 | 851 | ||
