@@ -146,6 +146,7 @@ struct ov5640_data {
146
146
uint32_t cur_pixrate ;
147
147
uint16_t cur_frmrate ;
148
148
const struct ov5640_mode_config * cur_mode ;
149
+ bool auto_gain ;
149
150
};
150
151
151
152
static const struct ov5640_reg init_params_common [] = {
@@ -997,25 +998,35 @@ static int ov5640_set_ctrl_contrast(const struct device *dev, int value)
997
998
static int ov5640_set_ctrl_gain (const struct device * dev , int value )
998
999
{
999
1000
const struct ov5640_config * cfg = dev -> config ;
1001
+ struct ov5640_data * data = dev -> data ;
1000
1002
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 )) {
1002
1008
return - EINVAL ;
1003
1009
}
1004
1010
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 );
1007
1012
1008
- if (ret ) {
1009
- return ret ;
1010
- }
1013
+ if (ret ) {
1014
+ return ret ;
1015
+ }
1011
1016
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
+ }
1014
1020
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 ));
1019
1030
}
1020
1031
1021
1032
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
1073
1084
return ov5640_set_ctrl_brightness (dev , (int )(value ));
1074
1085
case VIDEO_CID_CONTRAST :
1075
1086
return ov5640_set_ctrl_contrast (dev , (int )value );
1087
+ case VIDEO_CID_AUTOGAIN :
1088
+ return ov5640_set_ctrl_autogain (dev , (bool )(value ));
1076
1089
case VIDEO_CID_GAIN :
1077
1090
return ov5640_set_ctrl_gain (dev , (int )(value ));
1078
1091
case VIDEO_CID_HFLIP :
0 commit comments