From eed314ebb58772476971af49b36b68301eb0d8cc Mon Sep 17 00:00:00 2001 From: MathisDerooNXP <52401665+MathisDeroo@users.noreply.github.com> Date: Fri, 21 Nov 2025 10:00:01 -0800 Subject: Gpio support v2 (#26) * Improve GPIO driver and add button example - port and pcr registers are defined using paste! - added pin configuration for slew rate, drive strength, mux function, etc... - added button example to showcase input gpio feature Signed-off-by: Mathis Deroo * Add pull-up pull-down config support for input gpio Signed-off-by: Mathis Deroo * Replace GPIOs enum with existing ones in the PAC Signed-off-by: Mathis Deroo * Remove init_gpio_pin function as it is done in hal init config Signed-off-by: Mathis Deroo * Integrate feedback for the GPIO driver - Add again missing IO peripherals - Added function to configure separately slew rate, drive strength, pull. - Revert comment changes Signed-off-by: Mathis Deroo * Create user-readable field for the pin configuration Signed-off-by: Mathis Deroo * examples: button: remove left-over OSTIMER initialization While at that, also cargo fmt * Fix warnings * Add documentation for public functions Signed-off-by: Mathis Deroo * Expose port and pcr registers to AnyPin implementation Signed-off-by: Mathis Deroo * Remove unnecessary change Signed-off-by: Mathis Deroo * Run cargo fmt --------- Signed-off-by: Mathis Deroo Co-authored-by: Felipe Balbi --- examples/src/bin/button.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/src/bin/button.rs (limited to 'examples/src/bin/button.rs') diff --git a/examples/src/bin/button.rs b/examples/src/bin/button.rs new file mode 100644 index 000000000..2abfe0a9f --- /dev/null +++ b/examples/src/bin/button.rs @@ -0,0 +1,21 @@ +#![no_std] +#![no_main] + +use embassy_executor::Spawner; +use embassy_time::Timer; +use hal::gpio::{DriveStrength, Input, Pull, SlewRate}; +use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = hal::init(hal::config::Config::default()); + + defmt::info!("Button example"); + + let monitor = Input::new(p.P1_7, Pull::Disabled, DriveStrength::Normal, SlewRate::Slow); + + loop { + defmt::info!("Pin level is {:?}", monitor.get_level()); + Timer::after_millis(1000).await; + } +} -- cgit