ariel_os_nrf/
lib.rs

1//! Items specific to the Nordic Semiconductor nRF MCUs.
2
3#![no_std]
4#![cfg_attr(nightly, feature(doc_cfg))]
5#![deny(missing_docs)]
6
7pub mod gpio;
8
9mod irqs;
10
11#[doc(hidden)]
12pub mod peripheral {
13    pub use embassy_nrf::Peripheral;
14}
15
16#[cfg(feature = "ble")]
17#[doc(hidden)]
18pub mod ble;
19
20#[cfg(feature = "external-interrupts")]
21#[doc(hidden)]
22pub mod extint_registry;
23
24#[cfg(feature = "hwrng")]
25#[doc(hidden)]
26pub mod hwrng;
27
28#[cfg(feature = "i2c")]
29pub mod i2c;
30
31#[doc(hidden)]
32pub mod identity;
33
34#[cfg(feature = "nrf91-modem")]
35#[doc(hidden)]
36pub mod modem;
37
38#[cfg(feature = "spi")]
39pub mod spi;
40
41#[cfg(feature = "uart")]
42pub mod uart;
43
44#[cfg(feature = "storage")]
45#[doc(hidden)]
46pub mod storage;
47
48#[cfg(feature = "usb")]
49#[doc(hidden)]
50pub mod usb;
51
52#[cfg(feature = "executor-interrupt")]
53#[doc(hidden)]
54pub use embassy_executor::InterruptExecutor as Executor;
55
56#[cfg(feature = "executor-interrupt")]
57#[cfg(context = "nrf51")]
58ariel_os_embassy_common::executor_swi!(SWI0);
59
60#[cfg(feature = "executor-interrupt")]
61#[cfg(context = "nrf52")]
62ariel_os_embassy_common::executor_swi!(EGU0_SWI0);
63
64#[cfg(feature = "executor-interrupt")]
65#[cfg(any(context = "nrf53", context = "nrf91"))]
66ariel_os_embassy_common::executor_swi!(EGU0);
67
68use embassy_nrf::config::Config;
69
70#[doc(hidden)]
71pub use embassy_nrf::{OptionalPeripherals, interrupt};
72
73pub use embassy_nrf::peripherals;
74
75#[cfg(feature = "executor-interrupt")]
76#[doc(hidden)]
77pub static EXECUTOR: Executor = Executor::new();
78
79#[doc(hidden)]
80#[must_use]
81pub fn init() -> OptionalPeripherals {
82    enable_flash_cache();
83
84    let peripherals = embassy_nrf::init(Config::default());
85    OptionalPeripherals::from(peripherals)
86}
87
88fn enable_flash_cache() {
89    // (no flash cache on nrf51)
90    cfg_if::cfg_if! {
91        if #[cfg(any(
92                context = "nrf52",
93                context = "nrf5340-net",
94                context = "nrf91"
95            ))] {
96            embassy_nrf::pac::NVMC
97                .icachecnf()
98                .write(|w| w.set_cacheen(true));
99        }
100        else if #[cfg(context = "nrf5340")] {
101            embassy_nrf::pac::CACHE_S
102                .enable().write(|w| w.set_enable(true));
103        }
104    }
105}