1 """SPI Class for Pico u2if"""
 
   2 from .pico_u2if import pico_u2if
 
   4 # pylint: disable=protected-access, no-self-use
 
   6     """Custom SPI Class for Pico u2if"""
 
  10     def __init__(self, clock, *, baudrate=100000):
 
  17             raise ValueError("No SPI port on specified pin.")
 
  19         self._frequency = baudrate
 
  20         pico_u2if.spi_set_port(self._index)
 
  21         pico_u2if.spi_configure(self._frequency)
 
  23     # pylint: disable=too-many-arguments,unused-argument
 
  35         """Initialize the Port"""
 
  36         self._frequency = baudrate
 
  37         pico_u2if.spi_set_port(self._index)
 
  38         pico_u2if.spi_configure(self._frequency)
 
  40     # pylint: enable=too-many-arguments
 
  44         """Return the current frequency"""
 
  45         return self._frequency
 
  47     def write(self, buf, start=0, end=None):
 
  48         """Write data from the buffer to SPI"""
 
  49         pico_u2if.spi_write(buf, start=start, end=end)
 
  51     def readinto(self, buf, start=0, end=None, write_value=0):
 
  52         """Read data from SPI and into the buffer"""
 
  53         pico_u2if.spi_readinto(buf, start=start, end=end, write_value=write_value)
 
  55     # pylint: disable=too-many-arguments
 
  57         self, buffer_out, buffer_in, out_start=0, out_end=None, in_start=0, in_end=None
 
  59         """Perform a half-duplex write from buffer_out and then
 
  60         read data into buffer_in
 
  62         pico_u2if.spi_write_readinto(
 
  71     # pylint: enable=too-many-arguments