Skip to content

Commit 0a0401a

Browse files
authored
Merge pull request #2 from adafruit/optimize_spi
Optimization: remove read/write from SPI device and return SPI bus on context manager enter
2 parents b5cadae + a7d11f8 commit 0a0401a

File tree

1 file changed

+1
-33
lines changed

1 file changed

+1
-33
lines changed

adafruit_bus_device/spi_device.py

+1-33
Original file line numberDiff line numberDiff line change
@@ -51,45 +51,13 @@ def __init__(self, spi, chip_select, baudrate=100000, polarity=0, phase=0):
5151
self.chip_select = chip_select
5252
self.chip_select.switch_to_output(value=True)
5353

54-
def read(self, buffer, **kwargs):
55-
"""
56-
Read into ``buffer`` from the device. The number of bytes read will be the
57-
length of ``buffer``.
58-
59-
If ``start`` or ``end`` is provided, then the buffer will be sliced
60-
as if ``buffer[start:end]``. This will not cause an allocation like
61-
``buffer[start:end]`` will so it saves memory.
62-
63-
:param bytearray buffer: buffer to write into
64-
:param int start: Index to start writing at
65-
:param int end: Index to write up to but not include
66-
"""
67-
self.spi.read(buffer, **kwargs)
68-
69-
def write(self, buffer, **kwargs):
70-
"""
71-
Write the bytes from ``buffer`` to the device. Transmits a stop bit if
72-
``stop`` is set.
73-
74-
If ``start`` or ``end`` is provided, then the buffer will be sliced
75-
as if ``buffer[start:end]``. This will not cause an allocation like
76-
``buffer[start:end]`` will so it saves memory.
77-
78-
:param bytearray buffer: buffer containing the bytes to write
79-
:param int start: Index to start writing from
80-
:param int end: Index to read up to but not include
81-
:param bool stop: If true, output an I2C stop condition after the
82-
buffer is written
83-
"""
84-
self.spi.write(buffer, **kwargs)
85-
8654
def __enter__(self):
8755
while not self.spi.try_lock():
8856
pass
8957
self.spi.configure(baudrate=self.baudrate, polarity=self.polarity,
9058
phase=self.phase)
9159
self.chip_select.value = False
92-
return self
60+
return self.spi
9361

9462
def __exit__(self, *exc):
9563
self.chip_select.value = True

0 commit comments

Comments
 (0)