From patchwork Tue Aug 9 14:47:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 17050 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 D643AC3272 for ; Tue, 9 Aug 2022 14:47:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 989B963332; Tue, 9 Aug 2022 16:47:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660056435; bh=qU5aw/Jw76GpL2WQXt84DR+OO6C6wzVTR7vjAtoNTGs=; 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=nCSh7kmGArn7Q61mXDx6Z+RfgASWKw2WB4CkOGrF65AOpceua997Dl2EqMFp3lU5s H2KacojmkTU3usG/ksjd01DJYxos6GkNMrsjZrRv96qiZdC5/oEuRtbB6CfXCs2u/3 HU6RiAf8LGWz96i2uL/5rLTlOwfJg3t7ii90Q3UKPreAgHFXDUb1aquId6qWS/fyFV +kr17fLTQGb1p4Kpb1vTa9jg2k7hULnjtZ95U5EJPvMc2gK8P9V3/lD7UFBYSnTfD7 TiOBtFvPj1ar+ewe2pxAna0OsVLBZp9fEn+j5wx7YbcIWHzsBCl3QG5CXkJfr2jLgq XhRaQt7t6op2w== Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ED08363326 for ; Tue, 9 Aug 2022 16:47:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=thaumatec-com.20210112.gappssmtp.com header.i=@thaumatec-com.20210112.gappssmtp.com header.b="kkv0aXVB"; dkim-atps=neutral Received: by mail-ed1-x52f.google.com with SMTP id x21so15430864edd.3 for ; Tue, 09 Aug 2022 07:47:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=lIX7iN6BFHYMg1C5EJH+xkJnpsY8ZgYE6Zav8pi9O7s=; b=kkv0aXVBk4CjNkw+b/nkZTi/8dzLJ1HaLrq5nU44/TCduZTrCG0am/me/IxyhQL5vq 96ji8yY0PTkvU6ZbsXyhdgHf7w8BW5OpcP9ia7l3Q0BIOQZ2kmcHwgv++j8cuRMv4Yk6 5gioKuurb91wytEO2PDNKGkbtacxuuaVTfaoU3fCmbqhlU9LG/DQFDC/2KoVhAnWlbKJ 8UUkJcA99bU1/LIWR0kQutjIDJRurKj+rhcxHCFSuhX1eyddplJoVT0Wx/VTJknKrJxx m8UE9IsDGhmDHdbBNd/PdO5XOBGLFEbFF0/hxdsUjuQ+IXHTg2UJM+mfKKlg7iG81vNN yGzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=lIX7iN6BFHYMg1C5EJH+xkJnpsY8ZgYE6Zav8pi9O7s=; b=p+l0KHh5jUjQq+KAJZFs/pbN1Y5OSv882AYcMpvxdvioQ7Ysg7NsBEgqxueD8Hbr5f 856E12b31nnB9K+DhpYEt3JKN8buL/q05SieWjkZWarAd6eGsYJaJ1eEVRApDDmAWlEp Fq1Y9RVWZWfLELjWf9OcZF+sWdSuf2ohj/4ksdAU1BCkm8tMoYp2wFYcLg5TdJ8AK+aq QTneDGJQlQHcBKrDd92US6gj5ETgGXMf57mUCyVYGIi1JyUVM48k+nG7IaDbpdZ6VZio ZrZz3G0HBHZrtbLN/3nvOMvKabaLfzPSDqyOowJRTMIMUy/hf5eWiWOsylm7RlUQw0hh PX/w== X-Gm-Message-State: ACgBeo3K/5iJr/cZfANsg6d2bW8qDp7xvv8+mEZ5BkFr/PkrNQnj30HH mDnKCnmhAgJUyLsd5RNMafUnLVDfTTcxJw== X-Google-Smtp-Source: AA6agR4NoivrNZIOzSNTJ0okc8VwKFrcjXbXMMZjkUbeo62AQ3//dVFZKu36Qtk/ahf2sBHHnM4NDQ== X-Received: by 2002:a05:6402:40c2:b0:440:4ecd:f75f with SMTP id z2-20020a05640240c200b004404ecdf75fmr14722348edb.405.1660056431581; Tue, 09 Aug 2022 07:47:11 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id cn15-20020a0564020caf00b0043ba0cf5dbasm6058486edb.2.2022.08.09.07.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Aug 2022 07:47:11 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 9 Aug 2022 16:47:04 +0200 Message-Id: <20220809144704.61682-4-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220809144704.61682-1-dse@thaumatec.com> References: <20220809144704.61682-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/3] rkisp1: Add camera lens position control from IPA 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: Daniel Semkowicz via libcamera-devel From: Daniel Semkowicz Reply-To: Daniel Semkowicz Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Allow control of lens position from the IPA, by setting corresponding af fields in the IPAFrameContext structure. Controls are then passed to the pipeline handler, which sets the lens position in CameraLens. Signed-off-by: Daniel Semkowicz --- include/libcamera/ipa/rkisp1.mojom | 1 + src/ipa/rkisp1/ipa_context.h | 5 +++++ src/ipa/rkisp1/rkisp1.cpp | 12 ++++++++++++ src/libcamera/pipeline/rkisp1/rkisp1.cpp | 16 ++++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/include/libcamera/ipa/rkisp1.mojom b/include/libcamera/ipa/rkisp1.mojom index eaf3955e..caa1121a 100644 --- a/include/libcamera/ipa/rkisp1.mojom +++ b/include/libcamera/ipa/rkisp1.mojom @@ -32,5 +32,6 @@ interface IPARkISP1Interface { interface IPARkISP1EventInterface { paramsBufferReady(uint32 frame); setSensorControls(uint32 frame, libcamera.ControlList sensorControls); + setLensControls(libcamera.ControlList sensorControls); metadataReady(uint32 frame, libcamera.ControlList metadata); }; diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index 2bdb6a81..d6d46b57 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -42,6 +42,11 @@ struct IPASessionConfiguration { }; struct IPAFrameContext { + struct { + uint32_t lensPosition; + bool applyLensCtrls; + } af; + struct { uint32_t exposure; double gain; diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 9e4c48a2..39e1ab2f 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -253,6 +253,10 @@ int IPARkISP1::configure([[maybe_unused]] const IPACameraSensorInfo &info, context_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain); context_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain); + /* Lens position is unknown at the startup, so initilize the variable + * that holds the current position to something out of the range. */ + context_.frameContext.af.lensPosition = std::numeric_limits::max(); + context_.frameContext.frameCount = 0; for (auto const &algo : algorithms()) { @@ -348,6 +352,14 @@ void IPARkISP1::setControls(unsigned int frame) ctrls.set(V4L2_CID_ANALOGUE_GAIN, static_cast(gain)); setSensorControls.emit(frame, ctrls); + + if (lensCtrls_ && context_.frameContext.af.applyLensCtrls) { + context_.frameContext.af.applyLensCtrls = false; + ControlList lensCtrls(*lensCtrls_); + lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, + static_cast(context_.frameContext.af.lensPosition)); + setLensControls.emit(lensCtrls); + } } void IPARkISP1::prepareMetadata(unsigned int frame, unsigned int aeState) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 5f10c26b..de0d37da 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -108,6 +108,7 @@ private: void paramFilled(unsigned int frame); void setSensorControls(unsigned int frame, const ControlList &sensorControls); + void setLensControls(const ControlList &lensControls); void metadataReady(unsigned int frame, const ControlList &metadata); }; @@ -324,6 +325,7 @@ int RkISP1CameraData::loadIPA(unsigned int hwRevision) return -ENOENT; ipa_->setSensorControls.connect(this, &RkISP1CameraData::setSensorControls); + ipa_->setLensControls.connect(this, &RkISP1CameraData::setLensControls); ipa_->paramsBufferReady.connect(this, &RkISP1CameraData::paramFilled); ipa_->metadataReady.connect(this, &RkISP1CameraData::metadataReady); @@ -378,6 +380,20 @@ void RkISP1CameraData::setSensorControls([[maybe_unused]] unsigned int frame, delayedCtrls_->push(sensorControls); } +void RkISP1CameraData::setLensControls(const ControlList &lensControls) +{ + CameraLens *focusLens = sensor_->focusLens(); + if (!focusLens) + return; + + if (!lensControls.contains(V4L2_CID_FOCUS_ABSOLUTE)) + return; + + const ControlValue &focusValue = lensControls.get(V4L2_CID_FOCUS_ABSOLUTE); + + focusLens->setFocusPosition(focusValue.get()); +} + void RkISP1CameraData::metadataReady(unsigned int frame, const ControlList &metadata) { RkISP1FrameInfo *info = frameInfo_.find(frame);