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

Jacopo Mondi jacopo at jmondi.org
Mon Jun 10 18:40:52 CEST 2019


Not to merge patch to demonstrate how to set controls on the image
sensor device.

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

diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index b3e7fb0e9c64..59c1fe3c56fd 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -688,6 +688,86 @@ int PipelineHandlerIPU3::start(Camera *camera)
 	ImgUDevice *imgu = data->imgu_;
 	int ret;
 
+	/* --- Get control values --- */
+	std::vector<unsigned int> controlIds = {
+		V4L2_CID_EXPOSURE, V4L2_CID_ANALOGUE_GAIN,
+	};
+	V4L2Controls controls;
+	ret = cio2->sensor_->dev()->getControls(controlIds, &controls);
+	if (ret) {
+		LOG(Error) << "Failed to get control values";
+		return -EINVAL;
+	}
+
+	for (V4L2Control *ctrl : controls) {
+		unsigned int id = ctrl->id();
+
+		switch(ctrl->type()) {
+		case V4L2_CTRL_TYPE_INTEGER:
+		case V4L2_CTRL_TYPE_BOOLEAN:
+		{
+			uint32_t val = controls.getInt(id);
+			LOG(Error) << "Control : " << id
+				   << " - value: " << val;
+		}
+			break;
+		case V4L2_CTRL_TYPE_INTEGER64:
+		{
+			uint64_t val = controls.getInt64(id);
+			LOG(Error) << "Control : " << id
+				   << " - value: " << val;
+		}
+			break;
+		default:
+			LOG(Error) << "Unsupported type: " << ctrl->type();
+			return -EINVAL;
+		}
+	}
+
+	/* --- Set control values --- */
+	V4L2Controls setControls;
+	setControls.set(V4L2_CID_EXPOSURE, 2046);
+	setControls.set(V4L2_CID_ANALOGUE_GAIN, 1024);
+
+	ret = cio2->sensor_->dev()->setControls(setControls);
+	if (ret) {
+		LOG(IPU3, Error) << "Failed to set controls";
+		return ret;
+	}
+
+	/* --- Get control values back again and verify they have changed --- */
+	V4L2Controls newcontrols;
+	ret = cio2->sensor_->dev()->getControls(controlIds, &newcontrols);
+	if (ret) {
+		LOG(Error) << "Failed to get control values";
+		return -EINVAL;
+	}
+
+	for (V4L2Control *ctrl : newcontrols) {
+		unsigned int id = ctrl->id();
+
+		switch(ctrl->type()) {
+		case V4L2_CTRL_TYPE_INTEGER:
+		case V4L2_CTRL_TYPE_BOOLEAN:
+		{
+			uint32_t val = newcontrols.getInt(id);
+			LOG(Error) << "Control : " << id
+				   << " - value: " << val;
+		}
+			break;
+		case V4L2_CTRL_TYPE_INTEGER64:
+		{
+			uint64_t val = newcontrols.getInt64(id);
+			LOG(Error) << "Control : " << id
+				   << " - value: " << val;
+		}
+			break;
+		default:
+			LOG(Error) << "Unsupported type: " << ctrl->type();
+			return -EINVAL;
+		}
+	}
+
 	/*
 	 * Start the ImgU video devices, buffers will be queued to the
 	 * ImgU output and viewfinder when requests will be queued.
-- 
2.21.0



More information about the libcamera-devel mailing list