From 39fe4ad96803f4dd97f034c3e4c05c55757bce11 Mon Sep 17 00:00:00 2001 From: Paul Elder Date: Tue, 26 Nov 2024 00:13:57 +0900 Subject: utils: codegen: controls.py: Parse direction information In preparation for adding support for querying direction information from controls, parse the direction information from control ID definitions. This can later be plugged in directly to the IPA code generators simply by using ctrl.direction. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Stefan Klug --- utils/codegen/controls.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'utils/codegen/controls.py') diff --git a/utils/codegen/controls.py b/utils/codegen/controls.py index 03c77cc6..602f15b2 100644 --- a/utils/codegen/controls.py +++ b/utils/codegen/controls.py @@ -28,7 +28,7 @@ class ControlEnum(object): class Control(object): - def __init__(self, name, data, vendor): + def __init__(self, name, data, vendor, mode): self.__name = name self.__data = data self.__enum_values = None @@ -60,6 +60,16 @@ class Control(object): self.__size = num_elems + if mode == 'properties': + self.__direction = 'out' + else: + direction = self.__data.get('direction') + if direction is None: + raise RuntimeError(f'Control `{self.__name}` missing required field `{direction}`') + if direction not in ['in', 'out', 'inout']: + raise RuntimeError(f'Control `{self.__name}` direction `{direction}` is invalid; must be one of `in`, `out`, or `inout`') + self.__direction = direction + @property def description(self): """The control description""" @@ -111,6 +121,18 @@ class Control(object): else: return f"Span" + @property + def direction(self): + in_flag = 'ControlId::Direction::In' + out_flag = 'ControlId::Direction::Out' + + if self.__direction == 'inout': + return f'{in_flag} | {out_flag}' + if self.__direction == 'in': + return in_flag + if self.__direction == 'out': + return out_flag + @property def element_type(self): return self.__data.get('type') -- cgit v1.2.1