diff --git a/adafruit_epd/epd.py b/adafruit_epd/epd.py index fcccc26..6e61e1f 100644 --- a/adafruit_epd/epd.py +++ b/adafruit_epd/epd.py @@ -8,17 +8,28 @@ CircuitPython driver for Adafruit ePaper display breakouts * Author(s): Dean Miller """ +# pylint: disable=ungrouped-imports import time from micropython import const from digitalio import Direction from adafruit_epd import mcp_sram +try: + """Needed for type annotations""" + from typing import Any, Union, Callable, Optional + from busio import SPI + from digitalio import DigitalInOut + from circuitpython_typing.pil import Image + +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" -class Adafruit_EPD: # pylint: disable=too-many-instance-attributes, too-many-public-methods +class Adafruit_EPD: # pylint: disable=too-many-instance-attributes, too-many-public-methods, too-many-arguments """Base class for EPD displays""" BLACK = const(0) @@ -29,8 +40,16 @@ class Adafruit_EPD: # pylint: disable=too-many-instance-attributes, too-many-pu LIGHT = const(5) def __init__( - self, width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): # pylint: disable=too-many-arguments + self, + width: int, + height: int, + spi: SPI, + cs_pin: DigitalInOut, + dc_pin: DigitalInOut, + sramcs_pin: DigitalInOut, + rst_pin: DigitalInOut, + busy_pin: DigitalInOut, + ) -> None: # pylint: disable=too-many-arguments self._width = width self._height = height @@ -76,7 +95,7 @@ def __init__( self._black_inverted = self._color_inverted = True self.hardware_reset() - def display(self): # pylint: disable=too-many-branches + def display(self) -> None: # pylint: disable=too-many-branches """show the contents of the display buffer""" self.power_up() @@ -149,7 +168,7 @@ def display(self): # pylint: disable=too-many-branches self.update() - def hardware_reset(self): + def hardware_reset(self) -> None: """If we have a reset pin, do a hardware reset by toggling it""" if self._rst: self._rst.value = False @@ -157,7 +176,9 @@ def hardware_reset(self): self._rst.value = True time.sleep(0.1) - def command(self, cmd, data=None, end=True): + def command( + self, cmd: int, data: Optional[bytearray] = None, end: bool = True + ) -> int: """Send command byte to display.""" self._cs.value = True self._dc.value = False @@ -176,7 +197,7 @@ def command(self, cmd, data=None, end=True): return ret - def _spi_transfer(self, data): + def _spi_transfer(self, data: Union[int, bytearray]) -> Optional[int]: """Transfer one byte or bytearray, toggling the cs pin if required by the EPD chipset""" if isinstance(data, int): # single byte! self._spibuf[0] = data @@ -203,30 +224,30 @@ def _spi_transfer(self, data): self._spi_transfer(x) return None - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating. must be implemented in subclass""" raise NotImplementedError() - def power_down(self): + def power_down(self) -> None: """Power down the display, must be implemented in subclass""" raise NotImplementedError() - def update(self): + def update(self) -> None: """Update the display from internal memory, must be implemented in subclass""" raise NotImplementedError() - def write_ram(self, index): + def write_ram(self, index: int) -> None: """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. must be implemented in subclass""" raise NotImplementedError() - def set_ram_address(self, x, y): + def set_ram_address(self, x: int, y: int) -> None: """Set the RAM address location, must be implemented in subclass""" raise NotImplementedError() - def set_black_buffer(self, index, inverted): + def set_black_buffer(self, index: Union[0, 1], inverted: bool) -> None: """Set the index for the black buffer data (0 or 1) and whether its inverted""" if index == 0: self._blackframebuf = self._framebuf1 @@ -236,7 +257,7 @@ def set_black_buffer(self, index, inverted): raise RuntimeError("Buffer index must be 0 or 1") self._black_inverted = inverted - def set_color_buffer(self, index, inverted): + def set_color_buffer(self, index: Union[0, 1], inverted: bool) -> None: """Set the index for the color buffer data (0 or 1) and whether its inverted""" if index == 0: self._colorframebuf = self._framebuf1 @@ -246,7 +267,12 @@ def set_color_buffer(self, index, inverted): raise RuntimeError("Buffer index must be 0 or 1") self._color_inverted = inverted - def _color_dup(self, func, args, color): + def _color_dup( + self, + func: Callable, + args: Any, + color: Union[0, 1, 2, 3, 4, 5], + ) -> None: black = getattr(self._blackframebuf, func) red = getattr(self._colorframebuf, func) if self._blackframebuf is self._colorframebuf: # monochrome @@ -255,11 +281,11 @@ def _color_dup(self, func, args, color): black(*args, color=(color == Adafruit_EPD.BLACK) != self._black_inverted) red(*args, color=(color == Adafruit_EPD.RED) != self._color_inverted) - def pixel(self, x, y, color): + def pixel(self, x: int, y: int, color: int) -> None: """draw a single pixel in the display buffer""" self._color_dup("pixel", (x, y), color) - def fill(self, color): + def fill(self, color: int) -> None: """fill the screen with the passed color""" red_fill = ((color == Adafruit_EPD.RED) != self._color_inverted) * 0xFF black_fill = ((color == Adafruit_EPD.BLACK) != self._black_inverted) * 0xFF @@ -271,21 +297,34 @@ def fill(self, color): self._blackframebuf.fill(black_fill) self._colorframebuf.fill(red_fill) - def rect(self, x, y, width, height, color): # pylint: disable=too-many-arguments + def rect( + self, x: int, y: int, width: int, height: int, color: int + ) -> None: # pylint: disable=too-many-arguments """draw a rectangle""" self._color_dup("rect", (x, y, width, height), color) def fill_rect( - self, x, y, width, height, color - ): # pylint: disable=too-many-arguments + self, x: int, y: int, width: int, height: int, color: int + ) -> None: # pylint: disable=too-many-arguments """fill a rectangle with the passed color""" self._color_dup("fill_rect", (x, y, width, height), color) - def line(self, x_0, y_0, x_1, y_1, color): # pylint: disable=too-many-arguments + def line( + self, x_0: int, y_0: int, x_1: int, y_1: int, color: int + ) -> None: # pylint: disable=too-many-arguments """Draw a line from (x_0, y_0) to (x_1, y_1) in passed color""" self._color_dup("line", (x_0, y_0, x_1, y_1), color) - def text(self, string, x, y, color, *, font_name="font5x8.bin", size=1): + def text( + self, + string: str, + x: int, + y: int, + color: int, + *, + font_name: str = "font5x8.bin", + size: int = 1 + ) -> None: """Write text string at location (x, y) in given color, using font file""" if self._blackframebuf is self._colorframebuf: # monochrome self._blackframebuf.text( @@ -315,39 +354,51 @@ def text(self, string, x, y, color, *, font_name="font5x8.bin", size=1): ) @property - def width(self): + def width(self) -> int: """The width of the display, accounting for rotation""" if self.rotation in (0, 2): return self._width return self._height @property - def height(self): + def height(self) -> int: """The height of the display, accounting for rotation""" if self.rotation in (0, 2): return self._height return self._width @property - def rotation(self): + def rotation(self) -> Union[0, 1, 2, 3]: """The rotation of the display, can be one of (0, 1, 2, 3)""" return self._framebuf1.rotation @rotation.setter - def rotation(self, val): + def rotation(self, val: int) -> None: self._framebuf1.rotation = val if self._framebuf2: self._framebuf2.rotation = val - def hline(self, x, y, width, color): + def hline( + self, + x: int, + y: int, + width: int, + color: int, + ) -> None: """draw a horizontal line""" self.fill_rect(x, y, width, 1, color) - def vline(self, x, y, height, color): + def vline( + self, + x: int, + y: int, + height: int, + color: int, + ) -> None: """draw a vertical line""" self.fill_rect(x, y, 1, height, color) - def image(self, image): + def image(self, image: Image) -> None: """Set buffer to value of Python Imaging Library image. The image should be in RGB mode and a size equal to the display size. """ diff --git a/adafruit_epd/il0373.py b/adafruit_epd/il0373.py index 27e11ef..ac83270 100644 --- a/adafruit_epd/il0373.py +++ b/adafruit_epd/il0373.py @@ -14,6 +14,15 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + """Needed for type annotations""" + from typing import Union + 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" @@ -48,8 +57,17 @@ class Adafruit_IL0373(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + 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 ) @@ -75,13 +93,13 @@ def __init__( self.set_color_buffer(1, True) # pylint: enable=too-many-arguments - def begin(self, reset=True): + 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): + 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: @@ -90,7 +108,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() self.busy_wait() @@ -112,13 +130,13 @@ def power_up(self): self.command(_IL0373_VCM_DC_SETTING, bytearray([0x0A])) time.sleep(0.05) - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_IL0373_CDI, bytearray([0x17])) self.command(_IL0373_VCM_DC_SETTING, bytearray([0x00])) self.command(_IL0373_POWER_OFF) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_IL0373_DISPLAY_REFRESH) time.sleep(0.1) @@ -126,7 +144,7 @@ def update(self): if not self._busy: time.sleep(15) # wait 15 seconds - def write_ram(self, index): + def write_ram(self, index: Union[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.""" @@ -136,7 +154,9 @@ def write_ram(self, index): return self.command(_IL0373_DTM2, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + 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""" return # on this chip it does nothing diff --git a/adafruit_epd/il0398.py b/adafruit_epd/il0398.py index 039cca4..5b8fcac 100644 --- a/adafruit_epd/il0398.py +++ b/adafruit_epd/il0398.py @@ -14,6 +14,15 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + """Needed for type annotations""" + from typing import Union + 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" @@ -49,8 +58,17 @@ class Adafruit_IL0398(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + 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 ) @@ -76,13 +94,13 @@ def __init__( self.set_color_buffer(1, True) # pylint: enable=too-many-arguments - def begin(self, reset=True): + 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): + 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: @@ -92,7 +110,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() self.busy_wait() @@ -111,14 +129,14 @@ def power_up(self): self.command(_IL0398_RESOLUTION, bytearray([_b0, _b1, _b2, _b3])) time.sleep(0.05) - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_IL0398_CDI, bytearray([0xF7])) self.command(_IL0398_POWER_OFF) self.busy_wait() self.command(_IL0398_DEEP_SLEEP, bytearray([0xA5])) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_IL0398_DISPLAY_REFRESH) time.sleep(0.1) @@ -126,7 +144,7 @@ def update(self): if not self._busy: time.sleep(15) # wait 15 seconds - def write_ram(self, index): + def write_ram(self, index: Union[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.""" @@ -136,7 +154,9 @@ def write_ram(self, index): return self.command(_IL0398_DTM2, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + 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""" return # on this chip it does nothing diff --git a/adafruit_epd/il91874.py b/adafruit_epd/il91874.py index 910b01b..ac9472d 100644 --- a/adafruit_epd/il91874.py +++ b/adafruit_epd/il91874.py @@ -14,6 +14,15 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + "Needed for type annotations" + from typing import Union + 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" @@ -56,8 +65,17 @@ class Adafruit_IL91874(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + 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 ) @@ -83,14 +101,14 @@ def __init__( self.set_color_buffer(1, False) self._single_byte_tx = True - def begin(self, reset=True): + 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): + 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: @@ -99,7 +117,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() time.sleep(0.2) @@ -134,7 +152,7 @@ def power_up(self): self.command(_IL91874_RESOLUTION, bytearray([_b0, _b1, _b2, _b3])) self.command(_IL91874_PDRF, bytearray([0x00])) - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_IL91874_POWER_OFF, bytearray([0x17])) self.busy_wait() @@ -142,14 +160,14 @@ def power_down(self): if self._rst: # Only deep sleep if we can get out of it self.command(_IL91874_DEEP_SLEEP, bytearray([0xA5])) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_IL91874_DISPLAY_REFRESH) self.busy_wait() if not self._busy: time.sleep(16) # wait 16 seconds - def write_ram(self, index): + def write_ram(self, index: Union[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.""" @@ -159,7 +177,9 @@ def write_ram(self, index): return self.command(_IL91874_DTM2, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + 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""" return # on this chip it does nothing diff --git a/adafruit_epd/mcp_sram.py b/adafruit_epd/mcp_sram.py index f3f5974..d293bec 100644 --- a/adafruit_epd/mcp_sram.py +++ b/adafruit_epd/mcp_sram.py @@ -12,6 +12,15 @@ from micropython import const from adafruit_bus_device import spi_device + +try: + """Needed for type annotations""" + from typing import Any, List + from digitalio import DigitalInOut + from busio import SPI +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" @@ -21,15 +30,15 @@ class Adafruit_MCP_SRAM_View: """An interface class that turns an SRAM chip into something like a memoryview""" - def __init__(self, sram, offset): + def __init__(self, sram: int, offset: int) -> None: self._sram = sram self._offset = offset self._buf = [0] - def __getitem__(self, i): + def __getitem__(self, i: int) -> Any: return self._sram.read(self._offset + i, 1)[0] - def __setitem__(self, i, val): + def __setitem__(self, i: int, val: Any) -> None: self._buf[0] = val self._sram.write(self._offset + i, self._buf) @@ -43,7 +52,7 @@ class Adafruit_MCP_SRAM: SRAM_RDSR = 0x05 SRAM_WRSR = 0x01 - def __init__(self, cs_pin, spi): + def __init__(self, cs_pin: DigitalInOut, spi: SPI): # Handle hardware SPI self._spi = spi_device.SPIDevice(spi, cs_pin, baudrate=8000000) self.spi_device = spi @@ -54,11 +63,11 @@ def __init__(self, cs_pin, spi): with self._spi as spidev: spidev.write(self._buf, end=2) # pylint: disable=no-member - def get_view(self, offset): + def get_view(self, offset: int) -> Adafruit_MCP_SRAM_View: """Create an object that can be used as a memoryview, with a given offset""" return Adafruit_MCP_SRAM_View(self, offset) - def write(self, addr, buf, reg=SRAM_WRITE): + def write(self, addr: int, buf: List, reg=SRAM_WRITE): """write the passed buffer to the passed address""" self._buf[0] = reg self._buf[1] = (addr >> 8) & 0xFF @@ -68,7 +77,7 @@ def write(self, addr, buf, reg=SRAM_WRITE): spi.write(self._buf, end=3) # pylint: disable=no-member spi.write(bytearray(buf)) # pylint: disable=no-member - def read(self, addr, length, reg=SRAM_READ): + def read(self, addr: int, length: int, reg: int = SRAM_READ): """read passed number of bytes at the passed address""" self._buf[0] = reg self._buf[1] = (addr >> 8) & 0xFF @@ -80,24 +89,24 @@ def read(self, addr, length, reg=SRAM_READ): spi.readinto(buf) # pylint: disable=no-member return buf - def read8(self, addr, reg=SRAM_READ): + def read8(self, addr: int, reg: int = SRAM_READ): """read a single byte at the passed address""" return self.read(addr, 1, reg)[0] - def read16(self, addr, reg=SRAM_READ): + def read16(self, addr: int, reg: int = SRAM_READ): """read 2 bytes at the passed address""" buf = self.read(addr, 2, reg) return buf[0] << 8 | buf[1] - def write8(self, addr, value, reg=SRAM_WRITE): + def write8(self, addr: int, value: int, reg: int = SRAM_WRITE): """write a single byte at the passed address""" self.write(addr, [value], reg) - def write16(self, addr, value, reg=SRAM_WRITE): + def write16(self, addr: int, value: int, reg: int = SRAM_WRITE): """write 2 bytes at the passed address""" self.write(addr, [value >> 8, value], reg) - def erase(self, addr, length, value): + def erase(self, addr: int, length: int, value: Any): """erase the passed number of bytes starting at the passed address""" self._buf[0] = Adafruit_MCP_SRAM.SRAM_WRITE self._buf[1] = (addr >> 8) & 0xFF diff --git a/adafruit_epd/ssd1608.py b/adafruit_epd/ssd1608.py index 0bb4b7b..2792c0c 100644 --- a/adafruit_epd/ssd1608.py +++ b/adafruit_epd/ssd1608.py @@ -14,6 +14,15 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + """Needed for type annotations""" + from typing import Union + 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" @@ -57,8 +66,17 @@ class Adafruit_SSD1608(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + 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 ) @@ -80,13 +98,13 @@ def __init__( self.set_color_buffer(0, True) # pylint: enable=too-many-arguments - def begin(self, reset=True): + 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): + 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: @@ -95,7 +113,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() self.busy_wait() @@ -125,12 +143,12 @@ def power_up(self): self.command(_SSD1608_WRITE_LUT, _LUT_DATA) self.busy_wait() - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_SSD1608_DEEP_SLEEP, bytearray([0x01])) time.sleep(0.1) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_SSD1608_DISP_CTRL2, bytearray([0xC7])) self.command(_SSD1608_MASTER_ACTIVATE) @@ -138,7 +156,7 @@ def update(self): if not self._busy: time.sleep(3) # wait 3 seconds - def write_ram(self, index): + def write_ram(self, index: Union[0]) -> 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.""" @@ -146,7 +164,9 @@ def write_ram(self, index): return self.command(_SSD1608_WRITE_RAM, end=False) raise RuntimeError("RAM index must be 0") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + 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 diff --git a/adafruit_epd/ssd1675.py b/adafruit_epd/ssd1675.py index c86e4cf..6c72efa 100644 --- a/adafruit_epd/ssd1675.py +++ b/adafruit_epd/ssd1675.py @@ -14,6 +14,15 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + """Needed for type annotations""" + from typing import Union + 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" @@ -51,7 +60,16 @@ class Adafruit_SSD1675(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin + self, + width: int, + height: int, + spi: SPI, + *, + cs_pin: DigitalInOut, + dc_pin: DigitalInOut, + sramcs_pin: DigitalInOut, + rst_pin: DigitalInOut, + busy_pin: DigitalInOut ): super().__init__( width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin @@ -89,13 +107,13 @@ def __init__( self.set_color_buffer(0, True) # pylint: enable=too-many-arguments - def begin(self, reset=True): + 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): + 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: @@ -104,7 +122,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() time.sleep(0.1) @@ -147,12 +165,12 @@ def power_up(self): self.busy_wait() - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_SSD1675_DEEP_SLEEP, bytearray([0x01])) time.sleep(0.1) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_SSD1675_DISP_CTRL2, bytearray([0xC7])) self.command(_SSD1675_MASTER_ACTIVATE) @@ -160,7 +178,7 @@ def update(self): if not self._busy: time.sleep(3) # wait 3 seconds - def write_ram(self, index): + def write_ram(self, index: Union[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.""" @@ -170,7 +188,9 @@ def write_ram(self, index): return self.command(_SSD1675_WRITE_RAM2, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + 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""" self.command(_SSD1675_SET_RAMXCOUNT, bytearray([x])) diff --git a/adafruit_epd/ssd1675b.py b/adafruit_epd/ssd1675b.py index 81b2dfe..2542ce4 100644 --- a/adafruit_epd/ssd1675b.py +++ b/adafruit_epd/ssd1675b.py @@ -14,6 +14,15 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + """Needed for type annotations""" + from typing import Union + 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" @@ -77,8 +86,17 @@ class Adafruit_SSD1675B(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + 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 ) @@ -115,13 +133,13 @@ def __init__( self.set_color_buffer(0, True) # pylint: enable=too-many-arguments - def begin(self, reset=True): + 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): + 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: @@ -130,7 +148,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() time.sleep(0.1) @@ -189,12 +207,12 @@ def power_up(self): self.busy_wait() - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_SSD1675B_DEEP_SLEEP, bytearray([0x01])) time.sleep(0.1) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_SSD1675B_DISP_CTRL2, bytearray([0xC7])) self.command(_SSD1675B_MASTER_ACTIVATE) @@ -202,7 +220,7 @@ def update(self): if not self._busy: time.sleep(3) # wait 3 seconds - def write_ram(self, index): + def write_ram(self, index: Union[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.""" @@ -212,7 +230,9 @@ def write_ram(self, index): return self.command(_SSD1675B_WRITE_RAM2, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + 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""" self.command(_SSD1675B_SET_RAMXCOUNT, bytearray([x])) diff --git a/adafruit_epd/ssd1680.py b/adafruit_epd/ssd1680.py index 7c5f553..5f4e89c 100644 --- a/adafruit_epd/ssd1680.py +++ b/adafruit_epd/ssd1680.py @@ -14,6 +14,15 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + """Needed for type annotations""" + from typing import Union + 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" @@ -72,8 +81,17 @@ class Adafruit_SSD1680(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + 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 ) @@ -110,13 +128,13 @@ def __init__( self.set_color_buffer(1, False) # pylint: enable=too-many-arguments - def begin(self, reset=True): + 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): + 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: @@ -125,7 +143,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() self.busy_wait() @@ -160,12 +178,12 @@ def power_up(self): self.command(_SSD1680_SET_RAMYCOUNT, bytearray([self._height - 1, 0])) self.busy_wait() - def power_down(self): + 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): + def update(self) -> None: """Update the display from internal memory""" self.command(_SSD1680_DISP_CTRL2, bytearray([0xF4])) self.command(_SSD1680_MASTER_ACTIVATE) @@ -173,7 +191,7 @@ def update(self): if not self._busy: time.sleep(3) # wait 3 seconds - def write_ram(self, index): + def write_ram(self, index: Union[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.""" @@ -183,7 +201,9 @@ def write_ram(self, index): return self.command(_SSD1680_WRITE_REDRAM, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + 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 diff --git a/adafruit_epd/ssd1681.py b/adafruit_epd/ssd1681.py index 9482b01..15b3944 100644 --- a/adafruit_epd/ssd1681.py +++ b/adafruit_epd/ssd1681.py @@ -14,6 +14,14 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + from typing import Union + 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" @@ -72,8 +80,17 @@ class Adafruit_SSD1681(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + 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 ) @@ -101,13 +118,13 @@ def __init__( self.set_color_buffer(1, False) # pylint: enable=too-many-arguments - def begin(self, reset=True): + 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): + 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: @@ -116,7 +133,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() self.busy_wait() @@ -143,12 +160,12 @@ def power_up(self): self.busy_wait() - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_SSD1681_DEEP_SLEEP, bytearray([0x01])) time.sleep(0.1) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_SSD1681_DISP_CTRL2, bytearray([0xF7])) self.command(_SSD1681_MASTER_ACTIVATE) @@ -156,7 +173,7 @@ def update(self): if not self._busy: time.sleep(3) # wait 3 seconds - def write_ram(self, index): + def write_ram(self, index: Union[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.""" @@ -166,7 +183,9 @@ def write_ram(self, index): return self.command(_SSD1681_WRITE_REDRAM, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + 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 diff --git a/adafruit_epd/uc8151d.py b/adafruit_epd/uc8151d.py index 1d4ed83..4cbdb73 100644 --- a/adafruit_epd/uc8151d.py +++ b/adafruit_epd/uc8151d.py @@ -14,6 +14,15 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + """Needed for type annotations""" + from typing import Union + 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" @@ -63,8 +72,17 @@ class Adafruit_UC8151D(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + 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 ) @@ -90,13 +108,13 @@ def __init__( self.set_color_buffer(1, True) # pylint: enable=too-many-arguments - def begin(self, reset=True): + 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): + 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: @@ -105,7 +123,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() self.busy_wait() @@ -119,14 +137,14 @@ def power_up(self): self.command(_UC8151D_CDI, bytearray([0x97])) time.sleep(0.05) - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_UC8151D_CDI, bytearray([0xF7])) self.command(_UC8151D_POWER_OFF) self.busy_wait() self.command(_UC8151D_DEEP_SLEEP, bytearray([0xA5])) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_UC8151D_DISPLAY_REFRESH) time.sleep(0.1) @@ -134,7 +152,7 @@ def update(self): if not self._busy: time.sleep(15) # wait 15 seconds - def write_ram(self, index): + def write_ram(self, index: Union[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.""" @@ -144,7 +162,9 @@ def write_ram(self, index): return self.command(_UC8151D_DTM2, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + 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""" return # on this chip it does nothing