From patchwork Wed Mar 16 09:39:50 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: 15457 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 3C92BBDE17 for ; Wed, 16 Mar 2022 09:39:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 72DCA6118A; Wed, 16 Mar 2022 10:39:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647423597; bh=px9g9m4iliZYAxgzT/60BEvKxaq7Gee9SONa57PBcUs=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Hs/Jb7ZXNOp/TRU5eHRGDy5zjTZHD6tbW8rvqPQeKjcOCmUEluYDbaAsRyhgZ599H gL2lKFUbMZSK4VdWV6WJTayID8U6m/RTIMVhmUbzLbTotk7syjkDdvS71vg+IRYSSl Ca1MFkHVu9JvVM0NO4lXiPzdx97WrEM0g7LYCejlDOnTqrfuMFnHwSFMDLVkHn+LK+ gwIFM+jFpedzThWoaXfZTG7SSP8RakiVYUt7Ck6rS+RBICe/yIJX3l4s9WJjoAmfxw nO+Z5/yr/akeYJJ58m1nkJkFucmp5MgtIRuaUSbL1bBGhnKOLgSGRS3cyBhAsYpxig lcye8JdPvwGiQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B5973601F5 for ; Wed, 16 Mar 2022 10:39:55 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DZfqhMt6"; dkim-atps=neutral Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:3036:4976:879c:5c94]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4ADFDDD; Wed, 16 Mar 2022 10:39:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1647423595; bh=px9g9m4iliZYAxgzT/60BEvKxaq7Gee9SONa57PBcUs=; h=From:To:Cc:Subject:Date:From; b=DZfqhMt6Y4eKpdQHzifJL0w8HU5K+EL6A7INXYBTMCZJYjcMlSIXE20UvXqSTxea4 PZnhV9yE6Kgqnh7hNe6JSdhnhJCa7328cmGjGb3eloA6D2ZeFAM3/VrIkRK1AoYG4A BRQnn5iknirS9WAMnW6DihDZ9D5tYclrJRxx2eDI= To: libcamera-devel@lists.libcamera.org Date: Wed, 16 Mar 2022 10:39:50 +0100 Message-Id: <20220316093951.33779-1-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 | 15 +++++++++++++++ 2 files changed, 16 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..67a98daa 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,14 @@ void RPiCameraData::setDelayedControls(const ControlList &controls) handleState(); } +void RPiCameraData::setLensControls(const ControlList &controls) +{ + ControlList ctrls = controls; + + sensor_->focusLens()->setFocusPosition(ctrls.get(V4L2_CID_FOCUS_ABSOLUTE).get()); + handleState(); +} + void RPiCameraData::setSensorControls(ControlList &controls) { /* From patchwork Wed Mar 16 09:39:51 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: 15458 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 4324CC3262 for ; Wed, 16 Mar 2022 09:39:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DD9B8632E2; Wed, 16 Mar 2022 10:39:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647423597; bh=39nx0jN/BSL7NAeiCDh5ROPoY0goom8ufH1EyAcYehc=; 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=zzhQSASIi6J031zRZjd5uwcNfUa/0DBexHQVlvCiwWplqOQ6z2PbF+Nb7N24LU8iy iKZ+p3BJ9Z8LgFZslncJgyV4DL9QY7Vv7r2Whp2JcgxnRlhFXgoTpEaT7qPuE+vRT7 mgMbxjI55vdR6JUpAW0kpi6XPMrZwzs7GE3wvY5YaVI65v5QqAZlX1O+cNLIuG//E1 uKbn1hJ/I8hnE2CbT8PIcLDLbrvefSyn46tQ4FgkbONbfdr/3vqnYr5pMEy2rJEjK7 d3FBqmmDUNIlO+ZJhjSQmyifEktClWVMrAZMk88mCTTpxOwwGeUWsOQ6iRJOoK2kRS c5+ZCJCH6He9Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D33F5604E7 for ; Wed, 16 Mar 2022 10:39:55 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="vQgYOi1Q"; dkim-atps=neutral Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:3036:4976:879c:5c94]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 765BEA67; Wed, 16 Mar 2022 10:39:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1647423595; bh=39nx0jN/BSL7NAeiCDh5ROPoY0goom8ufH1EyAcYehc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vQgYOi1Q5xP7KwL50i4O5pB2KJNaIcfOY84seeRzlCz0UZMUtk9bSZu1VKg8wKFMy PeRzGiMB83GOG6f8z/rQfGs+CDRwq6WT5asEiXa6JunrMGiYs3q3rFCUBHuCJPRKum scatF/6Zeo1vrMYebTjsFwjcUT/AfKr3yKu29KgU= To: libcamera-devel@lists.libcamera.org Date: Wed, 16 Mar 2022 10:39:51 +0100 Message-Id: <20220316093951.33779-2-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220316093951.33779-1-jeanmichel.hautbois@ideasonboard.com> References: <20220316093951.33779-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 | 38 +++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index fd8fecb0..0a0b5a3a 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,13 +344,14 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, const ipa::RPi::IPAConfig &ipaConfig, ControlList *controls) { - if (entityControls.size() != 2) { - LOG(IPARPI, Error) << "No ISP or sensor controls found."; + if (entityControls.size() != 3) { + LOG(IPARPI, Error) << "No ISP, lens or sensor controls found."; return -1; } sensorCtrls_ = entityControls.at(0); ispCtrls_ = entityControls.at(1); + lensCtrls_ = entityControls.at(2); if (!validateSensorControls()) { LOG(IPARPI, Error) << "Sensor control validation failed."; @@ -360,6 +363,11 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, return -1; } + if (!validateLensControls()) { + LOG(IPARPI, Error) << "Lens control validation failed."; + return -1; + } + maxSensorGainCode_ = sensorCtrls_.at(V4L2_CID_ANALOGUE_GAIN).max().get(); /* Setup a metadata ControlList to output metadata. */ @@ -578,6 +586,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 +1091,15 @@ void IPARPi::processStats(unsigned int bufferId) setDelayedControls.emit(ctrls); } + + /* + * Set the focus position + * \todo Use an AF algorithm and replace the arbitrary value + */ + ControlList lensCtrls(lensCtrls_); + lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, static_cast(123)); + setLensControls.emit(lensCtrls); + } void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)