-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathsh1106.pyi
226 lines (180 loc) · 6.57 KB
/
sh1106.pyi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
"""
Type stub for the MicroPython SH1106 OLED driver.
This library provides a driver for controlling SH1106 OLED displays over
I2C or SPI interfaces. It supports basic drawing operations, text rendering,
and display configuration.
### Usage Examples:
#### SPI Interface:
```python
from machine import Pin, SPI
import sh1106
spi = SPI(1, baudrate=1000000)
display = sh1106.SH1106_SPI(128, 64, spi, dc=Pin(5), res=Pin(2), cs=Pin(4))
display.fill(0) # Clear the display
display.text("Hello, World!", 0, 0, 1) # Display text
display.show()
```
#### I2C Interface:
```python
from machine import Pin, I2C
import sh1106
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
display = sh1106.SH1106_I2C(128, 64, i2c, res=Pin(16))
display.fill(0) # Clear the display
display.text("Hello, World!", 0, 0, 1) # Display text
display.show()
```
### Features:
- Supports 128x64 SH1106 OLED displays.
- Drawing primitives (lines, rectangles, circles, etc.).
- Text rendering.
- Contrast adjustment and screen inversion.
For more details, visit the [SH1106 GitHub repository](https://github.com/robert-hh/SH1106).
"""
# sh1106.pyi - Stub file for SH1106 MicroPython library
from typing import Optional
from framebuf import FrameBuffer
from machine import I2C, SPI, Pin
class SH1106(FrameBuffer):
"""
Base class for SH1106 OLED display drivers.
Handles common functionality such as rendering, power management, and drawing operations.
"""
def __init__(self, width: int, height: int, external_vcc: bool, rotate: int = 0) -> None:
"""
Initialize the SH1106 driver.
:param width: Display width in pixels.
:param height: Display height in pixels.
:param external_vcc: Whether to use external VCC (True) or internal (False).
:param rotate: Rotation angle (0, 90, 180, 270 degrees).
"""
...
def init_display(self) -> None:
"""Initialize and reset the display."""
...
def poweroff(self) -> None:
"""Turn off the display."""
...
def poweron(self) -> None:
"""Turn on the display."""
...
def flip(self, flag: Optional[bool] = None, update: bool = True) -> None:
"""
Flip the display horizontally or vertically.
:param flag: If True, enable flipping; if False, disable.
:param update: Whether to update the display immediately.
"""
...
def sleep(self, value: bool) -> None:
"""
Put the display into sleep mode or wake it up.
:param value: True to sleep, False to wake up.
"""
...
def contrast(self, contrast: int) -> None:
"""
Set the display contrast level.
:param contrast: Contrast value (0-255).
"""
...
def invert(self, invert: bool) -> None:
"""
Invert the display colors.
:param invert: True to invert, False to reset to normal.
"""
...
def show(self, full_update: bool = False) -> None:
"""
Refresh the display with the current buffer content.
:param full_update: If True, update all pages; otherwise, update only modified pages.
"""
...
def pixel(self, x: int, y: int, color: Optional[int] = None) -> Optional[int]:
"""
Get or set the color of a specific pixel.
:param x: X-coordinate.
:param y: Y-coordinate.
:param color: Pixel color (0 or 1). If None, return the current color.
"""
...
def text(self, text: str, x: int, y: int, color: int = 1) -> None:
"""
Draw text on the display.
:param text: String to draw.
:param x: X-coordinate of the top-left corner.
:param y: Y-coordinate of the top-left corner.
:param color: Text color (1 for white, 0 for black).
"""
...
def line(self, x0: int, y0: int, x1: int, y1: int, color: int) -> None:
"""Draw a line between two points."""
...
def hline(self, x: int, y: int, w: int, color: int) -> None:
"""Draw a horizontal line."""
...
def vline(self, x: int, y: int, h: int, color: int) -> None:
"""Draw a vertical line."""
...
def fill(self, color: int) -> None:
"""Fill the entire display with a single color."""
...
def blit(self, fbuf: FrameBuffer, x: int, y: int, key: int = -1, palette: Optional[bytes] = None) -> None:
"""
Copy a framebuffer onto the display.
:param fbuf: Source framebuffer.
:param x: X-coordinate for placement.
:param y: Y-coordinate for placement.
:param key: Transparent color key.
:param palette: Optional color palette for translation.
"""
...
def scroll(self, x: int, y: int) -> None:
"""Scroll the display content by a certain amount."""
...
def fill_rect(self, x: int, y: int, w: int, h: int, color: int) -> None:
"""Draw a filled rectangle."""
...
def rect(self, x: int, y: int, w: int, h: int, color: int) -> None:
"""Draw an outlined rectangle."""
...
def reset(self, res: Optional[Pin]) -> None:
"""Reset the display using the reset pin."""
...
class SH1106_I2C(SH1106):
"""
SH1106 driver for I2C communication.
"""
def __init__(self, width: int, height: int, i2c: I2C, res: Optional[Pin] = None,
addr: int = 0x3c, rotate: int = 0, external_vcc: bool = False, delay: int = 0) -> None:
"""
Initialize the SH1106 I2C driver.
"""
...
def write_cmd(self, cmd: int) -> None:
"""Write a command to the display via I2C."""
...
def write_data(self, buf: bytes) -> None:
"""Write data to the display via I2C."""
...
def reset(self) -> None:
"""Reset the display via the reset pin (if available)."""
...
class SH1106_SPI(SH1106):
"""
SH1106 driver for SPI communication.
"""
def __init__(self, width: int, height: int, spi: SPI, dc: Pin, res: Optional[Pin] = None,
cs: Optional[Pin] = None, rotate: int = 0, external_vcc: bool = False, delay: int = 0) -> None:
"""
Initialize the SH1106 SPI driver.
"""
...
def write_cmd(self, cmd: int) -> None:
"""Write a command to the display via SPI."""
...
def write_data(self, buf: bytes) -> None:
"""Write data to the display via SPI."""
...
def reset(self) -> None:
"""Reset the display via the reset pin (if available)."""
...