This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 12435198609e54f445b6ad70856a90d97c912371 Author: niyinghao <[email protected]> AuthorDate: Tue Nov 10 16:40:41 2026 +0800 arch/sim: add sensor control ops to sim camera driver Implement get_supported_value, get_value, and set_value operations for the sim camera imgsensor driver. This allows libcamera and V4L2 control enumeration to work in the simulator environment by exposing brightness and exposure controls with configurable ranges. Signed-off-by: niyinghao <[email protected]> --- arch/sim/src/sim/sim_camera.c | 103 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/arch/sim/src/sim/sim_camera.c b/arch/sim/src/sim/sim_camera.c index 1a5be4fc6d2..93a0472668f 100644 --- a/arch/sim/src/sim/sim_camera.c +++ b/arch/sim/src/sim/sim_camera.c @@ -66,6 +66,12 @@ struct sim_camera_priv_s bool capture_started; int index; char devpath[32]; + + /* Simulated sensor controls */ + + int32_t brightness; + int32_t exposure_time; + int32_t gain; }; /**************************************************************************** @@ -91,6 +97,16 @@ static int sim_camera_start_capture(struct imgsensor_s *sensor, static int sim_camera_stop_capture(struct imgsensor_s *sensor, imgsensor_stream_type_t type); +static int sim_camera_get_supported_value(struct imgsensor_s *sensor, + uint32_t id, + imgsensor_supported_value_t *val); +static int sim_camera_get_value(struct imgsensor_s *sensor, + uint32_t id, uint32_t size, + imgsensor_value_t *val); +static int sim_camera_set_value(struct imgsensor_s *sensor, + uint32_t id, uint32_t size, + imgsensor_value_t val); + /* Video image data operations */ static int sim_camera_data_init(struct imgdata_s *data); @@ -126,6 +142,9 @@ static const struct imgsensor_ops_s g_sim_camera_ops = .validate_frame_setting = sim_camera_validate_frame_setting, .start_capture = sim_camera_start_capture, .stop_capture = sim_camera_stop_capture, + .get_supported_value = sim_camera_get_supported_value, + .get_value = sim_camera_get_value, + .set_value = sim_camera_set_value, }; static const struct imgdata_ops_s g_sim_camera_data_ops = @@ -266,6 +285,90 @@ static int sim_camera_stop_capture(struct imgsensor_s *sensor, return 0; } +static int sim_camera_get_supported_value(struct imgsensor_s *sensor, + uint32_t id, + imgsensor_supported_value_t *val) +{ + switch (id) + { + case IMGSENSOR_ID_BRIGHTNESS: + val->type = IMGSENSOR_CTRL_TYPE_INTEGER; + val->u.range.minimum = -100; + val->u.range.maximum = 100; + val->u.range.step = 1; + val->u.range.default_value = 0; + return 0; + + case IMGSENSOR_ID_EXPOSURE_ABSOLUTE: + val->type = IMGSENSOR_CTRL_TYPE_INTEGER; + val->u.range.minimum = 1; + val->u.range.maximum = 10000; + val->u.range.step = 1; + val->u.range.default_value = 100; + return 0; + + case IMGSENSOR_ID_EXPOSURE_AUTO: + val->type = IMGSENSOR_CTRL_TYPE_INTEGER; + val->u.range.minimum = 0; + val->u.range.maximum = 3; + val->u.range.step = 1; + val->u.range.default_value = 0; + return 0; + + default: + return -EINVAL; + } +} + +static int sim_camera_get_value(struct imgsensor_s *sensor, + uint32_t id, uint32_t size, + imgsensor_value_t *val) +{ + sim_camera_priv_t *priv = container_of(sensor, sim_camera_priv_t, sensor); + + switch (id) + { + case IMGSENSOR_ID_BRIGHTNESS: + val->value32 = priv->brightness; + return 0; + + case IMGSENSOR_ID_EXPOSURE_ABSOLUTE: + val->value32 = priv->exposure_time; + return 0; + + case IMGSENSOR_ID_EXPOSURE_AUTO: + val->value32 = 0; + return 0; + + default: + return -EINVAL; + } +} + +static int sim_camera_set_value(struct imgsensor_s *sensor, + uint32_t id, uint32_t size, + imgsensor_value_t val) +{ + sim_camera_priv_t *priv = container_of(sensor, sim_camera_priv_t, sensor); + + switch (id) + { + case IMGSENSOR_ID_BRIGHTNESS: + priv->brightness = val.value32; + return 0; + + case IMGSENSOR_ID_EXPOSURE_ABSOLUTE: + priv->exposure_time = val.value32; + return 0; + + case IMGSENSOR_ID_EXPOSURE_AUTO: + return 0; + + default: + return -EINVAL; + } +} + /* Data op functions do all the real work */ static int sim_camera_data_init(struct imgdata_s *data)
