[libcamera-devel,2/5] libcamera: raspberrypi: Control the lens from pipeline
diff mbox series

Message ID 20221201145133.479794-3-umang.jain@ideasonboard.com
State Not Applicable
Headers show
Series
  • ipa: rapsberrypi: Introduce auto-focus (auto-mode)
Related show

Commit Message

Umang Jain Dec. 1, 2022, 2:51 p.m. UTC
From: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>

The lens focus is controled by a VCM, which is linked to the sensor
using the ancillary links.
Pass the control to the config info structure and make it possible to
update by the IPA.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
---
 include/libcamera/ipa/raspberrypi.mojom         |  1 +
 .../pipeline/raspberrypi/raspberrypi.cpp        | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

Patch
diff mbox series

diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom
index d53644fe..e01f0b2b 100644
--- a/include/libcamera/ipa/raspberrypi.mojom
+++ b/include/libcamera/ipa/raspberrypi.mojom
@@ -130,4 +130,5 @@  interface IPARPiEventInterface {
 	embeddedComplete(uint32 bufferId);
 	setIspControls(libcamera.ControlList controls);
 	setDelayedControls(libcamera.ControlList controls);
+	setLensControls(libcamera.ControlList controls);
 };
diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
index 0e0b7194..911d5b55 100644
--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
@@ -32,6 +32,7 @@ 
 
 #include "libcamera/internal/bayer_format.h"
 #include "libcamera/internal/camera.h"
+#include "libcamera/internal/camera_lens.h"
 #include "libcamera/internal/camera_sensor.h"
 #include "libcamera/internal/delayed_controls.h"
 #include "libcamera/internal/device_enumerator.h"
@@ -209,6 +210,7 @@  public:
 	void setDelayedControls(const ControlList &controls);
 	void setSensorControls(ControlList &controls);
 	void unicamTimeout();
+	void setLensControls(const ControlList &controls);
 
 	/* bufferComplete signal handlers. */
 	void unicamBufferDequeue(FrameBuffer *buffer);
@@ -1551,6 +1553,7 @@  int RPiCameraData::loadIPA(ipa::RPi::IPAInitResult *result)
 	ipa_->embeddedComplete.connect(this, &RPiCameraData::embeddedComplete);
 	ipa_->setIspControls.connect(this, &RPiCameraData::setIspControls);
 	ipa_->setDelayedControls.connect(this, &RPiCameraData::setDelayedControls);
+	ipa_->setLensControls.connect(this, &RPiCameraData::setLensControls);
 
 	/*
 	 * The configuration (tuning file) is made from the sensor name unless
@@ -1591,6 +1594,10 @@  int RPiCameraData::configureIPA(const CameraConfiguration *config, ipa::RPi::IPA
 	entityControls.emplace(0, sensor_->controls());
 	entityControls.emplace(1, isp_[Isp::Input].dev()->controls());
 
+	CameraLens *lens = sensor_->focusLens();
+	if (lens)
+		entityControls.emplace(2, lens->controls());
+
 	/* Always send the user transform to the IPA. */
 	ipaConfig.transform = static_cast<unsigned int>(config->transform);
 
@@ -1807,6 +1814,16 @@  void RPiCameraData::setDelayedControls(const ControlList &controls)
 	handleState();
 }
 
+void RPiCameraData::setLensControls(const ControlList &ctrls)
+{
+	CameraLens *lens = sensor_->focusLens();
+	if (!lens)
+		return;
+
+	/* \todo Should we keep track of the latest value applied ? */
+	lens->setFocusPosition(ctrls.get(V4L2_CID_FOCUS_ABSOLUTE).get<int32_t>());
+}
+
 void RPiCameraData::setSensorControls(ControlList &controls)
 {
 	/*