Skip to content

Commit 7bc8d6c

Browse files
authored
Merge pull request #5 from tcfranks/main
Add Missing Type Annotations
2 parents 0941d3e + 365be29 commit 7bc8d6c

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

adafruit_st7565.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
from micropython import const
3333
from adafruit_bus_device import spi_device
3434

35+
try:
36+
from typing import Optional
37+
from digitalio import DigitalInOut
38+
from busio import SPI
39+
except ImportError:
40+
pass
41+
3542
try:
3643
import framebuf
3744
except ImportError:
@@ -81,8 +88,15 @@ class ST7565(framebuf.FrameBuffer):
8188
CMD_SET_STATIC_REG = const(0x00)
8289

8390
def __init__(
84-
self, spi, dc_pin, cs_pin, reset_pin=None, *, contrast=0, baudrate=1000000
85-
):
91+
self,
92+
spi: SPI,
93+
dc_pin: DigitalInOut,
94+
cs_pin: DigitalInOut,
95+
reset_pin: Optional[DigitalInOut] = None,
96+
*,
97+
contrast: int = 0,
98+
baudrate: int = 1000000
99+
) -> None:
86100
self._dc_pin = dc_pin
87101
dc_pin.switch_to_output(value=False)
88102

@@ -127,7 +141,7 @@ def __init__(
127141
# Contrast
128142
self.contrast = contrast
129143

130-
def reset(self):
144+
def reset(self) -> None:
131145
"""Reset the display"""
132146
if self._reset_pin:
133147
# Toggle RST low to reset.
@@ -136,13 +150,13 @@ def reset(self):
136150
self._reset_pin.value = True
137151
time.sleep(0.5)
138152

139-
def write_cmd(self, cmd):
153+
def write_cmd(self, cmd: int) -> None:
140154
"""Send a command to the SPI device"""
141155
self._dc_pin.value = False
142156
with self.spi_device as spi:
143157
spi.write(bytearray([cmd])) # pylint: disable=no-member
144158

145-
def show(self):
159+
def show(self) -> None:
146160
"""write out the frame buffer via SPI"""
147161
for page in self.pagemap:
148162
# Home cursor on the page
@@ -163,12 +177,12 @@ def show(self):
163177
spi.write(self.buffer[row_start:row_stop]) # pylint: disable=no-member
164178

165179
@property
166-
def invert(self):
180+
def invert(self) -> bool:
167181
"""Whether the display is inverted, cached value"""
168182
return self._invert
169183

170184
@invert.setter
171-
def invert(self, val):
185+
def invert(self, val: bool) -> None:
172186
"""Set invert on or normal display on"""
173187
self._invert = val
174188
if val:
@@ -177,12 +191,12 @@ def invert(self, val):
177191
self.write_cmd(self.CMD_SET_DISP_NORMAL)
178192

179193
@property
180-
def contrast(self):
194+
def contrast(self) -> int:
181195
"""The cached contrast value"""
182196
return self._contrast
183197

184198
@contrast.setter
185-
def contrast(self, val):
199+
def contrast(self, val: int) -> None:
186200
"""Set contrast to specified value (should be 0-127)."""
187201
self._contrast = max(0, min(val, 0x7F)) # Clamp to values 0-0x7f
188202
self.write_cmd(self.CMD_SET_VOLUME_FIRST)

0 commit comments

Comments
 (0)