2727
2828"""
2929# 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
3041
3142import adafruit_framebuf
3243from adafruit_bus_device .spi_device import SPIDevice
4556_SHARPMEM_BIT_CLEAR = const (0x20 ) # in lsb
4657
4758
48- def reverse_bit (num ) :
59+ def reverse_bit (num : int ) -> int :
4960 """Turn an LSB byte to an MSB byte, and vice versa. Used for SPI as
5061 it is LSB for the SHARP, but 99% of SPI implementations are MSB only!"""
5162 result = 0
@@ -62,7 +73,15 @@ class SharpMemoryDisplay(adafruit_framebuf.FrameBuffer):
6273
6374 # pylint: disable=too-many-instance-attributes,abstract-method
6475
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+ ):
6685 scs_pin .switch_to_output (value = True )
6786 self .spi_device = SPIDevice (
6887 spi , scs_pin , cs_active_value = True , baudrate = baudrate
@@ -78,7 +97,7 @@ def __init__(self, spi, scs_pin, width, height, *, baudrate=2000000):
7897 # Set the vcom bit to a defined state
7998 self ._vcom = True
8099
81- def show (self ):
100+ def show (self ) -> None :
82101 """write out the frame buffer via SPI, we use MSB SPI only so some
83102 bit-swapping is required.
84103 """
@@ -105,7 +124,7 @@ def show(self):
105124 image_buffer .extend (self ._buf )
106125 spi .write (image_buffer )
107126
108- def image (self , img ) :
127+ def image (self , img : Image ) -> None :
109128 """Set buffer to value of Python Imaging Library image. The image should
110129 be in 1 bit mode and a size equal to the display size."""
111130 # determine our effective width/height, taking rotation into account
0 commit comments