Rename to `BaseDisplayDriver`; ili9341 changes
What changed, and why it matters
This commit is a routine internal code cleanup. It renames the parent display class from DisplayDriver to BaseDisplayDriver, makes a couple of methods optional instead of requiring every display subclass to implement them, and adjusts the ILI9341 display driver to inherit from the new base class. There is no visible security fix or vulnerability being addressed.
No security action needed. Treat as normal refactoring; verify display rendering still works on supported hardware during regular QA.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff refactors the display driver hierarchy: DisplayDriver is renamed BaseDisplayDriver; invert() and cleanup() become no-op defaults rather than abstract raises; show_image() still requires implementation. ST7789 and ili9341 drivers are updated to inherit from BaseDisplayDriver. The ILI9341 driver moves initialization from init to post_init to fit the dataclass pattern and removes explicit width/height parameters in favor of inherited _width/_height. No input validation, privilege, cryptography, or network changes are present.
Changed components
src/seedsigner/hardware/displays/display_driver.pysrc/seedsigner/hardware/displays/ST7789.pysrc/seedsigner/hardware/displays/st7789_mpy.pysrc/seedsigner/hardware/displays/ili9341.pyInspect captured patch +31 / −32
diff --git a/src/seedsigner/hardware/displays/ST7789.py b/src/seedsigner/hardware/displays/ST7789.py
index b399aa6..6fb05ce 100644
--- a/src/seedsigner/hardware/displays/ST7789.py
+++ b/src/seedsigner/hardware/displays/ST7789.py
@@ -4,12 +4,12 @@ import time
import array
from dataclasses import dataclass
-from seedsigner.hardware.displays.display_driver import DisplayDriver
+from seedsigner.hardware.displays.display_driver import BaseDisplayDriver
@dataclass
-class ST7789(DisplayDriver):
+class ST7789(BaseDisplayDriver):
"""
The original SeedSigner display driver.
diff --git a/src/seedsigner/hardware/displays/display_driver.py b/src/seedsigner/hardware/displays/display_driver.py
index 9903476..0870e6e 100644
--- a/src/seedsigner/hardware/displays/display_driver.py
+++ b/src/seedsigner/hardware/displays/display_driver.py
@@ -10,13 +10,12 @@ ALL_DISPLAY_TYPES = [DISPLAY_TYPE__ST7789, DISPLAY_TYPE__ILI9341, DISPLAY_TYPE__
@dataclass
-class DisplayDriver:
+class BaseDisplayDriver:
_width: int
_height: int
-
def __str__(self):
- return f"DisplayDriver(display_type={self.display_type}, width={self.width}, height={self.height})"
+ return f"DisplayDriver(display_type={getattr(self, 'display_type', None)}, width={self.width}, height={self.height})"
@property
@@ -30,16 +29,26 @@ class DisplayDriver:
def invert(self, enabled: bool = True):
- """Invert how the display interprets colors"""
- raise Exception("Must be implemented in child class")
+ """
+ Invert how the display interprets colors.
+ Implementation in child classes is optional.
+ """
+ pass
def show_image(self, image, x_start: int = 0, y_start: int = 0):
- raise Exception("Must be implemented in child class")
-
+ """
+ The main rendering call to the display driver.
+ Must be implemented in child classes.
+ """
+ raise Exception("show_image() must be implemented in child classes")
+
def cleanup(self):
- """Cleanup resources related to the display driver."""
+ """
+ Cleanup resources used by the display driver.
+ Implementation in child classes is optional.
+ """
pass
@@ -52,7 +61,7 @@ class DisplayDriverFactory:
"""
@classmethod
- def instantiate_display_driver(cls, display_type: str = DISPLAY_TYPE__ST7789, width: int = None, height: int = None) -> DisplayDriver:
+ def instantiate_display_driver(cls, display_type: str = DISPLAY_TYPE__ST7789, width: int = None, height: int = None) -> BaseDisplayDriver:
if display_type not in ALL_DISPLAY_TYPES:
raise ValueError(f"Invalid display type: {display_type}")
diff --git a/src/seedsigner/hardware/displays/ili9341.py b/src/seedsigner/hardware/displays/ili9341.py
index 1330aa7..93492e6 100644
--- a/src/seedsigner/hardware/displays/ili9341.py
+++ b/src/seedsigner/hardware/displays/ili9341.py
@@ -35,6 +35,8 @@ from PIL import ImageDraw
import RPi.GPIO as GPIO
from spidev import SpiDev
+from seedsigner.hardware.displays.display_driver import BaseDisplayDriver
+
# Constants for interacting with display registers.
ILI9341_TFTWIDTH = 240
@@ -129,16 +131,14 @@ def image_to_data(image):
return arr.tobytes()
-class ILI9341(object):
+class ILI9341(BaseDisplayDriver):
"""Representation of an ILI9341 TFT LCD."""
- def __init__(self, dc=22, rst=13, led=12, width=ILI9341_TFTWIDTH,
- height=ILI9341_TFTHEIGHT, rotation=90):
- """Create an instance of the display using SPI communication. Must
- provide the GPIO pin number for the D/C pin and the SPI driver. Can
- optionally provide the GPIO pin number for the reset pin as the rst
- parameter.
- """
+ def __post_init__(self):
+ dc=22
+ rst=13
+ led=12
+ rotation=90
spi = SpiDev(0, 0)
# spi.mode = 0b10 # [CPOL|CPHA] -> polarity 1, phase 0
spi.max_speed_hz = 64_000_000
@@ -146,8 +146,6 @@ class ILI9341(object):
self._dc = dc
self._rst = rst
self._spi = spi
- self.width = width
- self.height = height
self.rotation = rotation
self.inverted = False
# if self._gpio is None:
@@ -165,15 +163,7 @@ class ILI9341(object):
GPIO.output(self._rst, GPIO.HIGH)
# Create an image buffer.
- self.buffer = Image.new('RGB', (width, height))
-
- # @property
- # def width(self):
- # return self.width
-
- # @property
- # def height(self):
- # return self.height
+ self.buffer = Image.new('RGB', (self.width, self.height))
def send(self, data, is_data=True, chunk_size=4096):
diff --git a/src/seedsigner/hardware/displays/st7789_mpy.py b/src/seedsigner/hardware/displays/st7789_mpy.py
index 2aad703..b69999c 100644
--- a/src/seedsigner/hardware/displays/st7789_mpy.py
+++ b/src/seedsigner/hardware/displays/st7789_mpy.py
@@ -57,7 +57,7 @@ import RPi.GPIO as GPIO
from dataclasses import dataclass
from math import sin, cos
-from seedsigner.hardware.displays.display_driver import DisplayDriver
+from seedsigner.hardware.displays.display_driver import BaseDisplayDriver
#
# This allows sphinx to build the docs
@@ -233,7 +233,7 @@ def color565(red, green=0, blue=0):
@dataclass
-class ST7789(DisplayDriver):
+class ST7789(BaseDisplayDriver):
"""
ST7789 driver class
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.