Skip to content

drivers: video: ov7670: Implement missing video API functions, controls and update init regs. #84229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions drivers/video/ov7670.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/drivers/video.h>
#include <zephyr/drivers/video-controls.h>
#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(video_ov7670, CONFIG_VIDEO_LOG_LEVEL);
Expand Down Expand Up @@ -181,6 +182,8 @@ const struct ov7670_resolution_cfg OV7670_RESOLUTION_VGA = {

/* OV7670 definitions */
#define OV7670_PROD_ID 0x76
#define OV7670_MVFP_HFLIP 0x20
#define OV7670_MVFP_VFLIP 0x10

#define OV7670_VIDEO_FORMAT_CAP(width, height, format) \
{ \
Expand All @@ -204,11 +207,11 @@ static const struct video_format_cap fmts[] = {
* Note that this table assumes the camera is fed a 6MHz XCLK signal
*/
static const struct ov7670_reg ov7670_init_regtbl[] = {
{OV7670_MVFP, 0x20}, /* MVFP: Mirror/VFlip,Normal image */
{OV7670_MVFP, 0x00}, /* MVFP: Mirror/VFlip,Normal image */

/* configure the output timing */
/* PCLK does not toggle during horizontal blank, one PCLK, one pixel */
{OV7670_COM10, 0x20}, /* COM10 */
/* Free running PCLK, default VSYNC, HSYNC and PCLK */
{OV7670_COM10, 0x00}, /* COM10 */
Comment on lines -210 to +214
Copy link
Collaborator

@josuah josuah Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to see if I can find the original platform used for testing this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3ce3ed3

FRDM-MCXN947: I have that board with me! If I find some time to test it, that would make things easy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Free-running clock shouldn't have any effect. The other change I wanted to make is set VSYNC/HSYNC active high (COM10 0x03), so we wouldn't need to change the polarity in the overlay when switching between OV to say GC. I don't know if this was the plan or not, but it would be a good idea if all sensors are made consistent (all active high or all active low). Also, it will be one less thing to worry about if/when selecting sensors at runtime is supported.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for commenting further on this.

Good idea about unifying the signals polarity. An issue about it sounds like a good first step.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @danieldegrasse just for visibility as you did the original driver.

{OV7670_COM12, 0x00}, /* COM12,No HREF when VSYNC is low */
/* Brightness Control, with signal -128 to +128, 0x00 is middle value */
{OV7670_BRIGHT, 0x2f},
Expand Down Expand Up @@ -253,7 +256,7 @@ static const struct ov7670_reg ov7670_init_regtbl[] = {

/* display , need retain */
{OV7670_COM15, 0xD0}, /* Common Control 15 */
{OV7670_TSLB, 0x0C}, /* Line Buffer Test Option */
{OV7670_TSLB, 0x04}, /* Reserved */
{OV7670_COM13, 0x80}, /* Common Control 13 */
{OV7670_MANU, 0x11}, /* Manual U Value */
{OV7670_MANV, 0xFF}, /* Manual V Value */
Expand Down Expand Up @@ -547,10 +550,39 @@ static int ov7670_init(const struct device *dev)
return 0;
}

static int ov7670_stream_start(const struct device *dev)
{
return 0;
}

static int ov7670_stream_stop(const struct device *dev)
{
return 0;
}

static int ov7670_set_ctrl(const struct device *dev, unsigned int cid, void *value)
{
const struct ov7670_config *config = dev->config;

switch (cid) {
case VIDEO_CID_HFLIP:
return i2c_reg_update_byte_dt(&config->bus, OV7670_MVFP,
OV7670_MVFP_HFLIP, ((int)value) ? OV7670_MVFP_HFLIP : 0);
case VIDEO_CID_VFLIP:
return i2c_reg_update_byte_dt(&config->bus, OV7670_MVFP,
OV7670_MVFP_VFLIP, ((int)value) ? OV7670_MVFP_VFLIP : 0);
default:
return -ENOTSUP;
}
}

static DEVICE_API(video, ov7670_api) = {
.set_format = ov7670_set_fmt,
.get_format = ov7670_get_fmt,
.get_caps = ov7670_get_caps,
.stream_start = ov7670_stream_start,
.stream_stop = ov7670_stream_stop,
.set_ctrl = ov7670_set_ctrl,
};

#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios)
Expand Down
Loading