Skip to main content

rusty_esp_mid_esp/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![deny(unsafe_code)]
3//! `rusty_esp_mid-esp` — chip backends for `rusty_esp_mid`.
4//!
5//! This is the **wrap** crate of the package: where the silicon must be
6//! touched, it calls the esp-rs HAL (Track B, `esp-hal`) or ESP-IDF (Track A,
7//! `esp-idf`) and exposes the core crate's seams over it — `Kv` for the key's
8//! home, `Rng` for the entropy the key is born from. Nothing identity-specific
9//! lives here; that is the core's job.
10//!
11//! `unsafe` is denied crate-wide; a backend that must use it at an FFI
12//! boundary opts in per block with `#[allow(unsafe_code)]` and a `// SAFETY:`
13//! comment stating the invariant.
14
15#[cfg(feature = "alloc")]
16extern crate alloc;
17
18#[cfg(all(feature = "esp-hal", feature = "esp-idf"))]
19compile_error!("enable exactly one track: `esp-hal` (no_std) or `esp-idf` (std)");
20
21pub use rusty_esp_mid_core as core;
22
23/// Which track this build of the backend crate was compiled for.
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25pub enum Track {
26    /// No chip backend compiled in: host build, traits only.
27    Host,
28    /// Track B — bare metal, esp-hal + Embassy.
29    EspHal,
30    /// Track A — std on ESP-IDF.
31    EspIdf,
32}
33
34/// The track this crate was built with.
35pub const TRACK: Track = if cfg!(feature = "esp-hal") {
36    Track::EspHal
37} else if cfg!(feature = "esp-idf") {
38    Track::EspIdf
39} else {
40    Track::Host
41};
42
43#[cfg(feature = "esp-hal")]
44pub mod hal;
45
46#[cfg(feature = "esp-idf")]
47pub mod idf {
48    //! Track A backends over esp-idf-svc 0.52.
49    pub mod nvs;
50    pub mod rng;
51    pub use nvs::{EspNvsKv, IDENTITY_PARTITION, Protection};
52    pub use rng::EspRng;
53}