Skip to main content

rusty_esp_image_esp/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![deny(unsafe_code)]
3//! `rusty_esp_image-esp` — chip backends for `rusty_esp_image`.
4//!
5//! This is the **wrap** crate of the package: where the silicon must be
6//! touched, it calls ESP-IDF (Track A, `esp-idf`) or the esp-rs HAL (Track B,
7//! `esp-hal`) and exposes the core crate's `ImageSource` over it.
8//!
9//! Track A's [`idf::IdfCamera`] binds Espressif's `esp32-camera` component —
10//! the honest label from the plan: *application in Rust, driver wrapped*. Its
11//! FFI calls are the only `unsafe` in the package, each fenced with the
12//! invariant it relies on.
13
14#[cfg(feature = "alloc")]
15extern crate alloc;
16
17#[cfg(all(feature = "esp-hal", feature = "esp-idf"))]
18compile_error!("enable exactly one track: `esp-hal` (no_std) or `esp-idf` (std)");
19
20pub use rusty_esp_image_core as core;
21
22/// Which track this build of the backend crate was compiled for.
23#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24pub enum Track {
25    /// No chip backend compiled in: host build, traits only.
26    Host,
27    /// Track B — bare metal, esp-hal + Embassy.
28    EspHal,
29    /// Track A — std on ESP-IDF.
30    EspIdf,
31}
32
33/// The track this crate was built with.
34pub const TRACK: Track = if cfg!(feature = "esp-hal") {
35    Track::EspHal
36} else if cfg!(feature = "esp-idf") {
37    Track::EspIdf
38} else {
39    Track::Host
40};
41
42/// The DVP/SCCB pins of a camera board. `-1` means "not connected".
43#[derive(Debug, Clone, Copy, PartialEq, Eq)]
44pub struct CameraPins {
45    /// Power-down.
46    pub pwdn: i32,
47    /// Reset.
48    pub reset: i32,
49    /// Master clock out.
50    pub xclk: i32,
51    /// SCCB data.
52    pub sccb_sda: i32,
53    /// SCCB clock.
54    pub sccb_scl: i32,
55    /// Data lines, `d[7]` is the MSB (Y9 on OmniVision naming).
56    pub d: [i32; 8],
57    /// Vertical sync.
58    pub vsync: i32,
59    /// Horizontal reference.
60    pub href: i32,
61    /// Pixel clock.
62    pub pclk: i32,
63}
64
65/// Seeed Studio XIAO ESP32-S3 Sense (OV2640 on the Sense expansion board).
66pub const XIAO_ESP32S3_SENSE: CameraPins = CameraPins {
67    pwdn: -1,
68    reset: -1,
69    xclk: 10,
70    sccb_sda: 40,
71    sccb_scl: 39,
72    // Y2..Y9 = d[0]..d[7]
73    d: [15, 17, 18, 16, 14, 12, 11, 48],
74    vsync: 38,
75    href: 47,
76    pclk: 13,
77};
78
79/// AI-Thinker ESP32-CAM (OV2640).
80pub const AI_THINKER_ESP32_CAM: CameraPins = CameraPins {
81    pwdn: 32,
82    reset: -1,
83    xclk: 0,
84    sccb_sda: 26,
85    sccb_scl: 27,
86    d: [5, 18, 19, 21, 36, 39, 34, 35],
87    vsync: 25,
88    href: 23,
89    pclk: 22,
90};
91
92#[cfg(feature = "esp-idf")]
93pub mod idf;
94
95#[cfg(feature = "esp-hal")]
96pub mod hal;