From patchwork Tue Jun 28 09:06:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16403 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 37B66BE173 for ; Tue, 28 Jun 2022 09:07:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DB4B765636; Tue, 28 Jun 2022 11:07:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656407237; bh=gfzwUG83+G0yymYmH0N1alx3bx8m4CacN2rgSnexuaM=; 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=Ps1/izySZocKPjuNolYWOq4G3/QSTY7rFwZj9sjOgj7RK15vwKzaQC+PwEDZyBZ/X V4G7wLAnzFCC1niO5iOxM8HRjkaRFk0Xp8utubQos0jXTJyqwv7p89vrMBV7Ay839t RwfIenUaQGUwCWODNxsvdnDT4M83YXrM67G8PNKiFdVpo0UDiPrp8UTnx+Z9VOMuEM lWEMjRFtR6MWlfjY0I00ce4ZucVODTRjH8HqS6BJ+pXrEeeWyPL2RdF82taBjP7SIP Gj7iQ88af6zLGpN660D9CZ7b+Y3v9aUAkwdWIAj/oqzR699qY6Hl/5g7SAX0ew8TAn gEEOQwwYS2L0g== Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 719986559A for ; Tue, 28 Jun 2022 11:07:15 +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="yHOiDYsQ"; dkim-atps=neutral Received: by mail-wr1-x431.google.com with SMTP id s1so16655078wra.9 for ; Tue, 28 Jun 2022 02:07:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZYSh6TtUV6Id9lYrR/VR4whhLRNG6xChpZLV3FOUjj4=; b=yHOiDYsQ/YJF9PfdUKPVbA/N2Zsp405kpkBNFoCHhxDcz/qncX14londaGcbcUcpCC ail24whucfNovrfAbYlLyKeL9TQPpw2F4cWQo+RVduoAWuA5xvKZehZ+MI1b9JGzTqIE vR9huRZEkVmL97Tz2FLQNAnUmOUR74vNnTYanvgNhb3A/q1+HiwbxVgq1Tr3kYMJZDwP hbSlEp39TiUQMAgrmxhfy1msp+0vZnEcxAQGhmyDlgSrkxdDZIr2bsSbBPXgV79zQ7Lv hl5iGOjNaL2pcwwYEkggJFJXaGBCnehcTHOnLrWXqYgJ1k1zFWYf88S81G/2/Ayi+TXC UA9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZYSh6TtUV6Id9lYrR/VR4whhLRNG6xChpZLV3FOUjj4=; b=bQ57uJiQE0ASInCHtJJfXR0zBnTJZf6eKkitMKIZi5tLH/HGZ/gfH9qiwsDojmUF42 2Jbo3gDbK38fxH0dP1fI3AfhVKSGd7F81YB2QMujx5sfCyWQck8Rqe2sJXCpUCdO9jaN I+nbMqYcsa0HsP2bfIg3D7TYFFnhXUH2KiJoFJsmTEOQcgSoFAI4IPhBfrh12UQLZMsv 7Ka6VJo6R/4q1AZ543/M2d+PXMoyWIqr4vlM7xrMpLbmY0pg8h/MAF8D8I5c9jQnex5K ERIklWoKIqYYYXXbfSwvzPcy2/R9seDiqFsVZXXtpTrOIc06NVvx5GOqThMVL9/SipjU SDVw== X-Gm-Message-State: AJIora/VoxgtexoKXBcQV+wIO6IY/Bx/k8hYoT2B5h5bpLR+E+q2VKld DpbLzZw4BDjCQwVi+IQ4Dkg634cKA3mCvg== X-Google-Smtp-Source: AGRyM1tTC6UUkZIFqd7NZR6fpldiQQZwEaeDHDF1Z5r8e9TvsG49JVOS2DUPNoUskBTHH/FEBckYig== X-Received: by 2002:a5d:47aa:0:b0:21b:ad9a:d48c with SMTP id 10-20020a5d47aa000000b0021bad9ad48cmr17919069wrb.610.1656407235061; Tue, 28 Jun 2022 02:07:15 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id r68-20020a1c2b47000000b0039c4b518df4sm20126972wmr.5.2022.06.28.02.07.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 02:07:14 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Jun 2022 11:06:56 +0200 Message-Id: <20220628090656.19572-4-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628090656.19572-1-dse@thaumatec.com> References: <20220628090656.19572-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] libcamera: rkisp1: Control the lens 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" Check if lens are available and have ability to control the focus. Connect IPA setLensControls() signal to the pipeline slot that controls the lens. If lens are valid, allow changing the focus from IPA by emitting signal to the pipeline. Signed-off-by: Daniel Semkowicz --- include/libcamera/ipa/rkisp1.mojom | 1 + src/ipa/rkisp1/ipa_context.h | 4 +++ src/ipa/rkisp1/rkisp1.cpp | 36 ++++++++++++++++++++++++ src/libcamera/pipeline/rkisp1/rkisp1.cpp | 1 + 4 files changed, 42 insertions(+) diff --git a/include/libcamera/ipa/rkisp1.mojom b/include/libcamera/ipa/rkisp1.mojom index e3537385..ee06a6b0 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 f387cace..4b199048 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -41,6 +41,10 @@ struct IPASessionConfiguration { }; struct IPAFrameContext { + struct { + uint32_t focus; + } af; + struct { uint32_t exposure; double gain; diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 3511a054..2447f4f4 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -59,6 +60,8 @@ public: void processStatsBuffer(const uint32_t frame, const uint32_t bufferId, const ControlList &sensorControls) override; private: + bool validateLensControls(const ControlInfoMap &lensControls); + void setControls(unsigned int frame); void prepareMetadata(unsigned int frame, unsigned int aeState); @@ -66,6 +69,7 @@ private: std::map mappedBuffers_; ControlInfoMap sensorCtrls_; + std::optional lensCtrls_; /* Camera sensor controls. */ bool autoExposure_; @@ -162,6 +166,14 @@ int IPARkISP1::configure([[maybe_unused]] const IPACameraSensorInfo &info, return -EINVAL; } + auto lensControls = entityControls.find(1); + if (lensControls != entityControls.end()) { + if (validateLensControls(lensControls->second)) + lensCtrls_ = lensControls->second; + else + LOG(IPARkISP1, Error) << "Lens control validation failed."; + } + autoExposure_ = true; int32_t minExposure = itExp->second.min().get(); @@ -205,6 +217,23 @@ int IPARkISP1::configure([[maybe_unused]] const IPACameraSensorInfo &info, return 0; } +bool IPARkISP1::validateLensControls(const ControlInfoMap &lensControls) +{ + static const uint32_t ctrls[] = { + V4L2_CID_FOCUS_ABSOLUTE, + }; + + for (auto c : ctrls) { + if (lensControls.find(c) == lensControls.end()) { + LOG(IPARkISP1, Error) << "Unable to find lens control " + << utils::hex(c); + return false; + } + } + + return true; +} + void IPARkISP1::mapBuffers(const std::vector &buffers) { for (const IPABuffer &buffer : buffers) { @@ -289,6 +318,13 @@ void IPARkISP1::setControls(unsigned int frame) ctrls.set(V4L2_CID_ANALOGUE_GAIN, static_cast(gain)); setSensorControls.emit(frame, ctrls); + + if (lensCtrls_) { + ControlList lensCtrls(*lensCtrls_); + lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, + static_cast(context_.frameContext.af.focus)); + 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 363273b2..55d3e3a9 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -320,6 +320,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);