From 1f589e9428542cd94bc630b623accf04d9c36edf Mon Sep 17 00:00:00 2001 From: James Munns Date: Fri, 14 Nov 2025 19:08:16 +0100 Subject: A little follow-up cleanup --- examples/src/bin/adc_interrupt.rs | 5 +++-- examples/src/bin/adc_polling.rs | 8 ++++---- examples/src/bin/blink.rs | 4 ++-- examples/src/bin/hello.rs | 2 +- examples/src/bin/lpuart_buffered.rs | 7 ++++--- examples/src/bin/lpuart_polling.rs | 4 ++-- examples/src/bin/ostimer_alarm.rs | 4 ++-- examples/src/bin/ostimer_async.rs | 9 +++++---- examples/src/bin/ostimer_counter.rs | 2 +- examples/src/bin/ostimer_race_test.rs | 2 +- examples/src/bin/rtc_alarm.rs | 9 +++++---- examples/src/lib.rs | 10 ++++------ 12 files changed, 34 insertions(+), 32 deletions(-) (limited to 'examples/src') 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 @@ #![no_main] use embassy_executor::Spawner; +use embassy_mcxa_examples::init_adc_pins; use hal::adc::{LpadcConfig, TriggerPriorityPolicy}; use hal::clocks::periph_helpers::{AdcClockSel, Div4}; use hal::clocks::PoweredClock; @@ -35,7 +36,7 @@ async fn main(_spawner: Spawner) { // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX unsafe { - embassy_mcxa_examples::init_uart2(hal::pac()); + embassy_mcxa_examples::init_uart2_pins(hal::pac()); } let mut uart = Lpuart::new_blocking( p.LPUART2, // Peripheral @@ -47,7 +48,7 @@ async fn main(_spawner: Spawner) { uart.write_str_blocking("\r\n=== ADC interrupt Example ===\r\n"); unsafe { - embassy_mcxa_examples::init_adc(hal::pac()); + init_adc_pins(hal::pac()); } 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 @@ use core::fmt::Write; use embassy_executor::Spawner; -use embassy_mcxa_examples::{init_adc, init_uart2}; +use embassy_mcxa_examples::{init_adc_pins, init_uart2_pins}; use hal::adc::{ConvResult, LpadcConfig, TriggerPriorityPolicy}; use hal::clocks::periph_helpers::{AdcClockSel, Div4}; use hal::clocks::PoweredClock; @@ -23,7 +23,7 @@ async fn main(_spawner: Spawner) { let p = hal::init(hal::config::Config::default()); unsafe { - init_uart2(hal::pac()); + init_uart2_pins(hal::pac()); } // Create UART configuration @@ -36,7 +36,7 @@ async fn main(_spawner: Spawner) { // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX unsafe { - init_uart2(hal::pac()); + init_uart2_pins(hal::pac()); } let mut uart = Lpuart::new_blocking( p.LPUART2, // Peripheral @@ -49,7 +49,7 @@ async fn main(_spawner: Spawner) { uart.write_str_blocking("\r\n=== ADC polling Example ===\r\n"); unsafe { - init_adc(hal::pac()); + init_adc_pins(hal::pac()); } 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 @@ use embassy_executor::Spawner; use embassy_mcxa as hal; use embassy_mcxa::bind_interrupts; -use embassy_mcxa_examples::init_led; +use embassy_mcxa_examples::init_led_gpio_clocks; use embassy_time::{Duration, Timer}; use hal::gpio::pins::PIO3_18; use hal::gpio::{Level, Output}; @@ -23,7 +23,7 @@ async fn main(_spawner: Spawner) { let _p = hal::init(hal::config::Config::default()); unsafe { - init_led(hal::pac()); + init_led_gpio_clocks(hal::pac()); } // 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) { // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX unsafe { - embassy_mcxa_examples::init_uart2(hal::pac()); + embassy_mcxa_examples::init_uart2_pins(hal::pac()); } let mut uart = Lpuart::new_blocking( 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; use embassy_mcxa as hal; use embassy_mcxa::interrupt::typelevel::Handler; use embassy_mcxa::lpuart::buffered::BufferedLpuart; +use embassy_mcxa::lpuart::Config; use embassy_mcxa::{bind_interrupts, lpuart}; -use embassy_mcxa_examples::init_uart2; +use embassy_mcxa_examples::init_uart2_pins; use embedded_io_async::{Read, Write}; // Bind OS_EVENT for timers plus LPUART2 IRQ for the buffered driver @@ -31,11 +32,11 @@ async fn main(_spawner: Spawner) { hal::interrupt::LPUART2.configure_for_uart(hal::interrupt::Priority::P3); unsafe { - init_uart2(hal::pac()); + init_uart2_pins(hal::pac()); } // UART configuration (enable both TX and RX) - let config = lpuart::Config { + let config = Config { baudrate_bps: 115_200, enable_tx: true, 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 @@ #![no_main] use embassy_executor::Spawner; -use embassy_mcxa_examples::init_uart2; +use embassy_mcxa_examples::init_uart2_pins; use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; use crate::hal::lpuart::{Config, Lpuart}; @@ -15,7 +15,7 @@ async fn main(_spawner: Spawner) { // Board-level init for UART2 clocks and pins. unsafe { - init_uart2(hal::pac()); + init_uart2_pins(hal::pac()); } // 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; use embassy_mcxa::clocks::periph_helpers::OstimerClockSel; use embassy_mcxa::clocks::PoweredClock; use embassy_mcxa::lpuart::{Config, Lpuart}; -use embassy_mcxa_examples::init_uart2; +use embassy_mcxa_examples::init_uart2_pins; use {cortex_m, defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; // 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) { // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX unsafe { - init_uart2(hal::pac()); + init_uart2_pins(hal::pac()); } let mut uart = Lpuart::new_blocking( 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 @@ use embassy_executor::Spawner; use embassy_mcxa::bind_interrupts; -use embassy_mcxa_examples::init_uart2; +use embassy_mcxa_examples::init_uart2_pins; use embassy_time::{Duration, Timer}; +use hal::lpuart::{Config, Lpuart}; use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; // 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) { let p = hal::init(hal::config::Config::default()); // Create UART configuration - let config = hal::lpuart::Config { + let config = Config { baudrate_bps: 115_200, enable_tx: true, enable_rx: true, @@ -30,9 +31,9 @@ async fn main(_spawner: Spawner) { // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX unsafe { - init_uart2(hal::pac()); + init_uart2_pins(hal::pac()); } - let mut uart = hal::lpuart::Lpuart::new_blocking( + let mut uart = Lpuart::new_blocking( p.LPUART2, // Peripheral p.PIO2_2, // TX pin 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) { // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX unsafe { - embassy_mcxa_examples::init_uart2(hal::pac()); + embassy_mcxa_examples::init_uart2_pins(hal::pac()); } let mut uart = Lpuart::new_blocking( 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) { // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX unsafe { - embassy_mcxa_examples::init_uart2(hal::pac()); + embassy_mcxa_examples::init_uart2_pins(hal::pac()); } let mut uart = Lpuart::new_blocking( 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 @@ #![no_main] use embassy_executor::Spawner; +use embassy_mcxa as hal; +use hal::lpuart::{Config, Lpuart}; use hal::rtc::{RtcDateTime, RtcInterruptEnable}; use hal::InterruptExt; -use {cortex_m, embassy_mcxa as hal}; type MyRtc = hal::rtc::Rtc<'static, hal::rtc::Rtc0>; @@ -24,7 +25,7 @@ async fn main(_spawner: Spawner) { let p = hal::init(hal::config::Config::default()); // Create UART configuration - let config = hal::lpuart::Config { + let config = Config { baudrate_bps: 115_200, enable_tx: true, enable_rx: true, @@ -33,9 +34,9 @@ async fn main(_spawner: Spawner) { // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX unsafe { - embassy_mcxa_examples::init_uart2(hal::pac()); + embassy_mcxa_examples::init_uart2_pins(hal::pac()); } - let mut uart = hal::lpuart::Lpuart::new_blocking( + let mut uart = Lpuart::new_blocking( p.LPUART2, // Peripheral p.PIO2_2, // TX pin 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 @@ #![no_std] +#![allow(clippy::missing_safety_doc)] //! Shared board-specific helpers for the FRDM-MCXA276 examples. //! These live with the examples so the HAL stays generic. @@ -8,8 +9,7 @@ use {embassy_mcxa as hal, panic_probe as _}; /// Initialize clocks and pin muxing for UART2 debug console. /// Safe to call multiple times; writes are idempotent for our use. -#[allow(dead_code)] -pub unsafe fn init_uart2(_p: &hal::pac::Peripherals) { +pub unsafe fn init_uart2_pins(_p: &hal::pac::Peripherals) { // NOTE: Lpuart has been updated to properly enable + reset its own clocks. // GPIO has not. _ = clocks::enable_and_reset::(&clocks::NoConfig); @@ -17,15 +17,13 @@ pub unsafe fn init_uart2(_p: &hal::pac::Peripherals) { } /// Initialize clocks for the LED GPIO/PORT used by the blink example. -#[allow(dead_code)] -pub unsafe fn init_led(_p: &hal::pac::Peripherals) { +pub unsafe fn init_led_gpio_clocks(_p: &hal::pac::Peripherals) { _ = clocks::enable_and_reset::(&clocks::NoConfig); _ = clocks::enable_and_reset::(&clocks::NoConfig); } /// Initialize clocks and pin muxing for ADC. -#[allow(dead_code)] -pub unsafe fn init_adc(_p: &hal::pac::Peripherals) { +pub unsafe fn init_adc_pins(_p: &hal::pac::Peripherals) { // NOTE: Lpuart has been updated to properly enable + reset its own clocks. // GPIO has not. _ = clocks::enable_and_reset::(&clocks::NoConfig); -- cgit