From patchwork Tue Oct 5 04:37: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: 14042 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 556E1BDC71 for ; Tue, 5 Oct 2021 04:37:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A8B98691B6; Tue, 5 Oct 2021 06:37:33 +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="Q3YcqKy2"; 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 4F0126023D for ; Tue, 5 Oct 2021 06:37:32 +0200 (CEST) Received: by mail-pj1-x102b.google.com with SMTP id v19so13124905pjh.2 for ; Mon, 04 Oct 2021 21:37:32 -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:mime-version :content-transfer-encoding; bh=wm9CI0zTYdCP1fcomBHQZ5l/2I8oLhDLJiJKKnThUss=; b=Q3YcqKy2bAcE/0lI4Xa17M/mAEJ5hc+rfYf+xBboTWMKxCsmsQCHbKYa+H3XYaVOFb xIFtHtdidUOy8LxiVckC+CSZr2APynI4pJP6HZed7lUu2g+K85NNvyUCyVP4to3BSd0N f0rL9eiZLL6sKLqMnk6AlEvKGu8npIcNNSf4g= 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:mime-version :content-transfer-encoding; bh=wm9CI0zTYdCP1fcomBHQZ5l/2I8oLhDLJiJKKnThUss=; b=CXSrfb59FIifjrEXQa9VItfl0SCD3TG54rlppek2m6zUOFMgEXTW3A8ypL2faBvZRe wEnqeJ4/FPd37Tf+cqAPglr4NFSh5Qrl2bgd31Q6pDr5lSX8/6A3LaiR7L8t3Ev5d6mv jWVTKxlJOoC7cdzCOzEdO+DwRLC7mNd00e8LoueuKWHE7Kv2vorORuEjGVT/UGFeyHWu 3eZs8qxHRvhlnCKSUshOTm1fH98Kn7tySjwCnF2v86B07uTY8qVmKNLQ1DxEb0+2nAcP kkvo9A/eqRwnha3U0sVFZqXsz3IGYQqJBHUhV7fnx3sQXMN+eL/4mMvgQnxm0RA9+kz0 SAAQ== X-Gm-Message-State: AOAM5309bYTc9BeMs73VXz9gs6yvDSd6JTzO6rDBWpqlDl+1n8DDsmE8 MrSV6zJB0AmjO6uBOUNq9in83fh+j9c67Q== X-Google-Smtp-Source: ABdhPJxRUccZ94sblXCsfrZd0lLq+oJyRSr1ePjmAdL/aJXSz+7zpH+uQrIin66rMSaVUi6hYv+I5w== X-Received: by 2002:a17:902:8307:b0:13c:ac55:5e1d with SMTP id bd7-20020a170902830700b0013cac555e1dmr3274951plb.56.1633408649952; Mon, 04 Oct 2021 21:37:29 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:debc:d0db:3bd8:f961]) by smtp.gmail.com with ESMTPSA id r8sm15776115pgp.30.2021.10.04.21.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Oct 2021 21:37:29 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 5 Oct 2021 13:37:23 +0900 Message-Id: <20211005043723.568685-1-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] 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 --- 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 d25a1165..df35df74 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 9fdb8c09..25b8c626 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( @@ -531,6 +531,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