{"id":10710,"url":"https://patchwork.libcamera.org/api/patches/10710/?format=json","web_url":"https://patchwork.libcamera.org/patch/10710/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20201223184516.58791-3-jacopo@jmondi.org>","date":"2020-12-23T18:45:13","name":"[libcamera-devel,2/5] libcamera: camera_sensor: Initialize controls","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"66707130a66387bed1597271808dd519ebfeed63","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":{"id":15,"url":"https://patchwork.libcamera.org/api/users/15/?format=json","username":"jmondi","first_name":"Jacopo","last_name":"Mondi","email":"jacopo@jmondi.org"},"mbox":"https://patchwork.libcamera.org/patch/10710/mbox/","series":[{"id":1545,"url":"https://patchwork.libcamera.org/api/series/1545/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1545","date":"2020-12-23T18:45:11","name":"libcamera: Register CameraSensor controls","version":1,"mbox":"https://patchwork.libcamera.org/series/1545/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/10710/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10710/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 5BD02C0F1A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 23 Dec 2020 18:45:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0415B61FF3;\n\tWed, 23 Dec 2020 19:45:11 +0100 (CET)","from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net\n\t[217.70.183.200])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7926760527\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 23 Dec 2020 19:45:08 +0100 (CET)","from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 3CD2520004\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 23 Dec 2020 18:45:08 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","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\n\tcontrols","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Initialize the ControlInfoMap of sensor available controls by\nreporting the sensor exposure time range.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/internal/camera_sensor.h |  2 ++\n src/libcamera/camera_sensor.cpp            | 42 +++++++++++++++++++++-\n 2 files changed, 43 insertions(+), 1 deletion(-)","diff":"diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\nindex aee10aa6e3c7..0357b2a630f7 100644\n--- a/include/libcamera/internal/camera_sensor.h\n+++ b/include/libcamera/internal/camera_sensor.h\n@@ -71,6 +71,7 @@ private:\n \tint generateId();\n \tint validateSensorDriver();\n \tint initProperties();\n+\tint initControls();\n \n \tconst MediaEntity *entity_;\n \tstd::unique_ptr<V4L2Subdevice> subdev_;\n@@ -85,6 +86,7 @@ private:\n \tstd::vector<Size> sizes_;\n \n \tControlList properties_;\n+\tControlInfoMap controls_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex 3a65ac3de5bc..609f948c56a6 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -15,6 +15,7 @@\n #include <regex>\n #include <string.h>\n \n+#include <libcamera/control_ids.h>\n #include <libcamera/property_ids.h>\n \n #include \"libcamera/internal/bayer_format.h\"\n@@ -215,7 +216,7 @@ int CameraSensor::init()\n \tif (ret)\n \t\treturn ret;\n \n-\treturn 0;\n+\treturn initControls();\n }\n \n int CameraSensor::validateSensorDriver()\n@@ -229,6 +230,7 @@ int CameraSensor::validateSensorDriver()\n \tconst std::vector<uint32_t> mandatoryControls{\n \t\tV4L2_CID_PIXEL_RATE,\n \t\tV4L2_CID_HBLANK,\n+\t\tV4L2_CID_EXPOSURE,\n \t};\n \n \tControlList ctrls = subdev_->getControls(mandatoryControls);\n@@ -430,6 +432,44 @@ int CameraSensor::initProperties()\n \treturn 0;\n }\n \n+int CameraSensor::initControls()\n+{\n+\tconst ControlInfoMap &v4l2Controls = subdev_->controls();\n+\n+\t/* Exposure time limits expressed in micro-seconds. */\n+\n+\t/* Calculate the line length in pixels. */\n+\tControlList ctrls = subdev_->getControls({ V4L2_CID_HBLANK });\n+\tint32_t hblank = ctrls.get(V4L2_CID_HBLANK).get<int32_t>();\n+\tV4L2SubdeviceFormat format{};\n+\tint ret = subdev_->getFormat(pad_, &format);\n+\tif (ret)\n+\t\treturn ret;\n+\tint32_t ppl = format.size.width + hblank;\n+\n+\tconst ControlInfo &v4l2ExposureInfo = v4l2Controls.find(V4L2_CID_EXPOSURE)->second;\n+\tint32_t minExposurePixels = v4l2ExposureInfo.min().get<int32_t>() * ppl;\n+\tint32_t maxExposurePixels = v4l2ExposureInfo.max().get<int32_t>() * ppl;\n+\tint32_t defExposurePixels = v4l2ExposureInfo.max().get<int32_t>() * ppl;\n+\n+\t/* Get the pixel rate (in useconds) and calculate the exposure timings. */\n+\tconst ControlInfo &pixelRateInfo = v4l2Controls.find(V4L2_CID_PIXEL_RATE)->second;\n+\tfloat minPixelRate = pixelRateInfo.min().get<int64_t>() / 1e6f;\n+\tfloat maxPixelRate = pixelRateInfo.max().get<int64_t>() / 1e6f;\n+\tfloat defPixelRate = pixelRateInfo.def().get<int64_t>() / 1e6f;\n+\n+\tint32_t minExposure = static_cast<int32_t>(minExposurePixels / maxPixelRate);\n+\tint32_t maxExposure = static_cast<int32_t>(maxExposurePixels / minPixelRate);\n+\tint32_t defExposure = static_cast<int32_t>(defExposurePixels / defPixelRate);\n+\n+\tControlInfoMap::Map map;\n+\tmap[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure,\n+\t\t\t\t\t\t   defExposure);\n+\tcontrols_ = std::move(map);\n+\n+\treturn 0;\n+}\n+\n /**\n  * \\fn CameraSensor::model()\n  * \\brief Retrieve the sensor model name\n","prefixes":["libcamera-devel","2/5"]}