From c9104548afd9c9f3f1f43937cc18ad2d7e3095da Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Mon, 18 Nov 2019 03:20:11 +0100 Subject: libcamera: controls: Parse 'enum' in gen-controls.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/libcamera/gen-controls.py | 48 ++++++++++++++++++++++++++++++++++++++----- 1 file 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 -- cgit v1.2.1