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#[cfg(any(esp32, esp32s2, esp32s3, esp32c5, esp32c6, esp32h2, esp32p4))]
22pub use pcnt::*;
23
24#[doc(hidden)]
25pub use build_time;
26#[doc(hidden)]
27pub use const_format;
28#[doc(hidden)]
29pub use patches::PatchesRef;
30
31#[cfg(feature = "std")]
32#[allow(unused_imports)]
33#[macro_use]
34extern crate std;
35
36#[cfg(feature = "alloc")]
37#[allow(unused_imports)]
38#[macro_use]
39extern crate alloc;
40
41mod alloc;
42#[cfg(esp_idf_version_at_least_5_1_0)]
43mod app_desc;
44mod error;
45mod panic;
46mod patches;
47#[cfg(any(esp32, esp32s2, esp32s3, esp32c5, esp32c6, esp32h2, esp32p4))]
48mod pcnt;
49
50mod start;
51
52/// If any of the two constants below do not compile, you have not properly setup the rustc cfg flag `espidf_time64`:
53/// When compiling against ESP-IDF V5.X or later, you need to define the following in your `.config/cargo.toml` file
54/// (look for this file in the root of your binary crate):
55/// ```
56/// [build]
57/// rustflags = "--cfg espidf_time64"
58/// ```
59///
60/// When compiling against ESP-IDF V4.X, you need to remove the above flag
61#[allow(deprecated)]
62#[allow(unused)]
63#[cfg(feature = "std")]
64const ESP_IDF_TIME64_CHECK: ::std::os::espidf::raw::time_t = 0 as crate::time_t;
65#[allow(unused)]
66const ESP_IDF_TIME64_CHECK_LIBC: ::libc::time_t = 0 as crate::time_t;
67
68/// A hack to make sure that a few patches to the ESP-IDF which are implemented in Rust
69/// are linked to the final executable
70///
71/// Call this function once at the beginning of your main function
72pub fn link_patches() -> PatchesRef {
73    patches::link_patches()
74}
75
76#[allow(clippy::all)]
77#[allow(unnecessary_transmutes)]
78#[allow(non_upper_case_globals)]
79#[allow(non_camel_case_types)]
80#[allow(non_snake_case)]
81#[allow(rustdoc::all)]
82#[allow(improper_ctypes)] // TODO: For now, as 5.0 spits out tons of these
83#[allow(dead_code)]
84mod bindings {
85    #[cfg(any(esp32, esp32s2, esp32s3, esp32c5, esp32c6, esp32h2, esp32p4))]
86    use crate::pcnt::*;
87
88    include!(env!("EMBUILD_GENERATED_BINDINGS_FILE"));
89}