From patchwork Thu Jun 20 15:31:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1487 Return-Path: Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D7E7060BA1 for ; Thu, 20 Jun 2019 17:30:42 +0200 (CEST) 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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 5C4A2240005; Thu, 20 Jun 2019 15:30:42 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 20 Jun 2019 17:31:42 +0200 Message-Id: <20190620153144.5394-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190620153144.5394-1-jacopo@jmondi.org> References: <20190620153144.5394-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 4/6] libcamera: camera_sensor: Add V4L2 control operations 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: Thu, 20 Jun 2019 15:30:43 -0000 Add operations to get and set control and to retrieve the informations on a V4L2 control. For simple camera sensors, the operations are directly called on the underlying V4L2 subdevice. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/camera_sensor.cpp | 65 +++++++++++++++++++++++++++ src/libcamera/include/camera_sensor.h | 6 +++ 2 files changed, 71 insertions(+) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index a804a68c9d91..637f86b05701 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -247,6 +247,71 @@ int CameraSensor::setFormat(V4L2SubdeviceFormat *format) return subdev_->setFormat(0, format); } +/** + * \brief Retrieve information about a control + * \param[in] id The control ID + * \return A pointer to the V4L2ControlInfo for control \a id, or nullptr + * if the sensor doesn't have such a control + */ +const V4L2ControlInfo *CameraSensor::getControlInfo(unsigned int id) const +{ + return subdev_->getControlInfo(id); +} + +/** + * \brief Read controls from the sensor + * \param[inout] ctrls The list of controls to read + * + * Read the value of each control contained in \a ctrls, and store the + * value in the corresponding \a ctrls entry. + * + * If an integer number less than the requested number of controls is returned, + * only controls up to that index have been successfully read. + * + * Each V4L2Control instance in \a ctrls should be supported by the sensor and + * accessible (ie the V4L2_CTRL_FLAG_DISABLED flag should not be set), otherwise + * a negative error code (-EINVAL) is returned + * + * \sa V4L2Device::getControls() + * + * \return 0 on success or an error code otherwise + * \retval -EINVAL One of the control is not supported or not accessible + * \retval i The index of the control that failed + */ +int CameraSensor::getControls(V4L2Controls *ctrls) +{ + return subdev_->getControls(ctrls); +} + +/** + * \brief Write controls to the sensor + * \param[in] ctrls The list of controls to write + * + * Write the value of each V4L2Control contained in \a ctrls. Each + * control should be initialized by the caller with a value, otherwise + * the result of the operation is undefined. + * + * The value of each control is updated to reflect what has been + * actually applied on the sensor. + * + * If an integer number less than the requested number of controls is returned, + * only controls up to that index have been successfully applied. + * + * Each V4L2Control instance in \a ctrls should be supported by the sensor and + * accessible (ie the V4L2_CTRL_FLAG_DISABLED flag should not be set), otherwise + * a negative error code (-EINVAL) is returned + * + * \sa V4L2Device::setControls() + * + * \return 0 on success or an error code otherwise + * \retval -EINVAL One of the control is not supported or not accessible + * \retval i The index of the control that failed + */ +int CameraSensor::setControls(V4L2Controls *ctrls) +{ + return subdev_->setControls(ctrls); +} + std::string CameraSensor::logPrefix() const { return "'" + subdev_->entity()->name() + "'"; diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h index b823480241a7..b4f4b66e96c4 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -17,6 +17,8 @@ namespace libcamera { class MediaEntity; +class V4L2ControlInfo; +class V4L2Controls; class V4L2Subdevice; struct V4L2SubdeviceFormat; @@ -41,6 +43,10 @@ public: const Size &size) const; int setFormat(V4L2SubdeviceFormat *format); + const V4L2ControlInfo *getControlInfo(unsigned int id) const; + int getControls(V4L2Controls *ctrls); + int setControls(V4L2Controls *ctrls); + protected: std::string logPrefix() const;