/ adafruit_ssd1327.py
adafruit_ssd1327.py
 1  # The MIT License (MIT)
 2  #
 3  # Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
 4  #
 5  # Permission is hereby granted, free of charge, to any person obtaining a copy
 6  # of this software and associated documentation files (the "Software"), to deal
 7  # in the Software without restriction, including without limitation the rights
 8  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 9  # copies of the Software, and to permit persons to whom the Software is
10  # furnished to do so, subject to the following conditions:
11  #
12  # The above copyright notice and this permission notice shall be included in
13  # all copies or substantial portions of the Software.
14  #
15  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  # THE SOFTWARE.
22  """
23  `adafruit_ssd1327`
24  ================================================================================
25  
26  DisplayIO drivers for grayscale OLEDs driven by SSD1327
27  
28  
29  * Author(s): Scott Shawcroft
30  
31  Implementation Notes
32  --------------------
33  
34  **Hardware:**
35  
36  * 128x128, General 1.5inch OLED display Module:
37    https://www.waveshare.com/1.5inch-oled-module.htm
38  
39  **Software and Dependencies:**
40  
41  * Adafruit CircuitPython firmware for the supported boards:
42    https://github.com/adafruit/circuitpython/releases
43  
44  """
45  
46  import displayio
47  
48  __version__ = "0.0.0-auto.0"
49  __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SSD1327.git"
50  
51  _INIT_SEQUENCE = (
52      b"\xAE\x00"  # DISPLAY_OFF
53      b"\x81\x01\x80"  # set contrast control
54      b"\xa0\x01\x53"  # remap memory, odd even columns, com flip and column swap
55      b"\xa1\x01\x00"  # Display start line is 0
56      b"\xa2\x01\x00"  # Display offset is 0
57      b"\xa4\x00"  # Normal display
58      b"\xa8\x01\x3f"  # Mux ratio is 1/64
59      b"\xb1\x01\x11"  # Set phase length
60      b"\xb8\x0f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x10\x18\x20\x2f\x38\x3f"  # Set graytable
61      b"\xb3\x01\x00"  # Set dclk to 100hz
62      b"\xab\x01\x01"  # enable internal regulator
63      b"\xb6\x01\x04"  # Set second pre-charge period
64      b"\xbe\x01\x0f"  # Set vcom voltage
65      b"\xbc\x01\x08"  # Set pre-charge voltage
66      b"\xd5\x01\x62"  # function selection B
67      b"\xfd\x01\x12"  # command unlock
68      b"\xAF\x00"  # DISPLAY_ON
69  )
70  
71  # pylint: disable=too-few-public-methods
72  class SSD1327(displayio.Display):
73      """SSD1327 driver"""
74  
75      def __init__(self, bus, **kwargs):
76          # Patch the init sequence for 32 pixel high displays.
77          init_sequence = bytearray(_INIT_SEQUENCE)
78          height = kwargs["height"]
79          if "rotation" in kwargs and kwargs["rotation"] % 180 != 0:
80              height = kwargs["width"]
81          init_sequence[18] = height - 1  # patch mux ratio
82          print(height)
83          super().__init__(
84              bus,
85              init_sequence,
86              **kwargs,
87              color_depth=4,
88              grayscale=True,
89              set_column_command=0x15,
90              set_row_command=0x75,
91              data_as_commands=True,
92              single_byte_bounds=True,
93          )