From patchwork Sat Feb 29 16:42:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2937 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4F79A6277E for ; Sat, 29 Feb 2020 17:43:29 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D2C1433E; Sat, 29 Feb 2020 17:43:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1582994609; bh=/Jg+xdEQxOoTTB/rjIlYQHdW2FhGyFXTnbbRLgKG8RY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ICdFKCFfq2p6dith20r9WEmljfFn0AYboI1YIbXtlDl92zESlHlHyIVSeg9c6jVTx EgVBxdcEJFzBO+KknJJqFTX+LT6pell1F9LcC+E/t1vXIOeTXxrqV5L+Ip7Gi2zGf+ Ds3B1Rw+L6Mt+bqEmOi4yfxGOBQq/Q+nN0m+6t44= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 29 Feb 2020 18:42:43 +0200 Message-Id: <20200229164254.23604-21-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200229164254.23604-1-laurent.pinchart@ideasonboard.com> References: <20200229164254.23604-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 20/31] libcamera: controls: Add support for int8_t 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: , X-List-Received-Date: Sat, 29 Feb 2020 16:43:35 -0000 From: Jacopo Mondi Add support for 8 bit integers to the control framework and to the control serializer. Signed-off-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- include/libcamera/controls.h | 6 ++++++ src/libcamera/control_serializer.cpp | 12 ++++++++++++ src/libcamera/controls.cpp | 14 +++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 97a662e3f4a6..9b3aaae55c78 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -22,6 +22,7 @@ class ControlValidator; enum ControlType { ControlTypeNone, ControlTypeBool, + ControlTypeInteger8, ControlTypeInteger32, ControlTypeInteger64, ControlTypeFloat, @@ -43,6 +44,11 @@ struct control_type { static constexpr ControlType value = ControlTypeBool; }; +template<> +struct control_type { + static constexpr ControlType value = ControlTypeInteger8; +}; + template<> struct control_type { static constexpr ControlType value = ControlTypeInteger32; diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp index 5feaaa965cc5..5537c5466025 100644 --- a/src/libcamera/control_serializer.cpp +++ b/src/libcamera/control_serializer.cpp @@ -153,6 +153,12 @@ void ControlSerializer::store(const ControlValue &value, break; } + case ControlTypeInteger8: { + int8_t data = value.get(); + buffer.write(&data); + break; + } + case ControlTypeInteger32: { int32_t data = value.get(); buffer.write(&data); @@ -331,6 +337,12 @@ ControlValue ControlSerializer::load(ControlType type, return ControlValue(value); } + case ControlTypeInteger8: { + int8_t value; + b.read(&value); + return ControlValue(value); + } + case ControlTypeInteger32: { int32_t value; b.read(&value); diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 46469dd8b98b..9970d75ea684 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -53,6 +53,7 @@ namespace { static constexpr size_t ControlValueSize[] = { [ControlTypeNone] = 0, [ControlTypeBool] = sizeof(bool), + [ControlTypeInteger8] = sizeof(int8_t), [ControlTypeInteger32] = sizeof(int32_t), [ControlTypeInteger64] = sizeof(int64_t), [ControlTypeFloat] = sizeof(float), @@ -67,6 +68,8 @@ static constexpr size_t ControlValueSize[] = { * Invalid type, for empty values * \var ControlTypeBool * The control stores a boolean value + * \var ControlTypeInteger8 + * The control stores an 8-bit integer value * \var ControlTypeInteger32 * The control stores a 32-bit integer value * \var ControlTypeInteger64 @@ -202,6 +205,11 @@ std::string ControlValue::toString() const str += *value ? "True" : "False"; break; } + case ControlTypeInteger8: { + const int8_t *value = reinterpret_cast(data); + str += std::to_string(*value); + break; + } case ControlTypeInteger32: { const int32_t *value = reinterpret_cast(data); str += std::to_string(*value); @@ -386,9 +394,9 @@ void ControlValue::set(ControlType type, bool isArray, const void *data, * instead of Control. * * Controls of any type can be defined through template specialisation, but - * libcamera only supports the bool, int32_t, int64_t and float types natively - * (this includes types that are equivalent to the supported types, such as int - * and long int). + * libcamera only supports the bool, int8_t, int32_t, int64_t and float types + * natively (this includes types that are equivalent to the supported types, + * such as int and long int). * * Controls IDs shall be unique. While nothing prevents multiple instances of * the Control class to be created with the same ID for the same object, doing