Skip to main content

esp_idf_sys/
lib.rs

1//! Raw Rust bindings for the [ESP-IDF SDK](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/).
2//!
3//! # Build Prerequisites
4//!
5//! Follow the [Prerequisites](https://github.com/esp-rs/esp-idf-template#prerequisites) section in the `esp-idf-template` crate.
6//!
7#![doc = include_str!("../BUILD-OPTIONS.md")]
8#![no_std]
9#![cfg_attr(
10    all(not(feature = "std"), feature = "alloc_handler"),
11    feature(alloc_error_handler)
12)]
13#![allow(unknown_lints)]
14#![allow(renamed_and_removed_lints)]
15#![allow(unexpected_cfgs)]
16
17pub use bindings::*;
18pub use error::*;
19
20// Don't use esp_idf_soc_pcnt_supported; that's only on ESP-IDF v5.x+.
21// pcnt_unit_t and friends are only needed for the legacy PCNT API (removed in v6.0).
22#[cfg(all(
23    not(esp_idf_version_at_least_6_0_0),
24    any(esp32, esp32s2, esp32s3, esp32c5, esp32c6, esp32h2, esp32p4)
25))]
26pub use pcnt::*;
27
28#[doc(hidden)]
29pub use build_time;
30#[doc(hidden)]
31pub use const_format;
32#[doc(hidden)]
33pub use patches::PatchesRef;
34
35#[cfg(feature = "std")]
36#[allow(unused_imports)]
37#[macro_use]
38extern crate std;
39
40#[cfg(feature = "alloc")]
41#[allow(unused_imports)]
42#[macro_use]
43extern crate alloc;
44
45mod alloc;
46#[cfg(esp_idf_version_at_least_5_1_0)]
47mod app_desc;
48mod error;
49mod panic;
50mod patches;
51#[cfg(all(
52    not(esp_idf_version_at_least_6_0_0),
53    any(esp32, esp32s2, esp32s3, esp32c5, esp32c6, esp32h2, esp32p4)
54))]
55mod pcnt;
56
57mod checks;
58mod start;
59mod stdio;
60
61pub use stdio::restore_posix_stdio_fds;
62
63/// A hack to make sure that a few patches to the ESP-IDF which are implemented in Rust
64/// are linked to the final executable
65///
66/// Call this function once at the beginning of your main function
67pub fn link_patches() -> PatchesRef {
68    patches::link_patches()
69}
70
71#[allow(clippy::all)]
72#[allow(unnecessary_transmutes)]
73#[allow(non_upper_case_globals)]
74#[allow(non_camel_case_types)]
75#[allow(non_snake_case)]
76#[allow(rustdoc::all)]
77#[allow(improper_ctypes)]
78// TODO: For now, as 5.0 spits out tons of these
79// bindgen maps `size_t` to `c_uint`, but std expects `usize` for these runtime
80// symbols; on the 32-bit ESP targets `c_uint == usize`, so the signatures are compatible
81#[allow(suspicious_runtime_symbol_definitions)]
82#[allow(dead_code)]
83mod bindings {
84    #[cfg(all(
85        not(esp_idf_version_at_least_6_0_0),
86        any(esp32, esp32s2, esp32s3, esp32c5, esp32c6, esp32h2, esp32p4)
87    ))]
88    use crate::pcnt::*;
89
90    include!(env!("EMBUILD_GENERATED_BINDINGS_FILE"));
91}