1 # SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams for Adafruit Industries
 
   3 # SPDX-License-Identifier: MIT
 
   7 ================================================================================
 
  11 **Software and Dependencies:**
 
  14   https://github.com/adafruit/Adafruit_Blinka/releases
 
  16 * Author(s): Melissa LeBlanc-Williams
 
  23 __version__ = "0.0.0-auto.0"
 
  24 __repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git"
 
  28     """Manage updating a display over SPI four wire protocol in the background while
 
  29     Python code runs. It doesn’t handle display initialization.
 
  43         """Create a FourWire object associated with the given pins.
 
  45         The SPI bus and pins are then in use by the display until
 
  46         displayio.release_displays() is called even after a reload. (It does this so
 
  47         CircuitPython can use the display after your code is done.)
 
  48         So, the first time you initialize a display bus in code.py you should call
 
  49         :py:func`displayio.release_displays` first, otherwise it will error after the
 
  52         self._dc = digitalio.DigitalInOut(command)
 
  53         self._dc.switch_to_output(value=False)
 
  54         self._chip_select = digitalio.DigitalInOut(chip_select)
 
  55         self._chip_select.switch_to_output(value=True)
 
  56         self._frequency = baudrate
 
  57         self._polarity = polarity
 
  61             self._reset = digitalio.DigitalInOut(reset)
 
  62             self._reset.switch_to_output(value=True)
 
  71         self._chip_select.deinit()
 
  72         if self._reset is not None:
 
  76         """Performs a hardware reset via the reset pin.
 
  77         Raises an exception if called when no reset pin is available.
 
  79         if self._reset is not None:
 
  80             self._reset.value = False
 
  82             self._reset.value = True
 
  85     def send(self, is_command, data, *, toggle_every_byte=False):
 
  86         """Sends the given command value followed by the full set of data. Display state,
 
  87         such as vertical scroll, set via ``send`` may or may not be reset once the code is
 
  90         self._dc.value = not is_command
 
  93                 self._spi.write(bytes([byte]))
 
  94                 self._chip_select.value = True
 
  96                 self._chip_select.value = False
 
 100     def begin_transaction(self):
 
 101         """Begin the SPI transaction by locking, configuring, and setting Chip Select"""
 
 102         while not self._spi.try_lock():
 
 105             baudrate=self._frequency, polarity=self._polarity, phase=self._phase
 
 107         self._chip_select.value = False
 
 109     def end_transaction(self):
 
 110         """End the SPI transaction by unlocking and setting Chip Select"""
 
 111         self._chip_select.value = True