diff options
author | Jacopo Mondi <jacopo@jmondi.org> | 2019-11-18 03:20:11 +0100 |
---|---|---|
committer | Jacopo Mondi <jacopo@jmondi.org> | 2020-02-14 16:27:42 +0100 |
commit | c9104548afd9c9f3f1f43937cc18ad2d7e3095da (patch) | |
tree | 14b88b4bf83ab5ac034312f8a59ae5153a00025b /src | |
parent | 366507962fa83b76d9bf9553fa53f46b1834c1a7 (diff) |
libcamera: controls: Parse 'enum' in gen-controls.py
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@ragnatech.se>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src')
-rwxr-xr-x | src/libcamera/gen-controls.py | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/src/libcamera/gen-controls.py b/src/libcamera/gen-controls.py index 2e5ac5c8..773e9b5d 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,30 @@ ${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: + value_info = { + 'name' : name, + 'value': entry['name'], + 'description': format_description(entry['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 +78,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 +97,18 @@ def generate_h(controls): 'type': ctrl['type'], } + enum = ctrl.get('enum') + if enum: + ctrls.append(enum_template_start.substitute(info)) + + for entry in enum: + value_info = { + 'name': entry['name'], + 'value': entry['value'], + } + ctrls.append(enum_value_template.substitute(value_info)) + ctrls.append("};") + ctrls.append(template.substitute(info)) id_value += 1 |