rusty_esp_audio_esp/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]
2#![deny(unsafe_code)]
3//! `rusty_esp_audio-esp` — chip backends and the Track A transport for
4//! `rusty_esp_audio`.
5//!
6//! This is the **wrap** crate of the package: where the silicon must be
7//! touched, it calls the esp-rs HAL (Track B, `esp-hal`) or ESP-IDF (Track A,
8//! `esp-idf`) and exposes the core crate's traits over it. Nothing product- or
9//! codec-specific lives here; that is the core's job.
10//!
11//! With `std` alone it also carries the transport a Track A device and its
12//! hub share: [`net`] (raw PCM over UDP, the datagrams `ffplay` and `rff`
13//! read directly) and [`wavfile`] (WAV files over `std::fs`). That code is
14//! the same on the laptop, the Pi and the chip, which is why its oracle tests
15//! run on the host.
16//!
17//! `unsafe` is denied crate-wide; a backend that must use it at a DMA or FFI
18//! boundary opts in per block with `#[allow(unsafe_code)]` and a `// SAFETY:`
19//! comment stating the invariant.
20
21#[cfg(feature = "alloc")]
22extern crate alloc;
23
24#[cfg(all(feature = "esp-hal", feature = "esp-idf"))]
25compile_error!("enable exactly one track: `esp-hal` (no_std) or `esp-idf` (std)");
26
27pub use rusty_esp_audio_core as core;
28
29#[cfg(feature = "std")]
30pub mod net;
31#[cfg(feature = "std")]
32pub mod wavfile;
33
34/// Which track this build of the backend crate was compiled for.
35#[derive(Debug, Clone, Copy, PartialEq, Eq)]
36pub enum Track {
37 /// No chip backend compiled in: host build, traits and transport only.
38 Host,
39 /// Track B — bare metal, esp-hal + Embassy.
40 EspHal,
41 /// Track A — std on ESP-IDF.
42 EspIdf,
43}
44
45/// The track this crate was built with.
46pub const TRACK: Track = if cfg!(feature = "esp-hal") {
47 Track::EspHal
48} else if cfg!(feature = "esp-idf") {
49 Track::EspIdf
50} else {
51 Track::Host
52};
53
54#[cfg(feature = "esp-hal")]
55pub mod hal {
56 //! Track B backends. Drivers land here with their esp-hal pin.
57}
58
59#[cfg(feature = "esp-idf")]
60pub mod idf {
61 //! Track A backends over esp-idf-hal 0.46.
62 pub mod pdm;
63 pub use pdm::PdmIn;
64}