|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
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"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... | |
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. | |
Transport-independent OV5640 SCCB register driver.
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.
Definition in file ra8_ov5640.c.
| enum ra8_ov5640_delay_t : uint32_t |
OV5640 settle delays around reset and register programming (ms).
Definition at line 150 of file ra8_ov5640.c.
| enum ra8_ov5640_jpeg_length_shift_t : uint32_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.
| enum ra8_ov5640_register_t : uint16_t |
OV5640 SCCB register addresses + the expected chip-ID value.
Definition at line 33 of file ra8_ov5640.c.
| enum ra8_ov5640_value_t : uint8_t |
OV5640 SCCB addressing, reset values, and byte-wrangling constants.
Definition at line 88 of file ra8_ov5640.c.
|
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.
| [in,out] | dev | Initialized sensor instance. |
| k_ra8_ok | The JPEG path was configured and the MCU held reset. |
| other | Propagated register-access error. |
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().
|
static |
Read and combine the OV5640 high and low chip-ID bytes.
Performs two SCCB reads at the instance's currently selected address.
| [in,out] | dev | Initialized sensor instance. |
| [out] | out_id | Combined big-endian chip identifier on success. |
| k_ra8_ok | Both bytes were read and combined. |
| other | Propagated register-read error. |
out_id points to writable storage. dev is initialized and the sensor is clocked. out_id contains the combined identifier. 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().
|
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.
| [in,out] | dev | Initialized sensor instance. |
| [out] | raw | Destination for raw register bytes. |
| k_ra8_ok | Every status register was read. |
| other | First propagated register-read error. |
raw is initialized. 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().
|
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.
| [in,out] | dev | Initialized sensor instance. |
| [out] | raw | Destination for raw register bytes. |
| k_ra8_ok | Every register in this half was read. |
| other | First propagated register-read error. |
raw are initialized. 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().
|
static |
Update selected bits in one sensor register.
Reads the current byte, merges value under mask, and writes it.
| [in,out] | dev | Initialized sensor instance. |
| [in] | reg | Sensor register address. |
| [in] | mask | Bits eligible for replacement. |
| [in] | value | Replacement bits. |
| k_ra8_ok | The merged byte was written. |
| other | Propagated register read or write error. |
dev is initialized and addresses a responding sensor. value masked by mask. 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().
|
static |
Verify a bounded set of masked sensor register expectations.
Reads each entry and compares only the bits selected by its mask.
| [in,out] | dev | Initialized sensor instance. |
| [in] | expected | Readback table containing count entries. |
| [in] | count | Bounded table-entry count. |
| k_ra8_ok | Every masked readback matched. |
| k_ra8_err_invalid_arg | A masked readback differed. |
| other | Propagated register-read error. |
expected addresses at least count readable entries. dev is initialized and the transport is idle. 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().
|
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.
| [in,out] | dev | Initialized sensor instance. |
| k_ra8_ok | Every JPEG-specific field matches. |
| other | Propagated read or mismatch error. |
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().
|
static |
Verify the common UYVY register scene.
Reads the format, ISP mux, and test-pattern controls through the masked table verifier.
| [in,out] | dev | Initialized sensor instance. |
| k_ra8_ok | Every common UYVY field matches. |
| other | Propagated read or mismatch error. |
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().
|
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.
| [in,out] | dev | Initialized sensor instance. |
| k_ra8_ok | Every base-table row was written. |
| other | Propagated register-write error. |
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().
|
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.
| [in,out] | dev | Probed sensor instance. |
| [in] | mode | Validated output mode to program. |
| k_ra8_ok | The selected mode was programmed and verified. |
| k_ra8_err_not_supported | mode has no validated table. |
| k_ra8_err_not_initialized | dev was not initialized. |
| other | Propagated SCCB transaction or readback error. |
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().
|
nodiscard |
Bind a caller-supplied SCCB transport without touching the sensor.
Copies the transport callbacks and selects the primary address.
| [out] | dev | Caller-owned sensor instance to initialize. |
| [in] | bus | Read, write, delay, and opaque-context callbacks. |
| k_ra8_ok | The instance was initialized. |
| k_ra8_err_null_ptr | An argument or mandatory callback was nullptr. |
dev points to writable storage. bus and its callbacks remain valid for the instance lifetime. dev is ready for probe and register access. 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().
|
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.
| [in,out] | dev | Sensor instance initialized by ra8_ov5640_init. |
| [out] | out_status | Caller-owned destination for the decoded snapshot. |
| k_ra8_ok | Every status register was read and decoded. |
| k_ra8_err_null_ptr | dev or out_status was nullptr. |
| k_ra8_err_not_initialized | dev has not been initialized. |
| other | Propagated SCCB read error. |
out_status points to writable storage. out_status describes the sampled sensor state. 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().
|
nodiscard |
Probe both legal SCCB addresses and verify chip ID 0x5640.
Reads the two identification registers at 0x3C, then 0x3D.
| [in,out] | dev | Initialized caller-owned sensor instance. |
| [out] | out_id | Last chip ID read, or the verified OV5640 ID. |
| k_ra8_ok | An OV5640 was found and selected. |
| k_ra8_err_not_found | Neither legal address returned the expected ID. |
| k_ra8_err_null_ptr | An argument was nullptr. |
| k_ra8_err_not_initialized | dev was not initialized. |
dev retains the responding SCCB address. dev returns to the primary SCCB address. 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().
|
nodiscard |
Read one sensor register through the bound transport.
Dispatches one 16-bit-register SCCB read at the selected address.
| [in,out] | dev | Initialized sensor instance. |
| [in] | reg | Sensor register address. |
| [out] | out_value | Register byte on success. |
| k_ra8_ok | The byte was read. |
| k_ra8_err_null_ptr | dev or out_value was nullptr. |
| k_ra8_err_not_initialized | dev was not initialized. |
| other | Propagated transport error. |
out_value contains the register byte. 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().
|
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.
| [in,out] | dev | Sensor instance initialized by ra8_ov5640_init. |
| [in] | quant_scale | Raw OV5640 quantization scale in the inclusive range [k_ra8_ov5640_jpeg_quant_scale_min, k_ra8_ov5640_jpeg_quant_scale_max]. |
| k_ra8_err_invalid_arg | quant_scale exceeds 63. |
| k_ra8_err_not_initialized | dev has not been initialized. |
| other | Propagated SCCB read or write error. |
quant_scale. 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.
|
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.
| [in,out] | dev | Initialized sensor instance. |
| [in] | enabled | true to stream, false for software standby. |
| k_ra8_ok | The requested state was written. |
| k_ra8_err_not_initialized | dev was not initialized. |
| other | Propagated SCCB write error. |
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().
|
nodiscard |
Write one sensor register through the bound transport.
Dispatches one 16-bit-register SCCB write at the selected address.
| [in,out] | dev | Initialized sensor instance. |
| [in] | reg | Sensor register address. |
| [in] | value | Register byte to write. |
| k_ra8_ok | The byte was written. |
| k_ra8_err_null_ptr | dev was nullptr. |
| k_ra8_err_not_initialized | dev was not initialized. |
| other | Propagated transport error. |
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().
|
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.
Definition at line 201 of file ra8_ov5640.c.
Referenced by internal_ov5640_write_vga_base().