24
24
* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards:
25
25
https://github.com/adafruit/circuitpython/releases
26
26
"""
27
+ try :
28
+ # Imports only used for typing.
29
+
30
+ # First check if the the typing module exists, to avoid loading
31
+ # other typing-only modules when running under circuitpython.
32
+ import typing # pylint: disable=unused-import
33
+ import busio
34
+ except ImportError :
35
+ pass
36
+
27
37
from micropython import const
28
38
29
39
__version__ = "0.0.0+auto.0"
@@ -53,14 +63,14 @@ class MAX9744:
53
63
# design!
54
64
_BUFFER = bytearray (1 )
55
65
56
- def __init__ (self , i2c , * , address = _MAX9744_DEFAULT_ADDRESS ):
66
+ def __init__ (self , i2c : busio . I2C , * , address : int = _MAX9744_DEFAULT_ADDRESS ):
57
67
# This device doesn't use registers and instead just accepts a single
58
68
# command string over I2C. As a result we don't use bus device or
59
69
# other abstractions and just talk raw I2C protocol.
60
70
self ._i2c = i2c
61
71
self ._address = address
62
72
63
- def _write (self , val ) :
73
+ def _write (self , val : int ) -> None :
64
74
# Perform a write to update the amplifier state.
65
75
try :
66
76
# Make sure bus is locked before write.
@@ -73,7 +83,7 @@ def _write(self, val):
73
83
# Ensure bus is always unlocked.
74
84
self ._i2c .unlock ()
75
85
76
- def _set_volume (self , volume ) :
86
+ def _set_volume (self , volume : int ) -> None :
77
87
# Set the volume to the specified level (0-63).
78
88
assert 0 <= volume <= 63
79
89
self ._write (_MAX9744_COMMAND_VOLUME | (volume & 0x3F ))
@@ -82,14 +92,15 @@ def _set_volume(self, volume):
82
92
volume = property (
83
93
None ,
84
94
_set_volume ,
95
+ None ,
85
96
"Set the volume of the amplifier. Specify a value from 0-63 where 0 is muted/off and 63 is maximum volume." ,
86
97
)
87
98
# pylint: enable=line-too-long
88
99
89
- def volume_up (self ):
100
+ def volume_up (self ) -> None :
90
101
"""Increase the volume by one level."""
91
102
self ._write (_MAX9744_COMMAND_VOLUME_UP )
92
103
93
- def volume_down (self ):
104
+ def volume_down (self ) -> None :
94
105
"""Decrease the volume by one level."""
95
106
self ._write (_MAX9744_COMMAND_VOLUME_DOWN )
0 commit comments