[{"id":32409,"web_url":"https://patchwork.libcamera.org/comment/32409/","msgid":"<20241127085700.GY5461@pendragon.ideasonboard.com>","date":"2024-11-27T08:57:00","subject":"Re: [PATCH v2 2/4] utils: codegen: controls.py: Parse direction\n\tinformation","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Wed, Nov 27, 2024 at 05:50:15PM +0900, Paul Elder wrote:\n> In preparation for adding support for querying direction information\n> from controls, parse the direction information from control ID\n> definitions. This can later be plugged in directly to the IPA code\n> generators simply by using ctrl.direction.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> ---\n> Changes in v2:\n> - prevent errors in parsing properties, since the direction field is now\n>   required yet properties can only be out\n>   - do this by expanding the Control constructor to take the mode\n>     argument, so that needs to be passed in by the users of Control\n> ---\n>  src/py/libcamera/gen-py-controls.py |  2 +-\n>  utils/codegen/controls.py           | 24 +++++++++++++++++++++++-\n>  utils/codegen/gen-controls.py       |  2 +-\n>  utils/codegen/gen-gst-controls.py   |  2 +-\n>  4 files changed, 26 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/py/libcamera/gen-py-controls.py b/src/py/libcamera/gen-py-controls.py\n> index cf09c146084d..d43a7c1c7eab 100755\n> --- a/src/py/libcamera/gen-py-controls.py\n> +++ b/src/py/libcamera/gen-py-controls.py\n> @@ -83,7 +83,7 @@ def main(argv):\n>              vendors.append(vendor)\n>  \n>          for ctrl in data['controls']:\n> -            ctrl = Control(*ctrl.popitem(), vendor)\n> +            ctrl = Control(*ctrl.popitem(), vendor, args.mode)\n>              controls.append(extend_control(ctrl, args.mode))\n>  \n>      data = {\n> diff --git a/utils/codegen/controls.py b/utils/codegen/controls.py\n> index 03c77cc64abe..b2dfc48b1bda 100644\n> --- a/utils/codegen/controls.py\n> +++ b/utils/codegen/controls.py\n> @@ -28,7 +28,7 @@ class ControlEnum(object):\n>  \n>  \n>  class Control(object):\n> -    def __init__(self, name, data, vendor):\n> +    def __init__(self, name, data, vendor, mode):\n>          self.__name = name\n>          self.__data = data\n>          self.__enum_values = None\n> @@ -60,6 +60,16 @@ class Control(object):\n>  \n>              self.__size = num_elems\n>  \n> +        direction = self.__data.get('direction')\n\nThis can go to the else branch, it's not needed for properties.\n\n> +        if mode == 'properties':\n> +            self.__direction = 'out'\n> +        else:\n> +            if direction is None:\n> +                raise RuntimeError(f'Control `{self.__name}` missing required field `{direction}`')\n> +            if direction not in ['in', 'out', 'inout']:\n> +                raise RuntimeError(f'Control `{self.__name}` direction `{direction}` is invalid; must be one of `in`, `out`, or `inout`')\n> +            self.__direction = direction\n> +\n>      @property\n>      def description(self):\n>          \"\"\"The control description\"\"\"\n> @@ -111,6 +121,18 @@ class Control(object):\n>          else:\n>              return f\"Span<const {typ}>\"\n>  \n> +    @property\n> +    def direction(self):\n> +        in_flag = 'ControlId::Direction::In'\n> +        out_flag = 'ControlId::Direction::Out'\n> +\n> +        if self.__direction == 'inout':\n> +            return f'{in_flag} | {out_flag}'\n> +        if self.__direction == 'in':\n> +            return in_flag\n> +        if self.__direction == 'out':\n> +            return out_flag\n> +\n>      @property\n>      def element_type(self):\n>          return self.__data.get('type')\n> diff --git a/utils/codegen/gen-controls.py b/utils/codegen/gen-controls.py\n> index 3034e9a54760..59b716c1c48c 100755\n> --- a/utils/codegen/gen-controls.py\n> +++ b/utils/codegen/gen-controls.py\n> @@ -71,7 +71,7 @@ def main(argv):\n>          ctrls = controls.setdefault(vendor, [])\n>  \n>          for i, ctrl in enumerate(data['controls']):\n> -            ctrl = Control(*ctrl.popitem(), vendor)\n> +            ctrl = Control(*ctrl.popitem(), vendor, args.mode)\n>              ctrls.append(extend_control(ctrl, i, ranges))\n>  \n>      # Sort the vendors by range numerical value\n> diff --git a/utils/codegen/gen-gst-controls.py b/utils/codegen/gen-gst-controls.py\n> index 2601a67588a3..df0988266294 100755\n> --- a/utils/codegen/gen-gst-controls.py\n> +++ b/utils/codegen/gen-gst-controls.py\n> @@ -154,7 +154,7 @@ def main(argv):\n>          ctrls = controls.setdefault(vendor, [])\n>  \n>          for ctrl in data['controls']:\n> -            ctrl = Control(*ctrl.popitem(), vendor)\n> +            ctrl = Control(*ctrl.popitem(), vendor, mode='controls')\n>  \n>              if ctrl.name in exposed_controls:\n>                  ctrls.append(extend_control(ctrl))","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id B572AC3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 27 Nov 2024 08:57:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C9035660B1;\n\tWed, 27 Nov 2024 09:57:13 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 725F96609E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Nov 2024 09:57:11 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 40A9578C;\n\tWed, 27 Nov 2024 09:56:48 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"bmVScyWL\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1732697808;\n\tbh=IUXd+C99Zg7JQHhbcpE2yO9FW0Ov5qazOXsxTA9mvng=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=bmVScyWLWxPf73LXUVpwuDJKpihqrUS0zmEFj6j6PRJnssUcwnUip625RjV8dZbM4\n\tyJDMHr4LxkXKlHdPoIJcTJYFpP5Fttg0LfAA2XQveIeoL7QMSjAlinYtp8bFQTyZKQ\n\t5m+XEYI0i+Jb0Uq7/cWiYLYyBhvWPv8qbwEiHJd4=","Date":"Wed, 27 Nov 2024 10:57:00 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2 2/4] utils: codegen: controls.py: Parse direction\n\tinformation","Message-ID":"<20241127085700.GY5461@pendragon.ideasonboard.com>","References":"<20241127085017.2192069-1-paul.elder@ideasonboard.com>\n\t<20241127085017.2192069-3-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20241127085017.2192069-3-paul.elder@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]