From patchwork Wed Mar 23 16:01:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 15529 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 984B2C3265 for ; Wed, 23 Mar 2022 16:01:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0DB4A610F8; Wed, 23 Mar 2022 17:01:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648051315; bh=veCQMbxbFw2w3L45sYunZOtpe4x5G1w83ycREIJOKzg=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=drbje7l2F/oLLKWY+QeJZ55ZYsoyBPp041qH1YvbIkUqRhwDkXv/xGnHEmCO9t0v/ vqlKdQChuIqGVxeqUkZISpWEtelSiZjGlJJquuVOlp7afH5JB+pyUr6asHtMPtvxU8 PRQsUB9p+xy0xsGf06zMuBj3+XA4Qw7KHosj0HXV2irUB5s5Z9Z6TfoFyOavq1ERDA jqoI9A3wdYVGFAkIjMGsPI/yNbaUj0fXe2L1sQ9YCMTysctdCqHk5HjdbyNegD4FAC RabIZ37Y/IGnyJqFze/LPhf09I5CgTu3KypKG5PXsX0LF5z1kGT75/Fm7Yd/oJRrpE ye947dAxhR5XA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 26AD0604DB for ; Wed, 23 Mar 2022 17:01:50 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OFwPHCcP"; dkim-atps=neutral Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:2e05:b10:1542:d51b]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D43CAFFD; Wed, 23 Mar 2022 17:01:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648051309; bh=veCQMbxbFw2w3L45sYunZOtpe4x5G1w83ycREIJOKzg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OFwPHCcPA6dXugMKATkkVp8KdSFKfAuK892CQJe452aAlfxfATNUzm/JmVyh6qSRw GLJ0BUyC78s283QdLVf+Wek+sKUqzntRF1OwIDj3usa6k/idULpO203ScJU+AsuL/V W+GIja56lnBOWkmedXdi2aoga5e70JnZfFPkU+H4= To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Mar 2022 17:01:45 +0100 Message-Id: <20220323160145.90606-5-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220323160145.90606-1-jeanmichel.hautbois@ideasonboard.com> References: <20220323160145.90606-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 4/4] ipa: raspberrypi: Control the lens position X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jean-Michel Hautbois via libcamera-devel From: Jean-Michel Hautbois Reply-To: Jean-Michel Hautbois Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Now that the ancillary links are configured, we can use the CameraLens class and control the VCM through the IPA. For now, force a default value for the lens position, until the AF algorithm is introduced. Signed-off-by: Jean-Michel Hautbois --- v2: Change the need for lens control to be present --- src/ipa/raspberrypi/raspberrypi.cpp | 42 ++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index cf4e6cab..ff302e37 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.hpp" #include "agc_status.h" #include "alsc_status.h" @@ -110,6 +111,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); @@ -134,6 +136,7 @@ private: ControlInfoMap sensorCtrls_; ControlInfoMap ispCtrls_; + ControlInfoMap lensCtrls_; ControlList libcameraMetadata_; /* Camera sensor params. */ @@ -344,7 +347,7 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, const IPAConfig &ipaConfig, ControlList *controls) { - if (entityControls.size() != 2) { + if (entityControls.size() < 2) { LOG(IPARPI, Error) << "No ISP or sensor controls found."; return -1; } @@ -352,6 +355,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; @@ -362,6 +373,10 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, return -1; } + if (!validateLensControls()) { + LOG(IPARPI, Error) << "Lens control validation failed."; + } + maxSensorGainCode_ = sensorCtrls_.at(V4L2_CID_ANALOGUE_GAIN).max().get(); /* Setup a metadata ControlList to output metadata. */ @@ -580,6 +595,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 @@ -1068,6 +1100,14 @@ void IPARPi::processStats(unsigned int bufferId) setDelayedControls.emit(ctrls); } + + struct AfStatus afStatus; + if (rpiMetadata_.Get("af.status", afStatus) == 0) { + ControlList lensCtrls(lensCtrls_); + lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, + static_cast(afStatus.focus)); + setLensControls.emit(lensCtrls); + } } void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)