From patchwork Mon Nov 29 08:34:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14834 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 725D4BF415 for ; Mon, 29 Nov 2021 08:34:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2E2FD60591; Mon, 29 Nov 2021 09:34:37 +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="M1oj65CE"; dkim-atps=neutral Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AB85E6057B for ; Mon, 29 Nov 2021 09:34:34 +0100 (CET) Received: by mail-pj1-x102b.google.com with SMTP id o6-20020a17090a0a0600b001a64b9a11aeso13507415pjo.3 for ; Mon, 29 Nov 2021 00:34:34 -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=XAfRIBSKo/Bk8R1ApMY0exYkZxGpkOH4t0UZkz0KP+c=; b=M1oj65CEOlSivSn5I4MxGoD+Vb6JJSPXx4jjwd5XUXWI15oi/GhE1+WooDkU1+dhN7 nQIObBw7RtGJeYd6oKglrxnwf9WzPgcQSDaI+6cj8GSIn6sS0dfZ4Sa4sscPILoOGygt MXrIJH8nsMzMrVzRWmuWEeGwYKWIL2tkF3xLQ= 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=XAfRIBSKo/Bk8R1ApMY0exYkZxGpkOH4t0UZkz0KP+c=; b=lkvCtZPlvdD8Dzc7UzfbmuiZbOt5MtBGlm5tFfbe+TaWOjz1uMSXoqHEpZdlhUbzwv dg/yW9JCDv7ZKPFD8wrXWVJIxwmOZdxBUL5p0w047NqDmSui8cPtWLkzOrBQYmgoHX3F f36oH5cIfHMiT0R9XQKVwen/bkaTlHAAGVa1Fmo5UFYGYIxlLrILBWmIMNimOkx/pEwx 81J53EeEn/pwSf++8P2Kmq8kn0izMQNEa4/Si0G23IZ2xyJM+xIiLk00a/mHnzqi5FWc o76InVfTnlFGaKdcsRtSISTxh1Zug/hh5sBXclk+3V6r8Olgsw8vYax6rualyK0UstNI KV2g== X-Gm-Message-State: AOAM532d8My+ZoyMkg/LPyFgYBBESUL4fzJTGYH7ubKtcNrNCez3/n4N sh+XAIQ20ZB8tbRakwO9wxJuUwHZQS4Fpw== X-Google-Smtp-Source: ABdhPJwyws4ogkQ9UyfDj4sPVv8lWj93rHn1lbhEudNrTbRdSFrE5A4Yy3MO5zLnFRVXixb2+VwoOg== X-Received: by 2002:a17:90a:72c4:: with SMTP id l4mr36561670pjk.149.1638174872814; Mon, 29 Nov 2021 00:34:32 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:f254:cda9:46e8:17b7]) by smtp.gmail.com with ESMTPSA id y7sm11245948pge.44.2021.11.29.00.34.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 00:34:32 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Nov 2021 17:34:23 +0900 Message-Id: <20211129083424.3136533-2-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211129083424.3136533-1-hiroh@chromium.org> References: <20211129083424.3136533-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v9 2/3] 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. CameraSensor initializes the test pattern mode by Off. Signed-off-by: Hirokazu Honda Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- include/libcamera/internal/camera_sensor.h | 11 ++- src/libcamera/camera_sensor.cpp | 82 +++++++++++++++++++--- 2 files changed, 80 insertions(+), 13 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 310571ca..3362eaff 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -28,6 +28,8 @@ namespace libcamera { class BayerFormat; class MediaEntity; +struct CameraSensorProperties; + class CameraSensor : protected Loggable { public: @@ -47,6 +49,7 @@ public: { return testPatternModes_; } + int setTestPatternMode(controls::draft::TestPatternModeEnum testPatternMode); V4L2SubdeviceFormat getFormat(const std::vector &mbusCodes, const Size &size) const; @@ -73,15 +76,16 @@ private: int validateSensorDriver(); void initVimcDefaultProperties(); void initStaticProperties(); - void initTestPatternModes( - const std::map - &testPatternModeMap); + void initTestPatternModes(); int initProperties(); + int initTestPatternMode(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 +93,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..8a79b970 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -54,8 +54,8 @@ 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), + bayerFormat_(nullptr), properties_(properties::properties) { } @@ -161,7 +161,7 @@ int CameraSensor::init() if (ret) return ret; - return 0; + return initTestPatternMode(controls::draft::TestPatternModeEnum::TestPatternModeOff); } int CameraSensor::validateSensorDriver() @@ -300,22 +300,33 @@ 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(); } -void CameraSensor::initTestPatternModes( - const std::map &testPatternModes) +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; + } + + ASSERT(staticProps_); + const auto &testPatternModes = staticProps_->testPatternModes; + 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 +542,57 @@ Size CameraSensor::resolution() const * \return The list of test pattern modes */ +/** + * \brief Set the test pattern mode for the camera sensor if it is not the + * currently set test pattern mode. + * \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; + + return initTestPatternMode(testPatternMode); +} + +/** + * \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::initTestPatternMode(controls::draft::TestPatternModeEnum testPatternMode) +{ + 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; + } + + LOG(CameraSensor, Debug) << "Apply test pattern mode: " << testPatternMode; + + 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