diff options
Diffstat (limited to 'examples/mimxrt1011/src/bin')
| -rw-r--r-- | examples/mimxrt1011/src/bin/blinky.rs | 48 | ||||
| -rw-r--r-- | examples/mimxrt1011/src/bin/button.rs | 62 |
2 files changed, 110 insertions, 0 deletions
diff --git a/examples/mimxrt1011/src/bin/blinky.rs b/examples/mimxrt1011/src/bin/blinky.rs new file mode 100644 index 000000000..a5d5de6b3 --- /dev/null +++ b/examples/mimxrt1011/src/bin/blinky.rs | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | //! This example works on the following boards: | ||
| 2 | //! - IMXRT1010-EVK | ||
| 3 | //! - Adafruit Metro M7 (with microSD or with AirLift), requires an external button | ||
| 4 | //! - Makerdiary iMX RT1011 Nano Kit (TODO: currently untested, please change this) | ||
| 5 | //! | ||
| 6 | //! Although beware you will need to change the GPIO pins being used (scroll down). | ||
| 7 | |||
| 8 | #![no_std] | ||
| 9 | #![no_main] | ||
| 10 | |||
| 11 | use defmt::info; | ||
| 12 | use embassy_executor::Spawner; | ||
| 13 | use embassy_nxp::gpio::{Level, Output}; | ||
| 14 | use embassy_time::Timer; | ||
| 15 | // Must include `embassy_imxrt1011_examples` to ensure the FCB gets linked. | ||
| 16 | use {defmt_rtt as _, embassy_imxrt1011_examples as _, panic_probe as _}; | ||
| 17 | |||
| 18 | #[embassy_executor::main] | ||
| 19 | async fn main(_spawner: Spawner) -> ! { | ||
| 20 | let p = embassy_nxp::init(Default::default()); | ||
| 21 | info!("Hello world!"); | ||
| 22 | |||
| 23 | /* Pick the pins to use depending on your board. */ | ||
| 24 | |||
| 25 | // IMXRT1010-EVK | ||
| 26 | // | ||
| 27 | // LED (D25) | ||
| 28 | let led = p.GPIO_11; | ||
| 29 | |||
| 30 | // Adafruit Metro M7 (both microSD and AirLift variants) | ||
| 31 | // | ||
| 32 | // The LED is connected to D13 on the board. | ||
| 33 | // let led = p.GPIO_03; | ||
| 34 | |||
| 35 | // Makerdiary iMX RT1011 Nano Kit | ||
| 36 | // | ||
| 37 | // LED0 | ||
| 38 | // let led = p.GPIO_SD_04; | ||
| 39 | |||
| 40 | let mut led = Output::new(led, Level::Low); | ||
| 41 | |||
| 42 | loop { | ||
| 43 | Timer::after_millis(500).await; | ||
| 44 | |||
| 45 | info!("Toggle"); | ||
| 46 | led.toggle(); | ||
| 47 | } | ||
| 48 | } | ||
diff --git a/examples/mimxrt1011/src/bin/button.rs b/examples/mimxrt1011/src/bin/button.rs new file mode 100644 index 000000000..e63d7171d --- /dev/null +++ b/examples/mimxrt1011/src/bin/button.rs | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | //! This example works on the following boards: | ||
| 2 | //! - IMXRT1010-EVK | ||
| 3 | //! - Adafruit Metro M7 (with microSD or with AirLift), requires an external button | ||
| 4 | //! - Makerdiary iMX RT1011 Nano Kit (TODO: currently untested, please change this) | ||
| 5 | //! | ||
| 6 | //! Although beware you will need to change the GPIO pins being used (scroll down). | ||
| 7 | |||
| 8 | #![no_std] | ||
| 9 | #![no_main] | ||
| 10 | |||
| 11 | use defmt::info; | ||
| 12 | use embassy_executor::Spawner; | ||
| 13 | use embassy_nxp::gpio::{Input, Level, Output, Pull}; | ||
| 14 | // Must include `embassy_imxrt1011_examples` to ensure the FCB gets linked. | ||
| 15 | use {defmt_rtt as _, embassy_imxrt1011_examples as _, panic_probe as _}; | ||
| 16 | |||
| 17 | #[embassy_executor::main] | ||
| 18 | async fn main(_spawner: Spawner) -> ! { | ||
| 19 | let p = embassy_nxp::init(Default::default()); | ||
| 20 | info!("Hello world!"); | ||
| 21 | |||
| 22 | /* Pick the pins to use depending on your board. */ | ||
| 23 | |||
| 24 | // IMXRT1010-EVK | ||
| 25 | // | ||
| 26 | // LED (D25) and user button (SW4) | ||
| 27 | let (led, button) = (p.GPIO_11, p.GPIO_SD_05); | ||
| 28 | |||
| 29 | // Adafruit Metro M7 (both microSD and AirLift variants) | ||
| 30 | // | ||
| 31 | // The LED is connected to D13 on the board. | ||
| 32 | // | ||
| 33 | // In particular the Metro M7 has no board user buttons, so you will need to connect a button. | ||
| 34 | // Any other GPIO pin can be used. GPIO_04 is used for example since it is on pin D12. | ||
| 35 | // let (led, button) = (p.GPIO_03, p.GPIO_04); | ||
| 36 | |||
| 37 | // Makerdiary iMX RT1011 Nano Kit | ||
| 38 | // | ||
| 39 | // LED0 and user button. | ||
| 40 | // let (led, button) = (p.GPIO_SD_04, p.GPIO_SD_03); | ||
| 41 | |||
| 42 | let mut button = Input::new(button, Pull::Up100K); | ||
| 43 | let mut led = Output::new(led, Level::Low); | ||
| 44 | led.set_high(); | ||
| 45 | |||
| 46 | loop { | ||
| 47 | button.wait_for_falling_edge().await; | ||
| 48 | |||
| 49 | info!("Toggled"); | ||
| 50 | led.toggle(); | ||
| 51 | |||
| 52 | // The RT1010EVK has a 100 nF debouncing capacitor which results in false positive events | ||
| 53 | // when listening for a falling edge in a loop, wait for the rising edge and then wait for | ||
| 54 | // stabilization. | ||
| 55 | button.wait_for_rising_edge().await; | ||
| 56 | |||
| 57 | // Stabilization. | ||
| 58 | for _ in 0..100_000 { | ||
| 59 | cortex_m::asm::nop(); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | } | ||
