|
| 1 | +# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | +""" |
| 5 | +`adafruit_rgb_display.gc9a01a` |
| 6 | +==================================================== |
| 7 | +A simple driver for the GC9A01A-based displays. |
| 8 | +
|
| 9 | +* Author(s): Liz Clark |
| 10 | +
|
| 11 | +""" |
| 12 | + |
| 13 | +import time |
| 14 | +import busio |
| 15 | +import digitalio |
| 16 | +from micropython import const |
| 17 | +from adafruit_rgb_display.rgb import DisplaySPI |
| 18 | + |
| 19 | +try: |
| 20 | + from typing import Optional |
| 21 | +except ImportError: |
| 22 | + pass |
| 23 | + |
| 24 | +__version__ = "0.0.0+auto.0" |
| 25 | +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display.git" |
| 26 | + |
| 27 | +# Command constants |
| 28 | +_SWRESET = const(0xFE) |
| 29 | +_SLPOUT = const(0x11) |
| 30 | +_NORON = const(0x13) |
| 31 | +_INVOFF = const(0x20) |
| 32 | +_INVON = const(0x21) |
| 33 | +_DISPOFF = const(0x28) |
| 34 | +_DISPON = const(0x29) |
| 35 | +_CASET = const(0x2A) |
| 36 | +_RASET = const(0x2B) |
| 37 | +_RAMWR = const(0x2C) |
| 38 | +_RAMRD = const(0x2E) |
| 39 | +_MADCTL = const(0x36) |
| 40 | +_COLMOD = const(0x3A) |
| 41 | + |
| 42 | + |
| 43 | +class GC9A01A(DisplaySPI): |
| 44 | + """ |
| 45 | + A simple driver for the GC9A01A-based displays. |
| 46 | +
|
| 47 | + >>> import busio |
| 48 | + >>> import digitalio |
| 49 | + >>> import board |
| 50 | + >>> from adafruit_rgb_display import gc9a01a |
| 51 | + >>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO) |
| 52 | + >>> display = gc9a01a.GC9A01A(spi, cs=digitalio.DigitalInOut(board.CE0), |
| 53 | + ... dc=digitalio.DigitalInOut(board.D25), rst=digitalio.DigitalInOut(board.D27)) |
| 54 | + >>> display.fill(0x7521) |
| 55 | + >>> display.pixel(64, 64, 0) |
| 56 | + """ |
| 57 | + |
| 58 | + _COLUMN_SET = _CASET |
| 59 | + _PAGE_SET = _RASET |
| 60 | + _RAM_WRITE = _RAMWR |
| 61 | + _RAM_READ = _RAMRD |
| 62 | + _INIT = ( |
| 63 | + (_SWRESET, None), |
| 64 | + (0xEF, None), # Inter Register Enable2 |
| 65 | + (0xB6, b"\x00\x00"), # Display Function Control |
| 66 | + (_MADCTL, b"\x48"), # Memory Access Control - Set to BGR color filter panel |
| 67 | + (_COLMOD, b"\x05"), # Interface Pixel Format - 16 bits per pixel |
| 68 | + (0xC3, b"\x13"), # Power Control 2 |
| 69 | + (0xC4, b"\x13"), # Power Control 3 |
| 70 | + (0xC9, b"\x22"), # Power Control 4 |
| 71 | + (0xF0, b"\x45\x09\x08\x08\x26\x2a"), # SET_GAMMA1 |
| 72 | + (0xF1, b"\x43\x70\x72\x36\x37\x6f"), # SET_GAMMA2 |
| 73 | + (0xF2, b"\x45\x09\x08\x08\x26\x2a"), # SET_GAMMA3 |
| 74 | + (0xF3, b"\x43\x70\x72\x36\x37\x6f"), # SET_GAMMA4 |
| 75 | + (0x66, b"\x3c\x00\xcd\x67\x45\x45\x10\x00\x00\x00"), |
| 76 | + (0x67, b"\x00\x3c\x00\x00\x00\x01\x54\x10\x32\x98"), |
| 77 | + (0x74, b"\x10\x85\x80\x00\x00\x4e\x00"), |
| 78 | + (0x98, b"\x3e\x07"), |
| 79 | + (0x35, None), # Tearing Effect Line ON |
| 80 | + (_INVON, None), # Display Inversion ON |
| 81 | + (_SLPOUT, None), # Sleep Out Mode |
| 82 | + (_NORON, None), # Normal Display Mode ON |
| 83 | + (_DISPON, None), # Display ON |
| 84 | + ) |
| 85 | + |
| 86 | + # pylint: disable-msg=useless-super-delegation, too-many-arguments |
| 87 | + def __init__( |
| 88 | + self, |
| 89 | + spi: busio.SPI, |
| 90 | + dc: digitalio.DigitalInOut, |
| 91 | + cs: digitalio.DigitalInOut, |
| 92 | + rst: Optional[digitalio.DigitalInOut] = None, |
| 93 | + width: int = 240, |
| 94 | + height: int = 240, |
| 95 | + baudrate: int = 24000000, |
| 96 | + polarity: int = 0, |
| 97 | + phase: int = 0, |
| 98 | + *, |
| 99 | + x_offset: int = 0, |
| 100 | + y_offset: int = 0, |
| 101 | + rotation: int = 0 |
| 102 | + ) -> None: |
| 103 | + super().__init__( |
| 104 | + spi, |
| 105 | + dc, |
| 106 | + cs, |
| 107 | + rst, |
| 108 | + width, |
| 109 | + height, |
| 110 | + baudrate=baudrate, |
| 111 | + polarity=polarity, |
| 112 | + phase=phase, |
| 113 | + x_offset=x_offset, |
| 114 | + y_offset=y_offset, |
| 115 | + rotation=rotation, |
| 116 | + ) |
| 117 | + |
| 118 | + def init(self) -> None: |
| 119 | + """Initialize the display.""" |
| 120 | + if self.rst: |
| 121 | + self.rst.value = 0 |
| 122 | + time.sleep(0.05) |
| 123 | + self.rst.value = 1 |
| 124 | + time.sleep(0.05) |
| 125 | + |
| 126 | + super().init() |
0 commit comments