/ adafruit_ssd1325.py
adafruit_ssd1325.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_ssd1325`
24  ================================================================================
25  
26  DisplayIO driver for grayscale OLEDs drive by SSD1325
27  
28  
29  * Author(s): Scott Shawcroft
30  
31  Implementation Notes
32  --------------------
33  
34  **Hardware:**
35  
36  * `Adafruit Monochrome 2.7" 128x64 OLED Graphic Display <https://www.adafruit.com/product/2674>`_
37  
38  **Software and Dependencies:**
39  
40  * Adafruit CircuitPython 5+ firmware for the supported boards:
41    https://github.com/adafruit/circuitpython/releases
42  
43  """
44  
45  import displayio
46  
47  __version__ = "0.0.0-auto.0"
48  __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SSD1325.git"
49  
50  _INIT_SEQUENCE = (
51      b"\xAE\x00"  # DISPLAY_OFF
52      b"\xb3\x01\xa1"  # Set clock
53      b"\xa8\x01\x3f"  # Mux ratio is 1/64
54      b"\xa1\x01\x00"  # Display start line is 0
55      b"\xa2\x01\x4c"  # Display offset is 0
56      b"\xad\x01\x02"  # set master config
57      b"\xa0\x01\x50"  # remap memory
58      b"\x86\x00"  # set current
59      b"\xb8\x08\x01\x11\x22\x32\x43\x54\x65\x76"  # Set graytable
60      b"\x81\x01\x7f"  # full contrast
61      b"\xb2\x01\x51"  # Set row period
62      b"\xb1\x01\x55"  # Set phase length
63      b"\xb4\x01\x02"  # Set pre-charge comp
64      b"\xb0\x01\x28"  # Set pre-charge comp enable
65      b"\xbc\x01\x3f"  # Set pre-charge voltage
66      b"\xbe\x01\x1c"  # Set vcom voltage
67      b"\xbf\x01\x0f"  # set Low Voltage Level of SEG Pin
68      b"\xa4\x00"  # Normal display
69      b"\xaf\x00"  # DISPLAY_ON
70  )
71  
72  # pylint: disable=too-few-public-methods
73  class SSD1325(displayio.Display):
74      """SSD1325 driver"""
75  
76      def __init__(self, bus, **kwargs):
77          # Patch the init sequence for 32 pixel high displays.
78          init_sequence = bytearray(_INIT_SEQUENCE)
79          height = kwargs["height"]
80          if "rotation" in kwargs and kwargs["rotation"] % 180 != 0:
81              height = kwargs["width"]
82          init_sequence[7] = height - 1  # patch mux ratio
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              set_vertical_scroll=0xD3,
92              data_as_commands=True,
93              brightness_command=0x81,
94              single_byte_bounds=True,
95          )