Skip to content
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

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

Merged
merged 3 commits into from
Jan 28, 2025

Conversation

iabdalkader
Copy link
Contributor

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. Additionally, I've changed PCLK to free-running as the STM32 DCMI doesn't seem to work without it.

I would also like to change the default VSYNC/HSYNC polarity to high (0x03) to make this driver consistent with others. This change would allow us to reuse the same overlay without modifying vsync-active. Since this driver wasn't functioning at all, I assume it is safe to make this change as it won't break anything else?

@zephyrbot zephyrbot added the area: Video Video subsystem label Jan 20, 2025
Copy link
Collaborator

@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.

I do not see a problem with it being merged like it is, but curious about what you think should be done about start()/stop() when it is not supported by the driver yet, to make sure I did not miss a bug elsewhere in the stack.

Thank you for this addition!

Comment on lines -210 to +214
/* 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 */
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.

@iabdalkader
Copy link
Contributor Author

iabdalkader commented Jan 20, 2025

curious about what you think should be done about start()/stop() when it is not supported by the driver yet

I think it should just not fail if stream start and stop are not provided. As far as I know there's no way to stop the stream, at least not for this sensor, once powered it just starts outputting frames. Yeah I see the kernel power_on/off but if we power down the sensor that way then any registers set will be lost. Either way is fine with me, if you allow these ops to be NULL, I can just remove the dummy start/stop.

EDIT: Actually now I remember that these OV sensors had a sleep function, which we could use instead, but I don't think I2C works in sleep state, it probably does. @josuah

@josuah josuah requested a review from danieldegrasse January 20, 2025 17:03
josuah
josuah previously approved these changes Jan 20, 2025
Copy link
Collaborator

@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 clarifying the different points and making sure that the implications were intended.

WRT start()/stop() missing, it seems like the return status needs to be "it did nothing" rather than "it failed because it had nothing to be done". return 0; is one way to do that. If many sensors need that, then this could become part of the API in the future.

josuah
josuah previously approved these changes Jan 21, 2025
@iabdalkader
Copy link
Contributor Author

Can I fix this too while we're at it? TSLB[3] swaps the YUYV/RGB565 output.

{OV7670_TSLB, 0x0C}, /* Line Buffer Test Option */

This doesn't fix YUV output, it still looks corrupted, but at least RGB won't have to be swapped in software.

@josuah
Copy link
Collaborator

josuah commented Jan 21, 2025

Always good to get more things to work!

but at least RGB won't have to be swapped in software.

Is this related to the image being swapped left/right per chance? This swaps the endianness for some sensors.

@kartben
Copy link
Collaborator

kartben commented Jan 21, 2025

Can I fix this too while we're at it?

of course :) however it's usually not a bad idea to split things in multiple PRs to get incremental fixes/improvements approved (like, e.g. this PR here is now good to go, and you will be losing approvals if you push updates, and then folks might not be available to review again :) )

@iabdalkader
Copy link
Contributor Author

iabdalkader commented Jan 21, 2025

Is this related to the image being swapped left/right per chance? This swaps the endianness for some sensors.

Yes this swaps the endianness. The current setting is set to UYVY. It seems to also swap RGB565 output.

image

@kartben Got it, will send any other fixes in another PR.

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 <[email protected]>
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 <[email protected]>
TSLB[3] swaps the YUYV/RGB565 output.

Signed-off-by: Ibrahim Abdalkader <[email protected]>
@iabdalkader iabdalkader requested a review from josuah January 28, 2025 13:56
@kartben kartben merged commit 5af9d55 into zephyrproject-rtos:main Jan 28, 2025
24 checks passed
@iabdalkader iabdalkader deleted the ov7670_fixes branch January 28, 2025 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Video Video subsystem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants