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
7 # pylint: disable=protected-access, no-self-use
9 """SPI Class for Generic MicroPython"""
14 def __init__(self, portId, baudrate=100000):
15 self._frequency = baudrate
16 self._spi = _SPI(portId)
18 # pylint: disable=too-many-arguments,unused-argument
27 """Initialize the Port"""
28 self._frequency = baudrate
38 # pylint: enable=too-many-arguments
42 """Return the current frequency"""
43 return self._frequency
45 def write(self, buf, start=0, end=None):
46 """Write data from the buffer to SPI"""
49 def readinto(self, buf, start=0, end=None, write_value=0):
50 """Read data from SPI and into the buffer"""
51 self._spi.readinto(buf)
53 # pylint: disable=too-many-arguments
55 self, buffer_out, buffer_in, out_start=0, out_end=None, in_start=0, in_end=None
57 """Perform a half-duplex write from buffer_out and then
58 read data into buffer_in
60 self._spi.write_readinto(
69 # pylint: enable=too-many-arguments