@@ -133,7 +133,13 @@ class ContextParams(Structure):
133133 pass # TODO
134134
135135class BufferParams (Structure ):
136- pass # TODO
136+ """Represents the low-level control over DMA buffer allocation."""
137+
138+ _fields_ = [
139+ ("idx" , c_uint ),
140+ ("dma_allocator" , c_int ),
141+ ("__rsrv" , c_char * 64 ),
142+ ]
137143
138144class DataFormat (Structure ):
139145 """Represents the data format of an IIO channel."""
@@ -304,6 +310,13 @@ class ChannelType(Enum):
304310 IIO_CHAN_TYPE_UNKNOWN = 0x7FFFFFFF
305311
306312
313+ class BufferDMAAllocator (Enum ):
314+ """Contains DMA allocator options."""
315+
316+ IIO_DMA_ALLOCATOR_SYSTEM = 0
317+ IIO_DMA_ALLOCATOR_CMA_LINUX = 1
318+
319+
307320# pylint: disable=invalid-name
308321_ScanPtr = _POINTER (_Scan )
309322_ContextPtr = _POINTER (_Context )
@@ -814,6 +827,36 @@ def _write(self, value):
814827 "Current value of this attribute.\n \t type=str" ,
815828 )
816829
830+ class ChannelsBufferParams (_IIO_Object ):
831+ """Represents buffer creation parameters."""
832+
833+ def __init__ (self , idx = 0 , dma_allocator = BufferDMAAllocator .IIO_DMA_ALLOCATOR_SYSTEM ):
834+ """
835+ Initialize a new instance of the ChannelsBufferParams class.
836+
837+ :param idx: type=int
838+ The index of the hardware buffer. Should be 0 in most cases.
839+ :param dma_allocator: type=BufferDMAAllocator
840+
841+ returns: type=iio.ChannelsBufferParams
842+ A new instance of this class
843+ """
844+ self ._params = BufferParams ()
845+ self ._params .idx = idx
846+ self ._params .dma_allocator = dma_allocator .value
847+
848+ super (ChannelsBufferParams , self ).__init__ (self ._params , None )
849+
850+ @property
851+ def idx (self ):
852+ """Get the buffer index."""
853+ return self ._params .idx
854+
855+ @property
856+ def dma_allocator (self ):
857+ """Get the DMA allocator type."""
858+ return self ._params .dma_allocator
859+
817860class ChannelsMask (_IIO_Object ):
818861 """A bitmask where each bit corresponds to an enabled channel."""
819862
@@ -1093,7 +1136,7 @@ def buffer(self):
10931136class Buffer (_IIO_Object ):
10941137 """Represents a hardware I/O buffer."""
10951138
1096- def __init__ (self , device , mask , params ):
1139+ def __init__ (self , device , mask , params = None ):
10971140 """
10981141 Initialize a new instance of the Buffer class.
10991142
@@ -1102,21 +1145,23 @@ def __init__(self, device, mask, params):
11021145 operations will be performed
11031146 :param mask: type=ChannelsMask
11041147 The mask of enabled channels
1105- :param idx : type=int
1106- The hardware index of the buffer to use. If unsure, leave it to 0
1148+ :param params : type=ChannelsBufferParams
1149+ The parameters of the buffer to use.
11071150
11081151 returns: type=iio.Buffer
11091152 An new instance of this class
11101153 """
1154+ if params is None :
1155+ params = ChannelsBufferParams ()
11111156 try :
1112- self ._buffer = _create_buffer (device ._device , params ._params , mask ._mask )
1157+ self ._buffer = _create_buffer (device ._device , _byref ( params ._params ) , mask ._mask )
11131158 except Exception :
11141159 self ._buffer = None
11151160 raise
11161161
11171162 super (Buffer , self ).__init__ (self ._buffer , device )
11181163
1119- self ._idx = idx
1164+ self ._params = params
11201165 self ._enabled = False
11211166
11221167 def __del__ (self ):
@@ -1159,6 +1204,14 @@ def _set_enabled(self, enabled):
11591204 "List of attributes for this buffer.\n \t type=dict of iio.Attr" ,
11601205 )
11611206
1207+ @property
1208+ def idx (self ):
1209+ """
1210+ Get the buffer index from the buffer parameters.
1211+ type: int
1212+ """
1213+ return self ._params .idx
1214+
11621215
11631216class Stream (_IIO_Object ):
11641217 def __init__ (self , buffer , samples_count , nb_blocks = 4 ):
0 commit comments