From patchwork Fri Jun 11 08:42:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12564 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 C4FEEC320B for ; Fri, 11 Jun 2021 08:42:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 81BD66892F; Fri, 11 Jun 2021 10:42:41 +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="hTAbdKRL"; dkim-atps=neutral Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 60B3F6029E for ; Fri, 11 Jun 2021 10:42:37 +0200 (CEST) Received: by mail-pl1-x62d.google.com with SMTP id x19so2496447pln.2 for ; Fri, 11 Jun 2021 01:42:37 -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=U9OEYzue8vc7okX16AMlQ3ov9LGscixMDny6HO81ri8=; b=hTAbdKRLoJLlyofT1c8sN9PB/sLMdGVyZkzez3hRxWMTuGHN4xlmo6BZmR2fyhm/Ma AErpI4jzY6aN/mLsY+VK2nkFgsrmNK+1mQocaIsGnfJufFGWaj5tx8IQWUvpXRglSAZ0 igzue8e7lh4MoraJr3U5TMptuyhmaJvFHVpCM= 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=U9OEYzue8vc7okX16AMlQ3ov9LGscixMDny6HO81ri8=; b=pHl9oRRxMcBeU8e39ZJuAWr5lcGgtMfP9is3+iaNDoU3TFVazOeH6Q0XMTAMeZdJBI E1ubXJP4H+jsQfRFLM5wUvpqaYcagnb/eTeKPFtpH42kUMS24SzA+Q8rjXWZDc8hsXic EojIS+Io/JFQ6U+2qJdxdYciNOgQ6Fb8F+7tNUIQ+l1tmQFjfqLdQzJk2mBf7dh1dvFt /Oyc5+k+mNG5hW6CG3EqsQymZNTl4DAMczD+Je/n2DFcpCORYFpEt/ituA7L3O6mkrie cHUo7Fsp29x/gwaptEqlYMlmNurCAH3FuQGS6l7nETBruj/L7To6OzZkvSQKMpU6+nwq kvow== X-Gm-Message-State: AOAM532r0DWUMzLpZXcKGHpG5wvFMPjIjvqE+8RrXcSxP6a1x12yQ6jD o6NBFE6nvBuYaQs9mTwu1GlZnE7pyUgc8g== X-Google-Smtp-Source: ABdhPJy/yjLigY+VDO4eSDoxzNI28JKgOiWcniM3Azy87tYrd/uW0OVFDbWmbdKcOUTyUaQi0HK/Iw== X-Received: by 2002:a17:90a:c384:: with SMTP id h4mr3445070pjt.134.1623400955870; Fri, 11 Jun 2021 01:42:35 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:367e:c2e4:d691:eca1]) by smtp.gmail.com with ESMTPSA id 20sm4323542pfi.170.2021.06.11.01.42.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 01:42:35 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 11 Jun 2021 17:42:25 +0900 Message-Id: <20210611084228.1830629-2-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210611084228.1830629-1-hiroh@chromium.org> References: <20210611084228.1830629-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 1/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" Provides a function to set the camera sensor a test pattern mode. Signed-off-by: Hirokazu Honda --- include/libcamera/internal/camera_sensor.h | 7 ++-- src/libcamera/camera_sensor.cpp | 40 ++++++++++++++++++++-- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index e133ebf4..834d3246 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -39,10 +39,8 @@ public: const std::vector &mbusCodes() const { return mbusCodes_; } const std::vector &sizes() const { return sizes_; } Size resolution() const; - const std::vector &testPatternModes() const - { - return testPatternModes_; - } + std::vector testPatternModes() const; + int setTestPatternMode(uint8_t testPatternMode); V4L2SubdeviceFormat getFormat(const std::vector &mbusCodes, const Size &size) const; @@ -84,6 +82,7 @@ private: std::vector mbusCodes_; std::vector sizes_; std::vector testPatternModes_; + std::map testPatternModeToIndex_; Size pixelArraySize_; Rectangle activeArea_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 3e135353..d2f033a5 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -329,7 +329,7 @@ void CameraSensor::initTestPatternModes( continue; } - testPatternModes_.push_back(it->second); + testPatternModeToIndex_[it->second] = index; } } @@ -496,12 +496,48 @@ Size CameraSensor::resolution() const } /** - * \fn CameraSensor::testPatternModes() * \brief Retrieve all the supported test pattern modes of the camera sensor * The test pattern mode values correspond to the controls::TestPattern control. * * \return The list of test pattern modes */ +std::vector CameraSensor::testPatternModes() const +{ + return utils::map_keys(testPatternModeToIndex_); +} + +/** + * \brief Set the camera sensor a specified controls::TestPatternMode + * + * \return 0 on success or a negative error code otherwise + */ +int CameraSensor::setTestPatternMode(uint8_t testPatternMode) +{ + auto it = testPatternModeToIndex_.find(testPatternMode); + if (it == testPatternModeToIndex_.end()) { + LOG(CameraSensor, Error) << "Unsupported test pattern mode: " + << testPatternMode; + return -EINVAL; + } + + const uint8_t index = it->second; + + ControlList ctrls = getControls({ V4L2_CID_TEST_PATTERN }); + if (ctrls.empty()) { + LOG(CameraSensor, Error) + << "Failed to retrieve test pattern control"; + return -EINVAL; + } + + ControlValue value = ctrls.get(V4L2_CID_TEST_PATTERN); + if (value.get() == index) + return 0; + + value.set(index); + ctrls.set(V4L2_CID_TEST_PATTERN, value); + + return setControls(&ctrls); +} /** * \brief Retrieve the best sensor format for a desired output