Skip to content

Commit c0d3cc3

Browse files
committed
feat(ssd1327): Add SSD1327Display wrapper for grayscale conversion
Migration from tutorial repo
1 parent 7054fde commit c0d3cc3

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

lib/ssd1327/ssd1327/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
SSD1327_I2C,
55
WS_OLED_128X128_I2C,
66
WS_OLED_128X128_SPI,
7+
SSD1327Display,
78
)
89

910
__all__ = [
@@ -13,4 +14,5 @@
1314
"SSD1327_I2C",
1415
"WS_OLED_128X128_I2C",
1516
"WS_OLED_128X128_SPI",
17+
"SSD1327Display",
1618
]

lib/ssd1327/ssd1327/device.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from time import sleep_us
22

33
import framebuf
4+
from steami_screen import rgb_to_gray4
45

56
from ssd1327.const import (
67
REG_CMD,
@@ -226,3 +227,45 @@ def __init__(self, spi, dc, res, cs):
226227
class WS_OLED_128X128_I2C(SSD1327_I2C):
227228
def __init__(self, i2c, address=0x3C):
228229
super().__init__(128, 128, i2c, address)
230+
231+
"""
232+
SSD1327 display wrapper — converts RGB colors to 4-bit grayscale.
233+
234+
Wraps the raw SSD1327 driver so that steami_screen can pass RGB tuples
235+
while the hardware receives grayscale values (0-15).
236+
237+
Usage on the STeaMi board:
238+
import ssd1327
239+
from steami_ssd1327 import SSD1327Display
240+
raw = ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs)
241+
display = SSD1327Display(raw)
242+
"""
243+
244+
class SSD1327Display:
245+
"""Thin wrapper around an SSD1327 driver that accepts RGB colors."""
246+
247+
def __init__(self, raw):
248+
self._raw = raw
249+
self.width = getattr(raw, 'width', 128)
250+
self.height = getattr(raw, 'height', 128)
251+
252+
def fill(self, color):
253+
self._raw.fill(rgb_to_gray4(color))
254+
255+
def pixel(self, x, y, color):
256+
self._raw.pixel(x, y, rgb_to_gray4(color))
257+
258+
def text(self, string, x, y, color):
259+
self._raw.text(string, x, y, rgb_to_gray4(color))
260+
261+
def line(self, x1, y1, x2, y2, color):
262+
self._raw.line(x1, y1, x2, y2, rgb_to_gray4(color))
263+
264+
def fill_rect(self, x, y, w, h, color):
265+
self._raw.fill_rect(x, y, w, h, rgb_to_gray4(color))
266+
267+
def rect(self, x, y, w, h, color):
268+
self._raw.rect(x, y, w, h, rgb_to_gray4(color))
269+
270+
def show(self):
271+
self._raw.show()

0 commit comments

Comments
 (0)