python-periphery 2.4.2__py2.py3-none-any.whl → 2.4.3__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
periphery/__init__.py CHANGED
@@ -1,9 +1,9 @@
1
1
  import time
2
2
 
3
- __version__ = "2.4.2"
3
+ __version__ = "2.4.3"
4
4
  "Module version string."
5
5
 
6
- version = (2, 4, 2)
6
+ version = (2, 4, 3)
7
7
  "Module version tuple."
8
8
 
9
9
 
periphery/spi.py CHANGED
@@ -149,12 +149,11 @@ class SPI(object):
149
149
 
150
150
  # Methods
151
151
 
152
- def transfer(self, data, inplace=False):
152
+ def transfer(self, data):
153
153
  """Shift out `data` and return shifted in data.
154
154
 
155
155
  Args:
156
156
  data (bytes, bytearray, list): a byte array or list of 8-bit integers to shift out.
157
- inplace (bool): read in-place into data. data must be of type `bytearray`.
158
157
 
159
158
  Returns:
160
159
  bytes, bytearray, list: data shifted in.
@@ -167,20 +166,20 @@ class SPI(object):
167
166
  """
168
167
  if not isinstance(data, (bytes, bytearray, list)):
169
168
  raise TypeError("Invalid data type, should be bytes, bytearray, or list.")
170
- elif inplace and not isinstance(data, bytearray):
171
- raise TypeError("Invalid data type, should be bytearray for in-place read.")
172
169
 
173
170
  # Create mutable array
174
171
  try:
175
- buf = data if inplace else bytearray(data)
172
+ buf = array.array('B', data)
176
173
  except OverflowError:
177
174
  raise ValueError("Invalid data bytes.")
178
175
 
176
+ buf_addr, buf_len = buf.buffer_info()
177
+
179
178
  # Prepare transfer structure
180
179
  spi_xfer = _CSpiIocTransfer()
181
- spi_xfer.tx_buf = (ctypes.c_ubyte * len(data)).from_buffer(buf)
182
- spi_xfer.rx_buf = spi_xfer.tx_buf
183
- spi_xfer.len = len(data)
180
+ spi_xfer.tx_buf = buf_addr
181
+ spi_xfer.rx_buf = buf_addr
182
+ spi_xfer.len = buf_len
184
183
 
185
184
  # Transfer
186
185
  try:
@@ -190,11 +189,11 @@ class SPI(object):
190
189
 
191
190
  # Return shifted out data with the same type as shifted in data
192
191
  if isinstance(data, bytes):
193
- return bytes(buf)
192
+ return bytes(bytearray(buf))
194
193
  elif isinstance(data, bytearray):
195
- return buf if inplace else bytearray(buf)
194
+ return bytearray(buf)
196
195
  elif isinstance(data, list):
197
- return list(buf)
196
+ return buf.tolist()
198
197
 
199
198
  def close(self):
200
199
  """Close the spidev SPI device.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-periphery
3
- Version: 2.4.2
3
+ Version: 2.4.3
4
4
  Summary: A pure Python 2/3 library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
5
5
  Home-page: https://github.com/vsergeev/python-periphery
6
6
  Author: vsergeev
@@ -1,4 +1,4 @@
1
- periphery/__init__.py,sha256=pZAY_rDiG1aYx4B4vek8QK9P5NdS5aLmyBnXSjXBcYo,1030
1
+ periphery/__init__.py,sha256=bFlQwbt4Eo3p9VjzuaRpVIhbPyIKhX50EOXmNi_Maak,1030
2
2
  periphery/__init__.pyi,sha256=kNV-srVZuc_gxTFhINQaQhFYhwfxePFOoW4zwZysiyA,698
3
3
  periphery/gpio.py,sha256=JhDIEcC2BEmpSKXlnAxNkeM3pvzaVClE42yAER_lEuw,9960
4
4
  periphery/gpio.pyi,sha256=3xHOcsmXxdcc-sXy3KNb0beuCp-KCW759Duq1jr88J4,1935
@@ -16,10 +16,10 @@ periphery/pwm.pyi,sha256=bHNZzrtRGRv7KSVL_-4zR8bjBt1JXYFlf1mhc0vu5TE,749
16
16
  periphery/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  periphery/serial.py,sha256=L-tNg7aOTL_-c4tJ2qOXtp1I8LMRgYFmQWLnMmW2VCo,25275
18
18
  periphery/serial.pyi,sha256=LCU7XhhD-yyCGG5cWM7C-K0r-FOaUydGo4GB1v9KD_Y,1114
19
- periphery/spi.py,sha256=_7JSHlON8xl-QJZERA0UNljqMi4dSuUdFS9Ep_3LdtU,15836
19
+ periphery/spi.py,sha256=LTEpKBvvrhIdfcav-Zr08JKt_75BMYLaPoOYBCPzvtg,15568
20
20
  periphery/spi.pyi,sha256=xpDxe72ffXmjT905fMwJDHTMZgTSxOY4Wtpk-JJiBrU,806
21
- python_periphery-2.4.2.dist-info/licenses/LICENSE,sha256=uv-e__4tQsDlgnHRd8NFan5DbsfFxHoC2pG7x23oOHc,1099
22
- python_periphery-2.4.2.dist-info/METADATA,sha256=Atkv1WPL6Qz3Eve2pHh7XPiOMpCoc0f4ZapvCA6cDrA,1629
23
- python_periphery-2.4.2.dist-info/WHEEL,sha256=qWEHOWeXof9kJLXAXJ1hukQ_MvVtaV9UUAew6N7Y99E,109
24
- python_periphery-2.4.2.dist-info/top_level.txt,sha256=b4Woy5NSzNa7ZPLaz2cmCExhZP2-5zOgtUZog8ASZy0,10
25
- python_periphery-2.4.2.dist-info/RECORD,,
21
+ python_periphery-2.4.3.dist-info/licenses/LICENSE,sha256=uv-e__4tQsDlgnHRd8NFan5DbsfFxHoC2pG7x23oOHc,1099
22
+ python_periphery-2.4.3.dist-info/METADATA,sha256=B7WyU7pOHadweyN-LfD02Uq74NCfAU29W-VWQJa9wgU,1629
23
+ python_periphery-2.4.3.dist-info/WHEEL,sha256=4YBfCYNH4wlLpv3pzq1hbEuIlXA4WJabKLFurZ7eTL0,109
24
+ python_periphery-2.4.3.dist-info/top_level.txt,sha256=b4Woy5NSzNa7ZPLaz2cmCExhZP2-5zOgtUZog8ASZy0,10
25
+ python_periphery-2.4.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (83.0.0)
2
+ Generator: setuptools (84.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py2-none-any
5
5
  Tag: py3-none-any