From 7ee5cb570f0c0daeb2e6a9d5120fd96ee885025f Mon Sep 17 00:00:00 2001 From: James Munns Date: Mon, 24 Nov 2025 18:41:43 +0100 Subject: Remove the pac singleton function (#42) There will be a follow up PR that removes the unsafe `init` functions, but I wanted to squash this out first in case I don't get to it all today. --- examples/src/bin/adc_interrupt.rs | 4 ++-- examples/src/bin/adc_polling.rs | 11 ++--------- examples/src/bin/hello.rs | 2 +- examples/src/bin/lpuart_buffered.rs | 2 +- examples/src/bin/lpuart_polling.rs | 2 +- examples/src/bin/rtc_alarm.rs | 2 +- examples/src/lib.rs | 4 ++-- src/lib.rs | 15 --------------- 8 files changed, 10 insertions(+), 32 deletions(-) diff --git a/examples/src/bin/adc_interrupt.rs b/examples/src/bin/adc_interrupt.rs index 9fed052fd..0d3a75a28 100644 --- a/examples/src/bin/adc_interrupt.rs +++ b/examples/src/bin/adc_interrupt.rs @@ -36,7 +36,7 @@ async fn main(_spawner: Spawner) { // Create UART instance using LPUART2 with P2_2 as TX and P2_3 as RX unsafe { - embassy_mcxa_examples::init_uart2_pins(hal::pac()); + embassy_mcxa_examples::init_uart2_pins(); } let mut uart = Lpuart::new_blocking( p.LPUART2, // Peripheral @@ -48,7 +48,7 @@ async fn main(_spawner: Spawner) { uart.write_str_blocking("\r\n=== ADC interrupt Example ===\r\n"); unsafe { - init_adc_pins(hal::pac()); + init_adc_pins(); } let adc_config = LpadcConfig { diff --git a/examples/src/bin/adc_polling.rs b/examples/src/bin/adc_polling.rs index 545f8f77a..02ac321b5 100644 --- a/examples/src/bin/adc_polling.rs +++ b/examples/src/bin/adc_polling.rs @@ -22,10 +22,6 @@ const G_LPADC_RESULT_SHIFT: u32 = 0; async fn main(_spawner: Spawner) { let p = hal::init(hal::config::Config::default()); - unsafe { - init_uart2_pins(hal::pac()); - } - // Create UART configuration let config = Config { baudrate_bps: 115_200, @@ -36,7 +32,8 @@ async fn main(_spawner: Spawner) { // Create UART instance using LPUART2 with P2_2 as TX and P2_3 as RX unsafe { - init_uart2_pins(hal::pac()); + init_uart2_pins(); + init_adc_pins(); } let mut uart = Lpuart::new_blocking( p.LPUART2, // Peripheral @@ -48,10 +45,6 @@ async fn main(_spawner: Spawner) { uart.write_str_blocking("\r\n=== ADC polling Example ===\r\n"); - unsafe { - init_adc_pins(hal::pac()); - } - let adc_config = LpadcConfig { enable_in_doze_mode: true, conversion_average_mode: CalAvgs::Average128, diff --git a/examples/src/bin/hello.rs b/examples/src/bin/hello.rs index e2d0b413d..0362480c1 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 P2_2 as TX and P2_3 as RX unsafe { - embassy_mcxa_examples::init_uart2_pins(hal::pac()); + embassy_mcxa_examples::init_uart2_pins(); } 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 b0d19ef16..4c9294f57 100644 --- a/examples/src/bin/lpuart_buffered.rs +++ b/examples/src/bin/lpuart_buffered.rs @@ -32,7 +32,7 @@ async fn main(_spawner: Spawner) { hal::interrupt::LPUART2.configure_for_uart(hal::interrupt::Priority::P3); unsafe { - init_uart2_pins(hal::pac()); + init_uart2_pins(); } // UART configuration (enable both TX and RX) diff --git a/examples/src/bin/lpuart_polling.rs b/examples/src/bin/lpuart_polling.rs index 525d42e2c..c8666e64a 100644 --- a/examples/src/bin/lpuart_polling.rs +++ b/examples/src/bin/lpuart_polling.rs @@ -15,7 +15,7 @@ async fn main(_spawner: Spawner) { // Board-level init for UART2 clocks and pins. unsafe { - init_uart2_pins(hal::pac()); + init_uart2_pins(); } // Create UART configuration diff --git a/examples/src/bin/rtc_alarm.rs b/examples/src/bin/rtc_alarm.rs index a54b4a817..6f8a77101 100644 --- a/examples/src/bin/rtc_alarm.rs +++ b/examples/src/bin/rtc_alarm.rs @@ -34,7 +34,7 @@ async fn main(_spawner: Spawner) { // Create UART instance using LPUART2 with P2_2 as TX and P2_3 as RX unsafe { - embassy_mcxa_examples::init_uart2_pins(hal::pac()); + embassy_mcxa_examples::init_uart2_pins(); } let mut uart = Lpuart::new_blocking( p.LPUART2, // Peripheral diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 66b93450a..f5f6124c0 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -9,7 +9,7 @@ use {defmt_rtt as _, 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. -pub unsafe fn init_uart2_pins(_p: &hal::pac::Peripherals) { +pub unsafe fn init_uart2_pins() { // NOTE: Lpuart has been updated to properly enable + reset its own clocks. // GPIO has not. _ = clocks::enable_and_reset::(&clocks::periph_helpers::NoConfig); @@ -17,7 +17,7 @@ pub unsafe fn init_uart2_pins(_p: &hal::pac::Peripherals) { } /// Initialize clocks and pin muxing for ADC. -pub unsafe fn init_adc_pins(_p: &hal::pac::Peripherals) { +pub unsafe fn init_adc_pins() { // NOTE: Lpuart has been updated to properly enable + reset its own clocks. // GPIO has not. _ = clocks::enable_and_reset::(&clocks::periph_helpers::NoConfig); diff --git a/src/lib.rs b/src/lib.rs index 6f3a63c94..95e6b3479 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -322,21 +322,6 @@ embassy_hal_internal::peripherals!( WWDT0, ); -/// Get access to the PAC Peripherals for low-level register access. -/// This is a lazy-initialized singleton that can be called after init(). -#[allow(static_mut_refs)] -pub fn pac() -> &'static pac::Peripherals { - // SAFETY: We only call this after init(), and the PAC is a singleton. - // The embassy peripheral tokens ensure we don't have multiple mutable accesses. - unsafe { - static mut PAC_INSTANCE: Option = None; - if PAC_INSTANCE.is_none() { - PAC_INSTANCE = Some(pac::Peripherals::steal()); - } - PAC_INSTANCE.as_ref().unwrap() - } -} - // Use cortex-m-rt's #[interrupt] attribute directly; PAC does not re-export it. // Re-export interrupt traits and types -- cgit