From 55668d025bdd97b12db2d67ea9a99e6ab9f534fd Mon Sep 17 00:00:00 2001 From: Mikey Sklar Date: Sun, 27 Oct 2024 10:25:32 -0700 Subject: [PATCH 1/9] added ssd1680z 2.13 eink bonnet --- adafruit_epd/ssd1680z.py | 208 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 adafruit_epd/ssd1680z.py diff --git a/adafruit_epd/ssd1680z.py b/adafruit_epd/ssd1680z.py new file mode 100644 index 0000000..a2cec80 --- /dev/null +++ b/adafruit_epd/ssd1680z.py @@ -0,0 +1,208 @@ +# SPDX-License-Identifier: MIT + +""" +`adafruit_epd.ssd1680z` - Adafruit SSD1680Z - ePaper display driver +==================================================================================== +CircuitPython driver for Adafruit SSD1680Z display breakouts +* Author(s): Mikey Sklar Melissa LeBlanc-Williams +""" + +import time +from micropython import const +import adafruit_framebuf +from adafruit_epd.epd import Adafruit_EPD + +try: + """Needed for type annotations""" + import typing # pylint: disable=unused-import + from typing_extensions import Literal + from busio import SPI + from digitalio import DigitalInOut + +except ImportError: + pass + +__version__ = "2.12.3" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" + +_SSD1680Z_DRIVER_CONTROL = const(0x01) +_SSD1680Z_GATE_VOLTAGE = const(0x03) +_SSD1680Z_SOURCE_VOLTAGE = const(0x04) +_SSD1680Z_INIT_SETTING = const(0x08) +_SSD1680Z_INIT_WRITE_REG = const(0x09) +_SSD1680Z_INIT_READ_REG = const(0x0A) +_SSD1680Z_BOOSTER_SOFT_START = const(0x0C) +_SSD1680Z_DEEP_SLEEP = const(0x10) +_SSD1680Z_DATA_MODE = const(0x11) +_SSD1680Z_SW_RESET = const(0x12) +_SSD1680Z_HV_DETECT = const(0x14) +_SSD1680Z_VCI_DETECT = const(0x15) +_SSD1680Z_TEMP_CONTROL = const(0x18) +_SSD1680Z_TEMP_WRITE = const(0x1A) +_SSD1680Z_TEMP_READ = const(0x1B) +_SSD1680Z_EXTTEMP_WRITE = const(0x1C) +_SSD1680Z_MASTER_ACTIVATE = const(0x20) +_SSD1680Z_DISP_CTRL1 = const(0x21) +_SSD1680Z_DISP_CTRL2 = const(0x22) +_SSD1680Z_WRITE_BWRAM = const(0x24) +_SSD1680Z_WRITE_REDRAM = const(0x26) +_SSD1680Z_READ_RAM = const(0x27) +_SSD1680Z_VCOM_SENSE = const(0x28) +_SSD1680Z_VCOM_DURATION = const(0x29) +_SSD1680Z_WRITE_VCOM_OTP = const(0x2A) +_SSD1680Z_WRITE_VCOM_CTRL = const(0x2B) +_SSD1680Z_WRITE_VCOM_REG = const(0x2C) +_SSD1680Z_READ_OTP = const(0x2D) +_SSD1680Z_READ_USERID = const(0x2E) +_SSD1680Z_READ_STATUS = const(0x2F) +_SSD1680Z_WRITE_WS_OTP = const(0x30) +_SSD1680Z_LOAD_WS_OTP = const(0x31) +_SSD1680Z_WRITE_LUT = const(0x32) +_SSD1680Z_CRC_CALC = const(0x34) +_SSD1680Z_CRC_READ = const(0x35) +_SSD1680Z_PROG_OTP = const(0x36) +_SSD1680Z_WRITE_DISPLAY_OPT = const(0x37) +_SSD1680Z_WRITE_USERID = const(0x38) +_SSD1680Z_OTP_PROGMODE = const(0x39) +_SSD1680Z_WRITE_BORDER = const(0x3C) +_SSD1680Z_END_OPTION = const(0x3F) +_SSD1680Z_SET_RAMXPOS = const(0x44) +_SSD1680Z_SET_RAMYPOS = const(0x45) +_SSD1680Z_AUTOWRITE_RED = const(0x46) +_SSD1680Z_AUTOWRITE_BW = const(0x47) +_SSD1680Z_SET_RAMXCOUNT = const(0x4E) +_SSD1680Z_SET_RAMYCOUNT = const(0x4F) +_SSD1680Z_NOP = const(0xFF) + + +class Adafruit_SSD1680Z(Adafruit_EPD): + """driver class for Adafruit SSD1680Z ePaper display breakouts""" + + # pylint: disable=too-many-arguments + def __init__( + self, + width: int, + height: int, + spi: SPI, + *, + cs_pin: DigitalInOut, + dc_pin: DigitalInOut, + sramcs_pin: DigitalInOut, + rst_pin: DigitalInOut, + busy_pin: DigitalInOut + ) -> None: + super().__init__( + width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin + ) + + stride = width + if stride % 8 != 0: + stride += 8 - stride % 8 + + self._buffer1_size = int(stride * height / 8) + self._buffer2_size = self._buffer1_size + + if sramcs_pin: + self._buffer1 = self.sram.get_view(0) + self._buffer2 = self.sram.get_view(self._buffer1_size) + else: + self._buffer1 = bytearray(self._buffer1_size) + self._buffer2 = bytearray(self._buffer2_size) + + self._framebuf1 = adafruit_framebuf.FrameBuffer( + self._buffer1, + width, + height, + stride=stride, + buf_format=adafruit_framebuf.MHMSB, + ) + self._framebuf2 = adafruit_framebuf.FrameBuffer( + self._buffer2, + width, + height, + stride=stride, + buf_format=adafruit_framebuf.MHMSB, + ) + self.set_black_buffer(0, True) + self.set_color_buffer(1, False) + # pylint: enable=too-many-arguments + + def begin(self, reset: bool = True) -> None: + """Begin communication with the display and set basic settings""" + if reset: + self.hardware_reset() + self.power_down() + + def busy_wait(self) -> None: + """Wait for display to be done with current task, either by polling the + busy pin, or pausing""" + if self._busy: + while self._busy.value: + time.sleep(0.01) + else: + time.sleep(0.5) + + def power_up(self) -> None: + """Power up the display and set basic settings for SSD1680Z""" + self.hardware_reset() + self.busy_wait() + + # Send a software reset command + self.command(_SSD1680Z_SW_RESET) + self.busy_wait() + + # Driver output control for SSD1680Z + self.command( + _SSD1680Z_DRIVER_CONTROL, + bytearray([self._height - 1, (self._height - 1) >> 8, 0x00]), + ) + + # Set data entry mode + self.command(_SSD1680Z_DATA_MODE, bytearray([0x03])) # Increment X and Y + + # Set RAM X and Y start/end positions + self.command(_SSD1680Z_SET_RAMXPOS, bytearray([0x00, (self._width // 8) - 1])) + self.command( + _SSD1680Z_SET_RAMYPOS, + bytearray([0x00, 0x00, self._height - 1, (self._height - 1) >> 8]), + ) + + # Set RAM X and Y count start + self.command(_SSD1680Z_SET_RAMXCOUNT, bytearray([0x00])) + self.command(_SSD1680Z_SET_RAMYCOUNT, bytearray([0x00, 0x00])) + + # Set border waveform control + self.command(_SSD1680Z_WRITE_BORDER, bytearray([0x80])) + + self.busy_wait() + + def power_down(self) -> None: + """Power down the display - required when not actively displaying!""" + self.command(_SSD1680Z_DEEP_SLEEP, bytearray([0x01])) + time.sleep(0.1) + + def update(self) -> None: + """Activate display update for SSD1680Z""" + self.command(_SSD1680Z_DISP_CTRL2, bytearray([0xF7])) # Full update + self.command(_SSD1680Z_MASTER_ACTIVATE) + self.busy_wait() + if not self._busy: + time.sleep(3) # Wait for update to complete + + def write_ram(self, index: int) -> int: + """Write to RAM for SSD1680Z.""" + if index == 0: + return self.command(_SSD1680Z_WRITE_BWRAM, end=False) + if index == 1: + return self.command(_SSD1680Z_WRITE_REDRAM, end=False) + raise RuntimeError("RAM index must be 0 or 1") + + def set_ram_address( + self, x: int, y: int + ) -> None: # pylint: disable=unused-argument, no-self-use + """Set the RAM address location, not used on this chipset but required by + the superclass""" + # Set RAM X address counter + self.command(_SSD1680Z_SET_RAMXCOUNT, bytearray([x + 1])) + # Set RAM Y address counter + self.command(_SSD1680Z_SET_RAMYCOUNT, bytearray([y, y >> 8])) From dbe8e89f6965a335eede5af28c6f54c59f90a34e Mon Sep 17 00:00:00 2001 From: Mikey Sklar Date: Sun, 27 Oct 2024 10:43:02 -0700 Subject: [PATCH 2/9] linting --- adafruit_epd/ssd1680z.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adafruit_epd/ssd1680z.py b/adafruit_epd/ssd1680z.py index a2cec80..f60d030 100644 --- a/adafruit_epd/ssd1680z.py +++ b/adafruit_epd/ssd1680z.py @@ -4,7 +4,7 @@ `adafruit_epd.ssd1680z` - Adafruit SSD1680Z - ePaper display driver ==================================================================================== CircuitPython driver for Adafruit SSD1680Z display breakouts -* Author(s): Mikey Sklar Melissa LeBlanc-Williams +* Author(s): Mikey Sklar Melissa LeBlanc-Williams """ import time @@ -15,7 +15,6 @@ try: """Needed for type annotations""" import typing # pylint: disable=unused-import - from typing_extensions import Literal from busio import SPI from digitalio import DigitalInOut From d17ab9ff0fe43d74ef7296900818a5ca5a6be6f2 Mon Sep 17 00:00:00 2001 From: Mikey Sklar Date: Sun, 27 Oct 2024 10:47:44 -0700 Subject: [PATCH 3/9] copyright text --- adafruit_epd/ssd1680z.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_epd/ssd1680z.py b/adafruit_epd/ssd1680z.py index f60d030..67887d4 100644 --- a/adafruit_epd/ssd1680z.py +++ b/adafruit_epd/ssd1680z.py @@ -1,5 +1,6 @@ +# SPDX-FileCopyrightText: 2018 Dean Miller for Adafruit Industries +# # SPDX-License-Identifier: MIT - """ `adafruit_epd.ssd1680z` - Adafruit SSD1680Z - ePaper display driver ==================================================================================== From 76814b02ac8416a69db247d7f77cacec0c63613f Mon Sep 17 00:00:00 2001 From: Mikey Sklar Date: Mon, 28 Oct 2024 12:02:43 -0700 Subject: [PATCH 4/9] 1680z sub-class dropped separate ssd1680z lib for a combined 1680 + 1680z. --- adafruit_epd/ssd1680.py | 232 ++++++++++++++------------------------- adafruit_epd/ssd1680z.py | 208 ----------------------------------- 2 files changed, 80 insertions(+), 360 deletions(-) delete mode 100644 adafruit_epd/ssd1680z.py diff --git a/adafruit_epd/ssd1680.py b/adafruit_epd/ssd1680.py index 790950e..203e8cf 100644 --- a/adafruit_epd/ssd1680.py +++ b/adafruit_epd/ssd1680.py @@ -6,97 +6,42 @@ `adafruit_epd.ssd1680` - Adafruit SSD1680 - ePaper display driver ==================================================================================== CircuitPython driver for Adafruit SSD1680 display breakouts -* Author(s): Melissa LeBlanc-Williams +* Author(s): Melissa LeBlanc-Williams Mikey Sklar """ - -import time from micropython import const import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +import time -try: - """Needed for type annotations""" - import typing # pylint: disable=unused-import - from typing_extensions import Literal - from busio import SPI - from digitalio import DigitalInOut - -except ImportError: - pass - -__version__ = "0.0.0+auto.0" -__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" - +# Define all SSD1680 constants _SSD1680_DRIVER_CONTROL = const(0x01) -_SSD1680_GATE_VOLTAGE = const(0x03) -_SSD1680_SOURCE_VOLTAGE = const(0x04) -_SSD1680_INIT_SETTING = const(0x08) -_SSD1680_INIT_WRITE_REG = const(0x09) -_SSD1680_INIT_READ_REG = const(0x0A) -_SSD1680_BOOSTER_SOFT_START = const(0x0C) -_SSD1680_DEEP_SLEEP = const(0x10) _SSD1680_DATA_MODE = const(0x11) _SSD1680_SW_RESET = const(0x12) -_SSD1680_HV_DETECT = const(0x14) -_SSD1680_VCI_DETECT = const(0x15) -_SSD1680_TEMP_CONTROL = const(0x18) -_SSD1680_TEMP_WRITE = const(0x1A) -_SSD1680_TEMP_READ = const(0x1B) -_SSD1680_EXTTEMP_WRITE = const(0x1C) -_SSD1680_MASTER_ACTIVATE = const(0x20) -_SSD1680_DISP_CTRL1 = const(0x21) -_SSD1680_DISP_CTRL2 = const(0x22) -_SSD1680_WRITE_BWRAM = const(0x24) -_SSD1680_WRITE_REDRAM = const(0x26) -_SSD1680_READ_RAM = const(0x27) -_SSD1680_VCOM_SENSE = const(0x28) -_SSD1680_VCOM_DURATION = const(0x29) -_SSD1680_WRITE_VCOM_OTP = const(0x2A) -_SSD1680_WRITE_VCOM_CTRL = const(0x2B) -_SSD1680_WRITE_VCOM_REG = const(0x2C) -_SSD1680_READ_OTP = const(0x2D) -_SSD1680_READ_USERID = const(0x2E) -_SSD1680_READ_STATUS = const(0x2F) -_SSD1680_WRITE_WS_OTP = const(0x30) -_SSD1680_LOAD_WS_OTP = const(0x31) -_SSD1680_WRITE_LUT = const(0x32) -_SSD1680_CRC_CALC = const(0x34) -_SSD1680_CRC_READ = const(0x35) -_SSD1680_PROG_OTP = const(0x36) -_SSD1680_WRITE_DISPLAY_OPT = const(0x37) -_SSD1680_WRITE_USERID = const(0x38) -_SSD1680_OTP_PROGMODE = const(0x39) -_SSD1680_WRITE_BORDER = const(0x3C) -_SSD1680_END_OPTION = const(0x3F) _SSD1680_SET_RAMXPOS = const(0x44) _SSD1680_SET_RAMYPOS = const(0x45) -_SSD1680_AUTOWRITE_RED = const(0x46) -_SSD1680_AUTOWRITE_BW = const(0x47) +_SSD1680_WRITE_BWRAM = const(0x24) +_SSD1680_WRITE_REDRAM = const(0x26) _SSD1680_SET_RAMXCOUNT = const(0x4E) _SSD1680_SET_RAMYCOUNT = const(0x4F) -_SSD1680_NOP = const(0xFF) - +_SSD1680_DISP_CTRL2 = const(0x22) +_SSD1680_MASTER_ACTIVATE = const(0x20) +_SSD1680_DEEP_SLEEP = const(0x10) class Adafruit_SSD1680(Adafruit_EPD): - """driver class for Adafruit SSD1680 ePaper display breakouts""" - - # pylint: disable=too-many-arguments - def __init__( - self, - width: int, - height: int, - spi: SPI, - *, - cs_pin: DigitalInOut, - dc_pin: DigitalInOut, - sramcs_pin: DigitalInOut, - rst_pin: DigitalInOut, - busy_pin: DigitalInOut - ) -> None: - super().__init__( - width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ) + """Driver for SSD1680 ePaper display, default driver.""" + + def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin): + super().__init__(width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin) + self.cs_pin = cs_pin + self.dc_pin = dc_pin + self.sramcs_pin = sramcs_pin + self.rst_pin = rst_pin + self.busy_pin = busy_pin + + self.initialize_buffers(width, height) + + def initialize_buffers(self, width, height): stride = width if stride % 8 != 0: stride += 8 - stride % 8 @@ -104,7 +49,7 @@ def __init__( self._buffer1_size = int(stride * height / 8) self._buffer2_size = self._buffer1_size - if sramcs_pin: + if self.sramcs_pin: self._buffer1 = self.sram.get_view(0) self._buffer2 = self.sram.get_view(self._buffer1_size) else: @@ -112,102 +57,85 @@ def __init__( self._buffer2 = bytearray(self._buffer2_size) self._framebuf1 = adafruit_framebuf.FrameBuffer( - self._buffer1, - width, - height, - stride=stride, - buf_format=adafruit_framebuf.MHMSB, + self._buffer1, width, height, buf_format=adafruit_framebuf.MHMSB ) self._framebuf2 = adafruit_framebuf.FrameBuffer( - self._buffer2, - width, - height, - stride=stride, - buf_format=adafruit_framebuf.MHMSB, + self._buffer2, width, height, buf_format=adafruit_framebuf.MHMSB ) self.set_black_buffer(0, True) self.set_color_buffer(1, False) - # pylint: enable=too-many-arguments - - def begin(self, reset: bool = True) -> None: - """Begin communication with the display and set basic settings""" - if reset: - self.hardware_reset() - self.power_down() - - def busy_wait(self) -> None: - """Wait for display to be done with current task, either by polling the - busy pin, or pausing""" - if self._busy: - while self._busy.value: + + def busy_wait(self): + """Wait for the display to complete its current task.""" + if self.busy_pin: + while self.busy_pin.value: time.sleep(0.01) else: time.sleep(0.5) - def power_up(self) -> None: - """Power up the display in preparation for writing RAM and updating""" + def power_up(self): + """Power up sequence for SSD1680.""" self.hardware_reset() self.busy_wait() self.command(_SSD1680_SW_RESET) self.busy_wait() - # driver output control - self.command( - _SSD1680_DRIVER_CONTROL, - bytearray([self._height - 1, (self._height - 1) >> 8, 0x00]), - ) - # data entry mode + + self.command(_SSD1680_DRIVER_CONTROL, bytearray([self._height - 1, (self._height - 1) >> 8, 0x00])) self.command(_SSD1680_DATA_MODE, bytearray([0x03])) + self.command(_SSD1680_SET_RAMXPOS, bytearray([0x01, 0x10])) + self.command(_SSD1680_SET_RAMYPOS, bytearray([0, 0, self._height - 1, (self._height - 1) >> 8])) - # Set voltages - self.command(_SSD1680_WRITE_VCOM_REG, bytearray([0x36])) - self.command(_SSD1680_GATE_VOLTAGE, bytearray([0x17])) - self.command(_SSD1680_SOURCE_VOLTAGE, bytearray([0x41, 0x00, 0x32])) + def write_ram(self, index): + """Write to RAM for SSD1680.""" + if index == 0: + return self.command(_SSD1680_WRITE_BWRAM, end=False) + elif index == 1: + return self.command(_SSD1680_WRITE_REDRAM, end=False) + else: + raise RuntimeError("RAM index must be 0 or 1") - # Set ram X start/end postion - self.command(_SSD1680_SET_RAMXPOS, bytearray([0x01, 0x10])) - # Set ram Y start/end postion - self.command( - _SSD1680_SET_RAMYPOS, - bytearray([0, 0, self._height - 1, (self._height - 1) >> 8]), - ) - # Set border waveform - self.command(_SSD1680_WRITE_BORDER, bytearray([0x05])) + def set_ram_address(self, x, y): + """Set RAM address location for SSD1680.""" + self.command(_SSD1680_SET_RAMXCOUNT, bytearray([x + 1])) + self.command(_SSD1680_SET_RAMYCOUNT, bytearray([y, y >> 8])) - # Set ram X count - self.command(_SSD1680_SET_RAMXCOUNT, bytearray([0x01])) - # Set ram Y count - self.command(_SSD1680_SET_RAMYCOUNT, bytearray([self._height - 1, 0])) + def update(self): + """Update the display from internal memory.""" + self.command(_SSD1680_DISP_CTRL2, bytearray([0xF4])) # Full update + self.command(_SSD1680_MASTER_ACTIVATE) self.busy_wait() + if not self.busy_pin: + time.sleep(3) # Wait for update to complete - def power_down(self) -> None: - """Power down the display - required when not actively displaying!""" + def power_down(self): + """Power down the display.""" self.command(_SSD1680_DEEP_SLEEP, bytearray([0x01])) time.sleep(0.1) - def update(self) -> None: - """Update the display from internal memory""" - self.command(_SSD1680_DISP_CTRL2, bytearray([0xF4])) - self.command(_SSD1680_MASTER_ACTIVATE) + +class Adafruit_SSD1680Z(Adafruit_SSD1680): + """Driver for SSD1680Z ePaper display, overriding SSD1680 settings.""" + + def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin): + super().__init__(width, height, spi, cs_pin=cs_pin, dc_pin=dc_pin, + sramcs_pin=sramcs_pin, rst_pin=rst_pin, busy_pin=busy_pin) + + def power_up(self): + """Power up sequence specifically for SSD1680Z.""" + self.hardware_reset() + self.busy_wait() + self.command(_SSD1680_SW_RESET) self.busy_wait() - if not self._busy: - time.sleep(3) # wait 3 seconds - def write_ram(self, index: Literal[0, 1]) -> int: - """Send the one byte command for starting the RAM write process. Returns - the byte read at the same time over SPI. index is the RAM buffer, can be - 0 or 1 for tri-color displays.""" - if index == 0: - return self.command(_SSD1680_WRITE_BWRAM, end=False) - if index == 1: - return self.command(_SSD1680_WRITE_REDRAM, end=False) - raise RuntimeError("RAM index must be 0 or 1") - - def set_ram_address( - self, x: int, y: int - ) -> None: # pylint: disable=unused-argument, no-self-use - """Set the RAM address location, not used on this chipset but required by - the superclass""" - # Set RAM X address counter - self.command(_SSD1680_SET_RAMXCOUNT, bytearray([x + 1])) - # Set RAM Y address counter - self.command(_SSD1680_SET_RAMYCOUNT, bytearray([y, y >> 8])) + self.command(_SSD1680_DRIVER_CONTROL, bytearray([self._height - 1, (self._height - 1) >> 8, 0x00])) + self.command(_SSD1680_DATA_MODE, bytearray([0x03])) + self.command(_SSD1680_SET_RAMXPOS, bytearray([0x00, (self._width // 8) - 1])) + self.command(_SSD1680_SET_RAMYPOS, bytearray([0x00, 0x00, self._height - 1, (self._height - 1) >> 8])) + + def update(self): + """Update the display specifically for SSD1680Z.""" + self.command(_SSD1680_DISP_CTRL2, bytearray([0xF7])) # Full update for SSD1680Z + self.command(_SSD1680_MASTER_ACTIVATE) + self.busy_wait() + if not self.busy_pin: + time.sleep(3) # Wait for update to complete diff --git a/adafruit_epd/ssd1680z.py b/adafruit_epd/ssd1680z.py deleted file mode 100644 index 67887d4..0000000 --- a/adafruit_epd/ssd1680z.py +++ /dev/null @@ -1,208 +0,0 @@ -# SPDX-FileCopyrightText: 2018 Dean Miller for Adafruit Industries -# -# SPDX-License-Identifier: MIT -""" -`adafruit_epd.ssd1680z` - Adafruit SSD1680Z - ePaper display driver -==================================================================================== -CircuitPython driver for Adafruit SSD1680Z display breakouts -* Author(s): Mikey Sklar Melissa LeBlanc-Williams -""" - -import time -from micropython import const -import adafruit_framebuf -from adafruit_epd.epd import Adafruit_EPD - -try: - """Needed for type annotations""" - import typing # pylint: disable=unused-import - from busio import SPI - from digitalio import DigitalInOut - -except ImportError: - pass - -__version__ = "2.12.3" -__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" - -_SSD1680Z_DRIVER_CONTROL = const(0x01) -_SSD1680Z_GATE_VOLTAGE = const(0x03) -_SSD1680Z_SOURCE_VOLTAGE = const(0x04) -_SSD1680Z_INIT_SETTING = const(0x08) -_SSD1680Z_INIT_WRITE_REG = const(0x09) -_SSD1680Z_INIT_READ_REG = const(0x0A) -_SSD1680Z_BOOSTER_SOFT_START = const(0x0C) -_SSD1680Z_DEEP_SLEEP = const(0x10) -_SSD1680Z_DATA_MODE = const(0x11) -_SSD1680Z_SW_RESET = const(0x12) -_SSD1680Z_HV_DETECT = const(0x14) -_SSD1680Z_VCI_DETECT = const(0x15) -_SSD1680Z_TEMP_CONTROL = const(0x18) -_SSD1680Z_TEMP_WRITE = const(0x1A) -_SSD1680Z_TEMP_READ = const(0x1B) -_SSD1680Z_EXTTEMP_WRITE = const(0x1C) -_SSD1680Z_MASTER_ACTIVATE = const(0x20) -_SSD1680Z_DISP_CTRL1 = const(0x21) -_SSD1680Z_DISP_CTRL2 = const(0x22) -_SSD1680Z_WRITE_BWRAM = const(0x24) -_SSD1680Z_WRITE_REDRAM = const(0x26) -_SSD1680Z_READ_RAM = const(0x27) -_SSD1680Z_VCOM_SENSE = const(0x28) -_SSD1680Z_VCOM_DURATION = const(0x29) -_SSD1680Z_WRITE_VCOM_OTP = const(0x2A) -_SSD1680Z_WRITE_VCOM_CTRL = const(0x2B) -_SSD1680Z_WRITE_VCOM_REG = const(0x2C) -_SSD1680Z_READ_OTP = const(0x2D) -_SSD1680Z_READ_USERID = const(0x2E) -_SSD1680Z_READ_STATUS = const(0x2F) -_SSD1680Z_WRITE_WS_OTP = const(0x30) -_SSD1680Z_LOAD_WS_OTP = const(0x31) -_SSD1680Z_WRITE_LUT = const(0x32) -_SSD1680Z_CRC_CALC = const(0x34) -_SSD1680Z_CRC_READ = const(0x35) -_SSD1680Z_PROG_OTP = const(0x36) -_SSD1680Z_WRITE_DISPLAY_OPT = const(0x37) -_SSD1680Z_WRITE_USERID = const(0x38) -_SSD1680Z_OTP_PROGMODE = const(0x39) -_SSD1680Z_WRITE_BORDER = const(0x3C) -_SSD1680Z_END_OPTION = const(0x3F) -_SSD1680Z_SET_RAMXPOS = const(0x44) -_SSD1680Z_SET_RAMYPOS = const(0x45) -_SSD1680Z_AUTOWRITE_RED = const(0x46) -_SSD1680Z_AUTOWRITE_BW = const(0x47) -_SSD1680Z_SET_RAMXCOUNT = const(0x4E) -_SSD1680Z_SET_RAMYCOUNT = const(0x4F) -_SSD1680Z_NOP = const(0xFF) - - -class Adafruit_SSD1680Z(Adafruit_EPD): - """driver class for Adafruit SSD1680Z ePaper display breakouts""" - - # pylint: disable=too-many-arguments - def __init__( - self, - width: int, - height: int, - spi: SPI, - *, - cs_pin: DigitalInOut, - dc_pin: DigitalInOut, - sramcs_pin: DigitalInOut, - rst_pin: DigitalInOut, - busy_pin: DigitalInOut - ) -> None: - super().__init__( - width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ) - - stride = width - if stride % 8 != 0: - stride += 8 - stride % 8 - - self._buffer1_size = int(stride * height / 8) - self._buffer2_size = self._buffer1_size - - if sramcs_pin: - self._buffer1 = self.sram.get_view(0) - self._buffer2 = self.sram.get_view(self._buffer1_size) - else: - self._buffer1 = bytearray(self._buffer1_size) - self._buffer2 = bytearray(self._buffer2_size) - - self._framebuf1 = adafruit_framebuf.FrameBuffer( - self._buffer1, - width, - height, - stride=stride, - buf_format=adafruit_framebuf.MHMSB, - ) - self._framebuf2 = adafruit_framebuf.FrameBuffer( - self._buffer2, - width, - height, - stride=stride, - buf_format=adafruit_framebuf.MHMSB, - ) - self.set_black_buffer(0, True) - self.set_color_buffer(1, False) - # pylint: enable=too-many-arguments - - def begin(self, reset: bool = True) -> None: - """Begin communication with the display and set basic settings""" - if reset: - self.hardware_reset() - self.power_down() - - def busy_wait(self) -> None: - """Wait for display to be done with current task, either by polling the - busy pin, or pausing""" - if self._busy: - while self._busy.value: - time.sleep(0.01) - else: - time.sleep(0.5) - - def power_up(self) -> None: - """Power up the display and set basic settings for SSD1680Z""" - self.hardware_reset() - self.busy_wait() - - # Send a software reset command - self.command(_SSD1680Z_SW_RESET) - self.busy_wait() - - # Driver output control for SSD1680Z - self.command( - _SSD1680Z_DRIVER_CONTROL, - bytearray([self._height - 1, (self._height - 1) >> 8, 0x00]), - ) - - # Set data entry mode - self.command(_SSD1680Z_DATA_MODE, bytearray([0x03])) # Increment X and Y - - # Set RAM X and Y start/end positions - self.command(_SSD1680Z_SET_RAMXPOS, bytearray([0x00, (self._width // 8) - 1])) - self.command( - _SSD1680Z_SET_RAMYPOS, - bytearray([0x00, 0x00, self._height - 1, (self._height - 1) >> 8]), - ) - - # Set RAM X and Y count start - self.command(_SSD1680Z_SET_RAMXCOUNT, bytearray([0x00])) - self.command(_SSD1680Z_SET_RAMYCOUNT, bytearray([0x00, 0x00])) - - # Set border waveform control - self.command(_SSD1680Z_WRITE_BORDER, bytearray([0x80])) - - self.busy_wait() - - def power_down(self) -> None: - """Power down the display - required when not actively displaying!""" - self.command(_SSD1680Z_DEEP_SLEEP, bytearray([0x01])) - time.sleep(0.1) - - def update(self) -> None: - """Activate display update for SSD1680Z""" - self.command(_SSD1680Z_DISP_CTRL2, bytearray([0xF7])) # Full update - self.command(_SSD1680Z_MASTER_ACTIVATE) - self.busy_wait() - if not self._busy: - time.sleep(3) # Wait for update to complete - - def write_ram(self, index: int) -> int: - """Write to RAM for SSD1680Z.""" - if index == 0: - return self.command(_SSD1680Z_WRITE_BWRAM, end=False) - if index == 1: - return self.command(_SSD1680Z_WRITE_REDRAM, end=False) - raise RuntimeError("RAM index must be 0 or 1") - - def set_ram_address( - self, x: int, y: int - ) -> None: # pylint: disable=unused-argument, no-self-use - """Set the RAM address location, not used on this chipset but required by - the superclass""" - # Set RAM X address counter - self.command(_SSD1680Z_SET_RAMXCOUNT, bytearray([x + 1])) - # Set RAM Y address counter - self.command(_SSD1680Z_SET_RAMYCOUNT, bytearray([y, y >> 8])) From ae5da03de47f52375797258b7423d6029db9f130 Mon Sep 17 00:00:00 2001 From: Mikey Sklar Date: Mon, 28 Oct 2024 12:40:38 -0700 Subject: [PATCH 5/9] linting --- adafruit_epd/ssd1680.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/adafruit_epd/ssd1680.py b/adafruit_epd/ssd1680.py index 203e8cf..b40fed0 100644 --- a/adafruit_epd/ssd1680.py +++ b/adafruit_epd/ssd1680.py @@ -8,10 +8,10 @@ CircuitPython driver for Adafruit SSD1680 display breakouts * Author(s): Melissa LeBlanc-Williams Mikey Sklar """ +import time from micropython import const import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD -import time # Define all SSD1680 constants _SSD1680_DRIVER_CONTROL = const(0x01) @@ -30,7 +30,9 @@ class Adafruit_SSD1680(Adafruit_EPD): """Driver for SSD1680 ePaper display, default driver.""" + # pylint: disable=too-many-arguments def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin): + # Call parent class's __init__ to initialize sram and other attributes super().__init__(width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin) self.cs_pin = cs_pin @@ -40,8 +42,10 @@ def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, b self.busy_pin = busy_pin self.initialize_buffers(width, height) + # pylint: enable=too-many-arguments def initialize_buffers(self, width, height): + """Initialize width height stride buffers""" stride = width if stride % 8 != 0: stride += 8 - stride % 8 @@ -80,16 +84,22 @@ def power_up(self): self.command(_SSD1680_SW_RESET) self.busy_wait() - self.command(_SSD1680_DRIVER_CONTROL, bytearray([self._height - 1, (self._height - 1) >> 8, 0x00])) + self.command( + _SSD1680_DRIVER_CONTROL, + bytearray([self._height - 1, (self._height - 1) >> 8, 0x00]), + ) self.command(_SSD1680_DATA_MODE, bytearray([0x03])) self.command(_SSD1680_SET_RAMXPOS, bytearray([0x01, 0x10])) - self.command(_SSD1680_SET_RAMYPOS, bytearray([0, 0, self._height - 1, (self._height - 1) >> 8])) + self.command( + _SSD1680_SET_RAMYPOS, + bytearray([0, 0, self._height - 1, (self._height - 1) >> 8]), + ) def write_ram(self, index): """Write to RAM for SSD1680.""" if index == 0: return self.command(_SSD1680_WRITE_BWRAM, end=False) - elif index == 1: + if index == 1: return self.command(_SSD1680_WRITE_REDRAM, end=False) else: raise RuntimeError("RAM index must be 0 or 1") @@ -112,13 +122,15 @@ def power_down(self): self.command(_SSD1680_DEEP_SLEEP, bytearray([0x01])) time.sleep(0.1) - class Adafruit_SSD1680Z(Adafruit_SSD1680): """Driver for SSD1680Z ePaper display, overriding SSD1680 settings.""" + # pylint: disable=too-many-arguments def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin): + # Call the parent class's __init__() to initialize attributes super().__init__(width, height, spi, cs_pin=cs_pin, dc_pin=dc_pin, sramcs_pin=sramcs_pin, rst_pin=rst_pin, busy_pin=busy_pin) + # pylint: enable=too-many-arguments def power_up(self): """Power up sequence specifically for SSD1680Z.""" @@ -127,10 +139,16 @@ def power_up(self): self.command(_SSD1680_SW_RESET) self.busy_wait() - self.command(_SSD1680_DRIVER_CONTROL, bytearray([self._height - 1, (self._height - 1) >> 8, 0x00])) + self.command( + _SSD1680_DRIVER_CONTROL, + bytearray([self._height - 1, (self._height - 1) >> 8, 0x00]), + ) self.command(_SSD1680_DATA_MODE, bytearray([0x03])) self.command(_SSD1680_SET_RAMXPOS, bytearray([0x00, (self._width // 8) - 1])) - self.command(_SSD1680_SET_RAMYPOS, bytearray([0x00, 0x00, self._height - 1, (self._height - 1) >> 8])) + self.command( + _SSD1680_SET_RAMYPOS, + bytearray([0x00, 0x00, self._height - 1, (self._height - 1) >> 8]), + ) def update(self): """Update the display specifically for SSD1680Z.""" From 723d5618a8e11af01bf3f2bb95a8896c5bd36c26 Mon Sep 17 00:00:00 2001 From: Mikey Sklar Date: Mon, 28 Oct 2024 12:55:02 -0700 Subject: [PATCH 6/9] more linting... --- adafruit_epd/ssd1680.py | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/adafruit_epd/ssd1680.py b/adafruit_epd/ssd1680.py index b40fed0..0eadb11 100644 --- a/adafruit_epd/ssd1680.py +++ b/adafruit_epd/ssd1680.py @@ -30,10 +30,14 @@ class Adafruit_SSD1680(Adafruit_EPD): """Driver for SSD1680 ePaper display, default driver.""" - # pylint: disable=too-many-arguments - def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin): + # pylint: disable=too-many-arguments, useless-parent-delegation + def __init__( + self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin + ): # Call parent class's __init__ to initialize sram and other attributes - super().__init__(width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin) + super().__init__( + width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin + ) self.cs_pin = cs_pin self.dc_pin = dc_pin @@ -42,7 +46,8 @@ def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, b self.busy_pin = busy_pin self.initialize_buffers(width, height) - # pylint: enable=too-many-arguments + # pylint: enable=too-many-arguments, useless-parent-delegation + def initialize_buffers(self, width, height): """Initialize width height stride buffers""" @@ -101,8 +106,9 @@ def write_ram(self, index): return self.command(_SSD1680_WRITE_BWRAM, end=False) if index == 1: return self.command(_SSD1680_WRITE_REDRAM, end=False) - else: - raise RuntimeError("RAM index must be 0 or 1") + + # Raise an error if the index is not 0 or 1 + raise RuntimeError("RAM index must be 0 or 1") def set_ram_address(self, x, y): """Set RAM address location for SSD1680.""" @@ -125,12 +131,22 @@ def power_down(self): class Adafruit_SSD1680Z(Adafruit_SSD1680): """Driver for SSD1680Z ePaper display, overriding SSD1680 settings.""" - # pylint: disable=too-many-arguments - def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin): + # pylint: disable=too-many-arguments, useless-parent-delegation + def __init__( + self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin + ): # Call the parent class's __init__() to initialize attributes - super().__init__(width, height, spi, cs_pin=cs_pin, dc_pin=dc_pin, - sramcs_pin=sramcs_pin, rst_pin=rst_pin, busy_pin=busy_pin) - # pylint: enable=too-many-arguments + super().__init__( + width, + height, + spi, + cs_pin=cs_pin, + dc_pin=dc_pin, + sramcs_pin=sramcs_pin, + rst_pin=rst_pin, + busy_pin=busy_pin, + ) + # pylint: enable=too-many-arguments, useless-parent-delegation def power_up(self): """Power up sequence specifically for SSD1680Z.""" From 9fa515e68fad5d0c445f39645258302debddea9e Mon Sep 17 00:00:00 2001 From: Mikey Sklar Date: Mon, 28 Oct 2024 13:00:44 -0700 Subject: [PATCH 7/9] whitespace --- adafruit_epd/ssd1680.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/adafruit_epd/ssd1680.py b/adafruit_epd/ssd1680.py index 0eadb11..df946c6 100644 --- a/adafruit_epd/ssd1680.py +++ b/adafruit_epd/ssd1680.py @@ -27,6 +27,7 @@ _SSD1680_MASTER_ACTIVATE = const(0x20) _SSD1680_DEEP_SLEEP = const(0x10) + class Adafruit_SSD1680(Adafruit_EPD): """Driver for SSD1680 ePaper display, default driver.""" @@ -46,9 +47,11 @@ def __init__( self.busy_pin = busy_pin self.initialize_buffers(width, height) + # pylint: enable=too-many-arguments, useless-parent-delegation + def initialize_buffers(self, width, height): """Initialize width height stride buffers""" stride = width @@ -128,6 +131,7 @@ def power_down(self): self.command(_SSD1680_DEEP_SLEEP, bytearray([0x01])) time.sleep(0.1) + class Adafruit_SSD1680Z(Adafruit_SSD1680): """Driver for SSD1680Z ePaper display, overriding SSD1680 settings.""" @@ -146,7 +150,8 @@ def __init__( rst_pin=rst_pin, busy_pin=busy_pin, ) - # pylint: enable=too-many-arguments, useless-parent-delegation + + # pylint: enable=too-many-arguments, useless-parent-delegation def power_up(self): """Power up sequence specifically for SSD1680Z.""" From a3b3346b4ea2dc1fc43745212d6e260684ad010e Mon Sep 17 00:00:00 2001 From: Mikey Sklar Date: Mon, 28 Oct 2024 13:04:01 -0700 Subject: [PATCH 8/9] spaces --- adafruit_epd/ssd1680.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/adafruit_epd/ssd1680.py b/adafruit_epd/ssd1680.py index df946c6..79cc16a 100644 --- a/adafruit_epd/ssd1680.py +++ b/adafruit_epd/ssd1680.py @@ -50,8 +50,6 @@ def __init__( # pylint: enable=too-many-arguments, useless-parent-delegation - - def initialize_buffers(self, width, height): """Initialize width height stride buffers""" stride = width @@ -151,7 +149,7 @@ def __init__( busy_pin=busy_pin, ) - # pylint: enable=too-many-arguments, useless-parent-delegation + # pylint: enable=too-many-arguments, useless-parent-delegation def power_up(self): """Power up sequence specifically for SSD1680Z.""" From 29cfedcfe467671d53287869c176cb8cae938399 Mon Sep 17 00:00:00 2001 From: Mikey Sklar Date: Wed, 30 Oct 2024 10:21:43 -0700 Subject: [PATCH 9/9] back to original plus 1680Z subclass at bottom --- adafruit_epd/ssd1680.py | 190 +++++++++++++++++++++++++++++----------- 1 file changed, 137 insertions(+), 53 deletions(-) diff --git a/adafruit_epd/ssd1680.py b/adafruit_epd/ssd1680.py index 79cc16a..ebcf68c 100644 --- a/adafruit_epd/ssd1680.py +++ b/adafruit_epd/ssd1680.py @@ -6,52 +6,97 @@ `adafruit_epd.ssd1680` - Adafruit SSD1680 - ePaper display driver ==================================================================================== CircuitPython driver for Adafruit SSD1680 display breakouts -* Author(s): Melissa LeBlanc-Williams Mikey Sklar +* Author(s): Melissa LeBlanc-Williams """ + import time from micropython import const import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD -# Define all SSD1680 constants +try: + """Needed for type annotations""" + import typing # pylint: disable=unused-import + from typing_extensions import Literal + from busio import SPI + from digitalio import DigitalInOut + +except ImportError: + pass + +__version__ = "0.0.0+auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" + _SSD1680_DRIVER_CONTROL = const(0x01) +_SSD1680_GATE_VOLTAGE = const(0x03) +_SSD1680_SOURCE_VOLTAGE = const(0x04) +_SSD1680_INIT_SETTING = const(0x08) +_SSD1680_INIT_WRITE_REG = const(0x09) +_SSD1680_INIT_READ_REG = const(0x0A) +_SSD1680_BOOSTER_SOFT_START = const(0x0C) +_SSD1680_DEEP_SLEEP = const(0x10) _SSD1680_DATA_MODE = const(0x11) _SSD1680_SW_RESET = const(0x12) -_SSD1680_SET_RAMXPOS = const(0x44) -_SSD1680_SET_RAMYPOS = const(0x45) +_SSD1680_HV_DETECT = const(0x14) +_SSD1680_VCI_DETECT = const(0x15) +_SSD1680_TEMP_CONTROL = const(0x18) +_SSD1680_TEMP_WRITE = const(0x1A) +_SSD1680_TEMP_READ = const(0x1B) +_SSD1680_EXTTEMP_WRITE = const(0x1C) +_SSD1680_MASTER_ACTIVATE = const(0x20) +_SSD1680_DISP_CTRL1 = const(0x21) +_SSD1680_DISP_CTRL2 = const(0x22) _SSD1680_WRITE_BWRAM = const(0x24) _SSD1680_WRITE_REDRAM = const(0x26) +_SSD1680_READ_RAM = const(0x27) +_SSD1680_VCOM_SENSE = const(0x28) +_SSD1680_VCOM_DURATION = const(0x29) +_SSD1680_WRITE_VCOM_OTP = const(0x2A) +_SSD1680_WRITE_VCOM_CTRL = const(0x2B) +_SSD1680_WRITE_VCOM_REG = const(0x2C) +_SSD1680_READ_OTP = const(0x2D) +_SSD1680_READ_USERID = const(0x2E) +_SSD1680_READ_STATUS = const(0x2F) +_SSD1680_WRITE_WS_OTP = const(0x30) +_SSD1680_LOAD_WS_OTP = const(0x31) +_SSD1680_WRITE_LUT = const(0x32) +_SSD1680_CRC_CALC = const(0x34) +_SSD1680_CRC_READ = const(0x35) +_SSD1680_PROG_OTP = const(0x36) +_SSD1680_WRITE_DISPLAY_OPT = const(0x37) +_SSD1680_WRITE_USERID = const(0x38) +_SSD1680_OTP_PROGMODE = const(0x39) +_SSD1680_WRITE_BORDER = const(0x3C) +_SSD1680_END_OPTION = const(0x3F) +_SSD1680_SET_RAMXPOS = const(0x44) +_SSD1680_SET_RAMYPOS = const(0x45) +_SSD1680_AUTOWRITE_RED = const(0x46) +_SSD1680_AUTOWRITE_BW = const(0x47) _SSD1680_SET_RAMXCOUNT = const(0x4E) _SSD1680_SET_RAMYCOUNT = const(0x4F) -_SSD1680_DISP_CTRL2 = const(0x22) -_SSD1680_MASTER_ACTIVATE = const(0x20) -_SSD1680_DEEP_SLEEP = const(0x10) +_SSD1680_NOP = const(0xFF) class Adafruit_SSD1680(Adafruit_EPD): - """Driver for SSD1680 ePaper display, default driver.""" + """driver class for Adafruit SSD1680 ePaper display breakouts""" - # pylint: disable=too-many-arguments, useless-parent-delegation + # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): - # Call parent class's __init__ to initialize sram and other attributes + self, + width: int, + height: int, + spi: SPI, + *, + cs_pin: DigitalInOut, + dc_pin: DigitalInOut, + sramcs_pin: DigitalInOut, + rst_pin: DigitalInOut, + busy_pin: DigitalInOut + ) -> None: super().__init__( width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin ) - self.cs_pin = cs_pin - self.dc_pin = dc_pin - self.sramcs_pin = sramcs_pin - self.rst_pin = rst_pin - self.busy_pin = busy_pin - - self.initialize_buffers(width, height) - - # pylint: enable=too-many-arguments, useless-parent-delegation - - def initialize_buffers(self, width, height): - """Initialize width height stride buffers""" stride = width if stride % 8 != 0: stride += 8 - stride % 8 @@ -59,7 +104,7 @@ def initialize_buffers(self, width, height): self._buffer1_size = int(stride * height / 8) self._buffer2_size = self._buffer1_size - if self.sramcs_pin: + if sramcs_pin: self._buffer1 = self.sram.get_view(0) self._buffer2 = self.sram.get_view(self._buffer1_size) else: @@ -67,68 +112,106 @@ def initialize_buffers(self, width, height): self._buffer2 = bytearray(self._buffer2_size) self._framebuf1 = adafruit_framebuf.FrameBuffer( - self._buffer1, width, height, buf_format=adafruit_framebuf.MHMSB + self._buffer1, + width, + height, + stride=stride, + buf_format=adafruit_framebuf.MHMSB, ) self._framebuf2 = adafruit_framebuf.FrameBuffer( - self._buffer2, width, height, buf_format=adafruit_framebuf.MHMSB + self._buffer2, + width, + height, + stride=stride, + buf_format=adafruit_framebuf.MHMSB, ) self.set_black_buffer(0, True) self.set_color_buffer(1, False) + # pylint: enable=too-many-arguments + + def begin(self, reset: bool = True) -> None: + """Begin communication with the display and set basic settings""" + if reset: + self.hardware_reset() + self.power_down() - def busy_wait(self): - """Wait for the display to complete its current task.""" - if self.busy_pin: - while self.busy_pin.value: + def busy_wait(self) -> None: + """Wait for display to be done with current task, either by polling the + busy pin, or pausing""" + if self._busy: + while self._busy.value: time.sleep(0.01) else: time.sleep(0.5) - def power_up(self): - """Power up sequence for SSD1680.""" + def power_up(self) -> None: + """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() self.busy_wait() self.command(_SSD1680_SW_RESET) self.busy_wait() - + # driver output control self.command( _SSD1680_DRIVER_CONTROL, bytearray([self._height - 1, (self._height - 1) >> 8, 0x00]), ) + # data entry mode self.command(_SSD1680_DATA_MODE, bytearray([0x03])) + + # Set voltages + self.command(_SSD1680_WRITE_VCOM_REG, bytearray([0x36])) + self.command(_SSD1680_GATE_VOLTAGE, bytearray([0x17])) + self.command(_SSD1680_SOURCE_VOLTAGE, bytearray([0x41, 0x00, 0x32])) + + # Set ram X start/end postion self.command(_SSD1680_SET_RAMXPOS, bytearray([0x01, 0x10])) + # Set ram Y start/end postion self.command( _SSD1680_SET_RAMYPOS, bytearray([0, 0, self._height - 1, (self._height - 1) >> 8]), ) + # Set border waveform + self.command(_SSD1680_WRITE_BORDER, bytearray([0x05])) + + # Set ram X count + self.command(_SSD1680_SET_RAMXCOUNT, bytearray([0x01])) + # Set ram Y count + self.command(_SSD1680_SET_RAMYCOUNT, bytearray([self._height - 1, 0])) + self.busy_wait() + + def power_down(self) -> None: + """Power down the display - required when not actively displaying!""" + self.command(_SSD1680_DEEP_SLEEP, bytearray([0x01])) + time.sleep(0.1) + + def update(self) -> None: + """Update the display from internal memory""" + self.command(_SSD1680_DISP_CTRL2, bytearray([0xF4])) + self.command(_SSD1680_MASTER_ACTIVATE) + self.busy_wait() + if not self._busy: + time.sleep(3) # wait 3 seconds - def write_ram(self, index): - """Write to RAM for SSD1680.""" + def write_ram(self, index: Literal[0, 1]) -> int: + """Send the one byte command for starting the RAM write process. Returns + the byte read at the same time over SPI. index is the RAM buffer, can be + 0 or 1 for tri-color displays.""" if index == 0: return self.command(_SSD1680_WRITE_BWRAM, end=False) if index == 1: return self.command(_SSD1680_WRITE_REDRAM, end=False) - - # Raise an error if the index is not 0 or 1 raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): - """Set RAM address location for SSD1680.""" + def set_ram_address( + self, x: int, y: int + ) -> None: # pylint: disable=unused-argument, no-self-use + """Set the RAM address location, not used on this chipset but required by + the superclass""" + # Set RAM X address counter self.command(_SSD1680_SET_RAMXCOUNT, bytearray([x + 1])) + # Set RAM Y address counter self.command(_SSD1680_SET_RAMYCOUNT, bytearray([y, y >> 8])) - def update(self): - """Update the display from internal memory.""" - self.command(_SSD1680_DISP_CTRL2, bytearray([0xF4])) # Full update - self.command(_SSD1680_MASTER_ACTIVATE) - self.busy_wait() - if not self.busy_pin: - time.sleep(3) # Wait for update to complete - - def power_down(self): - """Power down the display.""" - self.command(_SSD1680_DEEP_SLEEP, bytearray([0x01])) - time.sleep(0.1) - class Adafruit_SSD1680Z(Adafruit_SSD1680): """Driver for SSD1680Z ePaper display, overriding SSD1680 settings.""" @@ -148,6 +231,7 @@ def __init__( rst_pin=rst_pin, busy_pin=busy_pin, ) + self.busy_pin = busy_pin # Ensure busy_pin is set # pylint: enable=too-many-arguments, useless-parent-delegation