From patchwork Thu Jan 19 10:45:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18154 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 4D458C3295 for ; Thu, 19 Jan 2023 10:46:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EAF63625EB; Thu, 19 Jan 2023 11:46:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1674125164; bh=eACv0BMC4sIml13m6Dl1ayBXch/Gz9qY634FpBRZK7g=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=kdFjSAO57S52MpbPLXd18ptYuSbq09Y1RZbcO1Vg5O9E97ndl4N+dTx8liY1YoCWo qYvIEHzveRSbPH7riUrCv88VysBYPJM7o0faVmqVC85clq3R/oe/udpEaz342vL73p FGmR4J2CQjMHVU5rwUgr9hUM+4Z4ym/rzqglZSdJsZFAgD21TzCMQq3bybLHRZet5z CsT8Y15/kPLkJWs3gE7ZHNlntHAivg+DqgaiQqs9OtyGu2FW/xDKwfgXY5crD6SNyT wN7yCe8UjxLYgj3yklu9RIeApxOrQYGgzzTrgZLS1R5o10+Xnn2ZU1kdW/WnyrRYZO Dna+jiY70L8MQ== Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 087DB625E6 for ; Thu, 19 Jan 2023 11:45:57 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Qg897WW1"; dkim-atps=neutral Received: by mail-wm1-x32b.google.com with SMTP id c4-20020a1c3504000000b003d9e2f72093so3268024wma.1 for ; Thu, 19 Jan 2023 02:45:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+XOYlVwonbW9GffEkAtSqcC2zDy9aGi8XiunyvhmLkE=; b=Qg897WW1xClBlcb0Q9Zb4V06hcmJSWEZ797DEVvJeOuaU+ZwiPBxicjo18DyauTlWF fSZdFOGwCw6abj/ka694V7YFBO434KvvzSioErVJaiJ7JViwVA135uIJ7KzuHhtBvU3J EGJjNdTHVdYm7Bjt+dp+6tj11ZpoeWHeY6gHs5pliigz1O38ehKWn0d751oOKfqjyO2E AB+TxLmGaJlB2+7fen62kMHekK2RygC3W90DDB4J1QIQhLV9IZda6HIqHMeBdJW6NwGi PaQs0g1LzxabBpyfoWQtd4+X36jHg+9F8uELYWQ1yLgDUTa1MhZG4+xsEgVsS3u9XGrl qCHw== 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 :subject:date:message-id:reply-to; bh=+XOYlVwonbW9GffEkAtSqcC2zDy9aGi8XiunyvhmLkE=; b=1YR/Lhk6iWNLIn01FQZOgwn0+pLdhY25/CsAPtaAml9Ed33L9SSvBDsiteM5DldLs8 t1cl09dWaHdhFIK9el8qTBu7tA9N8j9ndvYL4qnZnibhkQ54wQcO2mUiqO/fVYxB7v42 VmNVDsnrIvLSc/fupZVkzwOiHp1LVkH4YkaPh50gyG/0Md0SUnLlVWmSMyRmFmM3rpIa +JqUmK+myOA+wvpitxAt33NK7sX3HTgcxjbD7Wyf9OyJD22Kx3Dv7Ey6pYgsUDU6eUag SncyOLFNJf/fS8dvT+2vXy9wwu/QvPfa51MIW2PW+h5N3u7ZtwRBcn+1pmMt7VsJXOwX J7dw== X-Gm-Message-State: AFqh2krQ8fdad78dYNZ98ZrE0MNdiKBDs23+3Ts7fneywJUfctYPJUG0 tK8eeycqiDMrzM6jHUKeXwTXuTdF2ClIFEJWSdc= X-Google-Smtp-Source: AMrXdXu9MNOB2xcnYqlqnGl5WGIOIXpakmfgEdMXuv+ACoB0NVMve2LEuf9IGNhrMngHfgjado3tyQ== X-Received: by 2002:a05:600c:2056:b0:3db:ce8:6662 with SMTP id p22-20020a05600c205600b003db0ce86662mr7690807wmg.31.1674125155887; Thu, 19 Jan 2023 02:45:55 -0800 (PST) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id be12-20020a05600c1e8c00b003db06224953sm5332029wmb.41.2023.01.19.02.45.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jan 2023 02:45:55 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Jan 2023 10:45:36 +0000 Message-Id: <20230119104544.9456-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230119104544.9456-1-naush@raspberrypi.com> References: <20230119104544.9456-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 06/14] ipa: raspberrypi: Add autofocus algorithm interface headers 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: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Nick Hollinghurst Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Nick Hollinghurst Add a new AfAlgorithm class that defines the interface for the Raspberry Pi autofocus algorithm. Add an AfStatus structure that returns the results of the autofocus algorithm back to the IPA. Add a structure for PDAF statistics provided by supported sensors for use with an autofocus algorithm. This structure is currently based on the IMX708's PDAF "Type 1" statistics. Signed-off-by: Nick Hollinghurst Signed-off-by: Naushir Patuck Reviewed-by: Naushir Patuck Reviewed-by: David Plowman --- src/ipa/raspberrypi/controller/af_algorithm.h | 76 +++++++++++++++++++ src/ipa/raspberrypi/controller/af_status.h | 35 +++++++++ src/ipa/raspberrypi/controller/pdaf_data.h | 21 +++++ 3 files changed, 132 insertions(+) create mode 100644 src/ipa/raspberrypi/controller/af_algorithm.h create mode 100644 src/ipa/raspberrypi/controller/af_status.h create mode 100644 src/ipa/raspberrypi/controller/pdaf_data.h diff --git a/src/ipa/raspberrypi/controller/af_algorithm.h b/src/ipa/raspberrypi/controller/af_algorithm.h new file mode 100644 index 000000000000..ad9b575450e3 --- /dev/null +++ b/src/ipa/raspberrypi/controller/af_algorithm.h @@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022, Raspberry Pi Ltd + * + * af_algorithm.hpp - auto focus algorithm interface + */ +#pragma once + +#include + +#include + +#include "algorithm.h" + +namespace RPiController { + +class AfAlgorithm : public Algorithm +{ +public: + AfAlgorithm(Controller *controller) + : Algorithm(controller) {} + + /* + * An autofocus algorithm should provide the following calls. + * + * Where a ControlList combines a change of AfMode with other AF + * controls, setMode() should be called first, to ensure the + * algorithm will be in the correct state to handle controls. + * + * setLensPosition() returns true if the mode was AfModeManual and + * the lens position has changed, otherwise returns false. When it + * returns true, hwpos should be sent immediately to the lens driver. + * + * getMode() is provided mainly for validating controls. + * getLensPosition() is provided for populating DeviceStatus. + */ + + enum AfRange { AfRangeNormal = 0, + AfRangeMacro, + AfRangeFull, + AfRangeMax }; + + enum AfSpeed { AfSpeedNormal = 0, + AfSpeedFast, + AfSpeedMax }; + + enum AfMode { AfModeManual = 0, + AfModeAuto, + AfModeContinuous }; + + enum AfPause { AfPauseImmediate = 0, + AfPauseDeferred, + AfPauseResume }; + + virtual void setRange([[maybe_unused]] AfRange range) + { + } + virtual void setSpeed([[maybe_unused]] AfSpeed speed) + { + } + virtual void setMetering([[maybe_unused]] bool use_windows) + { + } + virtual void setWindows([[maybe_unused]] libcamera::Span const &wins) + { + } + virtual void setMode(AfMode mode) = 0; + virtual AfMode getMode() const = 0; + virtual bool setLensPosition(double dioptres, int32_t *hwpos) = 0; + virtual std::optional getLensPosition() const = 0; + virtual void triggerScan() = 0; + virtual void cancelScan() = 0; + virtual void pause(AfPause pause) = 0; +}; + +} // namespace RPiController diff --git a/src/ipa/raspberrypi/controller/af_status.h b/src/ipa/raspberrypi/controller/af_status.h new file mode 100644 index 000000000000..92c088126733 --- /dev/null +++ b/src/ipa/raspberrypi/controller/af_status.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022, Raspberry Pi Ltd + * + * af_status.h - AF control algorithm status + */ +#pragma once + +#include + +/* + * The AF algorithm should post the following structure into the image's + * "af.status" metadata. lensSetting should control the lens. + */ + +enum class AfState { + Idle = 0, + Scanning, + Focused, + Failed +}; + +enum class AfPauseState { + Running = 0, + Pausing, + Paused +}; + +struct AfStatus { + /* state for reporting */ + AfState state; + AfPauseState pauseState; + /* lensSetting should be sent to the lens driver, when valid */ + std::optional lensSetting; +}; diff --git a/src/ipa/raspberrypi/controller/pdaf_data.h b/src/ipa/raspberrypi/controller/pdaf_data.h new file mode 100644 index 000000000000..03c00d72c0e8 --- /dev/null +++ b/src/ipa/raspberrypi/controller/pdaf_data.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022, Raspberry Pi Ltd + * + * pdaf_data.h - PDAF Metadata; for now this is + * largely based on IMX708's PDAF "Type 1" output. + */ +#pragma once + +#include + +#define PDAF_DATA_ROWS 12 +#define PDAF_DATA_COLS 16 + +struct PdafData { + /* Confidence values, in raster order, in arbitrary units */ + uint16_t conf[PDAF_DATA_ROWS][PDAF_DATA_COLS]; + + /* Phase error, in raster order, in s11 Q4 format (S.6.4) */ + int16_t phase[PDAF_DATA_ROWS][PDAF_DATA_COLS]; +};