-
Notifications
You must be signed in to change notification settings - Fork 7
/
adafruit_ssd1327.py
83 lines (66 loc) · 2.56 KB
/
adafruit_ssd1327.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# SPDX-FileCopyrightText: 2019 Scott Shawcroft for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
`adafruit_ssd1327`
================================================================================
DisplayIO drivers for grayscale OLEDs driven by SSD1327
* Author(s): Scott Shawcroft
Implementation Notes
--------------------
**Hardware:**
* 128x128, General 1.5inch OLED display Module:
https://www.waveshare.com/1.5inch-oled-module.htm
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases
"""
import displayio
__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SSD1327.git"
_INIT_SEQUENCE = (
b"\xAE\x00" # DISPLAY_OFF
b"\x81\x01\x80" # set contrast control
b"\xa0\x01\x53" # remap memory, odd even columns, com flip and column swap
b"\xa1\x01\x00" # Display start line is 0
b"\xa2\x01\x00" # Display offset is 0
b"\xa4\x00" # Normal display
b"\xa8\x01\x3f" # Mux ratio is 1/64
b"\xb1\x01\x11" # Set phase length
b"\xb8\x0f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x10\x18\x20\x2f\x38\x3f" # Set graytable
b"\xb3\x01\x00" # Set dclk to 100hz
b"\xab\x01\x01" # enable internal regulator
b"\xb6\x01\x04" # Set second pre-charge period
b"\xbe\x01\x0f" # Set vcom voltage
b"\xbc\x01\x08" # Set pre-charge voltage
b"\xd5\x01\x62" # function selection B
b"\xfd\x01\x12" # command unlock
b"\xAF\x00" # DISPLAY_ON
)
# pylint: disable=too-few-public-methods
class SSD1327(displayio.Display):
"""SSD1327 driver
:param ~displayio.I2CDisplay bus: The data bus the display is on
:param int height: (keyword-only) The height of the screen
:param int width: (keyword-only) The width of the screen
:param int rotation: (keyword-only) The rotation/orientation of the
screen, in degrees
"""
def __init__(self, bus: displayio.I2CDisplay, **kwargs) -> None:
# Patch the init sequence for 32 pixel high displays.
init_sequence = bytearray(_INIT_SEQUENCE)
height = kwargs["height"]
if "rotation" in kwargs and kwargs["rotation"] % 180 != 0:
height = kwargs["width"]
init_sequence[18] = height - 1 # patch mux ratio
super().__init__(
bus,
init_sequence,
**kwargs,
color_depth=4,
grayscale=True,
set_column_command=0x15,
set_row_command=0x75,
data_as_commands=True,
single_byte_bounds=True,
)