36
36
except ImportError :
37
37
import adafruit_framebuf as framebuf
38
38
39
+ try :
40
+ from typing import Optional
41
+ from digitalio import DigitalInOut
42
+ from busio import SPI
43
+ except ImportError :
44
+ pass
45
+
39
46
__version__ = "0.0.0+auto.0"
40
47
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PCD8544.git"
41
48
@@ -64,15 +71,15 @@ class PCD8544(framebuf.FrameBuffer):
64
71
65
72
def __init__ (
66
73
self ,
67
- spi ,
68
- dc_pin ,
69
- cs_pin ,
70
- reset_pin = None ,
74
+ spi : SPI ,
75
+ dc_pin : DigitalInOut ,
76
+ cs_pin : DigitalInOut ,
77
+ reset_pin : Optional [ DigitalInOut ] = None ,
71
78
* ,
72
- contrast = 80 ,
73
- bias = 4 ,
74
- baudrate = 1000000
75
- ):
79
+ contrast : int = 80 ,
80
+ bias : int = 4 ,
81
+ baudrate : int = 1000000
82
+ ) -> None :
76
83
self ._dc_pin = dc_pin
77
84
dc_pin .switch_to_output (value = False )
78
85
@@ -94,7 +101,7 @@ def __init__(
94
101
self .bias = bias
95
102
self .contrast = contrast
96
103
97
- def reset (self ):
104
+ def reset (self ) -> None :
98
105
"""Reset the display"""
99
106
if self ._reset_pin :
100
107
# Toggle RST low to reset.
@@ -103,13 +110,13 @@ def reset(self):
103
110
self ._reset_pin .value = True
104
111
time .sleep (0.5 )
105
112
106
- def write_cmd (self , cmd ) :
113
+ def write_cmd (self , cmd : int ) -> None :
107
114
"""Send a command to the SPI device"""
108
115
self ._dc_pin .value = 0
109
116
with self .spi_device as spi :
110
117
spi .write (bytearray ([cmd ])) # pylint: disable=no-member
111
118
112
- def extended_command (self , cmd ) :
119
+ def extended_command (self , cmd : int ) -> None :
113
120
"""Send a command in extended mode"""
114
121
# Set extended command mode
115
122
self .write_cmd (_PCD8544_FUNCTIONSET | _PCD8544_EXTENDEDINSTRUCTION )
@@ -118,7 +125,7 @@ def extended_command(self, cmd):
118
125
self .write_cmd (_PCD8544_FUNCTIONSET )
119
126
self .write_cmd (_PCD8544_DISPLAYCONTROL | _PCD8544_DISPLAYNORMAL )
120
127
121
- def show (self ):
128
+ def show (self ) -> None :
122
129
"""write out the frame buffer via SPI"""
123
130
self .write_cmd (_PCD8544_SETYADDR )
124
131
self .write_cmd (_PCD8544_SETXADDR )
@@ -127,12 +134,12 @@ def show(self):
127
134
spi .write (self .buffer ) # pylint: disable=no-member
128
135
129
136
@property
130
- def invert (self ):
137
+ def invert (self ) -> bool :
131
138
"""Whether the display is inverted, cached value"""
132
139
return self ._invert
133
140
134
141
@invert .setter
135
- def invert (self , val ) :
142
+ def invert (self , val : bool ) -> None :
136
143
"""Set invert on or normal display on"""
137
144
self ._invert = val
138
145
self .write_cmd (_PCD8544_FUNCTIONSET )
@@ -142,23 +149,23 @@ def invert(self, val):
142
149
self .write_cmd (_PCD8544_DISPLAYCONTROL | _PCD8544_DISPLAYNORMAL )
143
150
144
151
@property
145
- def contrast (self ):
152
+ def contrast (self ) -> int :
146
153
"""The cached contrast value"""
147
154
return self ._contrast
148
155
149
156
@contrast .setter
150
- def contrast (self , val ) :
157
+ def contrast (self , val : int ) -> None :
151
158
"""Set contrast to specified value (should be 0-127)."""
152
159
self ._contrast = max (0 , min (val , 0x7F )) # Clamp to values 0-0x7f
153
160
self .extended_command (_PCD8544_SETVOP | self ._contrast )
154
161
155
162
@property
156
- def bias (self ):
163
+ def bias (self ) -> int :
157
164
"""The cached bias value"""
158
165
return self ._bias
159
166
160
167
@bias .setter
161
- def bias (self , val ) :
168
+ def bias (self , val : int ) -> None :
162
169
"""Set display bias"""
163
170
self ._bias = val
164
171
self .extended_command (_PCD8544_SETBIAS | self ._bias )
0 commit comments