-
Notifications
You must be signed in to change notification settings - Fork 1
feat(steami_screen): Add SSD1327 display wrapper. #355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| """ | ||
| Tutorial 09 — Analog Watch | ||
| Displays an analog clock face using the built-in RTC. | ||
| """ | ||
|
|
||
| import time | ||
|
|
||
| import ssd1327 | ||
| from machine import RTC, SPI, Pin | ||
| from steami_screen import Screen, SSD1327Display | ||
|
|
||
| # --- Screen setup --- | ||
| spi = SPI(1) | ||
| dc = Pin("DATA_COMMAND_DISPLAY") | ||
| res = Pin("RST_DISPLAY") | ||
| cs = Pin("CS_DISPLAY") | ||
|
|
||
| display = SSD1327Display(ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs)) | ||
| screen = Screen(display) | ||
|
|
||
| # --- RTC setup --- | ||
| rtc = RTC() | ||
|
|
||
| # --- Main loop --- | ||
| while True: | ||
| _, _, _, _, h, m, s, _ = rtc.datetime() | ||
|
|
||
| screen.clear() | ||
| screen.watch(h, m, s) | ||
| screen.show() | ||
|
|
||
| time.sleep(0.5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """SSD1327 display wrapper — converts RGB colors to 4-bit grayscale. | ||
|
|
||
| Wraps the raw SSD1327 driver so that steami_screen can pass RGB tuples | ||
| while the hardware receives grayscale values (0-15). | ||
|
|
||
| Usage on the STeaMi board: | ||
| import ssd1327 | ||
| from steami_screen import SSD1327Display | ||
| raw = ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs) | ||
| display = SSD1327Display(raw) | ||
| """ | ||
|
|
||
| from steami_screen.colors import rgb_to_gray4 | ||
|
|
||
|
|
||
| class SSD1327Display: | ||
| """Thin wrapper around an SSD1327 driver that accepts RGB colors.""" | ||
|
|
||
| def __init__(self, raw): | ||
| self._raw = raw | ||
| self.width = getattr(raw, 'width', 128) | ||
| self.height = getattr(raw, 'height', 128) | ||
|
|
||
| def fill(self, color): | ||
| self._raw.fill(rgb_to_gray4(color)) | ||
|
|
||
| def pixel(self, x, y, color): | ||
| self._raw.pixel(x, y, rgb_to_gray4(color)) | ||
|
|
||
| def text(self, string, x, y, color): | ||
| self._raw.text(string, x, y, rgb_to_gray4(color)) | ||
|
|
||
| def line(self, x1, y1, x2, y2, color): | ||
| self._raw.line(x1, y1, x2, y2, rgb_to_gray4(color)) | ||
|
|
||
| def fill_rect(self, x, y, w, h, color): | ||
| gray = rgb_to_gray4(color) | ||
| if hasattr(self._raw, 'fill_rect'): | ||
| self._raw.fill_rect(x, y, w, h, gray) | ||
| else: | ||
| self._raw.framebuf.fill_rect(x, y, w, h, gray) | ||
|
|
||
| def rect(self, x, y, w, h, color): | ||
| gray = rgb_to_gray4(color) | ||
| if hasattr(self._raw, 'rect'): | ||
| self._raw.rect(x, y, w, h, gray) | ||
| else: | ||
| self._raw.framebuf.rect(x, y, w, h, gray) | ||
|
|
||
| def show(self): | ||
| self._raw.show() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Screenno longer does backend-wide color conversion, but_fill_rect()/_rect()still special-casedisplay.framebufand forcergb_to_gray4(). This leaves an inconsistent state where a framebuf-backed display might get gray4 ints for rects but RGB tuples forfill()/line()/pixel()/text(), which will break or render incorrectly depending on the framebuffer format. If the wrapper is now the single conversion point, consider removing theframebufbranches here (and thergb_to_gray4dependency) so all drawing paths consistently pass through the backend API.