From patchwork Mon Jan 23 15:49:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18181 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 46839C3240 for ; Mon, 23 Jan 2023 15:49:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DD001625FD; Mon, 23 Jan 2023 16:49:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1674488998; 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=KsDn1b5dPj6qYLAbnZNPITj768/DVg+6Lpk7RFmOgMmwluyXpY1iQwhINpdnndIeY eS+kFNHgemVWf4ce5ohSmuuZ2y8rn90Zn1EXBjsKaFjXID1otrSm4G7ViyDCR600ic xFlGjZxgvXJxuc0neJFb/9BUIOJhLpu6lqOqp7qEiudJijgevuOelO7fhVI3oFrhvE tpgKPTUIhfAuZc0QUom7Pftc80SnIfU0gcD6/BKmQsbQ81I2wKYMDh8UCqZXnqGOAU 19rzOvYYiC+hrfXL0RshFfgiS+YwgPUZuDCnRBPzz3wfeeukdHLW2aBoo9Z25TWb1A KbpUtSigGoGCQ== Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DE269625DF for ; Mon, 23 Jan 2023 16:49:51 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="BFjas/Q1"; dkim-atps=neutral Received: by mail-wm1-x32e.google.com with SMTP id e19-20020a05600c439300b003db1cac0c1fso9438488wmn.5 for ; Mon, 23 Jan 2023 07:49:51 -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=BFjas/Q1X5Nujzb5YNgAYiusNy1sIIto8+cNU0z2yd810tQPUIA6QG4vr21P99epDg MhFIAPguwxon/A/PMiFVMzbbZyDKihPqZeg8YaSLGCIri5skDHNBaMnaWGWSZvFog9+E QvkFn4CUpue6rCPkJ/1g6TKyEYjtnHECt/12OhLCQGwKy/T0i/3wCFzCqP95alcP7QT3 2OmambJqjYS4O72rUbHMkfciIgfSG0qBxXauBu1W3UtnkiZIenQDjs0WmozSDL/bVH0q LYuttpArCCVCvn6XOWVhqRi/zjZqrt5pL6ykBoP4bd2ty2txPPnEaKtwOcPAH+JLwZ4w aIgA== 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=AIHOXnjHByOCiiDQ8uaPR/cuUsZzfzWHdWsxEL58lNPzg4FKOJwHg5OaZc/gVoqyYz xz+v9g5Ukf5LP3oRHuikZnIBeZgoNlsrLEkBrMnXfCmK4CcYevU5meodIuY+5On59DJ5 TuVZAiGpJlCSgIUg8+VKDMitTQZ/Mbm7DCS4Ahr9qrZaL3kffCuVuQ9abMduUcBsmbyT 8fQ3+UqUKH2XE0/xPCm85E1fQO6W0gdGe83A5g2D9w0/5lHMoFTJ0WXozEB5RKEuqY9t lWwVjluhuhP9mWfeF+4kXfDj2p9TBYKwn4oC0GH/zVE8ZnjnFCjDRMl7tFNyDxR4n/Ci 6UuA== X-Gm-Message-State: AFqh2kpb/AxSpYQ4RKz7lmOpM6CBcGE2k1YHZQKXnXYpcCYyBNP9T54P Z7crArL3NS8ig+QeWknA0wRPsAJwc9JU47EOpWw= X-Google-Smtp-Source: AMrXdXtTPTTi1+HP12Om3rgRbAf13JQZZXCATSXSKC+M40AFyVYT+FqUEJEkx60hhKYlRCt7W1f1IQ== X-Received: by 2002:a1c:7907:0:b0:3cf:a39f:eb2a with SMTP id l7-20020a1c7907000000b003cfa39feb2amr24066242wme.11.1674488991303; Mon, 23 Jan 2023 07:49:51 -0800 (PST) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id n16-20020a05600c181000b003d1de805de5sm10339689wmp.16.2023.01.23.07.49.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:49:50 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Jan 2023 15:49:26 +0000 Message-Id: <20230123154934.27803-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230123154934.27803-1-naush@raspberrypi.com> References: <20230123154934.27803-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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]; +};