From patchwork Wed Nov 10 07:22:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14510 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 9D735BF415 for ; Wed, 10 Nov 2021 07:22:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 546B460362; Wed, 10 Nov 2021 08:22:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Ct0yArhi"; dkim-atps=neutral Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EA27A60362 for ; Wed, 10 Nov 2021 08:22:18 +0100 (CET) Received: by mail-pl1-x633.google.com with SMTP id y1so2225955plk.10 for ; Tue, 09 Nov 2021 23:22:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OoDCjuxpFNiBepFgfoMLjFldIJiE4G+lwYGfxB/7O5c=; b=Ct0yArhinlKRAFmtRC1C/YLy1HEEFIscAWlrHCLLZrI40mHMAh/LSoT4Qn1/Ia1SZu ohRQfkNhAtvVX8MEdZCzcfpK6/gyWxaao55+d9IjYah2BgZFdnT+9pdpgPNeoFbArf3l YM6StjcbLStQnP79hJTMXF8jwXoY+vdutxBAY= 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=OoDCjuxpFNiBepFgfoMLjFldIJiE4G+lwYGfxB/7O5c=; b=tIGD0TJUW0OJF+CRW9YqTp6mSHHNscrPgN5IhBB6vvr6vkfLfqGeR8v5rjs5HMlgCk hGbEejc72gQIX/10MYuvtkXaaLMa+h36fZuL6b2RNif8eqfyidwRKixj4JIy6YqsaDNp GJYlM6r9faNiVfqvrr9I9yBIuV7wubBRSe5NFNL0NMRMriWrstzaOFkjO8GKKZqvUM0K TUfy/2xdl6IyHKIFnGiaH7QK3rvTanFmN6uU7V9GHZneqXjzx0tiy+a5KjDdqWgEs1En G9dwBA0gIcYjmv8nLyfJ6db9nwpt+djDZNfzeM4qMQmu4FRZZ4htpkVujegq4m3vp4E5 z7DQ== X-Gm-Message-State: AOAM530225DyKCfetD1a+rN/BoIvLdUMcicK0fktZ/Jnli/+8uug2odL VKurXiRl9Dg4Ct79nef7LO7cy2p+oz64Mw== X-Google-Smtp-Source: ABdhPJzybb1LJLaGyJzcbcLYkad6bbEVoglJJ0Llurq/hoawU/eGmdaQ0KMM0ggLdnDg/RoopQGzFw== X-Received: by 2002:a17:90a:e60b:: with SMTP id j11mr14304023pjy.52.1636528936969; Tue, 09 Nov 2021 23:22:16 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:4a73:e1bd:9b3f:4903]) by smtp.gmail.com with ESMTPSA id r1sm5073669pjm.23.2021.11.09.23.22.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 23:22:16 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 10 Nov 2021 16:22:06 +0900 Message-Id: <20211110072207.3273703-3-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog In-Reply-To: <20211110072207.3273703-1-hiroh@chromium.org> References: <20211110072207.3273703-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 3/4] libcamera: camera_sensor: Enable to set a test pattern mode 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This adds a function to set a camera sensor driver a test pattern mode. Signed-off-by: Hirokazu Honda Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/internal/camera_sensor.h | 8 +++ src/libcamera/camera_sensor.cpp | 64 +++++++++++++++++++--- src/libcamera/control_ids.yaml | 5 ++ 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index edef2220..60ce0c45 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -27,6 +27,9 @@ namespace libcamera { class BayerFormat; class MediaEntity; +class Request; + +struct CameraSensorProperties; class CameraSensor : protected Loggable { @@ -78,10 +81,14 @@ private: &testPatternModeMap); int initProperties(); + int setTestPatternMode(controls::draft::TestPatternModeEnum testPatternMode); + const MediaEntity *entity_; std::unique_ptr subdev_; unsigned int pad_; + const CameraSensorProperties *staticProps_; + std::string model_; std::string id_; @@ -89,6 +96,7 @@ private: std::vector mbusCodes_; std::vector sizes_; std::vector testPatternModes_; + controls::draft::TestPatternModeEnum testPatternMode_; Size pixelArraySize_; Rectangle activeArea_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index f0aa9f24..cfb9bc17 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -17,6 +17,7 @@ #include #include +#include #include @@ -54,8 +55,9 @@ LOG_DEFINE_CATEGORY(CameraSensor) * Once constructed the instance must be initialized with init(). */ CameraSensor::CameraSensor(const MediaEntity *entity) - : entity_(entity), pad_(UINT_MAX), bayerFormat_(nullptr), - properties_(properties::properties) + : entity_(entity), pad_(UINT_MAX), staticProps_(nullptr), + testPatternMode_(controls::draft::TestPatternModeUnset), + bayerFormat_(nullptr), properties_(properties::properties) { } @@ -161,6 +163,10 @@ int CameraSensor::init() if (ret) return ret; + ret = setTestPatternMode(controls::draft::TestPatternModeOff); + if (ret) + return ret; + return 0; } @@ -300,14 +306,14 @@ void CameraSensor::initVimcDefaultProperties() void CameraSensor::initStaticProperties() { - const CameraSensorProperties *props = CameraSensorProperties::get(model_); - if (!props) + staticProps_ = CameraSensorProperties::get(model_); + if (!staticProps_) return; /* Register the properties retrieved from the sensor database. */ - properties_.set(properties::UnitCellSize, props->unitCellSize); + properties_.set(properties::UnitCellSize, staticProps_->unitCellSize); - initTestPatternModes(props->testPatternModes); + initTestPatternModes(staticProps_->testPatternModes); } void CameraSensor::initTestPatternModes( @@ -315,7 +321,15 @@ void CameraSensor::initTestPatternModes( { const auto &v4l2TestPattern = controls().find(V4L2_CID_TEST_PATTERN); if (v4l2TestPattern == controls().end()) { - LOG(CameraSensor, Debug) << "No static test pattern map for \'" + LOG(CameraSensor, Debug) + << "V4L2_CID_TEST_PATTERN is not supported"; + return; + } + + if (testPatternModes.empty()) { + // The camera sensor supports test patterns but we don't know + // how to map them so this should be fixed. + LOG(CameraSensor, Error) << "No static test pattern map for \'" << model() << "\'"; return; } @@ -531,6 +545,42 @@ Size CameraSensor::resolution() const * \return The list of test pattern modes */ +/** + * \brief Set the test pattern mode for the camera sensor + * \param[in] testPatternMode Test pattern mode control value to set the camera + * sensor + * + * \return 0 on success or a negative error code otherwise + */ +int CameraSensor::setTestPatternMode(controls::draft::TestPatternModeEnum testPatternMode) +{ + if (testPatternMode_ == testPatternMode) + return 0; + + if (!staticProps_ || testPatternModes_.empty()) + return 0; + + auto it = std::find(testPatternModes_.begin(), testPatternModes_.end(), + testPatternMode); + if (it == testPatternModes_.end()) { + LOG(CameraSensor, Error) << "Unsupported test pattern mode " + << testPatternMode; + return -EINVAL; + } + + int32_t index = staticProps_->testPatternModes.at(testPatternMode); + ControlList ctrls{ controls() }; + ctrls.set(V4L2_CID_TEST_PATTERN, index); + + int ret = setControls(&ctrls); + if (ret) + return ret; + + testPatternMode_ = testPatternMode; + + return 0; +} + /** * \brief Retrieve the best sensor format for a desired output * \param[in] mbusCodes The list of acceptable media bus codes diff --git a/src/libcamera/control_ids.yaml b/src/libcamera/control_ids.yaml index 9d4638ae..083bac7b 100644 --- a/src/libcamera/control_ids.yaml +++ b/src/libcamera/control_ids.yaml @@ -639,6 +639,11 @@ controls: Control to select the test pattern mode. Currently identical to ANDROID_SENSOR_TEST_PATTERN_MODE. enum: + - name: TestPatternModeUnset + value: -1 + description: | + No test pattern is set. Returned frames by the camera device are + undefined. - name: TestPatternModeOff value: 0 description: |