aboutsummaryrefslogtreecommitdiff
path: root/examples/src/bin/blinky.rs
diff options
context:
space:
mode:
authorFelipe Balbi <[email protected]>2025-11-18 12:16:14 -0800
committerGitHub <[email protected]>2025-11-18 12:16:14 -0800
commitffe3e5acae6c0038db4176dc7d031b57f865e07f (patch)
treef69475bd7f177ad2ceb69d77ea02a408e5bf6ef7 /examples/src/bin/blinky.rs
parente07497690faf1c8a14229183f4054f96832b1d5d (diff)
Correct gpio driver (#9)
* Correct gpio driver Signed-off-by: Felipe Balbi <[email protected]> * Simplify blinky example Make it look like every other HAL for consistency. While at that, also rename the example to match the name used by other HALs. Signed-off-by: Felipe Balbi <[email protected]> * Add some documentation to GPIO driver Signed-off-by: Felipe Balbi <[email protected]> * Enable GPIO clocks during HAL initialization Provide the user with working GPIO clocks. Signed-off-by: Felipe Balbi <[email protected]> --------- Signed-off-by: Felipe Balbi <[email protected]> Co-authored-by: Felipe Balbi <[email protected]>
Diffstat (limited to 'examples/src/bin/blinky.rs')
-rw-r--r--examples/src/bin/blinky.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/examples/src/bin/blinky.rs b/examples/src/bin/blinky.rs
new file mode 100644
index 000000000..28d83a12e
--- /dev/null
+++ b/examples/src/bin/blinky.rs
@@ -0,0 +1,49 @@
1#![no_std]
2#![no_main]
3
4use embassy_executor::Spawner;
5use embassy_mcxa::bind_interrupts;
6use embassy_time::Timer;
7use hal::gpio::{Level, Output};
8use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
9
10// Bind only OS_EVENT for timer interrupts
11bind_interrupts!(struct Irqs {
12 OS_EVENT => hal::ostimer::time_driver::OsEventHandler;
13});
14
15#[used]
16#[no_mangle]
17static KEEP_OS_EVENT: unsafe extern "C" fn() = OS_EVENT;
18
19#[embassy_executor::main]
20async fn main(_spawner: Spawner) {
21 let p = hal::init(hal::config::Config::default());
22
23 defmt::info!("Blink example");
24
25 // Initialize embassy-time global driver backed by OSTIMER0
26 hal::ostimer::time_driver::init(hal::config::Config::default().time_interrupt_priority, 1_000_000);
27
28 let mut red = Output::new(p.P3_18, Level::High);
29 let mut green = Output::new(p.P3_19, Level::High);
30 let mut blue = Output::new(p.P3_21, Level::High);
31
32 loop {
33 defmt::info!("Toggle LEDs");
34
35 red.toggle();
36 Timer::after_millis(250).await;
37
38 red.toggle();
39 green.toggle();
40 Timer::after_millis(250).await;
41
42 green.toggle();
43 blue.toggle();
44 Timer::after_millis(250).await;
45 blue.toggle();
46
47 Timer::after_millis(250).await;
48 }
49}