diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-08-08 03:41:32 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-08-16 00:27:54 +0300 |
commit | dc067c4bcea7f13e91f0e84591cd4fe6c77c196b (patch) | |
tree | 4be8d4064ec14e9e5cceb3a1a5f84cf277025ee7 /include | |
parent | 48f9660acd51dda1f4dbe778b5b5f9bec0483b34 (diff) |
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 <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/libcamera/control_ids.h.in | 42 | ||||
-rw-r--r-- | include/libcamera/meson.build | 2 | ||||
-rw-r--r-- | include/libcamera/property_ids.h.in | 34 |
3 files changed, 34 insertions, 44 deletions
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<const ControlValue, {{ctrl.enum_values_count}}> {{ctrl.name}}Values; +extern const std::map<std::string, {{ctrl.type}}> {{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 <map> -#include <stdint.h> -#include <string> - -#include <libcamera/controls.h> - -namespace libcamera { - -namespace properties { - -enum { -${ids} -}; - -${controls} - -extern const ControlIdMap properties; - -${vendor_controls} - -} /* namespace properties */ - -} /* namespace libcamera */ |