Skip to content

Commit e00e6fd

Browse files
committed
drivers: video: Add get_volatile_ctrl driver's API
Add get_volatile_ctrl() driver's API to retrieve the current value of a control marked as volatile, e.g. gain, exposure. This function triggers a hardware register reading instead of returning a cached value to ensure that users always get a fresh value which is constantly updated by the HW. Note that the driver is responsible for marking a control as volatile by setting VIDEO_CTRL_FLAG_VOLATILE when registering a control because not all hardwares work the same way for the same control. Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
1 parent f2f85c6 commit e00e6fd

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

drivers/video/video_ctrls.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ int video_get_ctrl(const struct device *dev, struct video_control *control)
151151
return -EACCES;
152152
}
153153

154+
if (ctrl->flags & VIDEO_CTRL_FLAG_VOLATILE) {
155+
if (DEVICE_API_GET(video, ctrl->vdev->dev)->get_volatile_ctrl == NULL) {
156+
return -ENOSYS;
157+
}
158+
159+
/* Call driver's get_volatile_ctrl */
160+
return DEVICE_API_GET(video, ctrl->vdev->dev)
161+
->get_volatile_ctrl(ctrl->vdev->dev, control);
162+
}
163+
164+
/* Read control value in cache memory */
154165
if (ctrl->type == VIDEO_CTRL_TYPE_INTEGER64) {
155166
control->val64 = ctrl->val64;
156167
} else {

include/zephyr/drivers/video.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,12 @@ typedef int (*video_api_flush_t)(const struct device *dev, enum video_endpoint_i
318318
typedef int (*video_api_set_stream_t)(const struct device *dev, bool enable);
319319

320320
/**
321-
* @typedef video_api_set_ctrl_t
322-
* @brief Set a video control value.
321+
* @typedef video_api_ctrl_t
322+
* @brief Set/Get a video control value.
323323
*
324-
* See video_set_ctrl() for argument descriptions.
324+
* See video_set_ctrl() or video_get_ctrl() for argument descriptions.
325325
*/
326-
typedef int (*video_api_set_ctrl_t)(const struct device *dev, struct video_control *ctrl);
326+
typedef int (*video_api_ctrl_t)(const struct device *dev, struct video_control *ctrl);
327327

328328
/**
329329
* @typedef video_api_get_caps_t
@@ -353,7 +353,8 @@ __subsystem struct video_driver_api {
353353
video_api_enqueue_t enqueue;
354354
video_api_dequeue_t dequeue;
355355
video_api_flush_t flush;
356-
video_api_set_ctrl_t set_ctrl;
356+
video_api_ctrl_t set_ctrl;
357+
video_api_ctrl_t get_volatile_ctrl;
357358
video_api_set_signal_t set_signal;
358359
video_api_set_frmival_t set_frmival;
359360
video_api_get_frmival_t get_frmival;

0 commit comments

Comments
 (0)