-
Notifications
You must be signed in to change notification settings - Fork 7.3k
drivers: video: emul-imager: use the emulated I2C bus #87937
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
base: main
Are you sure you want to change the base?
drivers: video: emul-imager: use the emulated I2C bus #87937
Conversation
00ea6a3
to
0a23ada
Compare
The emul imager now uses the emul i2c which is initialized with
|
0a23ada
to
11783a5
Compare
Force-push:
I went with I can switch to i.e. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Increase the CONFIG_VIDEO_IMAGER_INIT_PRIORITY
to 65 resolves the issue but it is a bit unusual as in general, all image sensors are initialized with priority CONFIG_VIDEO_INIT_PRIORITY = 60
.
I see that there is the I2C_EMUL driver, why can't we just use this instead of making a customized one ? I suppose you need some different behavior for the transfer_i2c function that i2c_emul cannot support ? If yes, can we emulate the read/write register so that it can be used with i2c_emul ?
Another thought is that I2C EMUL is an emulated driver but surprisingly, it can set its init priority to 50 (equal to the real i2c init priority), so I wonder if we can set the emul imager i2c the same way so that we don't need to change the imager priority as currently ?
Just some thoughts for us to dig deeper.
see below instead.
Maybe I missed something... Current situation: Lines 338 to 339 in c47926e
zephyr/drivers/video/video_emul_imager.c Lines 428 to 430 in c47926e
zephyr/drivers/video/video_emul_rx.c Lines 298 to 299 in c47926e
Between external sensors and on-chip video peripheral, the priority is sometimes in one direction, sometimes in the other direction?
The assumption is that the on-chip video RX will know whether it is initialized before or after, and the external chip is less likely to have this requirement. A solution for this would be splitting
I am not a big fan of my own proposal, as it's much nicer to have just one or two init priorities. |
No such requirement thankfully!
It seems like it is already set to 50 after all? 🤔 |
Yes, the i2c_emul driver is clearly initialized with
But in the emul imager, the emul imager i2c is defined as:
which does not specifiy an init priority, that made me think it will use the Maybe we can check this in the build/ ? Maybe I am wrong, if so, appologize for the mistake ! |
Good idea!
Max priority level (999 got introduced)
|
799f98d
to
d65b699
Compare
Cherry-picking your commit with All drivers (including imagers) use It took me long enough to get that but I think now we are good. 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see any usage of CONFIG_EMUL_INIT_PRIORITY
neither.
Anyways, I think with :
#define EMUL_I2C_DEFINE(inst) \
EMUL_DT_INST_DEFINE(inst, &emul_imager_init_i2c, NULL, NULL, &emul_imager_i2c_api, NULL);
DT_INST_FOREACH_STATUS_OKAY(EMUL_I2C_DEFINE)
it will take the inst of the i2c0
node of the native_sim.dts
which is drived by the i2c_emul driver which is initialized with priority 50. So, everything is fine.
i2c0: i2c@100 {
status = "okay";
compatible = "zephyr,i2c-emul-controller"; => this is i2c_emul driver.
I was a bit confused because of CONFIG_EMUL_INIT_PRIORITY (which has no role here) and because in video_emul_imager.c there are two DT_INST_FOREACH_STATUS_OKAY() calls so I was not sure which instant is used (the i2c or the imager) ...
Thanks and sorry for my confusion.
Better check twice than cause random CI failure for everyone 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the emulated image sensor drivers to use a dedicated I2C emulator rather than ad-hoc register emulation. Key changes include:
- Adjusting the initialization priority in the video emulation receiver driver.
- Replacing hard-coded register accesses in the imagers with proper I2C calls.
- Introducing an emulated I2C transfer function and related API for the image sensor.
Reviewed Changes
Copilot reviewed 2 out of 6 changed files in this pull request and generated no comments.
File | Description |
---|---|
drivers/video/video_emul_rx.c | Update of the initialization macro to use a dedicated init priority. |
drivers/video/video_emul_imager.c | Replacement of ad-hoc register emulation with I2C read/write operations and addition of a simulated I2C bus. |
Files not reviewed (4)
- drivers/video/Kconfig.emul_imager: Language not supported
- drivers/video/Kconfig.emul_rx: Language not supported
- tests/drivers/video/api/app.overlay: Language not supported
- tests/drivers/video/api/prj.conf: Language not supported
Replace the ad-hoc register emulation by the dedicated I2C emulator, making it usable with the same APIs as every other image sensors. Signed-off-by: Josuah Demangeon <[email protected]>
The Emul Rx needs to be initialized after the camera sensor which is generally initialized with CONFIG_VIDEO_INIT_PRIORITY. This is currently true "by chance" due to the order the linker links the object files. This linker order is not easily controlled, so use an explicit priority value to ensure this requirement. Signed-off-by: Phi Bang Nguyen <[email protected]>
d65b699
to
1690457
Compare
No dependency. Split out of:
Downstream:
Replace the ad-hoc register emulation by the dedicated I2C emulator, making it usable with the same APIs as every other image sensors.