Skip to content

Commit b633527

Browse files
authored
Merge pull request #23 from SebastienFauque/main
added typing for image, scs, and, reverse_bit num
2 parents 7aa8e90 + 0b5469b commit b633527

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

adafruit_sharpmemorydisplay.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@
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

3142
import adafruit_framebuf
3243
from adafruit_bus_device.spi_device import SPIDevice
@@ -45,7 +56,7 @@
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

Comments
 (0)