From patchwork Wed Dec 23 18:45:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10710 X-Patchwork-Delegate: jacopo@jmondi.org 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 5BD02C0F1A for ; Wed, 23 Dec 2020 18:45:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0415B61FF3; Wed, 23 Dec 2020 19:45:11 +0100 (CET) Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7926760527 for ; Wed, 23 Dec 2020 19:45:08 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 3CD2520004 for ; Wed, 23 Dec 2020 18:45:08 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Dec 2020 19:45:13 +0100 Message-Id: <20201223184516.58791-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201223184516.58791-1-jacopo@jmondi.org> References: <20201223184516.58791-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/5] libcamera: camera_sensor: Initialize controls 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" Initialize the ControlInfoMap of sensor available controls by reporting the sensor exposure time range. Signed-off-by: Jacopo Mondi --- include/libcamera/internal/camera_sensor.h | 2 ++ src/libcamera/camera_sensor.cpp | 42 +++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index aee10aa6e3c7..0357b2a630f7 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -71,6 +71,7 @@ private: int generateId(); int validateSensorDriver(); int initProperties(); + int initControls(); const MediaEntity *entity_; std::unique_ptr subdev_; @@ -85,6 +86,7 @@ private: std::vector sizes_; ControlList properties_; + ControlInfoMap controls_; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 3a65ac3de5bc..609f948c56a6 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include "libcamera/internal/bayer_format.h" @@ -215,7 +216,7 @@ int CameraSensor::init() if (ret) return ret; - return 0; + return initControls(); } int CameraSensor::validateSensorDriver() @@ -229,6 +230,7 @@ int CameraSensor::validateSensorDriver() const std::vector mandatoryControls{ V4L2_CID_PIXEL_RATE, V4L2_CID_HBLANK, + V4L2_CID_EXPOSURE, }; ControlList ctrls = subdev_->getControls(mandatoryControls); @@ -430,6 +432,44 @@ int CameraSensor::initProperties() return 0; } +int CameraSensor::initControls() +{ + const ControlInfoMap &v4l2Controls = subdev_->controls(); + + /* Exposure time limits expressed in micro-seconds. */ + + /* Calculate the line length in pixels. */ + ControlList ctrls = subdev_->getControls({ V4L2_CID_HBLANK }); + int32_t hblank = ctrls.get(V4L2_CID_HBLANK).get(); + V4L2SubdeviceFormat format{}; + int ret = subdev_->getFormat(pad_, &format); + if (ret) + return ret; + int32_t ppl = format.size.width + hblank; + + const ControlInfo &v4l2ExposureInfo = v4l2Controls.find(V4L2_CID_EXPOSURE)->second; + int32_t minExposurePixels = v4l2ExposureInfo.min().get() * ppl; + int32_t maxExposurePixels = v4l2ExposureInfo.max().get() * ppl; + int32_t defExposurePixels = v4l2ExposureInfo.max().get() * ppl; + + /* Get the pixel rate (in useconds) and calculate the exposure timings. */ + const ControlInfo &pixelRateInfo = v4l2Controls.find(V4L2_CID_PIXEL_RATE)->second; + float minPixelRate = pixelRateInfo.min().get() / 1e6f; + float maxPixelRate = pixelRateInfo.max().get() / 1e6f; + float defPixelRate = pixelRateInfo.def().get() / 1e6f; + + int32_t minExposure = static_cast(minExposurePixels / maxPixelRate); + int32_t maxExposure = static_cast(maxExposurePixels / minPixelRate); + int32_t defExposure = static_cast(defExposurePixels / defPixelRate); + + ControlInfoMap::Map map; + map[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure, + defExposure); + controls_ = std::move(map); + + return 0; +} + /** * \fn CameraSensor::model() * \brief Retrieve the sensor model name