ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_ov5640.c File Reference

Transport-independent OV5640 SCCB register driver. More...

#include "ra8_ov5640.h"
#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_check.h"
#include "ra8_err.h"
Include dependency graph for ra8_ov5640.c:

Go to the source code of this file.

Data Structures

struct  ra8_ov5640_reg_write_t
 One OV5640 SCCB register write (16-bit address, 8-bit value). More...
struct  ra8_ov5640_reg_expect_t
 One masked OV5640 register readback expectation. More...
struct  ra8_ov5640_jpeg_status_raw_t
 Raw register bytes used to assemble one JPEG status snapshot. More...

Enumerations

enum  ra8_ov5640_register_t : uint16_t {
  k_ov5640_reg_system_reset00 = 0x3000U ,
  k_ov5640_reg_system_reset02 = 0x3002U ,
  k_ov5640_reg_clock_enable02 = 0x3006U ,
  k_ov5640_reg_sw_reset = 0x3008U ,
  k_ov5640_reg_chip_id_hi = 0x300AU ,
  k_ov5640_reg_chip_id_lo = 0x300BU ,
  k_ov5640_reg_pll_bit_mode = 0x3034U ,
  k_ov5640_reg_pll_sys_div = 0x3035U ,
  k_ov5640_reg_pll_multiplier = 0x3036U ,
  k_ov5640_reg_pll_pre_div = 0x3037U ,
  k_ov5640_reg_pll_bypass = 0x3039U ,
  k_ov5640_reg_clock_select = 0x3103U ,
  k_ov5640_reg_clock_root = 0x3108U ,
  k_ov5640_reg_timing_y_start_hi = 0x3802U ,
  k_ov5640_reg_timing_y_start_lo = 0x3803U ,
  k_ov5640_reg_timing_y_end_hi = 0x3806U ,
  k_ov5640_reg_timing_y_end_lo = 0x3807U ,
  k_ov5640_reg_timing_hts_hi = 0x380CU ,
  k_ov5640_reg_timing_hts_lo = 0x380DU ,
  k_ov5640_reg_timing_vts_hi = 0x380EU ,
  k_ov5640_reg_timing_vts_lo = 0x380FU ,
  k_ov5640_reg_timing_y_offset_hi = 0x3812U ,
  k_ov5640_reg_timing_y_offset_lo = 0x3813U ,
  k_ov5640_reg_timing_tc_reg20 = 0x3820U ,
  k_ov5640_reg_timing_tc_reg21 = 0x3821U ,
  k_ov5640_reg_pclk_divider = 0x3824U ,
  k_ov5640_reg_format = 0x4300U ,
  k_ov5640_reg_jpeg_ctrl00 = 0x4400U ,
  k_ov5640_reg_jpeg_ctrl01 = 0x4401U ,
  k_ov5640_reg_jpeg_ctrl04 = 0x4404U ,
  k_ov5640_reg_jpeg_quality = 0x4407U ,
  k_ov5640_reg_jpeg_length_hi = 0x4414U ,
  k_ov5640_reg_jpeg_length_mid = 0x4415U ,
  k_ov5640_reg_jpeg_length_lo = 0x4416U ,
  k_ov5640_reg_jfifo_overflow = 0x4417U ,
  k_ov5640_reg_jpeg_timing14 = 0x4514U ,
  k_ov5640_reg_jpeg_timing20 = 0x4520U ,
  k_ov5640_reg_vfifo_ctrl00 = 0x4600U ,
  k_ov5640_reg_compression_w_hi = 0x4602U ,
  k_ov5640_reg_compression_w_lo = 0x4603U ,
  k_ov5640_reg_compression_h_hi = 0x4604U ,
  k_ov5640_reg_compression_h_lo = 0x4605U ,
  k_ov5640_reg_vfifo_ctrl0b = 0x460BU ,
  k_ov5640_reg_vfifo_ctrl0c = 0x460CU ,
  k_ov5640_reg_jpeg_mode = 0x4713U ,
  k_ov5640_reg_jpeg_ctrl1c = 0x471CU ,
  k_ov5640_reg_href_minimum = 0x471FU ,
  k_ov5640_reg_polarity_ctrl00 = 0x4740U ,
  k_ov5640_reg_isp_ctrl01 = 0x5001U ,
  k_ov5640_reg_isp_mux = 0x501FU ,
  k_ov5640_reg_test = 0x503DU
}
 OV5640 SCCB register addresses + the expected chip-ID value. More...
enum  ra8_ov5640_value_t : uint8_t {
  k_ov5640_sw_reset_hold = 0x82U ,
  k_ov5640_sw_standby = 0x42U ,
  k_ov5640_sw_reset_wake = 0x02U ,
  k_ov5640_mcu_reset_hold = 0x20U ,
  k_ov5640_hi_byte_shift = 8U ,
  k_ov5640_byte_mask = 0xFFU ,
  k_ov5640_format_yuyv = 0x30U ,
  k_ov5640_isp_mux_yuv = 0x00U ,
  k_ov5640_jpeg_mode_dvp_2 = 0x02U ,
  k_ov5640_jpeg_mode_mask = 0x07U ,
  k_ov5640_jpeg_sync_polarity_mask = 0x03U ,
  k_ov5640_jpeg_sync_polarity = 0x01U ,
  k_ov5640_jpeg_ctrl00 = 0x81U ,
  k_ov5640_jpeg_ctrl01 = 0x01U ,
  k_ov5640_jpeg_ctrl04 = 0x24U ,
  k_ov5640_jpeg_ctrl1c = 0x50U ,
  k_ov5640_jpeg_timing14_vga = 0xAAU ,
  k_ov5640_jpeg_timing20_vga = 0x0BU ,
  k_ov5640_timing_tc_reg20_jpeg = 0x01U ,
  k_ov5640_jpeg_y_start_hi = 0x00U ,
  k_ov5640_jpeg_y_start_lo = 0x00U ,
  k_ov5640_jpeg_y_end_hi = 0x07U ,
  k_ov5640_jpeg_y_end_lo = 0x9FU ,
  k_ov5640_jpeg_hts_hi = 0x08U ,
  k_ov5640_jpeg_hts_lo = 0x0CU ,
  k_ov5640_jpeg_vts_hi = 0x03U ,
  k_ov5640_jpeg_vts_lo = 0xD8U ,
  k_ov5640_jpeg_y_offset_hi = 0x00U ,
  k_ov5640_jpeg_y_offset_lo = 0x08U ,
  k_ov5640_jpeg_clock_mask = 0x28U ,
  k_ov5640_vfifo_ctrl0b_jpeg = 0x35U ,
  k_ov5640_vfifo_ctrl0c_jpeg = 0x22U ,
  k_ov5640_pll_bit_mode_raw = 0x18U ,
  k_ov5640_pll_sys_div_raw = 0x21U ,
  k_ov5640_pll_multiplier_raw = 0x46U ,
  k_ov5640_pll_pre_div_raw = 0x13U ,
  k_ov5640_pll_bypass_disabled = 0x00U ,
  k_ov5640_clock_root_raw = 0x01U ,
  k_ov5640_clock_select_raw = 0x02U ,
  k_ov5640_pclk_divider_raw = 0x01U ,
  k_ov5640_jpeg_enable_mask = 0x20U ,
  k_ov5640_jpeg_reset_mask = 0x1CU ,
  k_ov5640_jpeg_quant_scale_mask = 0x3FU ,
  k_ov5640_jpeg_input_yuv422_mask = 0x80U ,
  k_ov5640_jpeg_header_mask = 0x20U ,
  k_ov5640_jfifo_overflow_mask = 0x01U ,
  k_ov5640_isp_scale_enable_mask = 0x20U ,
  k_ov5640_jpeg_vga_width_hi = 0x02U ,
  k_ov5640_jpeg_vga_width_lo = 0x80U ,
  k_ov5640_jpeg_vga_height_hi = 0x01U ,
  k_ov5640_jpeg_vga_height_lo = 0xE0U
}
 OV5640 SCCB addressing, reset values, and byte-wrangling constants. More...
enum  ra8_ov5640_jpeg_length_shift_t : uint32_t {
  k_ov5640_jpeg_length_hi_shift = 16U ,
  k_ov5640_jpeg_length_mid_shift = 8U ,
  k_ov5640_dimension_hi_shift = 8U
}
 Bit positions used to combine the three JPEG length registers. More...
enum  ra8_ov5640_delay_t : uint32_t {
  k_ov5640_reset_guard_ms = 100U ,
  k_ov5640_mcu_reset_ms = 10U ,
  k_ov5640_stream_settle_ms = 5U ,
  k_ov5640_cfg_settle_ms = 500U
}
 OV5640 settle delays around reset and register programming (ms). More...

Functions

ra8_err_t ra8_ov5640_init (ra8_ov5640_t *dev, const ra8_ov5640_bus_t *bus)
 Bind a caller-supplied SCCB transport without touching the sensor.
ra8_err_t ra8_ov5640_read_reg (ra8_ov5640_t *dev, uint16_t reg, uint8_t *out_value)
 Read one sensor register through the bound transport.
ra8_err_t ra8_ov5640_write_reg (ra8_ov5640_t *dev, uint16_t reg, uint8_t value)
 Write one sensor register through the bound transport.
static ra8_err_t internal_ov5640_update_bits (ra8_ov5640_t *dev, uint16_t reg, uint8_t mask, uint8_t value)
 Update selected bits in one sensor register.
static ra8_err_t internal_ov5640_verify (ra8_ov5640_t *dev, const ra8_ov5640_reg_expect_t *expected, uint32_t count)
 Verify a bounded set of masked sensor register expectations.
static ra8_err_t internal_ov5640_read_chip_id (ra8_ov5640_t *dev, uint16_t *out_id)
 Read and combine the OV5640 high and low chip-ID bytes.
ra8_err_t ra8_ov5640_probe (ra8_ov5640_t *dev, uint16_t *out_id)
 Probe both legal SCCB addresses and verify chip ID 0x5640.
static ra8_err_t internal_ov5640_write_vga_base (ra8_ov5640_t *dev)
 Program the board-qualified VGA base table.
static ra8_err_t internal_ov5640_configure_jpeg (ra8_ov5640_t *dev)
 Apply the JPEG-specific overlay to the VGA base scene.
static ra8_err_t internal_ov5640_verify_uyvy (ra8_ov5640_t *dev)
 Verify the common UYVY register scene.
static ra8_err_t internal_ov5640_verify_jpeg (ra8_ov5640_t *dev)
 Verify the JPEG-specific register scene.
ra8_err_t ra8_ov5640_configure (ra8_ov5640_t *dev, ra8_ov5640_mode_t mode)
 Software-reset and program one validated output mode.
ra8_err_t ra8_ov5640_set_jpeg_quantization_scale (ra8_ov5640_t *dev, uint8_t quant_scale)
 Set the sensor JPEG encoder's raw quantization scale.
static ra8_err_t internal_ov5640_read_jpeg_status_format (ra8_ov5640_t *dev, ra8_ov5640_jpeg_status_raw_t *raw)
 Read the JPEG length, FIFO, and format status registers.
static ra8_err_t internal_ov5640_read_jpeg_status (ra8_ov5640_t *dev, ra8_ov5640_jpeg_status_raw_t *raw)
 Read the register bytes comprising one JPEG status snapshot.
ra8_err_t ra8_ov5640_jpeg_status_get (ra8_ov5640_t *dev, ra8_ov5640_jpeg_status_t *out_status)
 Snapshot sensor JPEG length, overflow, and routing controls.
ra8_err_t ra8_ov5640_stream_set (ra8_ov5640_t *dev, bool enabled)
 Enter software standby or resume sensor streaming.

Variables

static const ra8_ov5640_reg_write_t s_ov5640_vga_uyvy []
 OV5640 DVP init: PLL from 24 MHz XVCLK, VGA YUV422 live output.

Detailed Description

Transport-independent OV5640 SCCB register driver.

Tag
[Ring 4 / Service] {World: NS}

Holds validated OV5640 VGA DVP register settings and the sensor lifecycle. The caller supplies all SCCB and timing operations, so this module owns no RA8 peripheral, board pin, or global transport state. Every register value here is OV5640 device data rather than RA8D2 MMIO.

Since
0.1.0

Definition in file ra8_ov5640.c.

Enumeration Type Documentation

◆ ra8_ov5640_delay_t

enum ra8_ov5640_delay_t : uint32_t

OV5640 settle delays around reset and register programming (ms).

Enumerator
k_ov5640_reset_guard_ms 

Guard before and after reset.

k_ov5640_mcu_reset_ms 

Settle after holding the MCU reset.

k_ov5640_stream_settle_ms 

Settle after standby/wake change.

k_ov5640_cfg_settle_ms 

Settle after the register sequence.

Definition at line 150 of file ra8_ov5640.c.

◆ ra8_ov5640_jpeg_length_shift_t

Bit positions used to combine the three JPEG length registers.

Enumerator
k_ov5640_jpeg_length_hi_shift 

JPEG length high-byte shift.

k_ov5640_jpeg_length_mid_shift 

JPEG length middle-byte shift.

k_ov5640_dimension_hi_shift 

Compression dimension shift.

Definition at line 143 of file ra8_ov5640.c.

◆ ra8_ov5640_register_t

enum ra8_ov5640_register_t : uint16_t

OV5640 SCCB register addresses + the expected chip-ID value.

Enumerator
k_ov5640_reg_system_reset00 

MCU reset controls.

k_ov5640_reg_system_reset02 

JPEG reset controls.

k_ov5640_reg_clock_enable02 

JPEG clock controls.

k_ov5640_reg_sw_reset 

System control register.

k_ov5640_reg_chip_id_hi 

Chip-ID high byte register.

k_ov5640_reg_chip_id_lo 

Chip-ID low byte register.

k_ov5640_reg_pll_bit_mode 

PLL bit-mode control.

k_ov5640_reg_pll_sys_div 

PLL system-clock divider.

k_ov5640_reg_pll_multiplier 

PLL multiplier.

k_ov5640_reg_pll_pre_div 

PLL pre-divider.

k_ov5640_reg_pll_bypass 

PLL bypass control.

k_ov5640_reg_clock_select 

System clock source.

k_ov5640_reg_clock_root 

PCLK/SCLK root dividers.

k_ov5640_reg_timing_y_start_hi 

Sensor crop Y start high byte.

k_ov5640_reg_timing_y_start_lo 

Sensor crop Y start low byte.

k_ov5640_reg_timing_y_end_hi 

Sensor crop Y end high byte.

k_ov5640_reg_timing_y_end_lo 

Sensor crop Y end low byte.

k_ov5640_reg_timing_hts_hi 

Horizontal total high byte.

k_ov5640_reg_timing_hts_lo 

Horizontal total low byte.

k_ov5640_reg_timing_vts_hi 

Vertical total high byte.

k_ov5640_reg_timing_vts_lo 

Vertical total low byte.

k_ov5640_reg_timing_y_offset_hi 

Output Y offset high byte.

k_ov5640_reg_timing_y_offset_lo 

Output Y offset low byte.

k_ov5640_reg_timing_tc_reg20 

Vertical timing and binning.

k_ov5640_reg_timing_tc_reg21 

Timing/mirror and JPEG enable.

k_ov5640_reg_pclk_divider 

DVP pixel-clock divider.

k_ov5640_reg_format 

DVP output pixel format register.

k_ov5640_reg_jpeg_ctrl00 

JPEG input-format control.

k_ov5640_reg_jpeg_ctrl01 

JPEG FIFO pacing control.

k_ov5640_reg_jpeg_ctrl04 

JPEG header-output control.

k_ov5640_reg_jpeg_quality 

JPEG quantization scale.

k_ov5640_reg_jpeg_length_hi 

JPEG length bits 23:16.

k_ov5640_reg_jpeg_length_mid 

JPEG length bits 15:8.

k_ov5640_reg_jpeg_length_lo 

JPEG length bits 7:0.

k_ov5640_reg_jfifo_overflow 

JPEG FIFO overflow status.

k_ov5640_reg_jpeg_timing14 

JPEG binning/orientation timing.

k_ov5640_reg_jpeg_timing20 

JPEG sampling timing.

k_ov5640_reg_vfifo_ctrl00 

VFIFO output control.

k_ov5640_reg_compression_w_hi 

Compressed-output width high.

k_ov5640_reg_compression_w_lo 

Compressed-output width low.

k_ov5640_reg_compression_h_hi 

Compressed-output height high.

k_ov5640_reg_compression_h_lo 

Compressed-output height low.

k_ov5640_reg_vfifo_ctrl0b 

VFIFO output control.

k_ov5640_reg_vfifo_ctrl0c 

VFIFO output control.

k_ov5640_reg_jpeg_mode 

DVP JPEG mode select.

k_ov5640_reg_jpeg_ctrl1c 

JPEG DVP control.

k_ov5640_reg_href_minimum 

JPEG HREF minimum blanking.

k_ov5640_reg_polarity_ctrl00 

DVP clock and sync polarity.

k_ov5640_reg_isp_ctrl01 

ISP feature-enable register.

k_ov5640_reg_isp_mux 

ISP output format-mux register.

k_ov5640_reg_test 

Pre-output test-pattern register.

Definition at line 33 of file ra8_ov5640.c.

◆ ra8_ov5640_value_t

enum ra8_ov5640_value_t : uint8_t

OV5640 SCCB addressing, reset values, and byte-wrangling constants.

Enumerator
k_ov5640_sw_reset_hold 

Software reset (0x3008 bit 7).

k_ov5640_sw_standby 

Software standby.

k_ov5640_sw_reset_wake 

Normal operation.

k_ov5640_mcu_reset_hold 

Hold the internal MCU reset.

k_ov5640_hi_byte_shift 

Chip-ID high-byte shift.

k_ov5640_byte_mask 

Full-register readback mask.

k_ov5640_format_yuyv 

YUYV/JPEG ISP input format.

k_ov5640_isp_mux_yuv 

Route YUV through ISP.

k_ov5640_jpeg_mode_dvp_2 

DVP compressed-frame mode 2.

k_ov5640_jpeg_mode_mask 

JPEG mode-select field.

k_ov5640_jpeg_sync_polarity_mask 

JPEG VSYNC/HREF polarity bits.

k_ov5640_jpeg_sync_polarity 

Align HREF pulses with high VD.

k_ov5640_jpeg_ctrl00 

YUV422 input and FIFO enable.

k_ov5640_jpeg_ctrl01 

JPEG FIFO pacing control.

k_ov5640_jpeg_ctrl04 

Header and output control.

k_ov5640_jpeg_ctrl1c 

JPEG DVP control value.

k_ov5640_jpeg_timing14_vga 

VGA binning/orientation timing.

k_ov5640_jpeg_timing20_vga 

VGA sampling timing.

k_ov5640_timing_tc_reg20_jpeg 

VGA JPEG vertical binning.

k_ov5640_jpeg_y_start_hi 

VGA crop Y start bits 15:8.

k_ov5640_jpeg_y_start_lo 

VGA crop Y start bits 7:0.

k_ov5640_jpeg_y_end_hi 

VGA crop Y end bits 15:8.

k_ov5640_jpeg_y_end_lo 

VGA crop Y end bits 7:0.

k_ov5640_jpeg_hts_hi 

VGA horizontal total bits 15:8.

k_ov5640_jpeg_hts_lo 

VGA horizontal total bits 7:0.

k_ov5640_jpeg_vts_hi 

VGA vertical total bits 15:8.

k_ov5640_jpeg_vts_lo 

VGA vertical total bits 7:0.

k_ov5640_jpeg_y_offset_hi 

VGA Y offset bits 15:8.

k_ov5640_jpeg_y_offset_lo 

VGA Y offset bits 7:0.

k_ov5640_jpeg_clock_mask 

JPEG and JPEG2x clock bits.

k_ov5640_vfifo_ctrl0b_jpeg 

JPEG VFIFO setting.

k_ov5640_vfifo_ctrl0c_jpeg 

JPEG VFIFO setting.

k_ov5640_pll_bit_mode_raw 

Qualified DVP PLL 8-bit mode.

k_ov5640_pll_sys_div_raw 

Qualified system divider.

k_ov5640_pll_multiplier_raw 

Qualified PLL multiplier.

k_ov5640_pll_pre_div_raw 

Qualified PLL pre-divider.

k_ov5640_pll_bypass_disabled 

Use the programmed PLL.

k_ov5640_clock_root_raw 

Qualified clock-root dividers.

k_ov5640_clock_select_raw 

Qualified PLL clock selection.

k_ov5640_pclk_divider_raw 

Qualified DVP PCLK divider.

k_ov5640_jpeg_enable_mask 

0x3821 JPEG-enable bit.

k_ov5640_jpeg_reset_mask 

JFIFO/SFIFO/JPEG reset bits.

k_ov5640_jpeg_quant_scale_mask 

JPEG CTRL07 QS field.

k_ov5640_jpeg_input_yuv422_mask 

JPEG CTRL00 input-format bit.

k_ov5640_jpeg_header_mask 

JPEG CTRL04 header-output bit.

k_ov5640_jfifo_overflow_mask 

JPEG FIFO overflow bit.

k_ov5640_isp_scale_enable_mask 

ISP scaling-enable bit.

k_ov5640_jpeg_vga_width_hi 

VGA width bits 15:8.

k_ov5640_jpeg_vga_width_lo 

VGA width bits 7:0.

k_ov5640_jpeg_vga_height_hi 

VGA height bits 15:8.

k_ov5640_jpeg_vga_height_lo 

VGA height bits 7:0.

Definition at line 88 of file ra8_ov5640.c.

Function Documentation

◆ internal_ov5640_configure_jpeg()

ra8_err_t internal_ov5640_configure_jpeg ( ra8_ov5640_t * dev)
static

Apply the JPEG-specific overlay to the VGA base scene.

Programs JPEG quality and mode, then updates shared format, polarity, reset, and clock controls without disturbing other bits.

Parameters
[in,out]devInitialized sensor instance.
Returns
Error code.
Return values
k_ra8_okThe JPEG path was configured and the MCU held reset.
otherPropagated register-access error.
Precondition
The VGA base scene is programmed while the sensor is stopped.
The bound SCCB transport is idle.
Postcondition
On success JPEG format, clocks, reset, and polarity are configured.
On success the sensor MCU remains held reset until the final wake.
Note
Preserves unrelated bits in every shared control register.
Since
0.1.0

Definition at line 682 of file ra8_ov5640.c.

References internal_ov5640_update_bits(), k_ov5640_format_yuyv, k_ov5640_isp_mux_yuv, k_ov5640_jpeg_clock_mask, k_ov5640_jpeg_enable_mask, k_ov5640_jpeg_mode_dvp_2, k_ov5640_jpeg_reset_mask, k_ov5640_jpeg_sync_polarity, k_ov5640_jpeg_sync_polarity_mask, k_ov5640_mcu_reset_hold, k_ov5640_reg_clock_enable02, k_ov5640_reg_format, k_ov5640_reg_isp_mux, k_ov5640_reg_jpeg_mode, k_ov5640_reg_jpeg_quality, k_ov5640_reg_polarity_ctrl00, k_ov5640_reg_system_reset00, k_ov5640_reg_system_reset02, k_ov5640_reg_timing_tc_reg21, k_ra8_ok, k_ra8_ov5640_jpeg_quant_scale_default, RA8_INTERNAL, and ra8_ov5640_write_reg().

Referenced by ra8_ov5640_configure().

◆ internal_ov5640_read_chip_id()

ra8_err_t internal_ov5640_read_chip_id ( ra8_ov5640_t * dev,
uint16_t * out_id )
static

Read and combine the OV5640 high and low chip-ID bytes.

Performs two SCCB reads at the instance's currently selected address.

Parameters
[in,out]devInitialized sensor instance.
[out]out_idCombined big-endian chip identifier on success.
Returns
Error code.
Return values
k_ra8_okBoth bytes were read and combined.
otherPropagated register-read error.
Precondition
out_id points to writable storage.
dev is initialized and the sensor is clocked.
Postcondition
On success out_id contains the combined identifier.
The selected device address is unchanged.
Note
Not thread-safe with respect to the same sensor instance.
Since
0.1.0

Definition at line 597 of file ra8_ov5640.c.

References k_ov5640_hi_byte_shift, k_ov5640_reg_chip_id_hi, k_ov5640_reg_chip_id_lo, k_ra8_ok, RA8_INTERNAL, and ra8_ov5640_read_reg().

Referenced by ra8_ov5640_probe().

◆ internal_ov5640_read_jpeg_status()

ra8_err_t internal_ov5640_read_jpeg_status ( ra8_ov5640_t * dev,
ra8_ov5640_jpeg_status_raw_t * raw )
static

Read the register bytes comprising one JPEG status snapshot.

Reads the length/FIFO/format registers via internal_ov5640_read_jpeg_status_format, then continues with the geometry, blanking, and enable registers in a fixed order into caller-owned raw storage.

Parameters
[in,out]devInitialized sensor instance.
[out]rawDestination for raw register bytes.
Returns
Error code.
Return values
k_ra8_okEvery status register was read.
otherFirst propagated register-read error.
Precondition
The sensor stream is stopped so the multi-register snapshot is stable.
The bound SCCB transport is idle.
Postcondition
On success every field in raw is initialized.
Sensor register state is unchanged.
Note
The helper stops at the first transport error.
Since
0.1.0

Definition at line 907 of file ra8_ov5640.c.

References ra8_ov5640_jpeg_status_raw_t::height_hi, ra8_ov5640_jpeg_status_raw_t::height_lo, ra8_ov5640_jpeg_status_raw_t::href_minimum, internal_ov5640_read_jpeg_status_format(), k_ov5640_reg_compression_h_hi, k_ov5640_reg_compression_h_lo, k_ov5640_reg_compression_w_hi, k_ov5640_reg_compression_w_lo, k_ov5640_reg_href_minimum, k_ov5640_reg_timing_tc_reg21, k_ov5640_reg_vfifo_ctrl00, k_ra8_ok, RA8_INTERNAL, ra8_ov5640_read_reg(), ra8_ov5640_jpeg_status_raw_t::timing_ctrl21, ra8_ov5640_jpeg_status_raw_t::vfifo_ctrl00, ra8_ov5640_jpeg_status_raw_t::width_hi, and ra8_ov5640_jpeg_status_raw_t::width_lo.

Referenced by ra8_ov5640_jpeg_status_get().

◆ internal_ov5640_read_jpeg_status_format()

ra8_err_t internal_ov5640_read_jpeg_status_format ( ra8_ov5640_t * dev,
ra8_ov5640_jpeg_status_raw_t * raw )
static

Read the JPEG length, FIFO, and format status registers.

First half of the fixed-order JPEG status snapshot: length, overflow, input format, and header registers.

Parameters
[in,out]devInitialized sensor instance.
[out]rawDestination for raw register bytes.
Returns
Error code.
Return values
k_ra8_okEvery register in this half was read.
otherFirst propagated register-read error.
Precondition
The sensor stream is stopped so the multi-register snapshot is stable.
The bound SCCB transport is idle.
Postcondition
On success, the length/FIFO/format fields of raw are initialized.
Sensor register state is unchanged.
Note
The helper stops at the first transport error.
Since
0.1.0

Definition at line 865 of file ra8_ov5640.c.

References ra8_ov5640_jpeg_status_raw_t::jpeg_ctrl01, ra8_ov5640_jpeg_status_raw_t::jpeg_header, ra8_ov5640_jpeg_status_raw_t::jpeg_input, k_ov5640_reg_jfifo_overflow, k_ov5640_reg_jpeg_ctrl00, k_ov5640_reg_jpeg_ctrl01, k_ov5640_reg_jpeg_ctrl04, k_ov5640_reg_jpeg_length_hi, k_ov5640_reg_jpeg_length_lo, k_ov5640_reg_jpeg_length_mid, k_ra8_ok, ra8_ov5640_jpeg_status_raw_t::length_hi, ra8_ov5640_jpeg_status_raw_t::length_lo, ra8_ov5640_jpeg_status_raw_t::length_mid, ra8_ov5640_jpeg_status_raw_t::overflow, and ra8_ov5640_read_reg().

Referenced by internal_ov5640_read_jpeg_status().

◆ internal_ov5640_update_bits()

ra8_err_t internal_ov5640_update_bits ( ra8_ov5640_t * dev,
uint16_t reg,
uint8_t mask,
uint8_t value )
static

Update selected bits in one sensor register.

Reads the current byte, merges value under mask, and writes it.

Parameters
[in,out]devInitialized sensor instance.
[in]regSensor register address.
[in]maskBits eligible for replacement.
[in]valueReplacement bits.
Returns
Error code.
Return values
k_ra8_okThe merged byte was written.
otherPropagated register read or write error.
Precondition
dev is initialized and addresses a responding sensor.
The bound transport is idle.
Postcondition
On success masked bits equal value masked by mask.
On success unmasked bits retain their prior values.
Note
Not thread-safe with respect to the same sensor instance.
Since
0.1.0

Definition at line 538 of file ra8_ov5640.c.

References k_ra8_ok, ra8_ov5640_read_reg(), and ra8_ov5640_write_reg().

Referenced by internal_ov5640_configure_jpeg(), and ra8_ov5640_set_jpeg_quantization_scale().

◆ internal_ov5640_verify()

ra8_err_t internal_ov5640_verify ( ra8_ov5640_t * dev,
const ra8_ov5640_reg_expect_t * expected,
uint32_t count )
static

Verify a bounded set of masked sensor register expectations.

Reads each entry and compares only the bits selected by its mask.

Parameters
[in,out]devInitialized sensor instance.
[in]expectedReadback table containing count entries.
[in]countBounded table-entry count.
Returns
Error code.
Return values
k_ra8_okEvery masked readback matched.
k_ra8_err_invalid_argA masked readback differed.
otherPropagated register-read error.
Precondition
expected addresses at least count readable entries.
dev is initialized and the transport is idle.
Postcondition
Sensor state and the expectation table are unchanged.
Success proves every requested masked equality.
Note
Not thread-safe with respect to the same sensor instance.
Since
0.1.0

Definition at line 567 of file ra8_ov5640.c.

References k_ra8_err_invalid_arg, k_ra8_ok, and ra8_ov5640_read_reg().

Referenced by internal_ov5640_verify_jpeg(), and internal_ov5640_verify_uyvy().

◆ internal_ov5640_verify_jpeg()

ra8_err_t internal_ov5640_verify_jpeg ( ra8_ov5640_t * dev)
static

Verify the JPEG-specific register scene.

Reads the JPEG reset, clock, enable, quality, mode, polarity, and qualified DVP clock fields through the masked table verifier.

Parameters
[in,out]devInitialized sensor instance.
Returns
Error code from masked register verification.
Return values
k_ra8_okEvery JPEG-specific field matches.
otherPropagated read or mismatch error.
Precondition
JPEG overlay writes and their settle delay are complete.
The bound SCCB transport is idle.
Postcondition
Sensor state is unchanged.
Success proves all JPEG-specific expectations matched.
Note
Not thread-safe with respect to the same sensor instance.
Since
0.1.0

Definition at line 769 of file ra8_ov5640.c.

References internal_ov5640_verify(), k_ov5640_byte_mask, k_ov5640_jpeg_clock_mask, k_ov5640_jpeg_enable_mask, k_ov5640_jpeg_mode_dvp_2, k_ov5640_jpeg_mode_mask, k_ov5640_jpeg_quant_scale_mask, k_ov5640_jpeg_reset_mask, k_ov5640_jpeg_sync_polarity, k_ov5640_jpeg_sync_polarity_mask, k_ov5640_pclk_divider_raw, k_ov5640_pll_bypass_disabled, k_ov5640_reg_clock_enable02, k_ov5640_reg_jpeg_mode, k_ov5640_reg_jpeg_quality, k_ov5640_reg_pclk_divider, k_ov5640_reg_pll_bypass, k_ov5640_reg_polarity_ctrl00, k_ov5640_reg_system_reset02, k_ov5640_reg_timing_tc_reg21, k_ra8_ov5640_jpeg_quant_scale_default, and RA8_INTERNAL.

Referenced by ra8_ov5640_configure().

◆ internal_ov5640_verify_uyvy()

ra8_err_t internal_ov5640_verify_uyvy ( ra8_ov5640_t * dev)
static

Verify the common UYVY register scene.

Reads the format, ISP mux, and test-pattern controls through the masked table verifier.

Parameters
[in,out]devInitialized sensor instance.
Returns
Error code from masked register verification.
Return values
k_ra8_okEvery common UYVY field matches.
otherPropagated read or mismatch error.
Precondition
Configuration writes and their settle delay are complete.
The bound SCCB transport is idle.
Postcondition
Sensor state is unchanged.
Success proves all common UYVY expectations matched.
Note
Not thread-safe with respect to the same sensor instance.
Since
0.1.0

Definition at line 742 of file ra8_ov5640.c.

References internal_ov5640_verify(), k_ov5640_byte_mask, k_ov5640_format_yuyv, k_ov5640_isp_mux_yuv, k_ov5640_reg_format, k_ov5640_reg_isp_mux, k_ov5640_reg_test, and RA8_INTERNAL.

Referenced by ra8_ov5640_configure().

◆ internal_ov5640_write_vga_base()

ra8_err_t internal_ov5640_write_vga_base ( ra8_ov5640_t * dev)
static

Program the board-qualified VGA base table.

Writes every retained Renesas DVP scene row in order and applies the documented delay when the table holds the sensor MCU reset.

Parameters
[in,out]devInitialized sensor instance.
Returns
Error code.
Return values
k_ra8_okEvery base-table row was written.
otherPropagated register-write error.
Precondition
The sensor is held in software reset.
The bound SCCB transport is idle.
Postcondition
On success the VGA UYVY base scene is programmed.
On success the MCU-reset settling interval has elapsed.
Note
Applies the required MCU-reset delay at the matching table row.
Since
0.1.0

Definition at line 651 of file ra8_ov5640.c.

References ra8_ov5640_t::bus, ra8_ov5640_bus_t::ctx, ra8_ov5640_bus_t::delay_ms, k_ov5640_mcu_reset_ms, k_ov5640_reg_system_reset00, k_ra8_ok, RA8_INTERNAL, ra8_ov5640_write_reg(), and s_ov5640_vga_uyvy.

Referenced by ra8_ov5640_configure().

◆ ra8_ov5640_configure()

ra8_err_t ra8_ov5640_configure ( ra8_ov5640_t * dev,
ra8_ov5640_mode_t mode )
nodiscard

Software-reset and program one validated output mode.

Applies the proven VGA UYVY base table, optionally switches the sensor JPEG engine, then verifies critical register readbacks.

Parameters
[in,out]devProbed sensor instance.
[in]modeValidated output mode to program.
Returns
Error code.
Return values
k_ra8_okThe selected mode was programmed and verified.
k_ra8_err_not_supportedmode has no validated table.
k_ra8_err_not_initializeddev was not initialized.
otherPropagated SCCB transaction or readback error.
Precondition
ra8_ov5640_probe selected a responding sensor address.
Sensor XCLK remains running throughout configuration.
Postcondition
On success the sensor is awake and streaming the selected mode.
On success critical output registers match their expected masks.
Note
Not thread-safe with respect to the same instance or transport.
Since
0.1.0

Definition at line 801 of file ra8_ov5640.c.

References ra8_ov5640_t::bus, ra8_ov5640_bus_t::ctx, ra8_ov5640_bus_t::delay_ms, ra8_ov5640_t::initialized, internal_ov5640_configure_jpeg(), internal_ov5640_verify_jpeg(), internal_ov5640_verify_uyvy(), internal_ov5640_write_vga_base(), k_ov5640_cfg_settle_ms, k_ov5640_reg_sw_reset, k_ov5640_reset_guard_ms, k_ov5640_sw_reset_hold, k_ra8_err_not_initialized, k_ra8_err_not_supported, k_ra8_ok, k_ra8_ov5640_mode_vga_jpeg, k_ra8_ov5640_mode_vga_uyvy, RA8_CHECK_NULL_PTR, and ra8_ov5640_write_reg().

Referenced by c6_cam_camera_init(), cam_prepare_capture(), and internal_bring_up_sensor().

◆ ra8_ov5640_init()

ra8_err_t ra8_ov5640_init ( ra8_ov5640_t * dev,
const ra8_ov5640_bus_t * bus )
nodiscard

Bind a caller-supplied SCCB transport without touching the sensor.

Copies the transport callbacks and selects the primary address.

Parameters
[out]devCaller-owned sensor instance to initialize.
[in]busRead, write, delay, and opaque-context callbacks.
Returns
Error code.
Return values
k_ra8_okThe instance was initialized.
k_ra8_err_null_ptrAn argument or mandatory callback was nullptr.
Precondition
dev points to writable storage.
bus and its callbacks remain valid for the instance lifetime.
Postcondition
On success dev is ready for probe and register access.
No SCCB transaction or delay callback has occurred.
Note
Independent instances are thread-safe when their transports are.
Since
0.1.0

Definition at line 484 of file ra8_ov5640.c.

References ra8_ov5640_bus_t::delay_ms, k_ra8_ok, k_ra8_ov5640_addr_primary, RA8_CHECK_NULL_PTR, ra8_ov5640_bus_t::read_reg, and ra8_ov5640_bus_t::write_reg.

Referenced by cam_sensor_bind(), internal_c6_cam_sensor_bind(), and sensor_bind().

◆ ra8_ov5640_jpeg_status_get()

ra8_err_t ra8_ov5640_jpeg_status_get ( ra8_ov5640_t * dev,
ra8_ov5640_jpeg_status_t * out_status )
nodiscard

Snapshot sensor JPEG length, overflow, and routing controls.

Reads the documented JPEG length and status registers plus the input-format, header-output, and compression-enable controls.

Parameters
[in,out]devSensor instance initialized by ra8_ov5640_init.
[out]out_statusCaller-owned destination for the decoded snapshot.
Returns
Error code.
Return values
k_ra8_okEvery status register was read and decoded.
k_ra8_err_null_ptrdev or out_status was nullptr.
k_ra8_err_not_initializeddev has not been initialized.
otherPropagated SCCB read error.
Precondition
Sensor XCLK is running and the bound SCCB transport is idle.
out_status points to writable storage.
Postcondition
On success out_status describes the sampled sensor state.
Sensor configuration and streaming state remain unchanged.
Note
Stop streaming before this call when a frame-coherent length is needed.
Not thread-safe with respect to the same instance or transport.
Since
0.1.0

Definition at line 936 of file ra8_ov5640.c.

References ra8_ov5640_jpeg_status_raw_t::height_hi, ra8_ov5640_jpeg_status_raw_t::height_lo, ra8_ov5640_jpeg_status_raw_t::href_minimum, ra8_ov5640_t::initialized, internal_ov5640_read_jpeg_status(), ra8_ov5640_jpeg_status_raw_t::jpeg_ctrl01, ra8_ov5640_jpeg_status_raw_t::jpeg_header, ra8_ov5640_jpeg_status_raw_t::jpeg_input, k_ov5640_dimension_hi_shift, k_ov5640_jfifo_overflow_mask, k_ov5640_jpeg_enable_mask, k_ov5640_jpeg_header_mask, k_ov5640_jpeg_input_yuv422_mask, k_ov5640_jpeg_length_hi_shift, k_ov5640_jpeg_length_mid_shift, k_ra8_err_not_initialized, k_ra8_ok, ra8_ov5640_jpeg_status_raw_t::length_hi, ra8_ov5640_jpeg_status_raw_t::length_lo, ra8_ov5640_jpeg_status_raw_t::length_mid, ra8_ov5640_jpeg_status_raw_t::overflow, RA8_CHECK_NULL_PTR, ra8_ov5640_jpeg_status_raw_t::timing_ctrl21, ra8_ov5640_jpeg_status_raw_t::vfifo_ctrl00, ra8_ov5640_jpeg_status_raw_t::width_hi, and ra8_ov5640_jpeg_status_raw_t::width_lo.

Referenced by c6_cam_camera_capture_jpeg().

◆ ra8_ov5640_probe()

ra8_err_t ra8_ov5640_probe ( ra8_ov5640_t * dev,
uint16_t * out_id )
nodiscard

Probe both legal SCCB addresses and verify chip ID 0x5640.

Reads the two identification registers at 0x3C, then 0x3D.

Parameters
[in,out]devInitialized caller-owned sensor instance.
[out]out_idLast chip ID read, or the verified OV5640 ID.
Returns
Error code.
Return values
k_ra8_okAn OV5640 was found and selected.
k_ra8_err_not_foundNeither legal address returned the expected ID.
k_ra8_err_null_ptrAn argument was nullptr.
k_ra8_err_not_initializeddev was not initialized.
Precondition
ra8_ov5640_init completed successfully.
Sensor XCLK is running and hardware reset is released.
Postcondition
On success dev retains the responding SCCB address.
On failure dev returns to the primary SCCB address.
Note
Not thread-safe with respect to the same instance or transport.
Since
0.1.0

Definition at line 612 of file ra8_ov5640.c.

References ra8_ov5640_t::address, ra8_ov5640_t::initialized, internal_ov5640_read_chip_id(), k_ra8_err_not_found, k_ra8_err_not_initialized, k_ra8_ok, k_ra8_ov5640_addr_primary, k_ra8_ov5640_addr_secondary, k_ra8_ov5640_chip_id, and RA8_CHECK_NULL_PTR.

Referenced by c6_cam_camera_init(), cam_run(), and internal_bring_up_sensor().

◆ ra8_ov5640_read_reg()

ra8_err_t ra8_ov5640_read_reg ( ra8_ov5640_t * dev,
uint16_t reg,
uint8_t * out_value )
nodiscard

Read one sensor register through the bound transport.

Dispatches one 16-bit-register SCCB read at the selected address.

Parameters
[in,out]devInitialized sensor instance.
[in]regSensor register address.
[out]out_valueRegister byte on success.
Returns
Error code.
Return values
k_ra8_okThe byte was read.
k_ra8_err_null_ptrdev or out_value was nullptr.
k_ra8_err_not_initializeddev was not initialized.
otherPropagated transport error.
Precondition
ra8_ov5640_init completed successfully.
The bound transport is idle and the sensor is clocked.
Postcondition
On success out_value contains the register byte.
The selected device address is unchanged.
Note
Not thread-safe with respect to the same instance or transport.
Since
0.1.0

Definition at line 500 of file ra8_ov5640.c.

References ra8_ov5640_t::address, ra8_ov5640_t::bus, ra8_ov5640_bus_t::ctx, ra8_ov5640_t::initialized, k_ra8_err_not_initialized, RA8_CHECK_NULL_PTR, and ra8_ov5640_bus_t::read_reg.

Referenced by internal_ov5640_read_chip_id(), internal_ov5640_read_jpeg_status(), internal_ov5640_read_jpeg_status_format(), internal_ov5640_update_bits(), internal_ov5640_verify(), and sensor_report_register().

◆ ra8_ov5640_set_jpeg_quantization_scale()

ra8_err_t ra8_ov5640_set_jpeg_quantization_scale ( ra8_ov5640_t * dev,
uint8_t quant_scale )
nodiscard

Set the sensor JPEG encoder's raw quantization scale.

Programs JPEG CTRL07 bits [5:0]. The legal range is 0..63 and a smaller value produces higher quality. This is the sensor's raw scale, not a synthetic 1..100 quality percentage.

Parameters
[in,out]devSensor instance initialized by ra8_ov5640_init.
[in]quant_scaleRaw OV5640 quantization scale in the inclusive range [k_ra8_ov5640_jpeg_quant_scale_min, k_ra8_ov5640_jpeg_quant_scale_max].
Returns
k_ra8_ok on success, or the transport/validation error.
Return values
k_ra8_err_invalid_argquant_scale exceeds 63.
k_ra8_err_not_initializeddev has not been initialized.
otherPropagated SCCB read or write error.
Precondition
ra8_ov5640_init completed successfully.
JPEG mode was selected before changing its encoder scale.
Postcondition
On success JPEG CTRL07 bits [5:0] equal quant_scale.
Unrelated JPEG CTRL07 bits retain their prior values.
Note
Not thread-safe with respect to the same instance or transport.
Since
0.1.0

Definition at line 833 of file ra8_ov5640.c.

References ra8_ov5640_t::initialized, internal_ov5640_update_bits(), k_ov5640_jpeg_quant_scale_mask, k_ov5640_reg_jpeg_quality, k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_ov5640_jpeg_quant_scale_max, and RA8_CHECK_NULL_PTR.

◆ ra8_ov5640_stream_set()

ra8_err_t ra8_ov5640_stream_set ( ra8_ov5640_t * dev,
bool enabled )
nodiscard

Enter software standby or resume sensor streaming.

Writes the OV5640 system-control streaming state and waits for the transition to settle through the injected delay callback.

Parameters
[in,out]devInitialized sensor instance.
[in]enabledtrue to stream, false for software standby.
Returns
Error code.
Return values
k_ra8_okThe requested state was written.
k_ra8_err_not_initializeddev was not initialized.
otherPropagated SCCB write error.
Precondition
ra8_ov5640_init completed successfully.
Sensor XCLK remains running.
Postcondition
On success the sensor is in the requested streaming state.
Note
Not thread-safe with respect to the same instance or transport.
Since
0.1.0

Definition at line 971 of file ra8_ov5640.c.

References ra8_ov5640_t::bus, ra8_ov5640_bus_t::ctx, ra8_ov5640_bus_t::delay_ms, ra8_ov5640_t::initialized, k_ov5640_reg_sw_reset, k_ov5640_stream_settle_ms, k_ov5640_sw_reset_wake, k_ov5640_sw_standby, k_ra8_err_not_initialized, k_ra8_err_null_ptr, k_ra8_ok, and ra8_ov5640_write_reg().

Referenced by c6_cam_camera_capture_jpeg().

◆ ra8_ov5640_write_reg()

ra8_err_t ra8_ov5640_write_reg ( ra8_ov5640_t * dev,
uint16_t reg,
uint8_t value )
nodiscard

Write one sensor register through the bound transport.

Dispatches one 16-bit-register SCCB write at the selected address.

Parameters
[in,out]devInitialized sensor instance.
[in]regSensor register address.
[in]valueRegister byte to write.
Returns
Error code.
Return values
k_ra8_okThe byte was written.
k_ra8_err_null_ptrdev was nullptr.
k_ra8_err_not_initializeddev was not initialized.
otherPropagated transport error.
Precondition
ra8_ov5640_init completed successfully.
The bound transport is idle and the sensor is clocked.
Postcondition
On success the transport accepted the complete register write.
The selected device address is unchanged.
Note
Not thread-safe with respect to the same instance or transport.
Since
0.1.0

Definition at line 511 of file ra8_ov5640.c.

References ra8_ov5640_t::address, ra8_ov5640_t::bus, ra8_ov5640_bus_t::ctx, ra8_ov5640_t::initialized, k_ra8_err_not_initialized, RA8_CHECK_NULL_PTR, and ra8_ov5640_bus_t::write_reg.

Referenced by internal_ov5640_configure_jpeg(), internal_ov5640_update_bits(), internal_ov5640_write_vga_base(), ra8_ov5640_configure(), and ra8_ov5640_stream_set().

Variable Documentation

◆ s_ov5640_vga_uyvy

const ra8_ov5640_reg_write_t s_ov5640_vga_uyvy[]
static

OV5640 DVP init: PLL from 24 MHz XVCLK, VGA YUV422 live output.

Contains the DVP clock, VGA timing, ISP, auto-exposure, and colour-processing controls required for a live lens image.

Note
Each row is device data; see ra8_ov5640_reg_write_t.
Since
0.1.0

Definition at line 201 of file ra8_ov5640.c.

Referenced by internal_ov5640_write_vga_base().