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: emul: simplify, avoid mission creep #83220

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
drivers: video: emul_imager: use a "PRIV" video CID
Use a video control ID in the private range rather than using an existing
CID, as the emulated imager does not effectively applies these properties
to the image feed and are just for API test purpose.

Signed-off-by: Josuah Demangeon <me@josuah.net>
josuah committed Mar 19, 2025
commit db5abeb2b43653ef357ebb5f8446418b12d9a98c
28 changes: 8 additions & 20 deletions drivers/video/video_emul_imager.c
Original file line number Diff line number Diff line change
@@ -27,14 +27,15 @@ LOG_MODULE_REGISTER(video_emul_imager, CONFIG_VIDEO_LOG_LEVEL);
#define EMUL_IMAGER_REG_TIMING1 0x0004
#define EMUL_IMAGER_REG_TIMING2 0x0005
#define EMUL_IMAGER_REG_TIMING3 0x0006
#define EMUL_IMAGER_REG_EXPOSURE 0x0007
#define EMUL_IMAGER_REG_GAIN 0x0008
#define EMUL_IMAGER_REG_PATTERN 0x0009
#define EMUL_IMAGER_REG_CUSTOM 0x0007
#define EMUL_IMAGER_REG_FORMAT 0x000a
#define EMUL_IMAGER_PATTERN_OFF 0x00
#define EMUL_IMAGER_PATTERN_BARS1 0x01
#define EMUL_IMAGER_PATTERN_BARS2 0x02

/* Custom control that is just an I2C write for example and test purpose */
#define EMUL_IMAGER_CID_CUSTOM (VIDEO_CID_PRIVATE_BASE + 0x01)

/* Emulated register bank */
uint8_t emul_imager_fake_regs[10];

@@ -198,31 +199,18 @@ static int emul_imager_write_multi(const struct device *const dev,
static int emul_imager_set_ctrl(const struct device *dev, unsigned int cid, void *value)
{
switch (cid) {
case VIDEO_CID_EXPOSURE:
return emul_imager_write_reg(dev, EMUL_IMAGER_REG_EXPOSURE, (int)value);
case VIDEO_CID_GAIN:
return emul_imager_write_reg(dev, EMUL_IMAGER_REG_GAIN, (int)value);
case VIDEO_CID_TEST_PATTERN:
return emul_imager_write_reg(dev, EMUL_IMAGER_REG_PATTERN, (int)value);
case EMUL_IMAGER_CID_CUSTOM:
return emul_imager_write_reg(dev, EMUL_IMAGER_REG_CUSTOM, (int)value);
default:
return -ENOTSUP;
}
}

static int emul_imager_get_ctrl(const struct device *dev, unsigned int cid, void *value)
{
struct emul_imager_data *data = dev->data;

switch (cid) {
case VIDEO_CID_EXPOSURE:
return emul_imager_read_int(dev, EMUL_IMAGER_REG_EXPOSURE, value);
case VIDEO_CID_GAIN:
return emul_imager_read_int(dev, EMUL_IMAGER_REG_GAIN, value);
case VIDEO_CID_TEST_PATTERN:
return emul_imager_read_int(dev, EMUL_IMAGER_REG_PATTERN, value);
case VIDEO_CID_PIXEL_RATE:
*(int64_t *)value = (int64_t)data->fmt.width * data->fmt.pitch * data->mode->fps;
return 0;
case EMUL_IMAGER_CID_CUSTOM:
return emul_imager_read_int(dev, EMUL_IMAGER_REG_CUSTOM, value);
default:
return -ENOTSUP;
}
9 changes: 2 additions & 7 deletions tests/drivers/video/api/src/video_emul.c
Original file line number Diff line number Diff line change
@@ -130,13 +130,8 @@ ZTEST(video_common, test_video_ctrl)
int value;

/* Exposure control, expected to be supported by all imagers */
zexpect_ok(video_set_ctrl(imager_dev, VIDEO_CID_EXPOSURE, (void *)30));
zexpect_ok(video_get_ctrl(imager_dev, VIDEO_CID_EXPOSURE, &value));
zexpect_equal(value, 30);

/* Gain control, expected to be supported by all imagers */
zexpect_ok(video_set_ctrl(imager_dev, VIDEO_CID_GAIN, (void *)30));
zexpect_ok(video_get_ctrl(imager_dev, VIDEO_CID_GAIN, &value));
zexpect_ok(video_set_ctrl(imager_dev, VIDEO_CID_PRIVATE_BASE + 0x01, (void *)30));
zexpect_ok(video_get_ctrl(imager_dev, VIDEO_CID_PRIVATE_BASE + 0x01, &value));
zexpect_equal(value, 30);
}