1#![no_std]
4#![cfg_attr(nightly, feature(doc_cfg))]
5#![deny(missing_docs)]
6
7#[cfg(feature = "_radio-esp")]
8extern crate alloc;
9
10#[cfg(not(feature = "custom-app-descriptor"))]
11mod app_desc {
12 esp_bootloader_esp_idf::esp_app_desc!();
13}
14
15#[cfg(feature = "_radio-esp")]
16mod radio;
17#[cfg(feature = "_radio-esp")]
18mod scheduler;
19#[cfg(feature = "_radio-esp")]
20mod semaphore;
21#[cfg(feature = "_radio-esp")]
22mod wait_queue;
23
24pub mod gpio;
25
26#[cfg(feature = "ble-esp")]
27#[doc(hidden)]
28pub mod ble;
29
30#[cfg(feature = "hwrng")]
31#[doc(hidden)]
32pub mod hwrng {
33 pub fn construct_rng(_peripherals: &mut crate::OptionalPeripherals) {
34 }
36}
37
38#[cfg(feature = "i2c")]
39pub mod i2c;
40
41#[doc(hidden)]
42pub mod identity;
43
44#[cfg(feature = "spi")]
45pub mod spi;
46
47#[cfg(feature = "uart")]
48pub mod uart;
49
50#[cfg(feature = "usb")]
51#[doc(hidden)]
52pub mod usb;
53
54#[cfg(feature = "wifi")]
55#[doc(hidden)]
56pub mod wifi;
57
58#[doc(hidden)]
59pub mod peripheral {}
60
61pub mod peripherals {
62 pub use esp_hal::peripherals::*;
65}
66
67#[cfg(feature = "time")]
68mod time_driver;
69
70#[doc(hidden)]
71pub use esp_hal::peripherals::OptionalPeripherals;
72
73#[doc(hidden)]
74pub trait IntoPeripheral<'a, T> {
75 fn into_hal_peripheral(self) -> T;
76}
77
78#[doc(hidden)]
79impl<T> IntoPeripheral<'_, T> for T {
80 fn into_hal_peripheral(self) -> T {
81 self
82 }
83}
84
85#[doc(hidden)]
86#[must_use]
87pub fn init() -> OptionalPeripherals {
88 let config = esp_hal::Config::default().with_cpu_clock(esp_hal::clock::CpuClock::max());
89
90 #[allow(unused_mut, reason = "mut only needed for some features")]
91 let mut peripherals = OptionalPeripherals::from(esp_hal::init(config));
92
93 #[cfg(feature = "hwrng")]
94 {
95 ariel_os_log::debug!("initializing hwrng");
96 let mut rng = esp_hal::rng::Rng::new();
97 ariel_os_random::construct_rng(&mut ariel_os_random::RngAdapter(&mut rng));
98 }
99
100 #[cfg(feature = "time")]
101 {
102 let embassy_timer = {
103 cfg_select! {
104 context = "esp32" => {
105 use esp_hal::timer::timg::TimerGroup;
106 TimerGroup::new(peripherals.TIMG1.take().unwrap()).timer0
107 }
108 _ => {
109 use esp_hal::timer::systimer::SystemTimer;
110 SystemTimer::new(peripherals.SYSTIMER.take().unwrap()).alarm0
111 }
112 }
113 };
114
115 crate::time_driver::init(embassy_timer);
116 }
117
118 peripherals
119}
120
121#[cfg(feature = "time")]
122embassy_time_driver::time_driver_impl!(static TIMER_QUEUE: crate::time_driver::TimerQueue = crate::time_driver::TimerQueue::new());