aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJames Munns <[email protected]>2025-11-14 19:08:16 +0100
committerJames Munns <[email protected]>2025-11-14 19:08:16 +0100
commit1f589e9428542cd94bc630b623accf04d9c36edf (patch)
treec63ec2d0ef51f0d432e00f7f51ea2275b0e88f67 /examples
parent0bae6aa5aaab5d0f3a3e7e1ec83a0cee909de115 (diff)
A little follow-up cleanup
Diffstat (limited to 'examples')
-rw-r--r--examples/src/bin/adc_interrupt.rs5
-rw-r--r--examples/src/bin/adc_polling.rs8
-rw-r--r--examples/src/bin/blink.rs4
-rw-r--r--examples/src/bin/hello.rs2
-rw-r--r--examples/src/bin/lpuart_buffered.rs7
-rw-r--r--examples/src/bin/lpuart_polling.rs4
-rw-r--r--examples/src/bin/ostimer_alarm.rs4
-rw-r--r--examples/src/bin/ostimer_async.rs9
-rw-r--r--examples/src/bin/ostimer_counter.rs2
-rw-r--r--examples/src/bin/ostimer_race_test.rs2
-rw-r--r--examples/src/bin/rtc_alarm.rs9
-rw-r--r--examples/src/lib.rs10
12 files changed, 34 insertions, 32 deletions
diff --git a/examples/src/bin/adc_interrupt.rs b/examples/src/bin/adc_interrupt.rs
index be08ebf8c..6812ba5d3 100644
--- a/examples/src/bin/adc_interrupt.rs
+++ b/examples/src/bin/adc_interrupt.rs
@@ -2,6 +2,7 @@
2#![no_main] 2#![no_main]
3 3
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa_examples::init_adc_pins;
5use hal::adc::{LpadcConfig, TriggerPriorityPolicy}; 6use hal::adc::{LpadcConfig, TriggerPriorityPolicy};
6use hal::clocks::periph_helpers::{AdcClockSel, Div4}; 7use hal::clocks::periph_helpers::{AdcClockSel, Div4};
7use hal::clocks::PoweredClock; 8use hal::clocks::PoweredClock;
@@ -35,7 +36,7 @@ async fn main(_spawner: Spawner) {
35 36
36 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX 37 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX
37 unsafe { 38 unsafe {
38 embassy_mcxa_examples::init_uart2(hal::pac()); 39 embassy_mcxa_examples::init_uart2_pins(hal::pac());
39 } 40 }
40 let mut uart = Lpuart::new_blocking( 41 let mut uart = Lpuart::new_blocking(
41 p.LPUART2, // Peripheral 42 p.LPUART2, // Peripheral
@@ -47,7 +48,7 @@ async fn main(_spawner: Spawner) {
47 uart.write_str_blocking("\r\n=== ADC interrupt Example ===\r\n"); 48 uart.write_str_blocking("\r\n=== ADC interrupt Example ===\r\n");
48 49
49 unsafe { 50 unsafe {
50 embassy_mcxa_examples::init_adc(hal::pac()); 51 init_adc_pins(hal::pac());
51 } 52 }
52 53
53 let adc_config = LpadcConfig { 54 let adc_config = LpadcConfig {
diff --git a/examples/src/bin/adc_polling.rs b/examples/src/bin/adc_polling.rs
index 723f1e044..421306e9b 100644
--- a/examples/src/bin/adc_polling.rs
+++ b/examples/src/bin/adc_polling.rs
@@ -4,7 +4,7 @@
4use core::fmt::Write; 4use core::fmt::Write;
5 5
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_mcxa_examples::{init_adc, init_uart2}; 7use embassy_mcxa_examples::{init_adc_pins, init_uart2_pins};
8use hal::adc::{ConvResult, LpadcConfig, TriggerPriorityPolicy}; 8use hal::adc::{ConvResult, LpadcConfig, TriggerPriorityPolicy};
9use hal::clocks::periph_helpers::{AdcClockSel, Div4}; 9use hal::clocks::periph_helpers::{AdcClockSel, Div4};
10use hal::clocks::PoweredClock; 10use hal::clocks::PoweredClock;
@@ -23,7 +23,7 @@ async fn main(_spawner: Spawner) {
23 let p = hal::init(hal::config::Config::default()); 23 let p = hal::init(hal::config::Config::default());
24 24
25 unsafe { 25 unsafe {
26 init_uart2(hal::pac()); 26 init_uart2_pins(hal::pac());
27 } 27 }
28 28
29 // Create UART configuration 29 // Create UART configuration
@@ -36,7 +36,7 @@ async fn main(_spawner: Spawner) {
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 PIO2_2 as TX and PIO2_3 as RX
38 unsafe { 38 unsafe {
39 init_uart2(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
@@ -49,7 +49,7 @@ async fn main(_spawner: Spawner) {
49 uart.write_str_blocking("\r\n=== ADC polling Example ===\r\n"); 49 uart.write_str_blocking("\r\n=== ADC polling Example ===\r\n");
50 50
51 unsafe { 51 unsafe {
52 init_adc(hal::pac()); 52 init_adc_pins(hal::pac());
53 } 53 }
54 54
55 let adc_config = LpadcConfig { 55 let adc_config = LpadcConfig {
diff --git a/examples/src/bin/blink.rs b/examples/src/bin/blink.rs
index ee59ac591..8c48e79f1 100644
--- a/examples/src/bin/blink.rs
+++ b/examples/src/bin/blink.rs
@@ -4,7 +4,7 @@
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa as hal; 5use embassy_mcxa as hal;
6use embassy_mcxa::bind_interrupts; 6use embassy_mcxa::bind_interrupts;
7use embassy_mcxa_examples::init_led; 7use embassy_mcxa_examples::init_led_gpio_clocks;
8use embassy_time::{Duration, Timer}; 8use embassy_time::{Duration, Timer};
9use hal::gpio::pins::PIO3_18; 9use hal::gpio::pins::PIO3_18;
10use hal::gpio::{Level, Output}; 10use hal::gpio::{Level, Output};
@@ -23,7 +23,7 @@ async fn main(_spawner: Spawner) {
23 let _p = hal::init(hal::config::Config::default()); 23 let _p = hal::init(hal::config::Config::default());
24 24
25 unsafe { 25 unsafe {
26 init_led(hal::pac()); 26 init_led_gpio_clocks(hal::pac());
27 } 27 }
28 28
29 // Initialize embassy-time global driver backed by OSTIMER0 29 // Initialize embassy-time global driver backed by OSTIMER0
diff --git a/examples/src/bin/hello.rs b/examples/src/bin/hello.rs
index ff7afa01d..207c157c3 100644
--- a/examples/src/bin/hello.rs
+++ b/examples/src/bin/hello.rs
@@ -28,7 +28,7 @@ async fn main(_spawner: Spawner) {
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 PIO2_2 as TX and PIO2_3 as RX
30 unsafe { 30 unsafe {
31 embassy_mcxa_examples::init_uart2(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
diff --git a/examples/src/bin/lpuart_buffered.rs b/examples/src/bin/lpuart_buffered.rs
index e96ab7b81..642d4af65 100644
--- a/examples/src/bin/lpuart_buffered.rs
+++ b/examples/src/bin/lpuart_buffered.rs
@@ -5,8 +5,9 @@ use embassy_executor::Spawner;
5use embassy_mcxa as hal; 5use embassy_mcxa as hal;
6use embassy_mcxa::interrupt::typelevel::Handler; 6use embassy_mcxa::interrupt::typelevel::Handler;
7use embassy_mcxa::lpuart::buffered::BufferedLpuart; 7use embassy_mcxa::lpuart::buffered::BufferedLpuart;
8use embassy_mcxa::lpuart::Config;
8use embassy_mcxa::{bind_interrupts, lpuart}; 9use embassy_mcxa::{bind_interrupts, lpuart};
9use embassy_mcxa_examples::init_uart2; 10use embassy_mcxa_examples::init_uart2_pins;
10use embedded_io_async::{Read, Write}; 11use embedded_io_async::{Read, Write};
11 12
12// Bind OS_EVENT for timers plus LPUART2 IRQ for the buffered driver 13// Bind OS_EVENT for timers plus LPUART2 IRQ for the buffered driver
@@ -31,11 +32,11 @@ async fn main(_spawner: Spawner) {
31 hal::interrupt::LPUART2.configure_for_uart(hal::interrupt::Priority::P3); 32 hal::interrupt::LPUART2.configure_for_uart(hal::interrupt::Priority::P3);
32 33
33 unsafe { 34 unsafe {
34 init_uart2(hal::pac()); 35 init_uart2_pins(hal::pac());
35 } 36 }
36 37
37 // UART configuration (enable both TX and RX) 38 // UART configuration (enable both TX and RX)
38 let config = lpuart::Config { 39 let config = Config {
39 baudrate_bps: 115_200, 40 baudrate_bps: 115_200,
40 enable_tx: true, 41 enable_tx: true,
41 enable_rx: true, 42 enable_rx: true,
diff --git a/examples/src/bin/lpuart_polling.rs b/examples/src/bin/lpuart_polling.rs
index bdcfa0776..bea82c33e 100644
--- a/examples/src/bin/lpuart_polling.rs
+++ b/examples/src/bin/lpuart_polling.rs
@@ -2,7 +2,7 @@
2#![no_main] 2#![no_main]
3 3
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa_examples::init_uart2; 5use embassy_mcxa_examples::init_uart2_pins;
6use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; 6use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
7 7
8use crate::hal::lpuart::{Config, Lpuart}; 8use crate::hal::lpuart::{Config, Lpuart};
@@ -15,7 +15,7 @@ async fn main(_spawner: Spawner) {
15 15
16 // Board-level init for UART2 clocks and pins. 16 // Board-level init for UART2 clocks and pins.
17 unsafe { 17 unsafe {
18 init_uart2(hal::pac()); 18 init_uart2_pins(hal::pac());
19 } 19 }
20 20
21 // Create UART configuration 21 // Create UART configuration
diff --git a/examples/src/bin/ostimer_alarm.rs b/examples/src/bin/ostimer_alarm.rs
index 9e858b60b..36b1f403a 100644
--- a/examples/src/bin/ostimer_alarm.rs
+++ b/examples/src/bin/ostimer_alarm.rs
@@ -8,7 +8,7 @@ use embassy_mcxa::bind_interrupts;
8use embassy_mcxa::clocks::periph_helpers::OstimerClockSel; 8use embassy_mcxa::clocks::periph_helpers::OstimerClockSel;
9use embassy_mcxa::clocks::PoweredClock; 9use embassy_mcxa::clocks::PoweredClock;
10use embassy_mcxa::lpuart::{Config, Lpuart}; 10use embassy_mcxa::lpuart::{Config, Lpuart};
11use embassy_mcxa_examples::init_uart2; 11use embassy_mcxa_examples::init_uart2_pins;
12use {cortex_m, defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; 12use {cortex_m, defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
13 13
14// Bind only OS_EVENT, and retain the symbol explicitly so it can't be GC'ed. 14// Bind only OS_EVENT, and retain the symbol explicitly so it can't be GC'ed.
@@ -42,7 +42,7 @@ async fn main(_spawner: Spawner) {
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 PIO2_2 as TX and PIO2_3 as RX
44 unsafe { 44 unsafe {
45 init_uart2(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
diff --git a/examples/src/bin/ostimer_async.rs b/examples/src/bin/ostimer_async.rs
index 4e692a744..881f09374 100644
--- a/examples/src/bin/ostimer_async.rs
+++ b/examples/src/bin/ostimer_async.rs
@@ -3,8 +3,9 @@
3 3
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa::bind_interrupts; 5use embassy_mcxa::bind_interrupts;
6use embassy_mcxa_examples::init_uart2; 6use embassy_mcxa_examples::init_uart2_pins;
7use embassy_time::{Duration, Timer}; 7use embassy_time::{Duration, Timer};
8use hal::lpuart::{Config, Lpuart};
8use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; 9use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
9 10
10// Bind only OS_EVENT, and retain the symbol explicitly so it can’t be GC’ed. 11// Bind only OS_EVENT, and retain the symbol explicitly so it can’t be GC’ed.
@@ -21,7 +22,7 @@ async fn main(_spawner: Spawner) {
21 let p = hal::init(hal::config::Config::default()); 22 let p = hal::init(hal::config::Config::default());
22 23
23 // Create UART configuration 24 // Create UART configuration
24 let config = hal::lpuart::Config { 25 let config = Config {
25 baudrate_bps: 115_200, 26 baudrate_bps: 115_200,
26 enable_tx: true, 27 enable_tx: true,
27 enable_rx: true, 28 enable_rx: true,
@@ -30,9 +31,9 @@ async fn main(_spawner: Spawner) {
30 31
31 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX 32 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX
32 unsafe { 33 unsafe {
33 init_uart2(hal::pac()); 34 init_uart2_pins(hal::pac());
34 } 35 }
35 let mut uart = hal::lpuart::Lpuart::new_blocking( 36 let mut uart = Lpuart::new_blocking(
36 p.LPUART2, // Peripheral 37 p.LPUART2, // Peripheral
37 p.PIO2_2, // TX pin 38 p.PIO2_2, // TX pin
38 p.PIO2_3, // RX pin 39 p.PIO2_3, // RX pin
diff --git a/examples/src/bin/ostimer_counter.rs b/examples/src/bin/ostimer_counter.rs
index 47543160b..2fbc251b9 100644
--- a/examples/src/bin/ostimer_counter.rs
+++ b/examples/src/bin/ostimer_counter.rs
@@ -32,7 +32,7 @@ async fn main(_spawner: Spawner) {
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 PIO2_2 as TX and PIO2_3 as RX
34 unsafe { 34 unsafe {
35 embassy_mcxa_examples::init_uart2(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
diff --git a/examples/src/bin/ostimer_race_test.rs b/examples/src/bin/ostimer_race_test.rs
index c2ecff969..168a952cd 100644
--- a/examples/src/bin/ostimer_race_test.rs
+++ b/examples/src/bin/ostimer_race_test.rs
@@ -82,7 +82,7 @@ async fn main(_spawner: Spawner) {
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 PIO2_2 as TX and PIO2_3 as RX
84 unsafe { 84 unsafe {
85 embassy_mcxa_examples::init_uart2(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
diff --git a/examples/src/bin/rtc_alarm.rs b/examples/src/bin/rtc_alarm.rs
index e2eaa6ae2..40a1207df 100644
--- a/examples/src/bin/rtc_alarm.rs
+++ b/examples/src/bin/rtc_alarm.rs
@@ -2,9 +2,10 @@
2#![no_main] 2#![no_main]
3 3
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa as hal;
6use hal::lpuart::{Config, Lpuart};
5use hal::rtc::{RtcDateTime, RtcInterruptEnable}; 7use hal::rtc::{RtcDateTime, RtcInterruptEnable};
6use hal::InterruptExt; 8use hal::InterruptExt;
7use {cortex_m, embassy_mcxa as hal};
8 9
9type MyRtc = hal::rtc::Rtc<'static, hal::rtc::Rtc0>; 10type MyRtc = hal::rtc::Rtc<'static, hal::rtc::Rtc0>;
10 11
@@ -24,7 +25,7 @@ async fn main(_spawner: Spawner) {
24 let p = hal::init(hal::config::Config::default()); 25 let p = hal::init(hal::config::Config::default());
25 26
26 // Create UART configuration 27 // Create UART configuration
27 let config = hal::lpuart::Config { 28 let config = Config {
28 baudrate_bps: 115_200, 29 baudrate_bps: 115_200,
29 enable_tx: true, 30 enable_tx: true,
30 enable_rx: true, 31 enable_rx: true,
@@ -33,9 +34,9 @@ async fn main(_spawner: Spawner) {
33 34
34 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX 35 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX
35 unsafe { 36 unsafe {
36 embassy_mcxa_examples::init_uart2(hal::pac()); 37 embassy_mcxa_examples::init_uart2_pins(hal::pac());
37 } 38 }
38 let mut uart = hal::lpuart::Lpuart::new_blocking( 39 let mut uart = Lpuart::new_blocking(
39 p.LPUART2, // Peripheral 40 p.LPUART2, // Peripheral
40 p.PIO2_2, // TX pin 41 p.PIO2_2, // TX pin
41 p.PIO2_3, // RX pin 42 p.PIO2_3, // RX pin
diff --git a/examples/src/lib.rs b/examples/src/lib.rs
index a45ab708d..be4761c32 100644
--- a/examples/src/lib.rs
+++ b/examples/src/lib.rs
@@ -1,4 +1,5 @@
1#![no_std] 1#![no_std]
2#![allow(clippy::missing_safety_doc)]
2 3
3//! Shared board-specific helpers for the FRDM-MCXA276 examples. 4//! Shared board-specific helpers for the FRDM-MCXA276 examples.
4//! These live with the examples so the HAL stays generic. 5//! These live with the examples so the HAL stays generic.
@@ -8,8 +9,7 @@ use {embassy_mcxa as hal, panic_probe as _};
8 9
9/// Initialize clocks and pin muxing for UART2 debug console. 10/// Initialize clocks and pin muxing for UART2 debug console.
10/// Safe to call multiple times; writes are idempotent for our use. 11/// Safe to call multiple times; writes are idempotent for our use.
11#[allow(dead_code)] 12pub unsafe fn init_uart2_pins(_p: &hal::pac::Peripherals) {
12pub unsafe fn init_uart2(_p: &hal::pac::Peripherals) {
13 // NOTE: Lpuart has been updated to properly enable + reset its own clocks. 13 // NOTE: Lpuart has been updated to properly enable + reset its own clocks.
14 // GPIO has not. 14 // GPIO has not.
15 _ = clocks::enable_and_reset::<hal::peripherals::PORT2>(&clocks::NoConfig); 15 _ = clocks::enable_and_reset::<hal::peripherals::PORT2>(&clocks::NoConfig);
@@ -17,15 +17,13 @@ pub unsafe fn init_uart2(_p: &hal::pac::Peripherals) {
17} 17}
18 18
19/// Initialize clocks for the LED GPIO/PORT used by the blink example. 19/// Initialize clocks for the LED GPIO/PORT used by the blink example.
20#[allow(dead_code)] 20pub unsafe fn init_led_gpio_clocks(_p: &hal::pac::Peripherals) {
21pub unsafe fn init_led(_p: &hal::pac::Peripherals) {
22 _ = clocks::enable_and_reset::<hal::peripherals::PORT3>(&clocks::NoConfig); 21 _ = clocks::enable_and_reset::<hal::peripherals::PORT3>(&clocks::NoConfig);
23 _ = clocks::enable_and_reset::<hal::peripherals::GPIO3>(&clocks::NoConfig); 22 _ = clocks::enable_and_reset::<hal::peripherals::GPIO3>(&clocks::NoConfig);
24} 23}
25 24
26/// Initialize clocks and pin muxing for ADC. 25/// Initialize clocks and pin muxing for ADC.
27#[allow(dead_code)] 26pub unsafe fn init_adc_pins(_p: &hal::pac::Peripherals) {
28pub unsafe fn init_adc(_p: &hal::pac::Peripherals) {
29 // NOTE: Lpuart has been updated to properly enable + reset its own clocks. 27 // NOTE: Lpuart has been updated to properly enable + reset its own clocks.
30 // GPIO has not. 28 // GPIO has not.
31 _ = clocks::enable_and_reset::<hal::peripherals::PORT1>(&clocks::NoConfig); 29 _ = clocks::enable_and_reset::<hal::peripherals::PORT1>(&clocks::NoConfig);