Skip to content

Commit a5d006e

Browse files
committed
feat(steami_screen): Add SSD1327 and GC9A01 display wrappers
with example for analog clock
1 parent 7054fde commit a5d006e

5 files changed

Lines changed: 125 additions & 1 deletion

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Tutorial 09 — Analog Watch
3+
Displays an analog clock face using the built-in RTC.
4+
"""
5+
6+
import time
7+
8+
import ssd1327
9+
from machine import RTC, SPI, Pin
10+
from steami_screen import Screen, SSD1327Display
11+
12+
# --- Screen setup ---
13+
spi = SPI(1)
14+
dc = Pin("DATA_COMMAND_DISPLAY")
15+
res = Pin("RST_DISPLAY")
16+
cs = Pin("CS_DISPLAY")
17+
18+
display = SSD1327Display(ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs))
19+
screen = Screen(display)
20+
21+
# --- RTC setup ---
22+
rtc = RTC()
23+
24+
# --- Main loop ---
25+
while True:
26+
_, _, _, _, h, m, s, _ = rtc.datetime()
27+
28+
screen.clear()
29+
screen.watch(h, m, s)
30+
screen.show()
31+
32+
time.sleep(0.5)

lib/steami_screen/steami_screen/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from steami_screen.colors import rgb_to_gray4, rgb_to_rgb8, rgb_to_rgb565
2+
from steami_screen.gc9a01 import GC9A01Display
23
from steami_screen.screen import (
34
BLACK,
45
BLUE,
@@ -11,6 +12,7 @@
1112
YELLOW,
1213
Screen,
1314
)
15+
from steami_screen.sssd1327 import SSD1327Display
1416

1517
__all__ = [
1618
"BLACK",
@@ -22,6 +24,8 @@
2224
"RED",
2325
"WHITE",
2426
"YELLOW",
27+
"GC9A01Display",
28+
"SSD1327Display",
2529
"Screen",
2630
"rgb_to_gray4",
2731
"rgb_to_rgb8",
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
GC9A01 display wrapper — converts RGB colors to RGB565.
3+
4+
Wraps the raw GC9A01 driver so that steami_screen can pass RGB tuples
5+
while the hardware receives 16-bit RGB565 values.
6+
7+
Usage on the STeaMi board:
8+
import gc9a01
9+
from steami_gc9a01 import GC9A01Display
10+
raw = gc9a01.GC9A01(spi, dc, cs, rst, ...)
11+
display = GC9A01Display(raw)
12+
"""
13+
14+
from steami_screen.colors import rgb_to_rgb565
15+
16+
17+
class GC9A01Display:
18+
"""Thin wrapper around a GC9A01 driver that accepts RGB colors."""
19+
20+
def __init__(self, raw, width=240, height=240):
21+
self._raw = raw
22+
self.width = width
23+
self.height = height
24+
25+
def fill(self, color):
26+
self._raw.fill(rgb_to_rgb565(color))
27+
28+
def pixel(self, x, y, color):
29+
self._raw.pixel(x, y, rgb_to_rgb565(color))
30+
31+
def text(self, string, x, y, color):
32+
self._raw.text(string, x, y, rgb_to_rgb565(color))
33+
34+
def line(self, x1, y1, x2, y2, color):
35+
self._raw.line(x1, y1, x2, y2, rgb_to_rgb565(color))
36+
37+
def fill_rect(self, x, y, w, h, color):
38+
self._raw.fill_rect(x, y, w, h, rgb_to_rgb565(color))
39+
40+
def rect(self, x, y, w, h, color):
41+
self._raw.rect(x, y, w, h, rgb_to_rgb565(color))
42+
43+
def show(self):
44+
self._raw.show()

lib/steami_screen/steami_screen/screen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import math
1616

1717
# --- Color constants (RGB tuples) ---
18-
from colors import rgb_to_gray4
18+
from steami_screen.colors import rgb_to_gray4
1919

2020
# Grays map to exact SSD1327 levels: gray4 * 17 gives R=G=B
2121
BLACK = (0, 0, 0)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
SSD1327 display wrapper — converts RGB colors to 4-bit grayscale.
3+
4+
Wraps the raw SSD1327 driver so that steami_screen can pass RGB tuples
5+
while the hardware receives grayscale values (0-15).
6+
7+
Usage on the STeaMi board:
8+
import ssd1327
9+
from steami_ssd1327 import SSD1327Display
10+
raw = ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs)
11+
display = SSD1327Display(raw)
12+
"""
13+
14+
from steami_screen.colors import rgb_to_gray4
15+
16+
17+
class SSD1327Display:
18+
"""Thin wrapper around an SSD1327 driver that accepts RGB colors."""
19+
20+
def __init__(self, raw):
21+
self._raw = raw
22+
self.width = getattr(raw, 'width', 128)
23+
self.height = getattr(raw, 'height', 128)
24+
25+
def fill(self, color):
26+
self._raw.fill(rgb_to_gray4(color))
27+
28+
def pixel(self, x, y, color):
29+
self._raw.pixel(x, y, rgb_to_gray4(color))
30+
31+
def text(self, string, x, y, color):
32+
self._raw.text(string, x, y, rgb_to_gray4(color))
33+
34+
def line(self, x1, y1, x2, y2, color):
35+
self._raw.line(x1, y1, x2, y2, rgb_to_gray4(color))
36+
37+
def fill_rect(self, x, y, w, h, color):
38+
self._raw.fill_rect(x, y, w, h, rgb_to_gray4(color))
39+
40+
def rect(self, x, y, w, h, color):
41+
self._raw.rect(x, y, w, h, rgb_to_gray4(color))
42+
43+
def show(self):
44+
self._raw.show()

0 commit comments

Comments
 (0)