[libcamera-devel] [PATCH v1 3/5] libcamera: control: Add vendor control id range reservation
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Mon Nov 20 05:16:57 CET 2023
Hi Naush,
Thank you for the patch.
On Fri, Nov 10, 2023 at 11:00:00AM +0000, Naushir Patuck via libcamera-devel wrote:
> Add a new control_ranges.yaml file that is used to reserve control id
> ranges/offsets for libcamera and vendor specific controls. This file is
> used by the gen-controls.py script to generate control id values for
> each control.
>
> Draft controls now have a seprate range from core libcamera controls,
s/seprate/separate/
> breaking the existing numbering behaviour.
>
> Signed-off-by: Naushir Patuck <naush at raspberrypi.com>
> ---
> include/libcamera/meson.build | 3 ++-
> src/libcamera/control_ranges.yaml | 17 +++++++++++++++++
> utils/gen-controls.py | 15 ++++++++++++---
> 3 files changed, 31 insertions(+), 4 deletions(-)
> create mode 100644 src/libcamera/control_ranges.yaml
>
> diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
> index f8af51174f08..98339b93777c 100644
> --- a/include/libcamera/meson.build
> +++ b/include/libcamera/meson.build
> @@ -82,11 +82,12 @@ foreach header, mode : control_source_files
> endforeach
>
> template_file = files(header + '.h.in')
> + ranges_file = files('../../src/libcamera/control_ranges.yaml')
> control_headers += custom_target(header + '_h',
> input : input_files,
> output : header + '.h',
> command : [gen_controls, '-o', '@OUTPUT@', '-i', '@INPUT@',
> - '--mode', mode, '-t', template_file],
> + '--mode', mode, '-t', template_file, '-r', ranges_file],
> install : true,
> install_dir : libcamera_headers_install_dir)
> endforeach
> diff --git a/src/libcamera/control_ranges.yaml b/src/libcamera/control_ranges.yaml
> new file mode 100644
> index 000000000000..e908a8a3a110
> --- /dev/null
> +++ b/src/libcamera/control_ranges.yaml
> @@ -0,0 +1,17 @@
> +# SPDX-License-Identifier: LGPL-2.1-or-later
> +#
> +# Copyright (C) 2023, Raspberry Pi Ltd
> +#
> +%YAML 1.1
> +---
> +# Specifies the control id ranges/offsets for core libcamera and vendor specific
> +# controls.
> +ranges:
> + # Core libcamera controls
> + libcamera: 0
> + # Draft designated libcamera controls
> + draft: 1000
> + # Raspberry Pi vendor controls
> + rpi: 2000
> +
> +...
> diff --git a/utils/gen-controls.py b/utils/gen-controls.py
> index 3c490a562676..a10b9fdc19ee 100755
> --- a/utils/gen-controls.py
> +++ b/utils/gen-controls.py
> @@ -259,7 +259,7 @@ ${vendor_controls_map}
> }
>
>
> -def generate_h(controls, mode):
> +def generate_h(controls, mode, ranges):
> enum_template_start = string.Template('''enum ${name}Enum {''')
> enum_value_template = string.Template('''\t${name} = ${value},''')
> enum_values_template = string.Template('''extern const std::array<const ControlValue, ${size}> ${name}Values;''')
> @@ -277,8 +277,10 @@ def generate_h(controls, mode):
> vendor = 'draft' if ctrl.is_draft else 'libcamera'
>
> if vendor not in ctrls:
> + if vendor not in ranges.keys():
> + raise RuntimeError('Vendor range is not defined')
It would be nice to print the vendor name here.
> + id_value[vendor] = ranges[vendor] + 1
> ids[vendor] = []
> - id_value[vendor] = 1
> ctrls[vendor] = []
>
> # Core and draft controls use the same ID value
> @@ -370,8 +372,15 @@ def main(argv):
> help='Template file name.')
> parser.add_argument('--mode', type=str, required=True, choices=['controls', 'properties'],
> help='Mode of operation')
> + parser.add_argument('-r', dest='ranges', type=str,
> + help='Control id range reservation file.')
> args = parser.parse_args(argv[1:])
>
> + ranges = []
> + if args.ranges:
> + data = open(args.ranges, 'rb').read()
> + ranges = yaml.safe_load(data)['ranges']
> +
> controls = []
> for input in args.inputs:
> data = open(input, 'rb').read()
> @@ -382,7 +391,7 @@ def main(argv):
> if args.template.endswith('.cpp.in'):
> data = generate_cpp(controls)
> elif args.template.endswith('.h.in'):
> - data = generate_h(controls, args.mode)
> + data = generate_h(controls, args.mode, ranges)
> else:
> raise RuntimeError('Unknown template type')
>
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list