[libcamera-devel] [PATCH v5 2/9] libcamera: controls: Parse 'enum' in gen-controls.py
Jacopo Mondi
jacopo at jmondi.org
Thu Feb 6 02:25:54 CET 2020
In preparation to add libcamera Camera properties definitions by re-using
the control generation framework, augment the gen_controls.py script to
support parsing the 'enum' yaml tag and generate documentation and
definition of possible values associated with a Control or a Property
and defined through an enumeration of supported values.
Reviewed-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
src/libcamera/gen-controls.py | 50 +++++++++++++++++++++++++++++++----
1 file changed, 45 insertions(+), 5 deletions(-)
diff --git a/src/libcamera/gen-controls.py b/src/libcamera/gen-controls.py
index 2e5ac5c81cca..b251e528d50b 100755
--- a/src/libcamera/gen-controls.py
+++ b/src/libcamera/gen-controls.py
@@ -16,7 +16,18 @@ def snake_case(s):
return ''.join([c.isupper() and ('_' + c) or c for c in s]).strip('_')
+def format_description(description):
+ description = description.strip('\n').split('\n')
+ description[0] = '\\brief ' + description[0]
+ return '\n'.join([(line and ' * ' or ' *') + line for line in description])
+
+
def generate_cpp(controls):
+ enum_doc_start_template = string.Template('''/**
+ * \\enum ${name}Values
+ * \\brief Supported ${name} values''')
+ enum_doc_value_template = string.Template(''' * \\var ${name}Values::${value}
+${description}''')
doc_template = string.Template('''/**
* \\var extern const Control<${type}> ${name}
${description}
@@ -31,17 +42,31 @@ ${description}
name, ctrl = ctrl.popitem()
id_name = snake_case(name).upper()
- description = ctrl['description'].strip('\n').split('\n')
- description[0] = '\\brief ' + description[0]
- description = '\n'.join([(line and ' * ' or ' *') + line for line in description])
-
info = {
'name': name,
'type': ctrl['type'],
- 'description': description,
+ 'description': format_description(ctrl['description']),
'id_name': id_name,
}
+ enum = ctrl.get('enum')
+ if enum:
+ enum_doc = []
+ enum_doc.append(enum_doc_start_template.substitute(info))
+
+ for entry in enum:
+ entry_name, entry_info = entry.popitem()
+ value_info = {
+ 'name' : name,
+ 'value': entry_name,
+ 'description': format_description(entry_info['description']),
+ }
+ enum_doc.append(enum_doc_value_template.substitute(value_info))
+
+ enum_doc = '\n *\n'.join(enum_doc)
+ enum_doc += '\n */'
+ ctrls_doc.append(enum_doc)
+
ctrls_doc.append(doc_template.substitute(info))
ctrls_def.append(def_template.substitute(info))
ctrls_map.append('\t{ ' + id_name + ', &' + name + ' },')
@@ -54,6 +79,8 @@ ${description}
def generate_h(controls):
+ enum_template_start = string.Template('''enum ${name}Values {''')
+ enum_value_template = string.Template('''\t${name} = ${value},''')
template = string.Template('''extern const Control<${type}> ${name};''')
ctrls = []
@@ -71,6 +98,19 @@ def generate_h(controls):
'type': ctrl['type'],
}
+ enum = ctrl.get('enum')
+ if enum:
+ ctrls.append(enum_template_start.substitute(info))
+
+ for entry in enum:
+ entry_name, entry_info = entry.popitem()
+ value_info = {
+ 'name': entry_name,
+ 'value': entry_info['value'],
+ }
+ ctrls.append(enum_value_template.substitute(value_info))
+ ctrls.append("};")
+
ctrls.append(template.substitute(info))
id_value += 1
--
2.24.1
More information about the libcamera-devel
mailing list