|
6 | 6 | `adafruit_jd79661`
|
7 | 7 | ================================================================================
|
8 | 8 |
|
9 |
| -CircuitPython library for the JD79661 e-paper driver IC |
| 9 | +CircuitPython `displayio` driver for JD79661-based ePaper displays |
10 | 10 |
|
11 | 11 |
|
12 | 12 | * Author(s): Scott Shawcroft
|
|
16 | 16 |
|
17 | 17 | **Hardware:**
|
18 | 18 |
|
19 |
| -.. todo:: Add links to any specific hardware product page(s), or category page(s). |
20 |
| - Use unordered list & hyperlink rST inline format: "* `Link Text <url>`_" |
| 19 | +* JD79661-based 4-color ePaper displays (128x250 resolution) - Black, White, Red, Yellow |
21 | 20 |
|
22 | 21 | **Software and Dependencies:**
|
23 | 22 |
|
24 | 23 | * Adafruit CircuitPython firmware for the supported boards:
|
25 |
| - https://circuitpython.org/downloads |
| 24 | + https://github.com/adafruit/circuitpython/releases |
26 | 25 |
|
27 |
| -.. todo:: Uncomment or remove the Bus Device and/or the Register library dependencies |
28 |
| - based on the library's use of either. |
29 |
| -
|
30 |
| -# * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice |
31 |
| -# * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register |
32 | 26 | """
|
33 | 27 |
|
34 |
| -# imports |
| 28 | +from epaperdisplay import EPaperDisplay |
| 29 | + |
| 30 | +try: |
| 31 | + import typing |
| 32 | + |
| 33 | + from fourwire import FourWire |
| 34 | +except ImportError: |
| 35 | + pass |
| 36 | + |
35 | 37 |
|
36 | 38 | __version__ = "0.0.0+auto.0"
|
37 | 39 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_JD79661.git"
|
| 40 | + |
| 41 | +# JD79661 Command definitions |
| 42 | +_JD79661_PANEL_SETTING = 0x00 |
| 43 | +_JD79661_POWER_SETTING = 0x01 |
| 44 | +_JD79661_POWER_OFF = 0x02 |
| 45 | +_JD79661_POWER_ON = 0x04 |
| 46 | +_JD79661_BOOSTER_SOFTSTART = 0x06 |
| 47 | +_JD79661_DEEP_SLEEP = 0x07 |
| 48 | +_JD79661_DATA_START_XMIT = 0x10 |
| 49 | +_JD79661_DISPLAY_REFRESH = 0x12 |
| 50 | +_JD79661_CDI = 0x50 |
| 51 | +_JD79661_PLL_CONTROL = 0x60 |
| 52 | +_JD79661_RESOLUTION = 0x61 |
| 53 | + |
| 54 | +_START_SEQUENCE = ( |
| 55 | + b"\x4d\x01\x78" # Set register 0x4D to 0x78 |
| 56 | + b"\x00\x02\x8f\x29" # Panel setting (128x250 resolution) |
| 57 | + b"\x01\x02\x07\x00" # Power setting |
| 58 | + b"\x03\x03\x10\x54\x44" # Power offset |
| 59 | + b"\x06\x07\x05\x00\x3F\x0A\x25\x12\x1A" # Booster soft start |
| 60 | + b"\x50\x01\x37" # CDI |
| 61 | + b"\x60\x02\x02\x02" # TCON |
| 62 | + b"\x61\x04\x00\x80\x00\xfa" # Resolution (0, 128, 0, 250) |
| 63 | + b"\xe7\x01\x1c" # Additional config register |
| 64 | + b"\xe3\x01\x22" # Additional config register |
| 65 | + b"\xb4\x01\xd0" # Additional config register |
| 66 | + b"\xb5\x01\x03" # Additional config register |
| 67 | + b"\xe9\x01\x01" # Additional config register |
| 68 | + b"\x30\x01\x08" # PLL Control |
| 69 | + b"\x04\x00" # Power on and wait |
| 70 | +) |
| 71 | + |
| 72 | +_STOP_SEQUENCE = ( |
| 73 | + b"\x02\x80\x00" # Power off and wait |
| 74 | + b"\x07\x01\xa5" # Deep sleep |
| 75 | +) |
| 76 | + |
| 77 | +_REFRESH_SEQUENCE = ( |
| 78 | + b"\x12\x01\x00" # Display refresh |
| 79 | +) |
| 80 | + |
| 81 | +# pylint: disable=too-few-public-methods |
| 82 | +class JD79661(EPaperDisplay): |
| 83 | + r"""JD79661 driver |
| 84 | +
|
| 85 | + :param bus: The data bus the display is on |
| 86 | + :param \**kwargs: |
| 87 | + See below |
| 88 | +
|
| 89 | + :Keyword Arguments: |
| 90 | + * *width* (``int``) -- |
| 91 | + Display width |
| 92 | + * *height* (``int``) -- |
| 93 | + Display height |
| 94 | + * *rotation* (``int``) -- |
| 95 | + Display rotation |
| 96 | + """ |
| 97 | + |
| 98 | + def __init__(self, bus: FourWire, **kwargs) -> None: |
| 99 | + stop_sequence = bytearray(_STOP_SEQUENCE) |
| 100 | + try: |
| 101 | + bus.reset() |
| 102 | + except RuntimeError: |
| 103 | + # No reset pin defined, so no deep sleeping |
| 104 | + stop_sequence = b"" |
| 105 | + |
| 106 | + start_sequence = bytearray(_START_SEQUENCE ) |
| 107 | + |
| 108 | + width = kwargs.get("width", 128) |
| 109 | + height = kwargs.get("height", 250) |
| 110 | + if "rotation" in kwargs and kwargs["rotation"] % 180 != 90: |
| 111 | + width, height = height, width |
| 112 | + |
| 113 | + # Update resolution in start sequence (bytes at position for resolution command) |
| 114 | + # Find the resolution command in the sequence and update it |
| 115 | + res_pos = start_sequence.find(b'\x61\x04') |
| 116 | + if res_pos != -1: |
| 117 | + if height % 4 != 0: |
| 118 | + height += 4 - height % 4 |
| 119 | + start_sequence[res_pos + 2] = (height >> 8) & 0xFF |
| 120 | + start_sequence[res_pos + 3] = height & 0xFF |
| 121 | + start_sequence[res_pos + 4] = (width >> 8) & 0xFF |
| 122 | + start_sequence[res_pos + 5] = width & 0xFF |
| 123 | + |
| 124 | + print(start_sequence.hex(" ")) |
| 125 | + |
| 126 | + super().__init__( |
| 127 | + bus, |
| 128 | + start_sequence, |
| 129 | + stop_sequence, |
| 130 | + **kwargs, |
| 131 | + ram_width=128, |
| 132 | + ram_height=250, |
| 133 | + busy_state=False, |
| 134 | + write_black_ram_command=_JD79661_DATA_START_XMIT, |
| 135 | + write_color_ram_command=None, # JD79661 uses single RAM with 2-bit pixels |
| 136 | + refresh_display_command=_REFRESH_SEQUENCE, |
| 137 | + always_toggle_chip_select=True, |
| 138 | + address_little_endian=False |
| 139 | + ) |
0 commit comments