/ adafruit_displayio_ssd1305.py
adafruit_displayio_ssd1305.py
  1  # The MIT License (MIT)
  2  #
  3  # Copyright (c) 2019 Melissa LeBlanc-Williams 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_displayio_ssd1305`
 24  ================================================================================
 25  
 26  DisplayIO driver for SSD1305 monochrome displays
 27  
 28  
 29  * Author(s): Melissa LeBlanc-Williams
 30  
 31  Implementation Notes
 32  --------------------
 33  
 34  **Hardware:**
 35  
 36  * `Monochrome 1.54" 128x64 OLED Graphic Display Module Kit <https://www.adafruit.com/product/2720>`_
 37  * `Monochrome 2.42" 128x64 OLED Graphic Display Module Kit <https://www.adafruit.com/product/2719>`_
 38  * `Monochrome 2.3" 128x32 OLED Graphic Display Module Kit <https://www.adafruit.com/product/2675>`_
 39  
 40  **Software and Dependencies:**
 41  
 42  * Adafruit CircuitPython (version 5+) firmware for the supported boards:
 43    https://github.com/adafruit/circuitpython/releases
 44  
 45  """
 46  
 47  # imports
 48  
 49  import displayio
 50  
 51  __version__ = "0.0.0-auto.0"
 52  __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SSD1305.git"
 53  
 54  _INIT_SEQUENCE = (
 55      b"\xAE\x00"  # DISPLAY_OFF
 56      b"\xd5\x01\x80"  # SET_DISP_CLK_DIV
 57      b"\xA1\x00"  # Column 127 is segment 0
 58      b"\xA8\x01\x3F"  # Mux ratio is 1/64
 59      b"\xad\x01\x8e"  # Set Master Configuration
 60      b"\xd8\x01\x05"  # Set Area Color Mode On/Off & Low Power Display Mode
 61      b"\x20\x01\x00"  # Set memory addressing to horizontal mode.
 62      b"\x40\x01\x2E"  # SET_DISP_START_LINE ADD
 63      b"\xc8\x00"  # Set COM Output Scan Direction 64 to 1
 64      b"\xda\x01\x12"  # Set com configuration
 65      b"\x91\x04\x3f\x3f\x3f\x3f"  # Current drive pulse width of BANK0, Color A, Band C.
 66      b"\xd9\x01\xd2"  # Set pre-charge period orig: 0xd9, 0x22 if self.external_vcc else 0xf1,
 67      b"\xdb\x01\x34"  # Set vcom configuration 0xdb, 0x30, $ 0.83* Vcc
 68      b"\xA6\x00"  # Normal display
 69      b"\xA4\x00"  # output follows RAM contents  SET_ENTIRE_ON
 70      b"\x8d\x01\x14"  # Enable charge pump
 71      b"\xAF\x00\x00"  # DISPLAY_ON
 72  )
 73  
 74  # pylint: disable=too-few-public-methods
 75  class SSD1305(displayio.Display):
 76      """SSD1305 driver"""
 77  
 78      def __init__(self, bus, **kwargs):
 79          colstart = 0
 80          # Patch the init sequence for 32 pixel high displays.
 81          init_sequence = bytearray(_INIT_SEQUENCE)
 82  
 83          height = kwargs["height"]
 84          if "rotation" in kwargs and kwargs["rotation"] % 180 != 0:
 85              height = kwargs["width"]
 86          init_sequence[9] = height - 1  # patch mux ratio
 87  
 88          if kwargs["height"] == 32:
 89              colstart = 4
 90          super().__init__(
 91              bus,
 92              init_sequence,
 93              **kwargs,
 94              color_depth=1,
 95              grayscale=True,
 96              pixels_in_byte_share_row=False,
 97              set_column_command=0x21,
 98              set_row_command=0x22,
 99              data_as_commands=True,
100              set_vertical_scroll=0xD3,
101              brightness_command=0x81,
102              single_byte_bounds=True,
103              colstart=colstart,
104          )