1 # SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams for Adafruit Industries
2 # SPDX-FileCopyrightText: 2020 Erik Tollerud
3 # SPDX-FileCopyrightText: 2021 Jim Morris
4 # SPDX-FileCopyrightText: 2021 James Carr
6 # SPDX-License-Identifier: MIT
10 ================================================================================
14 **Software and Dependencies:**
17 https://github.com/adafruit/Adafruit_Blinka/releases
19 * Author(s): Melissa LeBlanc-Williams, Erik Tollerud, James Carr
23 __version__ = "0.0.0-auto.0"
24 __repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git"
30 import microcontroller
33 from typing import Optional
37 from _typing import ReadableBuffer
43 """Manage updating a display over I2C in the background while Python code runs.
44 It doesn’t handle display initialization.
52 reset: Optional[microcontroller.Pin] = None
54 """Create a I2CDisplay object associated with the given I2C bus and reset pin.
56 The I2C bus and pins are then in use by the display until displayio.release_displays() is
57 called even after a reload. (It does this so CircuitPython can use the display after your
58 code is done.) So, the first time you initialize a display bus in code.py you should call
59 :py:func`displayio.release_displays` first, otherwise it will error after the first
64 self._reset = digitalio.DigitalInOut(reset)
65 self._reset.switch_to_output(value=True)
69 self._dev_addr = device_address
74 if self._reset is not None:
77 def reset(self) -> None:
79 Performs a hardware reset via the reset pin if one is present.
82 if self._reset is None:
85 self._reset.value = False
87 self._reset.value = True
89 def begin_transaction(self) -> None:
91 Lock the bus before sending data.
93 while not self._i2c.try_lock():
96 def send(self, command: bool, data: ReadableBuffer) -> None:
98 Sends the given command value followed by the full set of data. Display state,
99 such as vertical scroll, set via ``send`` may or may not be reset once the code is
106 command_bytes = bytearray(n * 2)
108 command_bytes[2 * i] = 0x80
109 command_bytes[2 * i + 1] = data[i]
111 self._i2c.writeto(self._dev_addr, buffer=command_bytes, stop=True)
114 data_bytes = bytearray(len(data) + 1)
116 data_bytes[1:] = data
117 self._i2c.writeto(self._dev_addr, buffer=data_bytes, stop=True)
119 def end_transaction(self) -> None:
121 Release the bus after sending data.