26
26
"""
27
27
28
28
import digitalio
29
- import adafruit_bus_device .spi_device as spi_device
29
+ from adafruit_bus_device import spi_device
30
+
31
+ try :
32
+ import typing # pylint: disable=unused-import
33
+ from microcontroller import Pin
34
+ import busio
35
+ except ImportError :
36
+ pass
30
37
31
38
__version__ = "0.0.0-auto.0"
32
39
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_74HC595.git"
@@ -39,7 +46,11 @@ class DigitalInOut:
39
46
direction as input will raise an exception.
40
47
"""
41
48
42
- def __init__ (self , pin_number , shift_register_74hc595 ):
49
+ def __init__ (
50
+ self ,
51
+ pin_number : Pin ,
52
+ shift_register_74hc595 : "ShiftRegister74HC595" ,
53
+ ):
43
54
"""Specify the pin number of the shift register (0...7) and
44
55
ShiftRegister74HC595 instance.
45
56
"""
@@ -53,7 +64,7 @@ def __init__(self, pin_number, shift_register_74hc595):
53
64
# is unused by this class). Do not remove them, instead turn off pylint
54
65
# in this case.
55
66
# pylint: disable=unused-argument
56
- def switch_to_output (self , value = False , ** kwargs ):
67
+ def switch_to_output (self , value : bool = False , ** kwargs ):
57
68
"""``DigitalInOut switch_to_output``"""
58
69
self .direction = digitalio .Direction .OUTPUT
59
70
self .value = value
@@ -72,7 +83,7 @@ def value(self):
72
83
)
73
84
74
85
@value .setter
75
- def value (self , val ):
86
+ def value (self , val : bool ):
76
87
77
88
if (
78
89
self ._pin >= 0
@@ -91,7 +102,7 @@ def direction(self):
91
102
return digitalio .Direction .OUTPUT
92
103
93
104
@direction .setter
94
- def direction (self , val ): # pylint: disable=no-self-use
105
+ def direction (self , val : digitalio . Direction ): # pylint: disable=no-self-use
95
106
"""``Direction`` can only be set to ``OUTPUT``."""
96
107
if val != digitalio .Direction .OUTPUT :
97
108
raise RuntimeError ("Digital input not supported." )
@@ -102,7 +113,7 @@ def pull(self):
102
113
return None
103
114
104
115
@pull .setter
105
- def pull (self , val ): # pylint: disable=no-self-use
116
+ def pull (self , val : digitalio . Pull ): # pylint: disable=no-self-use
106
117
"""Only supports null/no pull state."""
107
118
if val is not None :
108
119
raise RuntimeError ("Pull-up and pull-down not supported." )
@@ -113,7 +124,12 @@ class ShiftRegister74HC595:
113
124
and indicate the number of shift registers being used
114
125
"""
115
126
116
- def __init__ (self , spi , latch , number_of_shift_registers = 1 ):
127
+ def __init__ (
128
+ self ,
129
+ spi : busio .SPI ,
130
+ latch : digitalio .DigitalInOut ,
131
+ number_of_shift_registers : int = 1 ,
132
+ ):
117
133
self ._device = spi_device .SPIDevice (spi , latch , baudrate = 1000000 )
118
134
self ._number_of_shift_registers = number_of_shift_registers
119
135
self ._gpio = bytearray (self ._number_of_shift_registers )
@@ -131,14 +147,14 @@ def gpio(self):
131
147
return self ._gpio
132
148
133
149
@gpio .setter
134
- def gpio (self , val ):
150
+ def gpio (self , val : bytearray ):
135
151
self ._gpio = val
136
152
137
153
with self ._device as spi :
138
154
# pylint: disable=no-member
139
155
spi .write (self ._gpio )
140
156
141
- def get_pin (self , pin ) :
157
+ def get_pin (self , pin : int ) -> Pin :
142
158
"""Convenience function to create an instance of the DigitalInOut class
143
159
pointing at the specified pin of this 74HC595 device .
144
160
"""
0 commit comments