Skip to content

Commit

Permalink
Rework new to config, add getters
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail-m1 committed Jul 9, 2024
1 parent ef2e100 commit 61a15d8
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 206 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
esp-idf-hal = "0.43.1"
esp-idf-sys = "0.34.1"
concat-idents = "1.1.5"

[patch.crates-io]
esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys", branch = "master" }
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# esp-camera-rs
Rust wrapper library to interface with the ESP32 camera
Rust wrapper library to interface with the ESP32 and ESP32S4 cameras. The way to define configuration
for camera was reworked, get methods added and set methods rewrote to use macro.

See [examples/camera-example/README.md](examples/camera-example/README.md) for usage details.
4 changes: 3 additions & 1 deletion examples/camera-example/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
This example assumes you have already set up all the tools necessary to compile Rust for ESP32. Follow [The Rust on ESP Book](https://docs.esp-rs.org/book/) for setup steps.
This example is set up for ESP32S3, but you can run it on other ESP32 chips by changing `.cargo/config.toml` and `sdkconfig.defaults` the camera's pins should be changed as well.

To build and run the example you need to set up all the tools necessary to compile Rust for ESP32. Follow [The Rust on ESP Book](https://docs.esp-rs.org/book/) for setup steps.

When you need to export `WIFI_SSID` and `WIFI_PASS` environment variables and run the example by using `cargo run -r`, it will compile and flash the program to an ESP32S3 with a camera. The pins are set up for this [Freenove board](https://github.com/Freenove/Freenove_ESP32_S3_WROOM_Board).

Expand Down
40 changes: 19 additions & 21 deletions examples/camera-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() -> anyhow::Result<()> {
esp_idf_svc::log::EspLogger::initialize_default();

info!("initializing peripherals");
let peripherals = Peripherals::take().unwrap();
let mut peripherals = Peripherals::take().unwrap();
let sysloop = EspSystemEventLoop::take()?;
let nvs = EspDefaultNvsPartition::take()?;

Expand Down Expand Up @@ -44,26 +44,24 @@ fn main() -> anyhow::Result<()> {
led.set_low()?;

info!("Initialize the camera");
let camera = esp_camera_rs::Camera::new(
None,
peripherals.pins.gpio15,
peripherals.pins.gpio11,
peripherals.pins.gpio9,
peripherals.pins.gpio8,
peripherals.pins.gpio10,
peripherals.pins.gpio12,
peripherals.pins.gpio18,
peripherals.pins.gpio17,
peripherals.pins.gpio16,
peripherals.pins.gpio6,
peripherals.pins.gpio7,
peripherals.pins.gpio13,
peripherals.pins.gpio4,
peripherals.pins.gpio5,
esp_idf_sys::camera::pixformat_t_PIXFORMAT_JPEG,
esp_idf_sys::camera::framesize_t_FRAMESIZE_UXGA,
esp_idf_sys::camera::camera_fb_location_t_CAMERA_FB_IN_PSRAM,
)?;

let camera_params = esp_camera_rs::CameraParams::new()
.set_clock_pin(&mut peripherals.pins.gpio15)
.set_d0_pin(&mut peripherals.pins.gpio11)
.set_d1_pin(&mut peripherals.pins.gpio9)
.set_d2_pin(&mut peripherals.pins.gpio8)
.set_d3_pin(&mut peripherals.pins.gpio10)
.set_d4_pin(&mut peripherals.pins.gpio12)
.set_d5_pin(&mut peripherals.pins.gpio18)
.set_d6_pin(&mut peripherals.pins.gpio17)
.set_d7_pin(&mut peripherals.pins.gpio16)
.set_vertical_sync_pin(&mut peripherals.pins.gpio6)
.set_horizontal_reference_pin(&mut peripherals.pins.gpio7)
.set_pixel_clock_pin(&mut peripherals.pins.gpio13)
.set_sda_pin(&mut peripherals.pins.gpio4)
.set_scl_pin(&mut peripherals.pins.gpio5);

let camera = esp_camera_rs::Camera::new(&camera_params)?;

info!("initializing http servert");

Expand Down
Loading

0 comments on commit 61a15d8

Please sign in to comment.