aboutsummaryrefslogtreecommitdiff
path: root/examples/src/bin/button.rs
diff options
context:
space:
mode:
authorMathisDerooNXP <[email protected]>2025-11-21 10:00:01 -0800
committerGitHub <[email protected]>2025-11-21 10:00:01 -0800
commiteed314ebb58772476971af49b36b68301eb0d8cc (patch)
treee89ac428dac9d24d96b0ef3cf2c96dc2e4f4dafe /examples/src/bin/button.rs
parenta8eb124e47e633cd81e0863253d5f6bdd7545260 (diff)
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 <[email protected]> * Add pull-up pull-down config support for input gpio Signed-off-by: Mathis Deroo <[email protected]> * Replace GPIOs enum with existing ones in the PAC Signed-off-by: Mathis Deroo <[email protected]> * Remove init_gpio_pin function as it is done in hal init config Signed-off-by: Mathis Deroo <[email protected]> * 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 <[email protected]> * Create user-readable field for the pin configuration Signed-off-by: Mathis Deroo <[email protected]> * 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 <[email protected]> * Expose port and pcr registers to AnyPin implementation Signed-off-by: Mathis Deroo <[email protected]> * Remove unnecessary change Signed-off-by: Mathis Deroo <[email protected]> * Run cargo fmt --------- Signed-off-by: Mathis Deroo <[email protected]> Co-authored-by: Felipe Balbi <[email protected]>
Diffstat (limited to 'examples/src/bin/button.rs')
-rw-r--r--examples/src/bin/button.rs21
1 files changed, 21 insertions, 0 deletions
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 @@
1#![no_std]
2#![no_main]
3
4use embassy_executor::Spawner;
5use embassy_time::Timer;
6use hal::gpio::{DriveStrength, Input, Pull, SlewRate};
7use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
8
9#[embassy_executor::main]
10async fn main(_spawner: Spawner) {
11 let p = hal::init(hal::config::Config::default());
12
13 defmt::info!("Button example");
14
15 let monitor = Input::new(p.P1_7, Pull::Disabled, DriveStrength::Normal, SlewRate::Slow);
16
17 loop {
18 defmt::info!("Pin level is {:?}", monitor.get_level());
19 Timer::after_millis(1000).await;
20 }
21}