[libcamera-devel,v5,6/6,HACK] ipu3: Set and get a few sensor controls

Message ID 20190620153144.5394-7-jacopo@jmondi.org
State Superseded
Headers show
Series
  • Add support for V4L2 controls
Related show

Commit Message

Jacopo Mondi June 20, 2019, 3:31 p.m. UTC
Not to merge patch to demonstrate how to set controls on the image
sensor device.

Not-Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/pipeline/ipu3/ipu3.cpp | 41 ++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

Patch

diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index 54a6735dfc87..f561b6cd5c53 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -677,6 +677,47 @@  int PipelineHandlerIPU3::start(Camera *camera)
 	ImgUDevice *imgu = data->imgu_;
 	int ret;
 
+	/* --- Get control values --- */
+	V4L2Controls controls;
+	controls.add(V4L2_CID_EXPOSURE);
+	controls.add(V4L2_CID_ANALOGUE_GAIN);
+	ret = cio2->sensor_->getControls(&controls);
+	if (ret) {
+		LOG(Error) << "Failed to get control values";
+		return -EINVAL;
+	}
+
+	for (const V4L2Control &ctrl : controls) {
+		unsigned int id = ctrl.id();
+		const V4L2ControlInfo *info = cio2->sensor_->getControlInfo(id);
+		if (!info)
+			continue;
+
+		LOG(Error) << "Control : " << id << " - name : " << info->name()
+			   << " - value: " << ctrl.value();
+	}
+
+	/* --- Set control values --- */
+	controls.reset();
+	controls.add(V4L2_CID_EXPOSURE, 2046);
+	controls.add(V4L2_CID_ANALOGUE_GAIN, 1024);
+
+	ret = cio2->sensor_->setControls(&controls);
+	if (ret) {
+		LOG(IPU3, Error) << "Failed to set controls";
+		return ret;
+	}
+
+	for (const V4L2Control &ctrl : controls) {
+		unsigned int id = ctrl.id();
+		const V4L2ControlInfo *info = cio2->sensor_->getControlInfo(id);
+		if (!info)
+			continue;
+
+		LOG(Error) << "Control : " << id << " - name : " << info->name()
+			   << " - value: " << ctrl.value();
+	}
+
 	/*
 	 * Start the ImgU video devices, buffers will be queued to the
 	 * ImgU output and viewfinder when requests will be queued.