[libcamera-devel] [PATCH v3 06/14] libcamera: controls: Generate a vector of enumerated values

Jacopo Mondi jacopo at jmondi.org
Wed Oct 21 16:36:27 CEST 2020


For each Control that support enumerated values generate a vector
of ControlValues which contains the full list of values.

At the expense of a slight increase in memory occupation this change
allows the construction of the ControlInfo associated with a Control
from the values list, defaulting the minimum and maximum values
reported by the ControlInfo.

Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
 src/libcamera/control_ids.cpp.in |  2 ++
 utils/gen-controls.py            | 10 ++++++++++
 2 files changed, 12 insertions(+)

diff --git a/src/libcamera/control_ids.cpp.in b/src/libcamera/control_ids.cpp.in
index 056645cfbdfb..ca0b5b22f899 100644
--- a/src/libcamera/control_ids.cpp.in
+++ b/src/libcamera/control_ids.cpp.in
@@ -6,8 +6,10 @@
  *
  * This file is auto-generated. Do not edit.
  */
+#include <vector>
 
 #include <libcamera/control_ids.h>
+#include <libcamera/controls.h>
 
 /**
  * \file control_ids.h
diff --git a/utils/gen-controls.py b/utils/gen-controls.py
index bf681503f86a..23aace50f666 100755
--- a/utils/gen-controls.py
+++ b/utils/gen-controls.py
@@ -100,6 +100,8 @@ ${description}
 def generate_h(controls):
     enum_template_start = string.Template('''enum ${name}Enum {''')
     enum_value_template = string.Template('''\t${name} = ${value},''')
+    enum_list_start = string.Template('''static const std::vector<ControlValue> ${name}Values = {''')
+    enum_list_values = string.Template('''\tstatic_cast<int32_t>(${name}),''')
     template = string.Template('''extern const Control<${type}> ${name};''')
 
     ctrls = []
@@ -140,6 +142,14 @@ def generate_h(controls):
                 target_ctrls.append(enum_value_template.substitute(value_info))
             target_ctrls.append("};")
 
+            target_ctrls.append(enum_list_start.substitute(info))
+            for entry in enum:
+                value_info = {
+                    'name': entry['name'],
+                }
+                target_ctrls.append(enum_list_values.substitute(value_info))
+            target_ctrls.append("};")
+
         target_ctrls.append(template.substitute(info))
         id_value += 1
 
-- 
2.28.0



More information about the libcamera-devel mailing list