27
27
28
28
"""
29
29
# pylint: enable=line-too-long
30
+ from __future__ import annotations
31
+
32
+
33
+ try :
34
+ # pylint: disable=unused-import
35
+ import typing
36
+ from busio import SPI
37
+ from digitalio import DigitalInOut
38
+ from circuitpython_typing .pil import Image
39
+ except ImportError :
40
+ pass
30
41
31
42
import adafruit_framebuf
32
43
from adafruit_bus_device .spi_device import SPIDevice
45
56
_SHARPMEM_BIT_CLEAR = const (0x20 ) # in lsb
46
57
47
58
48
- def reverse_bit (num ) :
59
+ def reverse_bit (num : int ) -> int :
49
60
"""Turn an LSB byte to an MSB byte, and vice versa. Used for SPI as
50
61
it is LSB for the SHARP, but 99% of SPI implementations are MSB only!"""
51
62
result = 0
@@ -62,7 +73,15 @@ class SharpMemoryDisplay(adafruit_framebuf.FrameBuffer):
62
73
63
74
# pylint: disable=too-many-instance-attributes,abstract-method
64
75
65
- def __init__ (self , spi , scs_pin , width , height , * , baudrate = 2000000 ):
76
+ def __init__ (
77
+ self ,
78
+ spi : SPI ,
79
+ scs_pin : DigitalInOut ,
80
+ width : int ,
81
+ height : int ,
82
+ * ,
83
+ baudrate = 2000000 ,
84
+ ):
66
85
scs_pin .switch_to_output (value = True )
67
86
self .spi_device = SPIDevice (
68
87
spi , scs_pin , cs_active_value = True , baudrate = baudrate
@@ -78,7 +97,7 @@ def __init__(self, spi, scs_pin, width, height, *, baudrate=2000000):
78
97
# Set the vcom bit to a defined state
79
98
self ._vcom = True
80
99
81
- def show (self ):
100
+ def show (self ) -> None :
82
101
"""write out the frame buffer via SPI, we use MSB SPI only so some
83
102
bit-swapping is required.
84
103
"""
@@ -105,7 +124,7 @@ def show(self):
105
124
image_buffer .extend (self ._buf )
106
125
spi .write (image_buffer )
107
126
108
- def image (self , img ) :
127
+ def image (self , img : Image ) -> None :
109
128
"""Set buffer to value of Python Imaging Library image. The image should
110
129
be in 1 bit mode and a size equal to the display size."""
111
130
# determine our effective width/height, taking rotation into account
0 commit comments