+ # NOTE: we have to have a toggle_every_byte parameter, which we ignore,
+ # because Display._write() sets it regardless of bus type.
+
+ if command:
+ n = len(data)
+ if n > 0:
+ command_bytes = bytearray(n * 2)
+ for i in range(n):
+ command_bytes[2 * i] = 0x80
+ command_bytes[2 * i + 1] = data[i]
+
+ self._i2c.writeto(self._dev_addr, buffer=command_bytes, stop=True)
+
+ else:
+ data_bytes = bytearray(len(data) + 1)
+ data_bytes[0] = 0x40
+ data_bytes[1:] = data
+ self._i2c.writeto(self._dev_addr, buffer=data_bytes, stop=True)
+
+ def end_transaction(self) -> None:
+ """
+ Release the bus after sending data.
+ """
+ self._i2c.unlock()