X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/blobdiff_plain/61d0fc3e10417302119c4ed479b31030dc17a064..84862c851a21caebff5194cbb7d94c9ff14ad132:/src/adafruit_blinka/microcontroller/nxp_lpc4330/spi.py diff --git a/src/adafruit_blinka/microcontroller/nxp_lpc4330/spi.py b/src/adafruit_blinka/microcontroller/nxp_lpc4330/spi.py index 55a439c..29f4734 100644 --- a/src/adafruit_blinka/microcontroller/nxp_lpc4330/spi.py +++ b/src/adafruit_blinka/microcontroller/nxp_lpc4330/spi.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries +# +# SPDX-License-Identifier: MIT """SPI Class for NXP LPC4330""" from greatfet import GreatFET @@ -11,6 +14,8 @@ class SPI: self._gf = GreatFET() self._frequency = None self.buffer_size = 255 + self._mode = 0 + self._spi = None self._presets = { 204000: (100, 9), 408000: (100, 4), @@ -28,7 +33,7 @@ class SPI: 102000000: (2, 0), } - # pylint: disable=too-many-arguments + # pylint: disable=too-many-arguments,unused-argument def init( self, baudrate=100000, @@ -67,8 +72,7 @@ class SPI: to the found value """ closest_preset = None - for frequency in self._presets: - preset = self._presets[frequency] + for frequency, preset in self._presets.items(): if self._frequency is None or abs(frequency - target_frequency) < abs( self._frequency - target_frequency ): @@ -91,7 +95,7 @@ class SPI: def readinto(self, buf, start=0, end=None, write_value=0): """Read data from SPI and into the buffer""" end = end if end else len(buf) - result = self._transmit([], end - start) + result = self._transmit([write_value] * (end - start), end - start) for i, b in enumerate(result): buf[start + i] = b @@ -108,8 +112,6 @@ class SPI: in_end = in_end if in_end else len(buffer_in) result = self._transmit(buffer_out[out_start:out_end], in_end - in_start) - for i, b in enumerate(result): - buf[start + i] = b for i, b in enumerate(result): buffer_in[in_start + i] = b