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 <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>
This commit is contained in:
Paul Elder 2024-11-26 00:13:57 +09:00
parent 9bd9d25a82
commit 39fe4ad968
4 changed files with 26 additions and 4 deletions

View file

@ -83,7 +83,7 @@ def main(argv):
vendors.append(vendor) vendors.append(vendor)
for ctrl in data['controls']: for ctrl in data['controls']:
ctrl = Control(*ctrl.popitem(), vendor) ctrl = Control(*ctrl.popitem(), vendor, args.mode)
controls.append(extend_control(ctrl, args.mode)) controls.append(extend_control(ctrl, args.mode))
data = { data = {

View file

@ -28,7 +28,7 @@ class ControlEnum(object):
class Control(object): class Control(object):
def __init__(self, name, data, vendor): def __init__(self, name, data, vendor, mode):
self.__name = name self.__name = name
self.__data = data self.__data = data
self.__enum_values = None self.__enum_values = None
@ -60,6 +60,16 @@ class Control(object):
self.__size = num_elems 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 @property
def description(self): def description(self):
"""The control description""" """The control description"""
@ -111,6 +121,18 @@ class Control(object):
else: else:
return f"Span<const {typ}>" return f"Span<const {typ}>"
@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 @property
def element_type(self): def element_type(self):
return self.__data.get('type') return self.__data.get('type')

View file

@ -71,7 +71,7 @@ def main(argv):
ctrls = controls.setdefault(vendor, []) ctrls = controls.setdefault(vendor, [])
for i, ctrl in enumerate(data['controls']): for i, ctrl in enumerate(data['controls']):
ctrl = Control(*ctrl.popitem(), vendor) ctrl = Control(*ctrl.popitem(), vendor, args.mode)
ctrls.append(extend_control(ctrl, i, ranges)) ctrls.append(extend_control(ctrl, i, ranges))
# Sort the vendors by range numerical value # Sort the vendors by range numerical value

View file

@ -154,7 +154,7 @@ def main(argv):
ctrls = controls.setdefault(vendor, []) ctrls = controls.setdefault(vendor, [])
for ctrl in data['controls']: for ctrl in data['controls']:
ctrl = Control(*ctrl.popitem(), vendor) ctrl = Control(*ctrl.popitem(), vendor, mode='controls')
if ctrl.name in exposed_controls: if ctrl.name in exposed_controls:
ctrls.append(extend_control(ctrl)) ctrls.append(extend_control(ctrl))