Skip to content

Commit 3023c51

Browse files
trunghieulenxpngphibang
authored andcommitted
drivers: video: ov5640: Fix gain controls
Separate autogain and gain controls. This type of controls depend on each other and will be supported as "control group" in the new video control framework. Signed-off-by: Trung Hieu Le <trunghieu.le@nxp.com> Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
1 parent a53ea06 commit 3023c51

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

drivers/video/ov5640.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ struct ov5640_data {
146146
uint32_t cur_pixrate;
147147
uint16_t cur_frmrate;
148148
const struct ov5640_mode_config *cur_mode;
149+
bool auto_gain;
149150
};
150151

151152
static const struct ov5640_reg init_params_common[] = {
@@ -997,25 +998,35 @@ static int ov5640_set_ctrl_contrast(const struct device *dev, int value)
997998
static int ov5640_set_ctrl_gain(const struct device *dev, int value)
998999
{
9991000
const struct ov5640_config *cfg = dev->config;
1001+
struct ov5640_data *data = dev->data;
10001002

1001-
if (!IN_RANGE(value, 0, UINT16_MAX)) {
1003+
if (data->auto_gain) {
1004+
return -ENOTSUP;
1005+
}
1006+
1007+
if (!IN_RANGE(value, 0, 1023)) {
10021008
return -EINVAL;
10031009
}
10041010

1005-
if (value) {
1006-
int ret = ov5640_modify_reg(&cfg->i2c, AEC_PK_MANUAL, BIT(1), BIT(0));
1011+
int ret = ov5640_modify_reg(&cfg->i2c, AEC_PK_REAL_GAIN, 0x03, (value >> 8) & 0x03);
10071012

1008-
if (ret) {
1009-
return ret;
1010-
}
1013+
if (ret) {
1014+
return ret;
1015+
}
10111016

1012-
struct ov5640_reg gain_params[] = {{AEC_PK_REAL_GAIN, value >> 8},
1013-
{AEC_PK_REAL_GAIN + 1, value & 0xff}};
1017+
ret = ov5640_write_reg(&cfg->i2c, AEC_PK_REAL_GAIN + 1, value & 0xff);
1018+
return ret;
1019+
}
10141020

1015-
return ov5640_write_multi_regs(&cfg->i2c, gain_params, ARRAY_SIZE(gain_params));
1016-
} else {
1017-
return ov5640_write_reg(&cfg->i2c, AEC_PK_MANUAL, 0);
1018-
}
1021+
static int ov5640_set_ctrl_autogain(const struct device *dev, bool value)
1022+
{
1023+
const struct ov5640_config *cfg = dev->config;
1024+
struct ov5640_data *data = dev->data;
1025+
int ret;
1026+
1027+
data->auto_gain = value;
1028+
1029+
return ov5640_modify_reg(&cfg->i2c, AEC_PK_MANUAL, BIT(1), data->auto_gain ? 0 : BIT(1));
10191030
}
10201031

10211032
static int ov5640_set_ctrl_hflip(const struct device *dev, int value)
@@ -1073,6 +1084,8 @@ static int ov5640_set_ctrl(const struct device *dev, unsigned int cid, void *val
10731084
return ov5640_set_ctrl_brightness(dev, (int)(value));
10741085
case VIDEO_CID_CONTRAST:
10751086
return ov5640_set_ctrl_contrast(dev, (int)value);
1087+
case VIDEO_CID_AUTOGAIN:
1088+
return ov5640_set_ctrl_autogain(dev, (bool)(value));
10761089
case VIDEO_CID_GAIN:
10771090
return ov5640_set_ctrl_gain(dev, (int)(value));
10781091
case VIDEO_CID_HFLIP:

include/zephyr/drivers/video-controls.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ extern "C" {
5454
/** Amount of time an image sensor is exposed to light, affecting the brightness */
5555
#define VIDEO_CID_EXPOSURE (VIDEO_CID_BASE + 17)
5656

57+
/** Enable/Disable the autogain */
58+
#define VIDEO_CID_AUTOGAIN (VIDEO_CID_BASE + 18)
59+
5760
/** Amount of amplification performed to each pixel electrical signal, affecting the brightness */
5861
#define VIDEO_CID_GAIN (VIDEO_CID_BASE + 19)
5962

0 commit comments

Comments
 (0)