aboutsummaryrefslogtreecommitdiff
path: root/examples
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
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')
-rw-r--r--examples/src/bin/blinky.rs8
-rw-r--r--examples/src/bin/button.rs21
2 files changed, 25 insertions, 4 deletions
diff --git a/examples/src/bin/blinky.rs b/examples/src/bin/blinky.rs
index ab1e59bdb..dd08ec0d9 100644
--- a/examples/src/bin/blinky.rs
+++ b/examples/src/bin/blinky.rs
@@ -3,7 +3,7 @@
3 3
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_time::Timer; 5use embassy_time::Timer;
6use hal::gpio::{Level, Output}; 6use hal::gpio::{DriveStrength, Level, Output, SlewRate};
7use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; 7use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
8 8
9#[embassy_executor::main] 9#[embassy_executor::main]
@@ -12,9 +12,9 @@ async fn main(_spawner: Spawner) {
12 12
13 defmt::info!("Blink example"); 13 defmt::info!("Blink example");
14 14
15 let mut red = Output::new(p.P3_18, Level::High); 15 let mut red = Output::new(p.P3_18, Level::High, DriveStrength::Normal, SlewRate::Fast);
16 let mut green = Output::new(p.P3_19, Level::High); 16 let mut green = Output::new(p.P3_19, Level::High, DriveStrength::Normal, SlewRate::Fast);
17 let mut blue = Output::new(p.P3_21, Level::High); 17 let mut blue = Output::new(p.P3_21, Level::High, DriveStrength::Normal, SlewRate::Fast);
18 18
19 loop { 19 loop {
20 defmt::info!("Toggle LEDs"); 20 defmt::info!("Toggle LEDs");
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}