[2/4] utils: codegen: controls.py: Parse direction information
diff mbox series

Message ID 20241125153003.3309066-3-paul.elder@ideasonboard.com
State Superseded
Headers show
Series
  • Add direction field to ControlId
Related show

Commit Message

Paul Elder Nov. 25, 2024, 3:30 p.m. UTC
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>
---
 utils/codegen/controls.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Laurent Pinchart Nov. 25, 2024, 11:06 p.m. UTC | #1
Hi Paul,

Thank you for the patch.

On Tue, Nov 26, 2024 at 12:30:01AM +0900, Paul Elder wrote:
> 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>
> ---
>  utils/codegen/controls.py | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/utils/codegen/controls.py b/utils/codegen/controls.py
> index 03c77cc64abe..bc1c655f1b9b 100644
> --- a/utils/codegen/controls.py
> +++ b/utils/codegen/controls.py
> @@ -60,6 +60,15 @@ class Control(object):
>  
>              self.__size = num_elems
>  
> +        direction = self.__data.get('direction')
> +        if direction is not None:
> +            valid_values = ['in', 'out', 'inout']
> +            if direction not in valid_values:

You can also write

            if direction not in ['in', 'out', 'inout']:

Up to you. With the changes proposed in a response to the cover letter,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +                raise RuntimeError(f'Control `{self.__name}` direction `{direction}` is invalid; must be one of `in`, `out`, or `inout`')
> +            self.__direction = direction
> +        else:
> +            self.__direction = 'inout'
> +
>      @property
>      def description(self):
>          """The control description"""
> @@ -111,6 +120,18 @@ class Control(object):
>          else:
>              return f"Span<const {typ}>"
>  
> +    @property
> +    def direction(self):
> +        in_flag = 'static_cast<ControlId::DirectionFlags>(ControlId::Direction::In)'
> +        out_flag = 'static_cast<ControlId::DirectionFlags>(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')

Patch
diff mbox series

diff --git a/utils/codegen/controls.py b/utils/codegen/controls.py
index 03c77cc64abe..bc1c655f1b9b 100644
--- a/utils/codegen/controls.py
+++ b/utils/codegen/controls.py
@@ -60,6 +60,15 @@  class Control(object):
 
             self.__size = num_elems
 
+        direction = self.__data.get('direction')
+        if direction is not None:
+            valid_values = ['in', 'out', 'inout']
+            if direction not in valid_values:
+                raise RuntimeError(f'Control `{self.__name}` direction `{direction}` is invalid; must be one of `in`, `out`, or `inout`')
+            self.__direction = direction
+        else:
+            self.__direction = 'inout'
+
     @property
     def description(self):
         """The control description"""
@@ -111,6 +120,18 @@  class Control(object):
         else:
             return f"Span<const {typ}>"
 
+    @property
+    def direction(self):
+        in_flag = 'static_cast<ControlId::DirectionFlags>(ControlId::Direction::In)'
+        out_flag = 'static_cast<ControlId::DirectionFlags>(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')