libcamera: controls: Generate and use fixed-sized Span types

Define Span types explicitly as either variable- or fixed-sized. This
introduces a new convention for defining Span dimensions in the property
and control value definitions and generates Span types as variable-sized
Span<T> or as fixed-sized Span<T,N>.

Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Christian Rauch 2022-08-02 23:03:24 +02:00 committed by Laurent Pinchart
parent 293e23e21c
commit 09c1b081ba
6 changed files with 38 additions and 25 deletions

View file

@ -7,6 +7,8 @@
# gen-controls.py - Generate control definitions from YAML
import argparse
from functools import reduce
import operator
import string
import sys
import yaml
@ -22,6 +24,24 @@ def format_description(description):
return '\n'.join([(line and ' * ' or ' *') + line for line in description])
def get_ctrl_type(ctrl):
ctrl_type = ctrl['type']
ctrl_size_arr = ctrl.get('size')
if ctrl_type == 'string':
return 'std::string'
elif ctrl_size_arr is not None:
if len(ctrl_size_arr) > 0:
# fixed-sized Span
ctrl_span_size = reduce(operator.mul, ctrl_size_arr)
return f"Span<const {ctrl_type}, {ctrl_span_size}>"
else:
# variable-sized Span
return f"Span<const {ctrl_type}>"
else:
return ctrl_type
def generate_cpp(controls):
enum_doc_start_template = string.Template('''/**
* \\enum ${name}Enum
@ -50,11 +70,7 @@ ${description}
name, ctrl = ctrl.popitem()
id_name = snake_case(name).upper()
ctrl_type = ctrl['type']
if ctrl_type == 'string':
ctrl_type = 'std::string'
elif ctrl.get('size'):
ctrl_type = 'Span<const %s>' % ctrl_type
ctrl_type = get_ctrl_type(ctrl)
info = {
'name': name,
@ -135,11 +151,7 @@ def generate_h(controls):
ids.append('\t' + id_name + ' = ' + str(id_value) + ',')
ctrl_type = ctrl['type']
if ctrl_type == 'string':
ctrl_type = 'std::string'
elif ctrl.get('size'):
ctrl_type = 'Span<const %s>' % ctrl_type
ctrl_type = get_ctrl_type(ctrl)
info = {
'name': name,