From patchwork Mon Dec 9 16:34:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2413 Return-Path: Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 89BA760BDB for ; Mon, 9 Dec 2019 17:32:41 +0100 (CET) X-Originating-IP: 93.34.114.233 Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 190E41C0012; Mon, 9 Dec 2019 16:32:40 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 9 Dec 2019 17:34:38 +0100 Message-Id: <20191209163446.32381-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191209163446.32381-1-jacopo@jmondi.org> References: <20191209163446.32381-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 02/10] libcamera: controls: Parse 'enum' in gen-controls.py X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Dec 2019 16:32:41 -0000 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. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/gen-controls.py | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/libcamera/gen-controls.py b/src/libcamera/gen-controls.py index 940386cc68c8..4a1ee52cdb04 100755 --- a/src/libcamera/gen-controls.py +++ b/src/libcamera/gen-controls.py @@ -17,6 +17,10 @@ def snake_case(s): def generate_cpp(controls): + enum_doc_start_template = string.Template('''/** + * \enum ${name}Values\n * Supported ${name} values\n\n''') + enum_doc_value_template = string.Template(''' * \\var ${name}Values::${value} +${description}\n *\n''') doc_template = string.Template('''/** * \\var extern const Control<${type}> ${name} ${description} @@ -42,6 +46,27 @@ ${description} 'id_name': id_name, } + enum_doc = [] + try: + enum = ctrl['enum'] + enum_doc += enum_doc_start_template.substitute(info) + + for value in enum: + enum_description = value['description'].strip('\n').split('\n') + enum_description[0] = '\\brief ' + enum_description[0] + enum_description = '\n'.join([' * ' + line for line in enum_description]) + value_info = { + 'name' : name, + 'value': list(value.keys())[0], + 'description': enum_description, + } + enum_doc += enum_doc_value_template.substitute(value_info) + enum_doc += " */" + enum_doc = ''.join(enum_doc) + ctrls_doc.append(enum_doc) + except KeyError: + pass + 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,20 @@ def generate_h(controls): 'type': ctrl['type'], } + try: + enum = ctrl['enum'] + ctrls.append(enum_template_start.substitute(info)) + + for value in enum: + value_info = { + 'name': list(value.keys())[0], + 'value': value['value'], + } + ctrls.append(enum_value_template.substitute(value_info)) + ctrls.append("};") + except KeyError: + pass + ctrls.append(template.substitute(info)) id_value += 1