summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNaushir Patuck <naush@raspberrypi.com>2023-11-09 11:31:31 +0000
committerNaushir Patuck <naush@raspberrypi.com>2023-11-29 09:05:39 +0000
commitd3365b358f350931ce5b1e51c39c23fa47b4a7ca (patch)
tree862d514e07ca37747a271d58d295bcfa46557aef
parent0455bbbf518cc834bd72ac65e13c9ed40bf21f3c (diff)
libcamera: control: Add vendor control id range reservation
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 separate range from core libcamera controls, breaking the existing numbering behaviour. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
-rw-r--r--include/libcamera/meson.build3
-rw-r--r--src/libcamera/control_ranges.yaml18
-rw-r--r--src/libcamera/meson.build4
-rwxr-xr-xutils/gen-controls.py15
4 files changed, 35 insertions, 5 deletions
diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
index c46a4e70..a2bb5d16 100644
--- a/include/libcamera/meson.build
+++ b/include/libcamera/meson.build
@@ -74,12 +74,13 @@ foreach mode, entry : controls_map
endif
template_file = files(outfile + '.in')
+ ranges_file = files('../../src/libcamera/control_ranges.yaml')
control_headers += custom_target(header + '_h',
input : input_files,
output : outfile,
command : [gen_controls, '-o', '@OUTPUT@',
'--mode', mode, '-t', template_file,
- '@INPUT@'],
+ '-r', ranges_file, '@INPUT@'],
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 00000000..d42447d0
--- /dev/null
+++ b/src/libcamera/control_ranges.yaml
@@ -0,0 +1,18 @@
+# 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/draft libcamera and vendor
+# controls and properties.
+ranges:
+ # Core libcamera controls
+ libcamera: 0
+ # Draft designated libcamera controls
+ draft: 10000
+ # Raspberry Pi vendor controls
+ rpi: 20000
+ # Next range starts at 30000
+
+...
diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
index 6d9902e6..45f63e93 100644
--- a/src/libcamera/meson.build
+++ b/src/libcamera/meson.build
@@ -141,11 +141,13 @@ foreach mode, input_files : controls_mode_files
template_file = files('property_ids.cpp.in')
endif
+ ranges_file = files('control_ranges.yaml')
control_sources += custom_target(mode + '_cpp',
input : input_files,
output : mode + '_ids.cpp',
command : [gen_controls, '-o', '@OUTPUT@',
- '--mode', mode, '-t', template_file, '@INPUT@'])
+ '--mode', mode, '-t', template_file,
+ '-r', ranges_file, '@INPUT@'])
endforeach
libcamera_sources += control_sources
diff --git a/utils/gen-controls.py b/utils/gen-controls.py
index 2a633cc0..8e592148 100755
--- a/utils/gen-controls.py
+++ b/utils/gen-controls.py
@@ -239,7 +239,7 @@ ${vendor_controls_str}
}
-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;''')
@@ -254,8 +254,10 @@ def generate_h(controls, mode):
vendor = 'draft' if ctrl.is_draft else ctrl.vendor
if vendor not in ctrls:
+ if vendor not in ranges.keys():
+ raise RuntimeError(f'Control id range is not defined for vendor {vendor}')
+ id_value[vendor] = ranges[vendor] + 1
ids[vendor] = []
- id_value[vendor] = 1
ctrls[vendor] = []
# Core and draft controls use the same ID value
@@ -341,6 +343,8 @@ def main(argv):
help='Mode of operation')
parser.add_argument('--output', '-o', metavar='file', type=str,
help='Output file name. Defaults to standard output if not specified.')
+ parser.add_argument('--ranges', '-r', type=str, required=True,
+ help='Control id range reservation file.')
parser.add_argument('--template', '-t', dest='template', type=str, required=True,
help='Template file name.')
parser.add_argument('input', type=str, nargs='+',
@@ -348,6 +352,11 @@ def main(argv):
args = parser.parse_args(argv[1:])
+ ranges = {}
+ with open(args.ranges, 'rb') as f:
+ data = open(args.ranges, 'rb').read()
+ ranges = yaml.safe_load(data)['ranges']
+
controls = []
for input in args.input:
with open(input, 'rb') as f:
@@ -359,7 +368,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')