[libcamera-devel,3/5] ipa: raspberrypi: Control the lens position
diff mbox series

Message ID 20221201145133.479794-4-umang.jain@ideasonboard.com
State New
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>

Now that the ancillary links are configured, we can use the CameraLens
class and control the VCM through the IPA.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
---
 src/ipa/raspberrypi/raspberrypi.cpp | 30 ++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
index 4e10c57d..3d1ac8fc 100644
--- a/src/ipa/raspberrypi/raspberrypi.cpp
+++ b/src/ipa/raspberrypi/raspberrypi.cpp
@@ -30,6 +30,7 @@ 
 
 #include "libcamera/internal/mapped_framebuffer.h"
 
+#include "af_status.h"
 #include "agc_algorithm.h"
 #include "agc_status.h"
 #include "alsc_status.h"
@@ -131,6 +132,7 @@  private:
 	void setMode(const IPACameraSensorInfo &sensorInfo);
 	bool validateSensorControls();
 	bool validateIspControls();
+	bool validateLensControls();
 	void queueRequest(const ControlList &controls);
 	void returnEmbeddedBuffer(unsigned int bufferId);
 	void prepareISP(const ISPConfig &data);
@@ -155,6 +157,7 @@  private:
 
 	ControlInfoMap sensorCtrls_;
 	ControlInfoMap ispCtrls_;
+	ControlInfoMap lensCtrls_;
 	ControlList libcameraMetadata_;
 
 	/* Camera sensor params. */
@@ -381,7 +384,7 @@  int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,
 		      const IPAConfig &ipaConfig,
 		      ControlList *controls, IPAConfigResult *result)
 {
-	if (entityControls.size() != 2) {
+	if (entityControls.size() < 2) {
 		LOG(IPARPI, Error) << "No ISP or sensor controls found.";
 		return -1;
 	}
@@ -389,6 +392,14 @@  int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,
 	sensorCtrls_ = entityControls.at(0);
 	ispCtrls_ = entityControls.at(1);
 
+	/* Lens may not be present, don't make it an hard assumption. */
+	auto lensControl = entityControls.find(2);
+	if (lensControl != entityControls.end()) {
+		lensCtrls_ = lensControl->second;
+		if (!validateLensControls())
+			LOG(IPARPI, Error) << "Lens control validation failed.";
+	}
+
 	if (!validateSensorControls()) {
 		LOG(IPARPI, Error) << "Sensor control validation failed.";
 		return -1;
@@ -650,6 +661,23 @@  bool IPARPi::validateIspControls()
 	return true;
 }
 
+bool IPARPi::validateLensControls()
+{
+	static const uint32_t ctrls[] = {
+		V4L2_CID_FOCUS_ABSOLUTE,
+	};
+
+	for (auto c : ctrls) {
+		if (lensCtrls_.find(c) == lensCtrls_.end()) {
+			LOG(IPARPI, Error) << "Unable to find lens control "
+					   << utils::hex(c);
+			return false;
+		}
+	}
+
+	return true;
+}
+
 /*
  * Converting between enums (used in the libcamera API) and the names that
  * we use to identify different modes. Unfortunately, the conversion tables