[libcamera-devel] libcamera: v4l2_device: Add support for V4L2_CTRL_TYPE_U32
diff mbox series

Message ID 20221115130848.1887943-1-xavier.roumegue@oss.nxp.com
State New
Headers show
Series
  • [libcamera-devel] libcamera: v4l2_device: Add support for V4L2_CTRL_TYPE_U32
Related show

Commit Message

Xavier Roumegue Nov. 15, 2022, 1:08 p.m. UTC
Support for the U16 and U32 compound control types is missing. U16 will
require a new libcamera control type, but U32 maps to the existing
ControlTypeInteger32 and can be added easily.

Signed-off-by: Xavier Roumegue <xavier.roumegue@oss.nxp.com>
---
 include/libcamera/controls.h  |  5 +++++
 src/libcamera/v4l2_device.cpp | 32 ++++++++++++++++++++++++--------
 2 files changed, 29 insertions(+), 8 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index cf942055..2039fb1f 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -62,6 +62,11 @@  struct control_type<int32_t> {
 	static constexpr ControlType value = ControlTypeInteger32;
 };
 
+template<>
+struct control_type<uint32_t> {
+	static constexpr ControlType value = ControlTypeInteger32;
+};
+
 template<>
 struct control_type<int64_t> {
 	static constexpr ControlType value = ControlTypeInteger64;
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index c17b323f..01dfb379 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -204,12 +204,26 @@  ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)
 		v4l2Ctrl.id = id;
 
 		if (info.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) {
-			ControlType type;
+			ControlValue &value = ctrl.second;
 
 			switch (info.type) {
-			case V4L2_CTRL_TYPE_U8:
-				type = ControlTypeByte;
+			case V4L2_CTRL_TYPE_U8: {
+				value.reserve(ControlTypeByte, true, info.elems);
+				Span<uint8_t> data = value.data();
+				v4l2Ctrl.p_u8 = data.data();
+				v4l2Ctrl.size = data.size_bytes();
+				break;
+			}
+
+			case V4L2_CTRL_TYPE_U32: {
+				value.reserve(ControlTypeInteger32, true, info.elems);
+				Span<uint32_t> data(
+					reinterpret_cast<uint32_t *>(value.data().data()),
+					info.elems);
+				v4l2Ctrl.p_u32 = data.data();
+				v4l2Ctrl.size = data.size_bytes();
 				break;
+			}
 
 			default:
 				LOG(V4L2, Error)
@@ -218,12 +232,7 @@  ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)
 				return {};
 			}
 
-			ControlValue &value = ctrl.second;
-			value.reserve(type, true, info.elems);
-			Span<uint8_t> data = value.data();
 
-			v4l2Ctrl.p_u8 = data.data();
-			v4l2Ctrl.size = data.size();
 		}
 	}
 
@@ -490,6 +499,7 @@  ControlType V4L2Device::v4l2CtrlType(uint32_t ctrlType)
 		return ControlTypeBool;
 
 	case V4L2_CTRL_TYPE_INTEGER:
+	case V4L2_CTRL_TYPE_U32:
 		return ControlTypeInteger32;
 
 	case V4L2_CTRL_TYPE_INTEGER64:
@@ -551,6 +561,11 @@  ControlInfo V4L2Device::v4l2ControlInfo(const v4l2_query_ext_ctrl &ctrl)
 	case V4L2_CTRL_TYPE_MENU:
 		return v4l2MenuControlInfo(ctrl);
 
+	case V4L2_CTRL_TYPE_U32:
+		return ControlInfo(static_cast<uint32_t>(ctrl.minimum),
+				   static_cast<uint32_t>(ctrl.maximum),
+				   static_cast<uint32_t>(ctrl.default_value));
+
 	default:
 		return ControlInfo(static_cast<int32_t>(ctrl.minimum),
 				   static_cast<int32_t>(ctrl.maximum),
@@ -615,6 +630,7 @@  void V4L2Device::listControls()
 		case V4L2_CTRL_TYPE_BITMASK:
 		case V4L2_CTRL_TYPE_INTEGER_MENU:
 		case V4L2_CTRL_TYPE_U8:
+		case V4L2_CTRL_TYPE_U32:
 			break;
 		/* \todo Support other control types. */
 		default: