arducam-legacy

Crates.ioarducam-legacy
lib.rsarducam-legacy
version0.1.2
sourcesrc
created_at2023-07-20 21:35:28.340908
updated_at2023-07-31 18:33:19.126754
descriptionDriver for Arducam legacy cameras based on embedded-hal
homepage
repositoryhttps://github.com/radekw8733/arducam-legacy
max_upload_size
id921782
size37,510
Radosław Wolański (radekw8733)

documentation

README

arducam-legacy

This Rust library provides embedded-hal support for legacy Arducam SPI-based cameras like e.g. ArduCAM MINI 2MP Plus. It has been rewritten from original Arducam library written in C.

Milestones

  • OV2640 support
  • JPEG image support
  • Different resolutions
  • More sensor models support
  • DMA API

Model support

Currently this library is only tested with Arducam Mini 2MP Plus model. Contributions for other models are welcome!

MCU support

Any microcontroller HAL with embedded-hal support should work with this driver

Usage

Add this line to Cargo.toml under [dependencies] of your project

[dependencies]
arducam-legacy = "0.1.0"

Example

This example shows how to capture image and store it in array buffer

#![no_std]
#![no_main]

use stm32_hal2::{pac, gpio::{Pin, Port, PinMode, OutputType}, spi::{Spi, BaudRate}, i2c::I2c, timer::Timer};
use cortex_m::delay::Delay;

use arducam_legacy::Arducam;

fn main() -> ! {
    let cp = cortex_m::Peripherals::take().unwrap();
    let dp = pac::Peripherals::take().unwrap();

    // Clocks setup
    let clock_cfg = stm32_hal2::clocks::Clocks::default();
    clock_cfg.setup().unwrap();
    let mut delay = Delay::new(cp.SYST, clock_cfg.systick());
    let mut mono_timer = Timer::new_tim2(dp.TIM2, 100.0, Default::default(), &clock_cfg);

    // Example pinout configuration
    // Adapt to your HAL crate
    let _arducam_spi_mosi = Pin::new(Port::D, 4, PinMode::Alt(5));
    let _arducam_spi_miso = Pin::new(Port::D, 3, PinMode::Alt(5));
    let _arducam_spi_sck = Pin::new(Port::D, 1, PinMode::Alt(5));
    let arducam_cs = Pin::new(Port::D, 0, PinMode::Output);
    let arducam_spi = Spi::new(dp.SPI2, Default::default(), BaudRate::Div32);
    let mut arducam_i2c_sda = Pin::new(Port::F, 0, PinMode::Alt(4));
    arducam_i2c_sda.output_type(OutputType::OpenDrain);
    let mut arducam_i2c_scl = Pin::new(Port::F, 1, PinMode::Alt(4));
    arducam_i2c_scl.output_type(OutputType::OpenDrain);
    let arducam_i2c = I2c::new(dp.I2C2, Default::default(), &clock_cfg);

    let mut arducam = Arducam::new(
        arducam_spi,
        arducam_i2c,
        arducam_cs,
        arducam_legacy::Resolution::Res320x240, arducam_legacy::ImageFormat::JPEG
        );
    arducam.init(&mut delay).unwrap();

    arducam.start_capture().unwrap();
    while !arducam.is_capture_done().unwrap() { delay.delay_ms(1) }
    let mut image = [0; 8192];
    let length = arducam.get_fifo_length().unwrap();
    let final_length = arducam.read_captured_image(&mut image).unwrap();

    loop {}
}
Commit count: 6

cargo fmt