Struct arducam_mega::ArducamMega
source · pub struct ArducamMega<SPI, Delay> { /* private fields */ }Expand description
The main ArducamMega struct
This struct is the driver’s main entrypoint. By providing it with a configured SPI device and Delay implementation, this driver will be able to configure the Arducam Mega camera, take pictures, and read the picture data back from the camera.
Examples
The following example shows how the camera could be used on an ESP32 using the SPI3 device.
let peripherals = Peripherals::take();
let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock240MHz).freeze();
let delay = Delay::new(&clocks);
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let sclk = io.pins.gpio18;
let miso = io.pins.gpio19;
let mosi = io.pins.gpio23;
let cs = io.pins.gpio5;
let spi_controller = SpiBusController::from_spi(Spi::new_no_cs(
peripherals.SPI3,
sclk,
mosi,
miso,
8u32.MHz(),
SpiMode::Mode0,
&mut system.peripheral_clock_control,
&clocks,
));
let spi_device_1 = spi_controller.add_device(cs);
let mut cam = ArducamMega::new(spi_device_1, delay);
cam.reset()?
.set_format(Format::Jpeg)?
.set_resolution(Resolution::Hd)?
.set_white_balance_mode(WhiteBalanceMode::Home)?;
let length = cam
.capture()?
.read_fifo_length()?;
// assuming buf.len() == length
cam.read_fifo_full(buf)?;Implementations§
source§impl<SPI, Delay> ArducamMega<SPI, Delay>where
SPI: SpiDevice,
SPI::Bus: SpiBus,
Delay: DelayUs,
impl<SPI, Delay> ArducamMega<SPI, Delay>where SPI: SpiDevice, SPI::Bus: SpiBus, Delay: DelayUs,
pub fn new(spi: SPI, delay: Delay) -> Self
sourcepub fn reset(&mut self) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn reset(&mut self) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Resets the camera sensor sensor
This command sends a reset command to the camera. The Arducam SDK uses this after initialisation to ensure that the sensor is in a known-good state.
sourcepub fn get_camera_type(
&mut self
) -> Result<CameraType, Error<SPI::Error, Delay::Error>>
pub fn get_camera_type( &mut self ) -> Result<CameraType, Error<SPI::Error, Delay::Error>>
Reads the camera model from the camera
This function uses the SensorId register in the camera to obtain information about the
sensor type. See CameraType for more information.
sourcepub fn set_auto_focus(
&mut self,
value: u8
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Available on crate feature 5mp only.
pub fn set_auto_focus( &mut self, value: u8 ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
5mp only.Sets the auto-focus of the camera
It is not clear how this feature should be used. As of current testing, only sending 0x00
actually produces successful captures. Sending 0x01 makes the camera produce invalid
image data. More testing welcome.
sourcepub fn set_format(
&mut self,
format: Format
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn set_format( &mut self, format: Format ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Sets the capture format of the camera
This function allows you to control what format the camera captures pictures in.
Format::Jpeg provides a good mix between image size and quality, and is the
default.
sourcepub fn set_resolution(
&mut self,
resolution: Resolution
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn set_resolution( &mut self, resolution: Resolution ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Sets the capture resolution of the camera
This function allows you to control the resolution of the pictures that are captured by the
camera. Both the 3MP and 5MP cameras have two different default resolutions. See
Resolution for more details.
sourcepub fn set_debug_device_address(
&mut self,
addr: u8
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn set_debug_device_address( &mut self, addr: u8 ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Sets the camera’s debug device address
The Arducam SDK uses this command as part of the camera initialisation with the address
0x78, however this does not appear to be necessary for the camera to function properly.
sourcepub fn capture_finished(
&mut self
) -> Result<bool, Error<SPI::Error, Delay::Error>>
pub fn capture_finished( &mut self ) -> Result<bool, Error<SPI::Error, Delay::Error>>
Checks whether the sensor has finished capturing an image
This command reads a register in the camera to check if the sensor has finished taking a
picture. You should not attempt to read the FIFO buffer length nor read any FIFO buffer
data prior to this returning true.
sourcepub fn capture(&mut self) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn capture(&mut self) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Takes a picture using the currently-configured settings
This command starts by emptying the camera’s FIFO buffer and subsequently tells the sensor to capture an image. The image will be captured using the currently-configured settings (white balance, gain, exposure, colour filters, etc). This command blocks until the sensor has finished capturing the image.
sourcepub fn capture_noblock(
&mut self
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn capture_noblock( &mut self ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Non-blocking version of capture()
sourcepub fn read_fifo_length(
&mut self
) -> Result<usize, Error<SPI::Error, Delay::Error>>
pub fn read_fifo_length( &mut self ) -> Result<usize, Error<SPI::Error, Delay::Error>>
Reads the size of the camera’s FIFO buffer length
This function reads out the size of the FIFO buffer length. This (roughly) represents the size of the picture. It appears that in some cases, the reported buffer is larger than the actual picture data.
sourcepub fn read_fifo_byte(&mut self) -> Result<u8, Error<SPI::Error, Delay::Error>>
pub fn read_fifo_byte(&mut self) -> Result<u8, Error<SPI::Error, Delay::Error>>
Reads a single byte out of the FIFO buffer
Returns the first byte out of the FIFO buffer. After it has been read, the FIFO buffer will
advance and the byte will be gone from the camera. In theory, calling this function
fifo_length times should provide you with the full
picture data.
Reading out the entire image data like this will be relatively slow, as each byte transfer
will require an SPI transaction to be setup and ended. For faster transfers, please see
read_fifo_full.
sourcepub fn read_fifo_full<T>(
&mut self,
data: &mut T
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>where
T: AsMut<[u8]>,
pub fn read_fifo_full<T>( &mut self, data: &mut T ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>where T: AsMut<[u8]>,
Reads out the entire FIFO buffer
Reads out the camera’s entire FIFO buffer into data. data must be large enough to
accomodate the entire data transfer (as indicated by
read_fifo_length()), or some data loss may occur. The
data is currently read in chunks of 63 bytes, as this appears to be how the camera responds
to burst read commands (however, this may be a side-effect of the ESP32’s SPI controller
used for testing). If the provided data buffer is longer than the FIFO contents, the
final bytes will be 0x00.
Please note: It appears the length reported by the camera through
read_fifo_length() for JPEG pictures is bigger than the
actual picture. Previous versions of this function made attempts at finding the EOF marker
in the JPEG stream, however this is no longer the case. Please see
find_jpeg_eof() to help trim the data stream.
This function is not currently tested with other data formats (YUV, RGB).
sourcepub fn enable_auto_white_balance(
&mut self
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn enable_auto_white_balance( &mut self ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Enables the camera’s auto white balance
Note: This appears to not work on the ArducamMega 5MP, where pictures are severely green-tinted when using AWB.
sourcepub fn disable_auto_white_balance(
&mut self
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn disable_auto_white_balance( &mut self ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Disables the camera’s auto white balance
This function is automatically called by
set_white_balance_mode().
sourcepub fn enable_auto_iso(
&mut self
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn enable_auto_iso( &mut self ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Enables the camera’s automatic gain adjustment
sourcepub fn disable_auto_iso(
&mut self
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn disable_auto_iso( &mut self ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Disables the camera’s automatic gain adjustment
sourcepub fn enable_auto_exposure(
&mut self
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn enable_auto_exposure( &mut self ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Enables the camera’s automatic exposure control
sourcepub fn disable_auto_exposure(
&mut self
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn disable_auto_exposure( &mut self ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Disables the camera’s automatic exposure control
sourcepub fn set_white_balance_mode(
&mut self,
mode: WhiteBalanceMode
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn set_white_balance_mode( &mut self, mode: WhiteBalanceMode ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Fixes the white balance of the camera to mode
This will set the white balance mode to the fixed value described by mode. The auto
mode has not been tested yet, and is copied straight from the SDK provided by Arducam.
This function ensures that auto white balance is disabled in the sensor by calling
disable_auto_white_balance() first.
sourcepub fn enable_low_power_mode(
&mut self
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn enable_low_power_mode( &mut self ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Turns on the camera’s low power mode
sourcepub fn disable_low_power_mode(
&mut self
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn disable_low_power_mode( &mut self ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Turns off the camera’s low power mode
sourcepub fn set_brightness_bias(
&mut self,
level: BrightnessLevel
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn set_brightness_bias( &mut self, level: BrightnessLevel ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Sets the camera’s brightness bias
sourcepub fn set_contrast(
&mut self,
level: Level
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn set_contrast( &mut self, level: Level ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Sets the camera’s contrast
sourcepub fn set_saturation(
&mut self,
level: Level
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn set_saturation( &mut self, level: Level ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Sets the camera’s saturation
sourcepub fn set_exposure(
&mut self,
level: Level
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn set_exposure( &mut self, level: Level ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Sets the camera’s exposure
sourcepub fn set_color_effect(
&mut self,
effect: ColorEffect
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
pub fn set_color_effect( &mut self, effect: ColorEffect ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Sets the camera’s color effect
sourcepub fn set_sharpness(
&mut self,
level: SharpnessLevel
) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
Available on crate feature 3mp only.
pub fn set_sharpness( &mut self, level: SharpnessLevel ) -> Result<&mut Self, Error<SPI::Error, Delay::Error>>
3mp only.Sets the camera’s sharpness