Skip to content

Conversation

@Hardevsinh-Palaniya
Copy link
Contributor

@Hardevsinh-Palaniya Hardevsinh-Palaniya commented Oct 7, 2025

Add driver to support ov5642 camera sensor

@github-actions
Copy link

github-actions bot commented Oct 7, 2025

Hello @hardevsinh-1, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@avolmat-st
Copy link

Thanks @hardevsinh-1 for this PR.

There is already an existing driver for the OV5640 sensor. Having very very rapidly checked the difference between the OV5642 and the OV5640, it seems that the OV5642 has less features than the OV5640, having for example only DVP support and limited to 720p maximum frames.
However, considering the numbering of the sensor I am wondering if the sensor behavior might be close enough to the OV5640 so that we could reuse the OV5640 sensor driver to also drive this new OV5642 sensor.
If that is so, and OV5642 is a "subset" of the OV5640, we might be able to make some of the OV5640 features optional or at least checked at runtime if applicable and have both OV5640 / OV5642 handled by the same driver.

Do you know the differences between the OV5640 and the OV5642 and the difference in the way to control it ? Looking very rapidly, it seems that at least on some aspects it is very similar to the OV5640.

Of course if the sensor are very different or if the way to control them is very different, then it makes sense to have a different driver.

@Hardevsinh-Palaniya
Copy link
Contributor Author

Thanks @hardevsinh-1 for this PR.

There is already an existing driver for the OV5640 sensor. Having very very rapidly checked the difference between the OV5642 and the OV5640, it seems that the OV5642 has less features than the OV5640, having for example only DVP support and limited to 720p maximum frames. However, considering the numbering of the sensor I am wondering if the sensor behavior might be close enough to the OV5640 so that we could reuse the OV5640 sensor driver to also drive this new OV5642 sensor. If that is so, and OV5642 is a "subset" of the OV5640, we might be able to make some of the OV5640 features optional or at least checked at runtime if applicable and have both OV5640 / OV5642 handled by the same driver.

Do you know the differences between the OV5640 and the OV5642 and the difference in the way to control it ? Looking very rapidly, it seems that at least on some aspects it is very similar to the OV5640.

Of course if the sensor are very different or if the way to control them is very different, then it makes sense to have a different driver.

@avolmat-st, Thanks for the review.
After comparing the OV5640 and OV5642 sensors and their drivers, here are the key points:

  • Register maps differ (clock, PLL, exposure, gain, and ISP controls).
  • OV5642 lacks AF and advanced ISP blocks present in OV5640.
  • DVP timing parameters also differ, and applying OV5640’s settings leads to jitter or frame corruption.
  • The initialization flow and power-up timings differ , reusing OV5640’s sequence causes I²C lockups. Sharing one driver would add unnecessary complexity.

Given these differences, what would you recommend ?

@Hardevsinh-Palaniya
Copy link
Contributor Author

Thanks @hardevsinh-1 for this PR.
There is already an existing driver for the OV5640 sensor. Having very very rapidly checked the difference between the OV5642 and the OV5640, it seems that the OV5642 has less features than the OV5640, having for example only DVP support and limited to 720p maximum frames. However, considering the numbering of the sensor I am wondering if the sensor behavior might be close enough to the OV5640 so that we could reuse the OV5640 sensor driver to also drive this new OV5642 sensor. If that is so, and OV5642 is a "subset" of the OV5640, we might be able to make some of the OV5640 features optional or at least checked at runtime if applicable and have both OV5640 / OV5642 handled by the same driver.
Do you know the differences between the OV5640 and the OV5642 and the difference in the way to control it ? Looking very rapidly, it seems that at least on some aspects it is very similar to the OV5640.
Of course if the sensor are very different or if the way to control them is very different, then it makes sense to have a different driver.

@avolmat-st, Thanks for the review. After comparing the OV5640 and OV5642 sensors and their drivers, here are the key points:

  • Register maps differ (clock, PLL, exposure, gain, and ISP controls).
  • OV5642 lacks AF and advanced ISP blocks present in OV5640.
  • DVP timing parameters also differ, and applying OV5640’s settings leads to jitter or frame corruption.
  • The initialization flow and power-up timings differ , reusing OV5640’s sequence causes I²C lockups. Sharing one driver would add unnecessary complexity.

Given these differences, what would you recommend ?

Hi @avolmat-st, did you get a chance to review my comparison between the OV5640 and OV5642 sensors?
I’d like to know your thoughts on whether keeping a separate driver still makes the most sense.
could you please reply?

Copy link
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

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

Thank you for this new driver!

Image sensor drivers are almost just configuration data.

I agree that it is worth considering de-duplicating all the code with ov5640.c video_common.c.

It might be possible to reduce the driver by a fair 50% once all video APIs are in place.

It is maybe surprising that copying an existing image sensor driver as much as possible leads to a lot of requests for modifications, but this is because image sensor currently in Zephyr almost all need a round of refactoring and I am very late on this!

Finally, you would need to add an extra commit to add this sensor to the build_all test:
https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/build_all/video/app.overlay

@Hardevsinh-Palaniya
Copy link
Contributor Author

Thank you for this new driver!

Image sensor drivers are almost just configuration data.

I agree that it is worth considering de-duplicating all the code with ov5640.c video_common.c.

It might be possible to reduce the driver by a fair 50% once all video APIs are in place.

It is maybe surprising that copying an existing image sensor driver as much as possible leads to a lot of requests for modifications, but this is because image sensor currently in Zephyr almost all need a round of refactoring and I am very late on this!

Finally, you would need to add an extra commit to add this sensor to the build_all test: https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/build_all/video/app.overlay

@josuah , Thanks for the reviewing. I will update the same.

@Hardevsinh-Palaniya Hardevsinh-Palaniya force-pushed the Add-driver-for-ov5642-camera branch from 596b096 to f7d02c4 Compare October 14, 2025 07:18
@zephyrbot zephyrbot added the area: Tests Issues related to a particular existing or missing test label Oct 14, 2025
@zephyrbot zephyrbot requested a review from nashif October 14, 2025 07:21
Copy link
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

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

Thank you for the changes!
It seems almost ready, with just a few minor coding style tuning but otherwise seems ready to me.
One more cycle to go!

@Hardevsinh-Palaniya Hardevsinh-Palaniya force-pushed the Add-driver-for-ov5642-camera branch from f7d02c4 to dfcf0fe Compare October 16, 2025 07:18
Copy link
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

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

Thank you for the edits!
I think there might be one more round needed as I changed my mind after doing other reviews and gave wrong instructions last time (sorry!).

Maybe other reviewers will find other things after that but for my part I think that's all of it after this round.

@Hardevsinh-Palaniya Hardevsinh-Palaniya force-pushed the Add-driver-for-ov5642-camera branch from dfcf0fe to 3d83017 Compare October 19, 2025 06:43
@Hardevsinh-Palaniya
Copy link
Contributor Author

Thank you for the edits! I think there might be one more round needed as I changed my mind after doing other reviews and gave wrong instructions last time (sorry!).

Maybe other reviewers will find other things after that but for my part I think that's all of it after this round.

Thanks @josuah , I’m interested in adjusting these lines. I’ve made changes based on your suggestions. Could you please review them?

Copy link
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

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

Thank you for the edits! The driver looks ready now.
But there is a "merge commit" that appeared, and you need to remove it.
Then this driver can be merged I think.


#define PI 3.141592654

#define ABS(a, b) (a > b ? a - b : b - a)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like you are now using the libc <stdlib.h> version abs() now, so you do not need this define.

@Hardevsinh-Palaniya Hardevsinh-Palaniya force-pushed the Add-driver-for-ov5642-camera branch from 052f7ce to 42ae093 Compare October 24, 2025 05:18
@josuah
Copy link
Contributor

josuah commented Oct 24, 2025

Good catch for chip_id = tmp.

I think you still need to remove the merge commits:

screenshot_2025_1024_1208_42

If you wish to catch-up with latest Zephyr main branch, you need to avoid git merge and instead use git rebase, or it will create "merge commits" like seen above.

Now you would need to remove them, for instance with git reset --hard HEAD~2 and then git fetch origin && git rebase origin/main (not tested, just to illustrate).

Feel free to reach on the Discord chat if you wanted to troubleshoot this interactively https://discord.com/invite/Ck7jw53nU2

@Hardevsinh-Palaniya Hardevsinh-Palaniya force-pushed the Add-driver-for-ov5642-camera branch from 42ae093 to 49a9390 Compare October 24, 2025 10:40
Comment on lines 706 to 707
case VIDEO_EXPOSURE_AUTO:
ret = video_modify_cci_reg(&cfg->i2c,
AEC_PK_CCI, BIT(0), 0);

break;
case VIDEO_EXPOSURE_MANUAL:
ret = video_modify_cci_reg(&cfg->i2c,
AEC_PK_CCI, BIT(0), BIT(0));
break;
Copy link
Contributor

@ngphibang ngphibang Nov 13, 2025

Choose a reason for hiding this comment

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

These two cases can be folded and may add a TODO to remember adding support for manual mode ?

	case VIDEO_EXPOSURE_AUTO:
	case VIDEO_EXPOSURE_MANUAL:
       /* TODO: Add support for manual exposure mode */
		ret = video_modify_cci_reg(&cfg->i2c, AEC_PK_CCI, BIT(0), value == VIDEO_EXPOSURE_AUTO ? BIT(0), 0);

Comment on lines 715 to 716
default:
return -EINVAL;
Copy link
Contributor

@ngphibang ngphibang Nov 13, 2025

Choose a reason for hiding this comment

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

These two cases need to be added as "unsupported" ?

case:
	VIDEO_EXPOSURE_SHUTTER_PRIORITY:
	VIDEO_EXPOSURE_APERTURE_PRIORITY:
	         return -ENOTSUP;

then the default case:

	default:
		CODE_UNREACHABLE;

as the video framework already handles values out of the control value range.

@Hardevsinh-Palaniya Hardevsinh-Palaniya force-pushed the Add-driver-for-ov5642-camera branch from 4f83c1c to dc90d33 Compare November 13, 2025 10:24
Comment on lines 706 to 707
case VIDEO_EXPOSURE_AUTO:
case VIDEO_EXPOSURE_MANUAL:
/* TODO: Add support for manual exposure mode */
ret = video_modify_cci_reg(&cfg->i2c, AEC_PK_CCI, BIT(0),
value == VIDEO_EXPOSURE_AUTO ? 0 : BIT(0));
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that VIDEO_EXPOSURE_AUTO = 0 and VIDEO_EXPOSURE_MANUAL = 1, this can be simplified a bit more ?

	`ret = video_modify_cci_reg(&cfg->i2c, AEC_PK_CCI, BIT(0), value);`

@Hardevsinh-Palaniya Hardevsinh-Palaniya force-pushed the Add-driver-for-ov5642-camera branch from dc90d33 to 5917aae Compare November 14, 2025 10:50
ngphibang
ngphibang previously approved these changes Nov 14, 2025
Copy link
Contributor

@ngphibang ngphibang left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks !

@Hardevsinh-Palaniya
Copy link
Contributor Author

@avolmat-st and @josuah, could you please review again?

@Hardevsinh-Palaniya
Copy link
Contributor Author

@avolmat-st and @josuah, please review this PR again and let me know your input if I need to update anything.

avolmat-st
avolmat-st previously approved these changes Nov 18, 2025
Copy link

@avolmat-st avolmat-st left a comment

Choose a reason for hiding this comment

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

Hi,
sorry for the delay. This looks good to me. Few multi-lines calls could be done in single line but that's really nitpicking so I am all fine with the current code as well.
Thanks.

{SDE_CTRL2_REG, abs(sin_coef)}
};

ret = video_modify_cci_reg(&cfg->i2c, SDE_CTRL10_CCI, 0x7F,

Choose a reason for hiding this comment

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

Nitpicking: can fit in one line.

return ret;
}

return video_write_cci_multiregs16(&cfg->i2c, hue_params,

Choose a reason for hiding this comment

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

Nitpicking: can fit in one line.

return ret;
}

ret = video_modify_cci_reg(&cfg->i2c, SDE_CTRL10_CCI, BIT(2),

Choose a reason for hiding this comment

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

Nitpicking: can fit in one line.

return ret;
}

return video_write_cci_reg(&cfg->i2c, SDE_CTRL9_CCI,

Choose a reason for hiding this comment

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

Nitpicking: can fit in one line.


switch (id) {
case VIDEO_CID_HFLIP:
return video_modify_cci_reg(&cfg->i2c,

Choose a reason for hiding this comment

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

Nitpicking: can fit in two lines ? same below ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@avolmat-st , Thanks for the suggestions. I have updated the PR to resolve alignment according to the suggestions. No other changes related to logic.

@avolmat-st, @ngphibang and @josuah, Please review it again.

avolmat-st
avolmat-st previously approved these changes Nov 19, 2025
Copy link

@avolmat-st avolmat-st left a comment

Choose a reason for hiding this comment

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

Thanks. Approved.

Comment on lines 34 to 35
zephyr_library_sources_ifdef(CONFIG_VIDEO_STM32_JPEG video_stm32_jpeg.c)
zephyr_library_sources_ifdef(CONFIG_VIDEO_HIMAX_HM01B0 hm01b0.c)
Copy link
Contributor

Choose a reason for hiding this comment

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

unrelated changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @ngphibang , It was a rebase issue. I resolved it.

Add driver to support ov5642 camera sensor

Co-developed-by: Rutvij Trivedi <rutvij.trivedi@siliconsignals.io>
Signed-off-by: Rutvij Trivedi <rutvij.trivedi@siliconsignals.io>
Signed-off-by: Hardevsinh Palaniya <hardevsinh.palaniya@siliconsignals.io>
@Hardevsinh-Palaniya Hardevsinh-Palaniya force-pushed the Add-driver-for-ov5642-camera branch from 1023925 to c50c81f Compare November 19, 2025 10:34
@sonarqubecloud
Copy link

@nashif nashif merged commit c784481 into zephyrproject-rtos:main Nov 19, 2025
26 checks passed
@github-actions
Copy link

Hi @Hardevsinh-Palaniya!
Congratulations on getting your very first Zephyr pull request merged 🎉🥳. This is a fantastic achievement, and we're thrilled to have you as part of our community!

To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge.

Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Boards/SoCs area: Devicetree Bindings area: Tests Issues related to a particular existing or missing test area: Video Video subsystem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants