From 22da986fe77d445f364e118758dbb791e18ee844 Mon Sep 17 00:00:00 2001 From: Ibrahim Abdalkader Date: Tue, 21 Jan 2025 09:20:14 +0100 Subject: [PATCH 1/3] drivers: video: ov7670: Implement missing video API functions Add the missing stream_start and stream_stop API functions (the driver doesn't work without them) and implement video controls for horizontal mirror (hmirror) and vertical flip. Signed-off-by: Ibrahim Abdalkader --- drivers/video/ov7670.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/video/ov7670.c b/drivers/video/ov7670.c index 84107a8bac59..f247f96c4579 100644 --- a/drivers/video/ov7670.c +++ b/drivers/video/ov7670.c @@ -9,6 +9,7 @@ #include #include #include +#include #include LOG_MODULE_REGISTER(video_ov7670, CONFIG_VIDEO_LOG_LEVEL); @@ -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) \ { \ @@ -204,7 +207,7 @@ 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 */ @@ -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) From da435b171ee8a5823be26d551306e8bc41b0c477 Mon Sep 17 00:00:00 2001 From: Ibrahim Abdalkader Date: Tue, 21 Jan 2025 09:20:33 +0100 Subject: [PATCH 2/3] drivers: video: ov7670: Use a free-running pixel clock. The STM32 DCMI capture seems to stop when the pixel clock is disabled during horizontal blank. This patch switches pixel clock to free-running, which shouldn't have any effect on other capture devices. Signed-off-by: Ibrahim Abdalkader --- drivers/video/ov7670.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/video/ov7670.c b/drivers/video/ov7670.c index f247f96c4579..f5c70f4676bb 100644 --- a/drivers/video/ov7670.c +++ b/drivers/video/ov7670.c @@ -210,8 +210,8 @@ static const struct ov7670_reg ov7670_init_regtbl[] = { {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 */ {OV7670_COM12, 0x00}, /* COM12,No HREF when VSYNC is low */ /* Brightness Control, with signal -128 to +128, 0x00 is middle value */ {OV7670_BRIGHT, 0x2f}, From 08e5319ec273b1e5749dfc7b02308c7b7ac5abb4 Mon Sep 17 00:00:00 2001 From: Ibrahim Abdalkader Date: Fri, 24 Jan 2025 07:35:07 +0100 Subject: [PATCH 3/3] drivers: video: ov7670: Use default YUYV/RGB565 order. TSLB[3] swaps the YUYV/RGB565 output. Signed-off-by: Ibrahim Abdalkader --- drivers/video/ov7670.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/video/ov7670.c b/drivers/video/ov7670.c index f5c70f4676bb..543d0ac1f6d4 100644 --- a/drivers/video/ov7670.c +++ b/drivers/video/ov7670.c @@ -256,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 */