From patchwork Mon Jun 13 14:28:52 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: 16218 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 6A0B4C327A for ; Mon, 13 Jun 2022 14:29:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E54FE65657; Mon, 13 Jun 2022 16:29:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655130551; bh=iWjADkK045MYS1Dm7UxHvu762oUHDwJbDtPi/pi8KmE=; 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=Qe+zXQBN/MFQvgju6b9BXwokkYvoH2lmGjO5qKhN4H136i9Gon3E5lk7mcFQ8CZRr Qb2Dv1bvK5bGtXSNYcAt3VxF7T5Pe64C43VngRUJ2BwStcxEvB0a9dRvsVEbEm4BqH fMq5Pf9T/gwA7EYLLc6PfpOi+6F0vJUjEJ/yDUZeiNRL3u3ZUYiBD+46hMZQDir7qZ Z4bvXj9VfULCfIXErGutvrLRwn3/+utclKTLf+6CpCqWaqQ0HH6ksnUJTVESNSnO1l RDVHTTEz3s6lj9RCgsSBln82T0yID+FvEvIzJvgqSCU6Zn/eqi/KWr/HsP7SrmVQrc g4t/kJVFcZSXQ== 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 E870465643 for ; Mon, 13 Jun 2022 16:29:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="csmdBXU+"; dkim-atps=neutral Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:a1c7:c28c:7720:9b30]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 97BDB440; Mon, 13 Jun 2022 16:29:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655130541; bh=iWjADkK045MYS1Dm7UxHvu762oUHDwJbDtPi/pi8KmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=csmdBXU+9pfhcUtIBzW7Hxi8wgadCaB2pOQ5YysGg4SQ6SfQu7I/afqL/wxuCeviv goZY/gGkvi7u1amCorlexKuMg43G8ZFJ8oObf7Hsnrl077z+FEjTHj9hIFK91aWX2W 2HNmnM/1OTuI0ebKQwQsCC+MKAt7j1GZnwYA1uYg= To: libcamera-devel@lists.libcamera.org Date: Mon, 13 Jun 2022 16:28:52 +0200 Message-Id: <20220613142853.98484-10-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220613142853.98484-1-jeanmichel.hautbois@ideasonboard.com> References: <20220613142853.98484-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 09/10] ipa: raspberrypi: Set a constrained range 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" Give the algorithm a way to have a constrained range for the lens. Add a default SetRange() call and implement it to set the low bound and high bound for the search. There is no functionnal change expected but gives the ability for the pipeline handler to set the range at runtime. Signed-off-by: Jean-Michel Hautbois --- .../raspberrypi/controller/af_algorithm.hpp | 2 ++ src/ipa/raspberrypi/controller/iob/af.cpp | 24 ++++++++++++++----- src/ipa/raspberrypi/controller/iob/af.h | 4 ++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/ipa/raspberrypi/controller/af_algorithm.hpp b/src/ipa/raspberrypi/controller/af_algorithm.hpp index 925b2d03..0008113b 100644 --- a/src/ipa/raspberrypi/controller/af_algorithm.hpp +++ b/src/ipa/raspberrypi/controller/af_algorithm.hpp @@ -28,6 +28,8 @@ public: virtual void SetWindows(const libcamera::Rectangle &afWindows) = 0; // set AF range virtual void SetRange(const uint32_t &range) = 0; + // set Lens Range + virtual void SetLensRange(const uint32_t &low, const uint32_t &high) = 0; // set AF speed virtual void setSpeed(const uint32_t &speed) = 0; }; diff --git a/src/ipa/raspberrypi/controller/iob/af.cpp b/src/ipa/raspberrypi/controller/iob/af.cpp index 1d9bc2bc..a10e1d0a 100644 --- a/src/ipa/raspberrypi/controller/iob/af.cpp +++ b/src/ipa/raspberrypi/controller/iob/af.cpp @@ -40,7 +40,7 @@ Af::Af(Controller *controller) : AfAlgorithm(controller), focus_(0), bestFocus_(0), currentContrast_(0.0), previousContrast_(0.0), maxContrast_(0.0), maxStep_(0), coarseCompleted_(false), fineCompleted_(false), - mode_(libcamera::controls::AfModeManual) + mode_(libcamera::controls::AfModeManual), lowStep_(0), highStep_(kMaxFocusSteps) { } @@ -90,6 +90,18 @@ void Af::SetRange([[maybe_unused]] const uint32_t &range) { } +void Af::SetLensRange(const uint32_t &low, const uint32_t &high) +{ + lowStep_ = low; + highStep_ = high; + + LOG(IoBAf, Debug) << "Lens range set between " << lowStep_ + << " and " << highStep_; + + focus_ = lowStep_; + maxStep_ = highStep_; +} + void Af::setSpeed([[maybe_unused]] const uint32_t &speed) { } @@ -118,7 +130,7 @@ void Af::afCoarseScan() status_.lensPosition = focus_; previousContrast_ = 0; maxStep_ = std::clamp(focus_ + static_cast((focus_ * kFineRange)), - 0U, kMaxFocusSteps); + 0U, highStep_); } } @@ -136,7 +148,7 @@ void Af::afFineScan() bool Af::afScan(uint32_t minSteps) { - if (focus_ > maxStep_) { + if (focus_ + minSteps > maxStep_) { /* If the max step is reached, move lens to the position. */ status_.lensPosition = bestFocus_; return true; @@ -180,13 +192,13 @@ bool Af::afScan(uint32_t minSteps) void Af::afReset() { LOG(IoBAf, Debug) << "Reset AF parameters"; - status_.lensPosition = 0; - focus_ = 0; + status_.lensPosition = lowStep_; + focus_ = lowStep_; + maxStep_ = highStep_; status_.state = libcamera::controls::AfStateScanning; previousContrast_ = 0.0; coarseCompleted_ = false; fineCompleted_ = false; - maxStep_ = kMaxFocusSteps; maxContrast_ = 0.0; } diff --git a/src/ipa/raspberrypi/controller/iob/af.h b/src/ipa/raspberrypi/controller/iob/af.h index 12d7bbbd..52b9c37d 100644 --- a/src/ipa/raspberrypi/controller/iob/af.h +++ b/src/ipa/raspberrypi/controller/iob/af.h @@ -29,6 +29,7 @@ public: void Pause(const uint32_t &pause) override; void SetWindows(const libcamera::Rectangle &afWindows) override; void SetRange(const uint32_t &range) override; + void SetLensRange(const uint32_t &low, const uint32_t &high) override; void setSpeed(const uint32_t &speed) override; private: bool afNeedIgnoreFrame(); @@ -58,6 +59,9 @@ private: bool fineCompleted_; uint32_t mode_; + + uint32_t lowStep_; + uint32_t highStep_; }; } /* namespace RPiController */