summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2020-02-26 10:38:38 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-03-06 18:10:37 +0200
commit97cba0ebea6e553065f77f18471b3a5997c390d4 (patch)
tree5ae59ca67d9a86dae7cea6620b6baee200db0c7e
parent8b12a161e0280c086dfc037570ab8aee4c16bdaf (diff)
libcamera: controls: Add support for byte controls
Add support for byte values to the control framework and to the control serializer. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
-rw-r--r--include/libcamera/controls.h6
-rw-r--r--src/libcamera/control_serializer.cpp12
-rw-r--r--src/libcamera/controls.cpp14
3 files changed, 29 insertions, 3 deletions
diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 0ad442b9..4767e2d3 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -22,6 +22,7 @@ class ControlValidator;
enum ControlType {
ControlTypeNone,
ControlTypeBool,
+ ControlTypeByte,
ControlTypeInteger32,
ControlTypeInteger64,
ControlTypeFloat,
@@ -44,6 +45,11 @@ struct control_type<bool> {
};
template<>
+struct control_type<uint8_t> {
+ static constexpr ControlType value = ControlTypeByte;
+};
+
+template<>
struct control_type<int32_t> {
static constexpr ControlType value = ControlTypeInteger32;
};
diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp
index 5feaaa96..6c676811 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 ControlTypeByte: {
+ uint8_t data = value.get<uint8_t>();
+ buffer.write(&data);
+ break;
+ }
+
case ControlTypeInteger32: {
int32_t data = value.get<int32_t>();
buffer.write(&data);
@@ -331,6 +337,12 @@ ControlValue ControlSerializer::load<ControlValue>(ControlType type,
return ControlValue(value);
}
+ case ControlTypeByte: {
+ uint8_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 d095efd4..0663a220 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),
+ [ControlTypeByte] = sizeof(uint8_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 ControlTypeByte
+ * The control stores a byte value as an unsigned 8-bit integer
* \var ControlTypeInteger32
* The control stores a 32-bit integer value
* \var ControlTypeInteger64
@@ -198,6 +201,11 @@ std::string ControlValue::toString() const
str += *value ? "True" : "False";
break;
}
+ case ControlTypeByte: {
+ const uint8_t *value = reinterpret_cast<const uint8_t *>(data);
+ str += std::to_string(*value);
+ break;
+ }
case ControlTypeInteger32: {
const int32_t *value = reinterpret_cast<const int32_t *>(data);
str += std::to_string(*value);
@@ -382,9 +390,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, uint8_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