From patchwork Tue Jun 22 02:36:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12673 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 45BABC321B for ; Tue, 22 Jun 2021 02:37:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D83B26893F; Tue, 22 Jun 2021 04:37:05 +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="gGX0GNNG"; dkim-atps=neutral Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 74AC568932 for ; Tue, 22 Jun 2021 04:37:02 +0200 (CEST) Received: by mail-pg1-x536.google.com with SMTP id p9so1523320pgb.1 for ; Mon, 21 Jun 2021 19:37:02 -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=qC6xpyNnKBKxXei/YEgiG06a5xluSsOfyqqMgqQxzA4=; b=gGX0GNNGXYJEW2Vvp6PNDpCz2anucxcZlXV1UkzQUq1sBhibJP7BCS5TwqtkbCrp9T bdW4BVRoNXdjM6peQ77j6l93wen4FLQ8GO6c0NTHKSesHmJsqaK9EoIeRa+7zXBZuXjG NUigEo4EJzJ1S7FGg622Ou2eM1OSb4DBQ66G8= 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=qC6xpyNnKBKxXei/YEgiG06a5xluSsOfyqqMgqQxzA4=; b=M8mYp9fKtiH43596SxiI2Z3eui+OhAazn5ol6DQ7CymoNFiSJeCpqYEZN5UqRUtYXn QQk2USYZY5GT78Kl3YgTmBUkmY1k2v2cy++hIjj3GjEjkKHjhqO9+zsUJoweYgulXbk4 l7GoF5YAxouhrUjwKo0rpOeHs9fMZY1zdRCnYaCPxbVpMe6+UXB+18eVMYRmzIzkywmX S3JyrYUindJZ/4Xs2+Je1b/4wzwjMIK6EglZ792sLDyf04to4ykN10/nvG4mmomgOax8 DKtWgcANBBH+TgkyL8kbfNnM1WFMoLKRELvy0qttG1Pz8vjDVKVr/sK40KGkYUBs1rGX MnAg== X-Gm-Message-State: AOAM530xUdkgnlhUY8Ym3F/S+Nw+s4l02xWDq4wC6l2khKX8O+sJx/RY pmRj/56Z5CUmmDOiE0030eGbsLqlMbmZjQ== X-Google-Smtp-Source: ABdhPJybxfnGjF2To51FnmJWsO0qajYpr4PvWvY4cUAsNh/NayG6CagCTtVyaBeWKtDwKs9nMboUnA== X-Received: by 2002:a63:5445:: with SMTP id e5mr1513954pgm.62.1624329420960; Mon, 21 Jun 2021 19:37:00 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:a025:f98b:b63b:e6b2]) by smtp.gmail.com with ESMTPSA id o7sm18947145pgs.45.2021.06.21.19.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 19:37:00 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Jun 2021 11:36:51 +0900 Message-Id: <20210622023654.969162-2-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210622023654.969162-1-hiroh@chromium.org> References: <20210622023654.969162-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 2/5] 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 | 1 + src/libcamera/camera_sensor.cpp | 39 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index e133ebf4..8b9f84c9 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -43,6 +43,7 @@ public: { return testPatternModes_; } + int setTestPatternMode(uint8_t testPatternMode); V4L2SubdeviceFormat getFormat(const std::vector &mbusCodes, const Size &size) const; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 70bbd97a..ce8ff274 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -507,6 +507,45 @@ Size CameraSensor::resolution() const * \return The list of test pattern modes */ +/** + * \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) +{ + if (std::find(testPatternModes_.begin(), testPatternModes_.end(), + testPatternMode) == testPatternModes_.end()) { + LOG(CameraSensor, Error) << "Unsupported test pattern mode: " + << testPatternMode; + return -EINVAL; + } + + const CameraSensorProperties *props = CameraSensorProperties::get(model_); + if (!props) + return -EINVAL; + + auto it = props->testPatternModes.find(testPatternMode); + ASSERT(it != props->testPatternModes.end()); + 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 * \param[in] mbusCodes The list of acceptable media bus codes