From patchwork Fri Nov 29 09:19:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 22137 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 185D8C3220 for ; Fri, 29 Nov 2024 09:19:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BBCD46601C; Fri, 29 Nov 2024 10:19:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JFx9FvTP"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A3476600E for ; Fri, 29 Nov 2024 10:19:29 +0100 (CET) Received: from neptunite.flets-east.jp (unknown [IPv6:2404:7a81:160:2100:b147:f3c:c4e8:a42a]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EFA30A8F; Fri, 29 Nov 2024 10:19:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1732871945; bh=iQm6WPZeBSpP166Iei4GvPkzWGOj7V2fubQkL7HzY/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JFx9FvTPvPohJeWbT9RIqPDrgKME/aAt0geCg7FEKI7DQZ8v7YBXLq2POPnN57ajN 1svrb69XFS4bfGBWoz/O3H+UOq10MdZEpVTd729W3UH97ti7V4MwAH7rT4F3uVzuwz DZ04Tdft/rY6KJpIuGQ9dH3wZr/QXSfp8WY54SBk= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , Laurent Pinchart Subject: [PATCH v3 2/4] utils: codegen: controls.py: Parse direction information Date: Fri, 29 Nov 2024 18:19:14 +0900 Message-Id: <20241129091916.298359-3-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241129091916.298359-1-paul.elder@ideasonboard.com> References: <20241129091916.298359-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 --- Changes in v3: - minor reordering Changes in v2: - prevent errors in parsing properties, since the direction field is now required yet properties can only be out - do this by expanding the Control constructor to take the mode argument, so that needs to be passed in by the users of Control --- src/py/libcamera/gen-py-controls.py | 2 +- utils/codegen/controls.py | 24 +++++++++++++++++++++++- utils/codegen/gen-controls.py | 2 +- utils/codegen/gen-gst-controls.py | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/py/libcamera/gen-py-controls.py b/src/py/libcamera/gen-py-controls.py index cf09c146084d..d43a7c1c7eab 100755 --- a/src/py/libcamera/gen-py-controls.py +++ b/src/py/libcamera/gen-py-controls.py @@ -83,7 +83,7 @@ def main(argv): vendors.append(vendor) for ctrl in data['controls']: - ctrl = Control(*ctrl.popitem(), vendor) + ctrl = Control(*ctrl.popitem(), vendor, args.mode) controls.append(extend_control(ctrl, args.mode)) data = { diff --git a/utils/codegen/controls.py b/utils/codegen/controls.py index 03c77cc64abe..602f15b25fb6 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') diff --git a/utils/codegen/gen-controls.py b/utils/codegen/gen-controls.py index 3034e9a54760..59b716c1c48c 100755 --- a/utils/codegen/gen-controls.py +++ b/utils/codegen/gen-controls.py @@ -71,7 +71,7 @@ def main(argv): ctrls = controls.setdefault(vendor, []) 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)) # Sort the vendors by range numerical value diff --git a/utils/codegen/gen-gst-controls.py b/utils/codegen/gen-gst-controls.py index 2601a67588a3..df0988266294 100755 --- a/utils/codegen/gen-gst-controls.py +++ b/utils/codegen/gen-gst-controls.py @@ -154,7 +154,7 @@ def main(argv): ctrls = controls.setdefault(vendor, []) for ctrl in data['controls']: - ctrl = Control(*ctrl.popitem(), vendor) + ctrl = Control(*ctrl.popitem(), vendor, mode='controls') if ctrl.name in exposed_controls: ctrls.append(extend_control(ctrl))