|
1 | 1 | from time import sleep_us |
2 | 2 |
|
3 | 3 | import framebuf |
| 4 | +from steami_screen import rgb_to_gray4 |
4 | 5 |
|
5 | 6 | from ssd1327.const import ( |
6 | 7 | REG_CMD, |
@@ -226,3 +227,45 @@ def __init__(self, spi, dc, res, cs): |
226 | 227 | class WS_OLED_128X128_I2C(SSD1327_I2C): |
227 | 228 | def __init__(self, i2c, address=0x3C): |
228 | 229 | 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