From patchwork Mon Jun 10 16:40:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1387 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 45ACE635E2 for ; Mon, 10 Jun 2019 18:39:49 +0200 (CEST) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id D79DB240007; Mon, 10 Jun 2019 16:39:48 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 10 Jun 2019 18:40:52 +0200 Message-Id: <20190610164052.30741-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190610164052.30741-1-jacopo@jmondi.org> References: <20190610164052.30741-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 6/6] [HACK] ipu3: Set and get a few sensor controls X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Jun 2019 16:39:49 -0000 Not to merge patch to demonstrate how to set controls on the image sensor device. Not-Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/ipu3.cpp | 80 ++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index b3e7fb0e9c64..59c1fe3c56fd 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -688,6 +688,86 @@ int PipelineHandlerIPU3::start(Camera *camera) ImgUDevice *imgu = data->imgu_; int ret; + /* --- Get control values --- */ + std::vector controlIds = { + V4L2_CID_EXPOSURE, V4L2_CID_ANALOGUE_GAIN, + }; + V4L2Controls controls; + ret = cio2->sensor_->dev()->getControls(controlIds, &controls); + if (ret) { + LOG(Error) << "Failed to get control values"; + return -EINVAL; + } + + for (V4L2Control *ctrl : controls) { + unsigned int id = ctrl->id(); + + switch(ctrl->type()) { + case V4L2_CTRL_TYPE_INTEGER: + case V4L2_CTRL_TYPE_BOOLEAN: + { + uint32_t val = controls.getInt(id); + LOG(Error) << "Control : " << id + << " - value: " << val; + } + break; + case V4L2_CTRL_TYPE_INTEGER64: + { + uint64_t val = controls.getInt64(id); + LOG(Error) << "Control : " << id + << " - value: " << val; + } + break; + default: + LOG(Error) << "Unsupported type: " << ctrl->type(); + return -EINVAL; + } + } + + /* --- Set control values --- */ + V4L2Controls setControls; + setControls.set(V4L2_CID_EXPOSURE, 2046); + setControls.set(V4L2_CID_ANALOGUE_GAIN, 1024); + + ret = cio2->sensor_->dev()->setControls(setControls); + if (ret) { + LOG(IPU3, Error) << "Failed to set controls"; + return ret; + } + + /* --- Get control values back again and verify they have changed --- */ + V4L2Controls newcontrols; + ret = cio2->sensor_->dev()->getControls(controlIds, &newcontrols); + if (ret) { + LOG(Error) << "Failed to get control values"; + return -EINVAL; + } + + for (V4L2Control *ctrl : newcontrols) { + unsigned int id = ctrl->id(); + + switch(ctrl->type()) { + case V4L2_CTRL_TYPE_INTEGER: + case V4L2_CTRL_TYPE_BOOLEAN: + { + uint32_t val = newcontrols.getInt(id); + LOG(Error) << "Control : " << id + << " - value: " << val; + } + break; + case V4L2_CTRL_TYPE_INTEGER64: + { + uint64_t val = newcontrols.getInt64(id); + LOG(Error) << "Control : " << id + << " - value: " << val; + } + break; + default: + LOG(Error) << "Unsupported type: " << ctrl->type(); + return -EINVAL; + } + } + /* * Start the ImgU video devices, buffers will be queued to the * ImgU output and viewfinder when requests will be queued.