1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
3 # SPDX-License-Identifier: MIT
4 """SPI Class for Generic MicroPython"""
5 from machine import SPI as _SPI
8 # pylint: disable=protected-access, no-self-use
10 """SPI Class for Generic MicroPython"""
15 def __init__(self, portId, baudrate=100000):
16 self._frequency = baudrate
17 self._spi = _SPI(portId)
19 # pylint: disable=too-many-arguments,unused-argument
28 """Initialize the Port"""
29 self._frequency = baudrate
39 # pylint: enable=too-many-arguments
43 """Return the current frequency"""
44 return self._frequency
46 def write(self, buf, start=0, end=None):
47 """Write data from the buffer to SPI"""
50 def readinto(self, buf, start=0, end=None, write_value=0):
51 """Read data from SPI and into the buffer"""
52 self._spi.readinto(buf)
54 # pylint: disable=too-many-arguments
56 self, buffer_out, buffer_in, out_start=0, out_end=None, in_start=0, in_end=None
58 """Perform a half-duplex write from buffer_out and then
59 read data into buffer_in
61 self._spi.write_readinto(
70 # pylint: enable=too-many-arguments