diff options
| author | James Munns <[email protected]> | 2025-11-18 14:19:09 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-18 14:19:09 +0100 |
| commit | 5b1149a52dbec9e3bdd10dc341dc0751ab4798a6 (patch) | |
| tree | 3ff7098471cf660a54a707464a0e2feb2080b09e /examples/src/lib.rs | |
| parent | 62e297c130ac26afe4d7d5752bb79709bd370e39 (diff) | |
| parent | c8942aec2478ff077b55da0e86801f8a6a88a7de (diff) | |
Merge pull request #11 from jamesmunns/james/impl-clocks
Implement initial `clock` driver.
This PR introduces an initial two-phase clock driver system:
1. The first stage is responsible for initializing the core/system clocks at the time of `embassy_mcxa::init()`
2. The second stage is done on creation of peripherals
This work is limited to currently used clocks and peripherals, but has room for expansion for later peripherals. This model is based on the preliminary refactoring performed for the `embassy-imxrt` crate.
Diffstat (limited to 'examples/src/lib.rs')
| -rw-r--r-- | examples/src/lib.rs | 58 |
1 files changed, 13 insertions, 45 deletions
diff --git a/examples/src/lib.rs b/examples/src/lib.rs index cf4194559..4bb334da5 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs | |||
| @@ -1,63 +1,31 @@ | |||
| 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. |
| 5 | 6 | ||
| 6 | use hal::{clocks, pins, reset}; | 7 | use hal::{clocks, pins}; |
| 7 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | 8 | use {defmt_rtt as _, 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 | /// | 12 | pub unsafe fn init_uart2_pins(_p: &hal::pac::Peripherals) { |
| 12 | /// # Safety | 13 | // NOTE: Lpuart has been updated to properly enable + reset its own clocks. |
| 13 | /// | 14 | // GPIO has not. |
| 14 | /// Called only once to initialize the peripheral | 15 | _ = clocks::enable_and_reset::<hal::peripherals::PORT2>(&clocks::periph_helpers::NoConfig); |
| 15 | #[allow(dead_code)] | ||
| 16 | pub unsafe fn init_uart2(p: &hal::pac::Peripherals) { | ||
| 17 | clocks::ensure_frolf_running(p); | ||
| 18 | clocks::enable_uart2_port2(p); | ||
| 19 | reset::release_reset_port2(p); | ||
| 20 | reset::release_reset_lpuart2(p); | ||
| 21 | pins::configure_uart2_pins_port2(); | 16 | pins::configure_uart2_pins_port2(); |
| 22 | clocks::select_uart2_clock(p); | ||
| 23 | } | 17 | } |
| 24 | 18 | ||
| 25 | /// 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. |
| 26 | /// | 20 | pub unsafe fn init_led_gpio_clocks(_p: &hal::pac::Peripherals) { |
| 27 | /// # Safety | 21 | _ = clocks::enable_and_reset::<hal::peripherals::PORT3>(&clocks::periph_helpers::NoConfig); |
| 28 | /// | 22 | _ = clocks::enable_and_reset::<hal::peripherals::GPIO3>(&clocks::periph_helpers::NoConfig); |
| 29 | /// Called only once to initialize the peripheral | ||
| 30 | #[allow(dead_code)] | ||
| 31 | pub unsafe fn init_led(p: &hal::pac::Peripherals) { | ||
| 32 | clocks::enable_led_port(p); | ||
| 33 | reset::release_reset_gpio3(p); | ||
| 34 | reset::release_reset_port3(p); | ||
| 35 | } | ||
| 36 | |||
| 37 | /// Initialize clocks for OSTIMER0 (1 MHz source). | ||
| 38 | /// | ||
| 39 | /// # Safety | ||
| 40 | /// | ||
| 41 | /// Called only once to initialize the peripheral | ||
| 42 | #[allow(dead_code)] | ||
| 43 | pub unsafe fn init_ostimer0(p: &hal::pac::Peripherals) { | ||
| 44 | clocks::ensure_frolf_running(p); | ||
| 45 | clocks::enable_ostimer0(p); | ||
| 46 | reset::release_reset_ostimer0(p); | ||
| 47 | clocks::select_ostimer0_clock_1m(p); | ||
| 48 | } | 23 | } |
| 49 | 24 | ||
| 50 | /// Initialize clocks and pin muxing for ADC. | 25 | /// Initialize clocks and pin muxing for ADC. |
| 51 | /// | 26 | pub unsafe fn init_adc_pins(_p: &hal::pac::Peripherals) { |
| 52 | /// # Safety | 27 | // NOTE: Lpuart has been updated to properly enable + reset its own clocks. |
| 53 | /// | 28 | // GPIO has not. |
| 54 | /// Called only once to initialize the peripheral | 29 | _ = clocks::enable_and_reset::<hal::peripherals::PORT1>(&clocks::periph_helpers::NoConfig); |
| 55 | #[allow(dead_code)] | ||
| 56 | pub unsafe fn init_adc(p: &hal::pac::Peripherals) { | ||
| 57 | clocks::ensure_frolf_running(p); | ||
| 58 | clocks::enable_adc(p); | ||
| 59 | reset::release_reset_port1(p); | ||
| 60 | reset::release_reset_adc1(p); | ||
| 61 | pins::configure_adc_pins(); | 30 | pins::configure_adc_pins(); |
| 62 | clocks::select_adc_clock(p); | ||
| 63 | } | 31 | } |
