3737**Notes:**
3838#. Datasheet: https://cdn-shop.adafruit.com/datasheets/MAX7219.pdf
3939"""
40- # MicroPython SSD1306 OLED driver, I2C and SPI interfaces
40+ # MicroPython MAX7219 driver, SPI interfaces
4141import digitalio
4242from adafruit_bus_device import spi_device
4343from micropython import const
4444import adafruit_framebuf as framebuf
4545
46+ try :
47+ # Used only for typing
48+ import typing # pylint: disable=unused-import
49+ import busio
50+ except ImportError :
51+ pass
52+
4653__version__ = "0.0.0-auto.0"
4754__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MAX7219.git"
4855
@@ -57,15 +64,23 @@ class MAX7219:
5764
5865 :param int width: the number of pixels wide
5966 :param int height: the number of pixels high
60- :param object spi: an spi busio or spi bitbangio object
67+ :param ~busio.SPI spi: an spi busio or spi bitbangio object
6168 :param ~digitalio.DigitalInOut chip_select: digital in/out to use as chip select signal
62- :param baudrate: for SPIDevice baudrate (default 8000000)
63- :param polarity: for SPIDevice polarity (default 0)
64- :param phase: for SPIDevice phase (default 0)
69+ :param int baudrate: for SPIDevice baudrate (default 8000000)
70+ :param int polarity: for SPIDevice polarity (default 0)
71+ :param int phase: for SPIDevice phase (default 0)
6572 """
6673
6774 def __init__ (
68- self , width , height , spi , cs , * , baudrate = 8000000 , polarity = 0 , phase = 0
75+ self ,
76+ width : int ,
77+ height : int ,
78+ spi : busio .SPI ,
79+ cs : digitalio .DigitalInOut ,
80+ * ,
81+ baudrate : int = 8000000 ,
82+ polarity : int = 0 ,
83+ phase : int = 0
6984 ):
7085
7186 self ._chip_select = cs
@@ -83,10 +98,10 @@ def __init__(
8398
8499 self .init_display ()
85100
86- def init_display (self ):
101+ def init_display (self ) -> None :
87102 """Must be implemented by derived class (``matrices``, ``bcddigits``)"""
88103
89- def brightness (self , value ) :
104+ def brightness (self , value : int ) -> None :
90105 """
91106 Controls the brightness of the display.
92107
@@ -96,39 +111,48 @@ def brightness(self, value):
96111 raise ValueError ("Brightness out of range" )
97112 self .write_cmd (_INTENSITY , value )
98113
99- def show (self ):
114+ def show (self ) -> None :
100115 """
101116 Updates the display.
102117 """
103118 for ypos in range (8 ):
104119 self .write_cmd (_DIGIT0 + ypos , self ._buffer [ypos ])
105120
106- def fill (self , bit_value ) :
121+ def fill (self , bit_value : int ) -> None :
107122 """
108123 Fill the display buffer.
109124
110125 :param int bit_value: value > 0 set the buffer bit, else clears the buffer bit
111126 """
112127 self .framebuf .fill (bit_value )
113128
114- def pixel (self , xpos , ypos , bit_value = None ):
129+ def pixel (self , xpos : int , ypos : int , bit_value : int = None ) -> None :
115130 """
116131 Set one buffer bit
117132
118- :param xpos: x position to set bit
119- :param ypos: y position to set bit
133+ :param int xpos: x position to set bit
134+ :param int ypos: y position to set bit
120135 :param int bit_value: value > 0 sets the buffer bit, else clears the buffer bit
121136 """
122137 bit_value = 0x01 if bit_value else 0x00
123138 self .framebuf .pixel (xpos , ypos , bit_value )
124139
125- def scroll (self , delta_x , delta_y ):
126- """Srcolls the display using delta_x,delta_y."""
140+ def scroll (self , delta_x : int , delta_y : int ) -> None :
141+ """
142+ Srcolls the display using delta_x,delta_y.
143+
144+ :param int delta_x: positions to scroll in the x direction
145+ :param int delta_y: positions to scroll in the y direction
146+ """
127147 self .framebuf .scroll (delta_x , delta_y )
128148
129- def write_cmd (self , cmd , data ):
130- # pylint: disable=no-member
131- """Writes a command to spi device."""
149+ def write_cmd (self , cmd : int , data : int ) -> None :
150+ """
151+ Writes a command to spi device.
152+
153+ :param int cmd: register address to write data to
154+ :param int data: data to be written to commanded register
155+ """
132156 # print('cmd {} data {}'.format(cmd,data))
133157 self ._chip_select .value = False
134158 with self ._spi_device as my_spi_device :
0 commit comments