From dc067c4bcea7f13e91f0e84591cd4fe6c77c196b Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 8 Aug 2024 03:41:32 +0300 Subject: utils: codegen: gen-controls.py: Convert to jinja2 templates Jinja2 templates help separate the logic related to the template from the generation of the data. The python code becomes much clearer as a result. As an added bonus, we can use a single template file for both controls and properties. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder --- include/libcamera/control_ids.h.in | 42 +++++++++++++++++++++++++++++-------- include/libcamera/meson.build | 2 +- include/libcamera/property_ids.h.in | 34 ------------------------------ 3 files changed, 34 insertions(+), 44 deletions(-) delete mode 100644 include/libcamera/property_ids.h.in (limited to 'include') diff --git a/include/libcamera/control_ids.h.in b/include/libcamera/control_ids.h.in index 293ba966..858ef872 100644 --- a/include/libcamera/control_ids.h.in +++ b/include/libcamera/control_ids.h.in @@ -2,7 +2,7 @@ /* * Copyright (C) 2019, Google Inc. * - * Control ID list + * {{mode|capitalize}} ID list * * This file is auto-generated. Do not edit. */ @@ -18,18 +18,42 @@ namespace libcamera { -namespace controls { +namespace {{mode}} { -enum { -${ids} -}; +extern const ControlIdMap {{mode}}; + +{%- for vendor, ctrls in controls -%} -${controls} +{% if vendor != 'libcamera' %} +namespace {{vendor}} { -extern const ControlIdMap controls; +#define LIBCAMERA_HAS_{{vendor|upper}}_VENDOR_{{mode|upper}} +{%- endif %} -${vendor_controls} +enum { +{%- for ctrl in ctrls %} + {{ctrl.name|snake_case|upper}} = {{ctrl.id}}, +{%- endfor %} +}; -} /* namespace controls */ +{% for ctrl in ctrls -%} +{% if ctrl.is_enum -%} +enum {{ctrl.name}}Enum { +{%- for enum in ctrl.enum_values %} + {{enum.name}} = {{enum.value}}, +{%- endfor %} +}; +extern const std::array {{ctrl.name}}Values; +extern const std::map {{ctrl.name}}NameValueMap; +{% endif -%} +extern const Control<{{ctrl.type}}> {{ctrl.name}}; +{% endfor -%} + +{% if vendor != 'libcamera' %} +} /* namespace {{vendor}} */ +{% endif -%} + +{% endfor %} +} /* namespace {{mode}} */ } /* namespace libcamera */ diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index 87b9a941..d90a8615 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -80,7 +80,7 @@ foreach mode, entry : controls_map properties_files_names += files_list endif - template_file = files(outfile + '.in') + template_file = files('control_ids.h.in') ranges_file = files('../../src/libcamera/control_ranges.yaml') control_headers += custom_target(header + '_h', input : input_files, diff --git a/include/libcamera/property_ids.h.in b/include/libcamera/property_ids.h.in deleted file mode 100644 index e6edabca..00000000 --- a/include/libcamera/property_ids.h.in +++ /dev/null @@ -1,34 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * Property ID list - * - * This file is auto-generated. Do not edit. - */ - -#pragma once - -#include -#include -#include - -#include - -namespace libcamera { - -namespace properties { - -enum { -${ids} -}; - -${controls} - -extern const ControlIdMap properties; - -${vendor_controls} - -} /* namespace properties */ - -} /* namespace libcamera */ -- cgit v1.2.1