/ adafruit_il91874.py
adafruit_il91874.py
  1  # The MIT License (MIT)
  2  #
  3  # Copyright (c) 2019 Scott Shawcroft for Adafruit Industries LLC
  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_il91874`
 24  ================================================================================
 25  
 26  CircuitPython `displayio` driver for IL91874-based ePaper displays
 27  
 28  
 29  * Author(s): Scott Shawcroft
 30  
 31  Implementation Notes
 32  --------------------
 33  
 34  **Hardware:**
 35  
 36  * `Adafruit 2.7" Tri-Color ePaper Display Shield <https://www.adafruit.com/product/4229>`_
 37  
 38  **Software and Dependencies:**
 39  
 40  * Adafruit CircuitPython firmware (version 5+) for the supported boards:
 41    https://github.com/adafruit/circuitpython/releases
 42  
 43  # * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
 44  # * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
 45  """
 46  
 47  import displayio
 48  
 49  __version__ = "0.0.0-auto.0"
 50  __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_IL91874.git"
 51  
 52  _START_SEQUENCE = (
 53      b"\x04\x00"  # Power on
 54      b"\x00\x01\xaf"  # panel setting
 55      b"\x30\x01\x3a"  # PLL
 56      b"\x01\x05\x03\x00\x2b\x2b\x09"  # power setting
 57      b"\x06\x03\x07\x07\x17"  # booster soft start
 58      b"\xf8\x02\x60\xa5"  # mystery command in example code
 59      b"\xf8\x02\x89\xa5"  # mystery command in example code
 60      b"\xf8\x02\x90\x00"  # mystery command in example code
 61      b"\xf8\x02\x93\xa2"  # mystery command in example code
 62      b"\xf8\x02\x73\x41"  # mystery command in example code
 63      b"\x82\x01\x12"  # VCM DC
 64      b"\x50\x01\x87"  # CDI setting
 65      # Look Up Tables
 66      # LUT1
 67      b"\x20\x2c\x00\x00\x00\x1a\x1a\x00\x00\x01\x00\x0a\x0a\x00\x00\x08\x00\x0e\x01\x0e\x01\x10\x00"
 68      b"\x0a\x0a\x00\x00\x08\x00\x04\x10\x00\x00\x05\x00\x03\x0e\x00\x00\x0a\x00\x23\x00\x00\x00\x01"
 69      # LUTWW
 70      b"\x21\x2a\x90\x1a\x1a\x00\x00\x01\x40\x0a\x0a\x00\x00\x08\x84\x0e\x01\x0e\x01\x10\x80\x0a\x0a"
 71      b"\x00\x00\x08\x00\x04\x10\x00\x00\x05\x00\x03\x0e\x00\x00\x0a\x00\x23\x00\x00\x00\x01"
 72      # LUTBW
 73      b"\x22\x2a\xa0\x1a\x1a\x00\x00\x01\x00\x0a\x0a\x00\x00\x08\x84\x0e\x01\x0e\x01\x10\x90\x0a\x0a"
 74      b"\x00\x00\x08\xb0\x04\x10\x00\x00\x05\xb0\x03\x0e\x00\x00\x0a\xc0\x23\x00\x00\x00\x01"
 75      # LUTWB
 76      b"\x23\x2a\x90\x1a\x1a\x00\x00\x01\x40\x0a\x0a\x00\x00\x08\x84\x0e\x01\x0e\x01\x10\x80\x0a\x0a"
 77      b"\x00\x00\x08\x00\x04\x10\x00\x00\x05\x00\x03\x0e\x00\x00\x0a\x00\x23\x00\x00\x00\x01"
 78      # LUTBB
 79      b"\x24\x2a\x90\x1a\x1a\x00\x00\x01\x20\x0a\x0a\x00\x00\x08\x84\x0e\x01\x0e\x01\x10\x10\x0a\x0a"
 80      b"\x00\x00\x08\x00\x04\x10\x00\x00\x05\x00\x03\x0e\x00\x00\x0a\x00\x23\x00\x00\x00\x01"
 81      b"\x61\x04\x00\x00\x00\x00"  # Resolution
 82      b"\x16\x80\x00"  # PDRF
 83  )
 84  
 85  _STOP_SEQUENCE = b"\x02\x01\x17"  # Power off
 86  
 87  # pylint: disable=too-few-public-methods
 88  class IL91874(displayio.EPaperDisplay):
 89      """IL91874 display driver"""
 90  
 91      def __init__(self, bus, **kwargs):
 92          start_sequence = bytearray(_START_SEQUENCE)
 93  
 94          width = kwargs["width"]
 95          height = kwargs["height"]
 96          if "rotation" in kwargs and kwargs["rotation"] % 180 != 0:
 97              width, height = height, width
 98          start_sequence[-7] = (width >> 8) & 0xFF
 99          start_sequence[-6] = width & 0xFF
100          start_sequence[-5] = (height >> 8) & 0xFF
101          start_sequence[-4] = height & 0xFF
102  
103          super().__init__(
104              bus,
105              start_sequence,
106              _STOP_SEQUENCE,
107              **kwargs,
108              ram_width=320,
109              ram_height=300,
110              busy_state=False,
111              write_black_ram_command=0x10,
112              black_bits_inverted=True,
113              write_color_ram_command=0x13,
114              refresh_display_command=0x12,
115              always_toggle_chip_select=True,
116          )