From patchwork Thu Mar 17 09:19:37 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: 15463 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 D564DBF415 for ; Thu, 17 Mar 2022 09:20:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 15B88604DC; Thu, 17 Mar 2022 10:20:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647508840; bh=Q8iGi+LQryGFePvlcMQyHcRls0AQ0SqTr99aoozW7kE=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jirfgYchQZon+BgvAq4RRbi1aLZxjBjOCvhJkWf7m1bUyy8FE9qfdjWj31W1v429z s6HTOj9pB1zMSA39UARyUmfU8HEtE2C5LFo8S0fSwamZheSwK61EP905uulV9yWYPr OVHYQNn3XKDfBXIupAtMCnTj527S5b1JOZ5HePmmXqQUji/m4PVKJ8KgfpO8QJoROu 8nk8wLdgbXMMhbB2xxNU8kssyKW3TpXRgIVjt1NiZ/Tn8awrrMyfRkIXHmQtWVJf1u lTwFC37nSyuvp8C0lAhtX8rsisIhXxIb3QrZnNQEBmGtYWKoZfrAgGtjJHtimseEta BW8kmwtwRWeAQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 366D0604DB for ; Thu, 17 Mar 2022 10:20:38 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="GBph0MKM"; dkim-atps=neutral Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:2f87:7946:75e2:1cf1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CE710493; Thu, 17 Mar 2022 10:20:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1647508837; bh=Q8iGi+LQryGFePvlcMQyHcRls0AQ0SqTr99aoozW7kE=; h=From:To:Cc:Subject:Date:From; b=GBph0MKMLpvIcDtqvNUo5HRgVijJpw9V6ShNbLWFxnDfT0A9Rz8Z3c6M5Mq2PenE4 dK1e8DxfOynyhZEF/3vz048tGICa1CGAhNCXNFRndngQy0xuxXILqydVgS8EanLP4B KaRbJaeZyODdt+fzCXW9OA2ZIg7uS9Sam/Wxf5CM= To: libcamera-devel@lists.libcamera.org Date: Thu, 17 Mar 2022 10:19:37 +0100 Message-Id: <20220317091937.168527-1-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] libcamera: raspberrypi: Control the lens from pipeline 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" 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 --- include/libcamera/ipa/raspberrypi.mojom | 1 + .../pipeline/raspberrypi/raspberrypi.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index acd3cafe..0c3922b0 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -125,4 +125,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 c2230199..41be10ff 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -33,6 +33,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" @@ -202,6 +203,7 @@ public: void setIspControls(const ControlList &controls); void setDelayedControls(const ControlList &controls); void setSensorControls(ControlList &controls); + void setLensControls(const ControlList &controls); /* bufferComplete signal handlers. */ void unicamBufferDequeue(FrameBuffer *buffer); @@ -1483,6 +1485,7 @@ int RPiCameraData::loadIPA(ipa::RPi::SensorConfig *sensorConfig) 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 @@ -1519,6 +1522,10 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config) 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(config->transform); @@ -1735,6 +1742,16 @@ void RPiCameraData::setDelayedControls(const ControlList &controls) handleState(); } +void RPiCameraData::setLensControls(const ControlList &controls) +{ + ControlList ctrls = controls; + + CameraLens *lens = sensor_->focusLens(); + if (lens) + lens->setFocusPosition(ctrls.get(V4L2_CID_FOCUS_ABSOLUTE).get()); + handleState(); +} + void RPiCameraData::setSensorControls(ControlList &controls) { /* From patchwork Thu Mar 17 09:19:38 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: 15464 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 99F4FC3262 for ; Thu, 17 Mar 2022 09:20:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 849FD6118A; Thu, 17 Mar 2022 10:20:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647508840; bh=bdgDfuPJ1ozz5TXBn7Aby1v5pkCWt/fZPD98PuF8clk=; 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=Z6001+cEib7Xc1tPNIYIYVmNt69GhSUKYzUqkisrTkBATvNYan3BaQbUEvkU5P6L0 8ag0rya2TRTkUoE6BM/qNT3Ja1X3t3bjOTglZdvpHcVDCZXT7Tc+cmos9ge/+p2Pez NN2+6AqQKuGdJyeZ4oZnuhLEx3wi+QWbJL7bOebpLOBiKsaM+894KvqOOZFi5vpUhm MtBtmsv2Tp2i4vKiD8KkshgAW5COlj+XaMJN/JVJaLYrpyhsOb7wrSw8be5hw4AjtF R0Z1AvL1yRvv10DpNe44E5TF7bfJwu06J4m02pxif3p3grU0l7CnwDUR4ycHJJEcZa hRa/ZWGngS0ng== 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 D9765604DB for ; Thu, 17 Mar 2022 10:20:38 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HEckDv1a"; dkim-atps=neutral Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:2f87:7946:75e2:1cf1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9FE7E493; Thu, 17 Mar 2022 10:20:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1647508838; bh=bdgDfuPJ1ozz5TXBn7Aby1v5pkCWt/fZPD98PuF8clk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HEckDv1aFh0bNlN8dliagiMbQKJOJ+JMo5K3xKkRV9FRRECHiOBn/yXzlLSkQwArH H0cLQig+7WM/b75gXAk+oQ2Se6UWL4Ks/8kTOXjLd3aZ4q7UIZS6MJz/QOhXvn3oE6 1pDtqpyAMeL4Mi8m1ofWy7rce/jrJi9dE6zo84Ls= To: libcamera-devel@lists.libcamera.org Date: Thu, 17 Mar 2022 10:19:38 +0100 Message-Id: <20220317091937.168527-2-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220317091937.168527-1-jeanmichel.hautbois@ideasonboard.com> References: <20220317091937.168527-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/2] 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 --- src/ipa/raspberrypi/raspberrypi.cpp | 41 ++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index fd8fecb0..9e66f8fd 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -108,6 +108,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 ipa::RPi::ISPConfig &data); @@ -132,6 +133,7 @@ private: ControlInfoMap sensorCtrls_; ControlInfoMap ispCtrls_; + ControlInfoMap lensCtrls_; ControlList libcameraMetadata_; /* Camera sensor params. */ @@ -342,7 +344,7 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, const ipa::RPi::IPAConfig &ipaConfig, ControlList *controls) { - if (entityControls.size() != 2) { + if (entityControls.size() < 2) { LOG(IPARPI, Error) << "No ISP or sensor controls found."; return -1; } @@ -360,6 +362,14 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, return -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."; + } + maxSensorGainCode_ = sensorCtrls_.at(V4L2_CID_ANALOGUE_GAIN).max().get(); /* Setup a metadata ControlList to output metadata. */ @@ -578,6 +588,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 @@ -1066,6 +1093,18 @@ void IPARPi::processStats(unsigned int bufferId) setDelayedControls.emit(ctrls); } + + /* + * Set the focus position + * \todo Use an AF algorithm and replace the arbitrary value + */ + struct FocusStatus focusStatus; + if (rpiMetadata_.Get("focus.status", focusStatus) == 0) { + ControlList lensCtrls(lensCtrls_); + lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, static_cast(123)); + setLensControls.emit(lensCtrls); + } + } void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)