aboutsummaryrefslogtreecommitdiff
path: root/examples/src/bin
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
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')
-rw-r--r--examples/src/bin/adc_interrupt.rs6
-rw-r--r--examples/src/bin/adc_polling.rs6
-rw-r--r--examples/src/bin/blink.rs81
-rw-r--r--examples/src/bin/blinky.rs49
-rw-r--r--examples/src/bin/hello.rs6
-rw-r--r--examples/src/bin/lpuart_buffered.rs4
-rw-r--r--examples/src/bin/lpuart_polling.rs6
-rw-r--r--examples/src/bin/ostimer_alarm.rs6
-rw-r--r--examples/src/bin/ostimer_async.rs6
-rw-r--r--examples/src/bin/ostimer_counter.rs6
-rw-r--r--examples/src/bin/ostimer_race_test.rs6
-rw-r--r--examples/src/bin/rtc_alarm.rs6
12 files changed, 78 insertions, 110 deletions
diff --git a/examples/src/bin/adc_interrupt.rs b/examples/src/bin/adc_interrupt.rs
index 6812ba5d3..9fed052fd 100644
--- a/examples/src/bin/adc_interrupt.rs
+++ b/examples/src/bin/adc_interrupt.rs
@@ -34,14 +34,14 @@ async fn main(_spawner: Spawner) {
34 ..Default::default() 34 ..Default::default()
35 }; 35 };
36 36
37 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX 37 // Create UART instance using LPUART2 with P2_2 as TX and P2_3 as RX
38 unsafe { 38 unsafe {
39 embassy_mcxa_examples::init_uart2_pins(hal::pac()); 39 embassy_mcxa_examples::init_uart2_pins(hal::pac());
40 } 40 }
41 let mut uart = Lpuart::new_blocking( 41 let mut uart = Lpuart::new_blocking(
42 p.LPUART2, // Peripheral 42 p.LPUART2, // Peripheral
43 p.PIO2_2, // TX pin 43 p.P2_2, // TX pin
44 p.PIO2_3, // RX pin 44 p.P2_3, // RX pin
45 config, 45 config,
46 ) 46 )
47 .unwrap(); 47 .unwrap();
diff --git a/examples/src/bin/adc_polling.rs b/examples/src/bin/adc_polling.rs
index 421306e9b..545f8f77a 100644
--- a/examples/src/bin/adc_polling.rs
+++ b/examples/src/bin/adc_polling.rs
@@ -34,14 +34,14 @@ async fn main(_spawner: Spawner) {
34 ..Default::default() 34 ..Default::default()
35 }; 35 };
36 36
37 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX 37 // Create UART instance using LPUART2 with P2_2 as TX and P2_3 as RX
38 unsafe { 38 unsafe {
39 init_uart2_pins(hal::pac()); 39 init_uart2_pins(hal::pac());
40 } 40 }
41 let mut uart = Lpuart::new_blocking( 41 let mut uart = Lpuart::new_blocking(
42 p.LPUART2, // Peripheral 42 p.LPUART2, // Peripheral
43 p.PIO2_2, // TX pin 43 p.P2_2, // TX pin
44 p.PIO2_3, // RX pin 44 p.P2_3, // RX pin
45 config, 45 config,
46 ) 46 )
47 .unwrap(); 47 .unwrap();
diff --git a/examples/src/bin/blink.rs b/examples/src/bin/blink.rs
deleted file mode 100644
index d8b158d50..000000000
--- a/examples/src/bin/blink.rs
+++ /dev/null
@@ -1,81 +0,0 @@
1#![no_std]
2#![no_main]
3
4use embassy_executor::Spawner;
5use embassy_mcxa as hal;
6use embassy_mcxa::bind_interrupts;
7use embassy_mcxa_examples::init_led_gpio_clocks;
8use embassy_time::{Duration, Timer};
9use hal::gpio::pins::PIO3_18;
10use hal::gpio::{Level, Output};
11
12// Bind only OS_EVENT for timer interrupts
13bind_interrupts!(struct Irqs {
14 OS_EVENT => hal::ostimer::time_driver::OsEventHandler;
15});
16
17#[used]
18#[no_mangle]
19static KEEP_OS_EVENT: unsafe extern "C" fn() = OS_EVENT;
20
21#[embassy_executor::main]
22async fn main(_spawner: Spawner) {
23 let _p = hal::init(hal::config::Config::default());
24
25 unsafe {
26 init_led_gpio_clocks(hal::pac());
27 }
28
29 defmt::info!("Blink example");
30
31 // Initialize embassy-time global driver backed by OSTIMER0
32 hal::ostimer::time_driver::init(hal::config::Config::default().time_interrupt_priority, 1_000_000);
33
34 // Configure LED pin for GPIO mode
35 PIO3_18::set_mux_gpio();
36
37 let mut led = Output::new(PIO3_18::degrade(), Level::High);
38
39 // Complex blinking pattern: SOS in Morse code
40 // S: ... (3 short)
41 // O: --- (3 long)
42 // S: ... (3 short)
43 // With pauses between letters and words
44
45 loop {
46 defmt::info!("SOS");
47
48 // S: three short blinks
49 for _ in 0..3 {
50 led.set_low();
51 Timer::after(Duration::from_millis(150)).await;
52 led.set_high();
53 Timer::after(Duration::from_millis(150)).await;
54 }
55
56 // Pause between letters
57 Timer::after(Duration::from_millis(300)).await;
58
59 // O: three long blinks
60 for _ in 0..3 {
61 led.set_low();
62 Timer::after(Duration::from_millis(450)).await;
63 led.set_high();
64 Timer::after(Duration::from_millis(150)).await;
65 }
66
67 // Pause between letters
68 Timer::after(Duration::from_millis(300)).await;
69
70 // S: three short blinks
71 for _ in 0..3 {
72 led.set_low();
73 Timer::after(Duration::from_millis(150)).await;
74 led.set_high();
75 Timer::after(Duration::from_millis(150)).await;
76 }
77
78 // Long pause between words (SOS repeats)
79 Timer::after(Duration::from_millis(1000)).await;
80 }
81}
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}
diff --git a/examples/src/bin/hello.rs b/examples/src/bin/hello.rs
index 207c157c3..e2d0b413d 100644
--- a/examples/src/bin/hello.rs
+++ b/examples/src/bin/hello.rs
@@ -26,14 +26,14 @@ async fn main(_spawner: Spawner) {
26 ..Default::default() 26 ..Default::default()
27 }; 27 };
28 28
29 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX 29 // Create UART instance using LPUART2 with P2_2 as TX and P2_3 as RX
30 unsafe { 30 unsafe {
31 embassy_mcxa_examples::init_uart2_pins(hal::pac()); 31 embassy_mcxa_examples::init_uart2_pins(hal::pac());
32 } 32 }
33 let mut uart = Lpuart::new_blocking( 33 let mut uart = Lpuart::new_blocking(
34 p.LPUART2, // Peripheral 34 p.LPUART2, // Peripheral
35 p.PIO2_2, // TX pin 35 p.P2_2, // TX pin
36 p.PIO2_3, // RX pin 36 p.P2_3, // RX pin
37 config, 37 config,
38 ) 38 )
39 .unwrap(); 39 .unwrap();
diff --git a/examples/src/bin/lpuart_buffered.rs b/examples/src/bin/lpuart_buffered.rs
index 642d4af65..b0d19ef16 100644
--- a/examples/src/bin/lpuart_buffered.rs
+++ b/examples/src/bin/lpuart_buffered.rs
@@ -51,8 +51,8 @@ async fn main(_spawner: Spawner) {
51 // Create a buffered LPUART2 instance with both TX and RX 51 // Create a buffered LPUART2 instance with both TX and RX
52 let mut uart = BufferedLpuart::new( 52 let mut uart = BufferedLpuart::new(
53 p.LPUART2, 53 p.LPUART2,
54 p.PIO2_2, // TX pin 54 p.P2_2, // TX pin
55 p.PIO2_3, // RX pin 55 p.P2_3, // RX pin
56 Irqs, 56 Irqs,
57 &mut tx_buf, 57 &mut tx_buf,
58 &mut rx_buf, 58 &mut rx_buf,
diff --git a/examples/src/bin/lpuart_polling.rs b/examples/src/bin/lpuart_polling.rs
index bea82c33e..525d42e2c 100644
--- a/examples/src/bin/lpuart_polling.rs
+++ b/examples/src/bin/lpuart_polling.rs
@@ -26,11 +26,11 @@ async fn main(_spawner: Spawner) {
26 ..Default::default() 26 ..Default::default()
27 }; 27 };
28 28
29 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX 29 // Create UART instance using LPUART2 with P2_2 as TX and P2_3 as RX
30 let lpuart = Lpuart::new_blocking( 30 let lpuart = Lpuart::new_blocking(
31 p.LPUART2, // Peripheral 31 p.LPUART2, // Peripheral
32 p.PIO2_2, // TX pin 32 p.P2_2, // TX pin
33 p.PIO2_3, // RX pin 33 p.P2_3, // RX pin
34 config, 34 config,
35 ) 35 )
36 .unwrap(); 36 .unwrap();
diff --git a/examples/src/bin/ostimer_alarm.rs b/examples/src/bin/ostimer_alarm.rs
index 03fb93319..6d38741b7 100644
--- a/examples/src/bin/ostimer_alarm.rs
+++ b/examples/src/bin/ostimer_alarm.rs
@@ -40,14 +40,14 @@ async fn main(_spawner: Spawner) {
40 ..Default::default() 40 ..Default::default()
41 }; 41 };
42 42
43 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX 43 // Create UART instance using LPUART2 with P2_2 as TX and P2_3 as RX
44 unsafe { 44 unsafe {
45 init_uart2_pins(hal::pac()); 45 init_uart2_pins(hal::pac());
46 } 46 }
47 let mut uart = Lpuart::new_blocking( 47 let mut uart = Lpuart::new_blocking(
48 p.LPUART2, // Peripheral 48 p.LPUART2, // Peripheral
49 p.PIO2_2, // TX pin 49 p.P2_2, // TX pin
50 p.PIO2_3, // RX pin 50 p.P2_3, // RX pin
51 config, 51 config,
52 ) 52 )
53 .unwrap(); 53 .unwrap();
diff --git a/examples/src/bin/ostimer_async.rs b/examples/src/bin/ostimer_async.rs
index 881f09374..f043184e7 100644
--- a/examples/src/bin/ostimer_async.rs
+++ b/examples/src/bin/ostimer_async.rs
@@ -29,14 +29,14 @@ async fn main(_spawner: Spawner) {
29 ..Default::default() 29 ..Default::default()
30 }; 30 };
31 31
32 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX 32 // Create UART instance using LPUART2 with P2_2 as TX and P2_3 as RX
33 unsafe { 33 unsafe {
34 init_uart2_pins(hal::pac()); 34 init_uart2_pins(hal::pac());
35 } 35 }
36 let mut uart = Lpuart::new_blocking( 36 let mut uart = Lpuart::new_blocking(
37 p.LPUART2, // Peripheral 37 p.LPUART2, // Peripheral
38 p.PIO2_2, // TX pin 38 p.P2_2, // TX pin
39 p.PIO2_3, // RX pin 39 p.P2_3, // RX pin
40 config, 40 config,
41 ) 41 )
42 .unwrap(); 42 .unwrap();
diff --git a/examples/src/bin/ostimer_counter.rs b/examples/src/bin/ostimer_counter.rs
index 2fbc251b9..f36915ff2 100644
--- a/examples/src/bin/ostimer_counter.rs
+++ b/examples/src/bin/ostimer_counter.rs
@@ -30,14 +30,14 @@ async fn main(_spawner: Spawner) {
30 ..Default::default() 30 ..Default::default()
31 }; 31 };
32 32
33 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX 33 // Create UART instance using LPUART2 with P2_2 as TX and P2_3 as RX
34 unsafe { 34 unsafe {
35 embassy_mcxa_examples::init_uart2_pins(hal::pac()); 35 embassy_mcxa_examples::init_uart2_pins(hal::pac());
36 } 36 }
37 let mut uart = Lpuart::new_blocking( 37 let mut uart = Lpuart::new_blocking(
38 p.LPUART2, // Peripheral 38 p.LPUART2, // Peripheral
39 p.PIO2_2, // TX pin 39 p.P2_2, // TX pin
40 p.PIO2_3, // RX pin 40 p.P2_3, // RX pin
41 config, 41 config,
42 ) 42 )
43 .unwrap(); 43 .unwrap();
diff --git a/examples/src/bin/ostimer_race_test.rs b/examples/src/bin/ostimer_race_test.rs
index 168a952cd..0106b92a7 100644
--- a/examples/src/bin/ostimer_race_test.rs
+++ b/examples/src/bin/ostimer_race_test.rs
@@ -80,14 +80,14 @@ async fn main(_spawner: Spawner) {
80 ..Default::default() 80 ..Default::default()
81 }; 81 };
82 82
83 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX 83 // Create UART instance using LPUART2 with P2_2 as TX and P2_3 as RX
84 unsafe { 84 unsafe {
85 embassy_mcxa_examples::init_uart2_pins(hal::pac()); 85 embassy_mcxa_examples::init_uart2_pins(hal::pac());
86 } 86 }
87 let mut uart = Lpuart::new_blocking( 87 let mut uart = Lpuart::new_blocking(
88 p.LPUART2, // Peripheral 88 p.LPUART2, // Peripheral
89 p.PIO2_2, // TX pin 89 p.P2_2, // TX pin
90 p.PIO2_3, // RX pin 90 p.P2_3, // RX pin
91 config, 91 config,
92 ) 92 )
93 .unwrap(); 93 .unwrap();
diff --git a/examples/src/bin/rtc_alarm.rs b/examples/src/bin/rtc_alarm.rs
index 40a1207df..a54b4a817 100644
--- a/examples/src/bin/rtc_alarm.rs
+++ b/examples/src/bin/rtc_alarm.rs
@@ -32,14 +32,14 @@ async fn main(_spawner: Spawner) {
32 ..Default::default() 32 ..Default::default()
33 }; 33 };
34 34
35 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX 35 // Create UART instance using LPUART2 with P2_2 as TX and P2_3 as RX
36 unsafe { 36 unsafe {
37 embassy_mcxa_examples::init_uart2_pins(hal::pac()); 37 embassy_mcxa_examples::init_uart2_pins(hal::pac());
38 } 38 }
39 let mut uart = Lpuart::new_blocking( 39 let mut uart = Lpuart::new_blocking(
40 p.LPUART2, // Peripheral 40 p.LPUART2, // Peripheral
41 p.PIO2_2, // TX pin 41 p.P2_2, // TX pin
42 p.PIO2_3, // RX pin 42 p.P2_3, // RX pin
43 config, 43 config,
44 ) 44 )
45 .unwrap(); 45 .unwrap();