From patchwork Mon Jun 28 17:27:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12733 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 350D4C3220 for ; Mon, 28 Jun 2021 17:28:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E972C684D8; Mon, 28 Jun 2021 19:28:08 +0200 (CEST) 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="aUtZLc7S"; dkim-atps=neutral Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AF6EA684D4 for ; Mon, 28 Jun 2021 19:28:05 +0200 (CEST) Received: by mail-pj1-x1034.google.com with SMTP id x21-20020a17090aa395b029016e25313bfcso510772pjp.2 for ; Mon, 28 Jun 2021 10:28:05 -0700 (PDT) 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=ar9/+S5S66A5XGDuDYAJXnxakDrp0s2FQsZbl04X+dk=; b=aUtZLc7S7RiO4l79oIc9iORY2sLyMSYppe89jgnnGVOEsMScQ+pAsrOX2UiTYzhLHX AD3uuWVrTd1b1M3VFiI/SdGvKnn6+LTIbD/W6BnVx5LTftK/puPxeqF91IwEAjjiFZaG RQVFdBNVqaFLeo5l3X86FwF1c1Ib1rIPPekqc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ar9/+S5S66A5XGDuDYAJXnxakDrp0s2FQsZbl04X+dk=; b=Nx2yldOw6Pl30zt4L3yUzDvP7wwEtqyghHfHuNDpUVbNqasK4jXEWuZKaEhI2fFo1+ rqpo6DGVCtjpNrSl0VAg/T96aSiUOmaoLEkNMxg1oFMkdUYoou+FqrDmjFHOWD8j23Kx cDsbvf97nAOU8fN/S1rl/IzGLONfBBsQGpP6q1O3B9m78452YyDw00OpZgGO+ydMGAOJ kULMtzJHfOlS7+h+VUpbQ23c/1IN8THXtinYdJSQDgOM6Xwqf7URhiCRrO4KRYrfNNqc UmTy9a2MEk23cAT/FjCRBjt3X0ZKW3L8lYvn35S9f4nH7uglQMBS5GRmQYX/45XzkiFB 9/Sg== X-Gm-Message-State: AOAM532eR3KZ8NcdKFe5Me85+JaVSwcm5oPRDn47+MWWAMFNC4lmmI5b INfLJ7U8K0fIQjrgcMLRjLVlhb29gUfZ9w== X-Google-Smtp-Source: ABdhPJxZC0AR61RlscaJFHE1hT9J3oT3iNghdNKjgzlKIC8cNrl6Q7xvajo28HyuHJu5IOsKYR6YNg== X-Received: by 2002:a17:90a:17ad:: with SMTP id q42mr39528265pja.181.1624901284034; Mon, 28 Jun 2021 10:28:04 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:a147:1cb:e226:4ed9]) by smtp.gmail.com with ESMTPSA id d1sm4682358pju.16.2021.06.28.10.28.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 10:28:03 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Jun 2021 02:27:55 +0900 Message-Id: <20210628172755.3201441-2-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog In-Reply-To: <20210628172755.3201441-1-hiroh@chromium.org> References: <20210628172755.3201441-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/2] 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" Provides a function to set the camera sensor a test pattern mode. Signed-off-by: Hirokazu Honda --- include/libcamera/internal/camera_sensor.h | 5 +++ src/libcamera/camera_sensor.cpp | 46 +++++++++++++++++++--- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index db12b07e..0c3222ac 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -24,6 +24,7 @@ namespace libcamera { class BayerFormat; +struct CameraSensorProperties; class MediaEntity; class CameraSensor : protected Loggable @@ -44,6 +45,7 @@ public: { return testPatternModes_; } + int setTestPatternMode(int32_t testPatternMode); V4L2SubdeviceFormat getFormat(const std::vector &mbusCodes, const Size &size) const; @@ -78,6 +80,8 @@ private: std::unique_ptr subdev_; unsigned int pad_; + const CameraSensorProperties *props_; + std::string model_; std::string id_; @@ -85,6 +89,7 @@ private: std::vector mbusCodes_; std::vector sizes_; std::vector testPatternModes_; + int32_t testPatternMode_; Size pixelArraySize_; Rectangle activeArea_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index ee53adf3..a9cc95c7 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), testPatternMode_(-1), + bayerFormat_(nullptr), properties_(properties::properties) { } @@ -300,14 +300,14 @@ void CameraSensor::initVimcDefaultProperties() void CameraSensor::initStaticProperties() { - const CameraSensorProperties *props = CameraSensorProperties::get(model_); - if (!props) + props_ = CameraSensorProperties::get(model_); + if (!props_) return; /* Register the properties retrieved from the sensor database. */ - properties_.set(properties::UnitCellSize, props->unitCellSize); + properties_.set(properties::UnitCellSize, props_->unitCellSize); - initTestPatternModes(props->testPatternModes); + initTestPatternModes(props_->testPatternModes); } void CameraSensor::initTestPatternModes( @@ -515,6 +515,40 @@ Size CameraSensor::resolution() const * \return The list of test pattern modes */ +/** + * \brief Set the camera sensor a specified controls::TestPatternMode + * \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(int32_t testPatternMode) +{ + if (testPatternMode_ == testPatternMode) + return 0; + + if (!props_) + return -EINVAL; + + auto it = props_->testPatternModes.find(testPatternMode); + if (it == props_->testPatternModes.end()) { + LOG(CameraSensor, Error) << "Unsupported test pattern mode: " + << testPatternMode; + return -EINVAL; + } + + ControlList ctrls{ controls() }; + ctrls.set(V4L2_CID_TEST_PATTERN, it->second); + + 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