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