| 
 | 1 | +// This file is part of the CircuitPython project: https://circuitpython.org  | 
 | 2 | +//  | 
 | 3 | +// SPDX-FileCopyrightText: Copyright (c) 2025 natheihei  | 
 | 4 | +//  | 
 | 5 | +// SPDX-License-Identifier: MIT  | 
 | 6 | + | 
 | 7 | +#include "supervisor/board.h"  | 
 | 8 | +#include "mpconfigboard.h"  | 
 | 9 | +#include "shared-bindings/microcontroller/Pin.h"  | 
 | 10 | +#include "shared-bindings/busio/SPI.h"  | 
 | 11 | +#include "shared-bindings/fourwire/FourWire.h"  | 
 | 12 | +#include "shared-module/displayio/__init__.h"  | 
 | 13 | +#include "shared-module/displayio/mipi_constants.h"  | 
 | 14 | +#include "shared-bindings/board/__init__.h"  | 
 | 15 | + | 
 | 16 | +#define DELAY 0x80  | 
 | 17 | + | 
 | 18 | +// Driver is JD9853  | 
 | 19 | +// 172 X 320 Pixels RGB 18-bit  | 
 | 20 | +// Init sequence converted from Arduino example  | 
 | 21 | + | 
 | 22 | +uint8_t display_init_sequence[] = {  | 
 | 23 | +    // Command: 0x11 (SLPOUT: Sleep Out)  | 
 | 24 | +    // Description: Exits sleep mode. A 120ms delay is added for the power supply and clock circuits to stabilize.  | 
 | 25 | +    0x11, 0 | DELAY, 120,  | 
 | 26 | + | 
 | 27 | +    0xDF, 2, 0x98, 0x53,  | 
 | 28 | +    0xB2, 1, 0x23,  | 
 | 29 | + | 
 | 30 | +    0xB7, 4, 0x00, 0x47, 0x00, 0x6F,  | 
 | 31 | +    0xBB, 6, 0x1C, 0x1A, 0x55, 0x73, 0x63, 0xF0,  | 
 | 32 | +    0xC0, 2, 0x44, 0xA4,  | 
 | 33 | +    0xC1, 1, 0x16,  | 
 | 34 | +    0xC3, 8, 0x7D, 0x07, 0x14, 0x06, 0xCF, 0x71, 0x72, 0x77,  | 
 | 35 | +    0xC4, 12, 0x00, 0x00, 0xA0, 0x79, 0x0B, 0x0A, 0x16, 0x79, 0x0B, 0x0A, 0x16, 0x82,  | 
 | 36 | + | 
 | 37 | +    0xC8, 32, 0x3F, 0x32, 0x29, 0x29, 0x27, 0x2B, 0x27, 0x28, 0x28, 0x26, 0x25, 0x17, 0x12, 0x0D, 0x04, 0x00,  | 
 | 38 | +    0x3F, 0x32, 0x29, 0x29, 0x27, 0x2B, 0x27, 0x28, 0x28, 0x26, 0x25, 0x17, 0x12, 0x0D, 0x04, 0x00,  | 
 | 39 | + | 
 | 40 | +    0xD0, 5, 0x04, 0x06, 0x6B, 0x0F, 0x00,  | 
 | 41 | +    0xD7, 2, 0x00, 0x30,  | 
 | 42 | +    0xE6, 1, 0x14,  | 
 | 43 | +    0xDE, 1, 0x01,  | 
 | 44 | + | 
 | 45 | +    0xB7, 5, 0x03, 0x13, 0xEF, 0x35, 0x35,  | 
 | 46 | +    0xC1, 3, 0x14, 0x15, 0xC0,  | 
 | 47 | +    0xC2, 2, 0x06, 0x3A,  | 
 | 48 | +    0xC4, 2, 0x72, 0x12,  | 
 | 49 | +    0xBE, 1, 0x00,  | 
 | 50 | +    0xDE, 1, 0x02,  | 
 | 51 | + | 
 | 52 | +    0xE5, 3, 0x00, 0x02, 0x00,  | 
 | 53 | +    0xE5, 3, 0x01, 0x02, 0x00,  | 
 | 54 | + | 
 | 55 | +    0xDE, 1, 0x00,  | 
 | 56 | + | 
 | 57 | +    // Command: 0x35 (TEON: Tearing Effect Line ON)  | 
 | 58 | +    // Description: Turns on the Tearing Effect output signal.  | 
 | 59 | +    0x35, 1, 0x00,  | 
 | 60 | + | 
 | 61 | +    // Command: 0x3A (COLMOD: Pixel Format Set)  | 
 | 62 | +    // Description: Sets the pixel format for the MCU interface.  | 
 | 63 | +    0x3A, 1, 0x05,  | 
 | 64 | + | 
 | 65 | +    // Command: 0x2A (CASET: Column Address Set)  | 
 | 66 | +    // Description: Defines the accessible column range in frame memory.  | 
 | 67 | +    0x2A, 4, 0x00, 0x22, 0x00, 0xCD,  | 
 | 68 | + | 
 | 69 | +    // Command: 0x2B (PASET: Page Address Set)  | 
 | 70 | +    // Description: Defines the accessible page (row) range.  | 
 | 71 | +    0x2B, 4, 0x00, 0x00, 0x01, 0x3F,  | 
 | 72 | + | 
 | 73 | +    0xDE, 1, 0x02,  | 
 | 74 | +    0xE5, 3, 0x00, 0x02, 0x00,  | 
 | 75 | +    0xDE, 1, 0x00,  | 
 | 76 | + | 
 | 77 | +    // Command: 0x36 (MADCTL: Memory Access Control)  | 
 | 78 | +    // Description: Sets the read/write scanning direction of the frame memory.  | 
 | 79 | +    0x36, 1, 0x00,  | 
 | 80 | + | 
 | 81 | +    // Command: 0x21 (INVON: Display Inversion ON)  | 
 | 82 | +    // 0x21, 0 | DELAY, 10,  | 
 | 83 | + | 
 | 84 | +    // Command: 0x29 (DISPON: Display ON)  | 
 | 85 | +    // Description: Turns the display on by enabling output from the frame memory.  | 
 | 86 | +    0x29, 0,  | 
 | 87 | +};  | 
 | 88 | + | 
 | 89 | +static void display_init(void) {  | 
 | 90 | +    busio_spi_obj_t *spi = common_hal_board_create_spi(0);  | 
 | 91 | +    fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;  | 
 | 92 | +    bus->base.type = &fourwire_fourwire_type;  | 
 | 93 | + | 
 | 94 | +    common_hal_fourwire_fourwire_construct(  | 
 | 95 | +        bus,  | 
 | 96 | +        spi,  | 
 | 97 | +        &pin_GPIO45,    // DC  | 
 | 98 | +        &pin_GPIO21,    // CS  | 
 | 99 | +        &pin_GPIO40,    // RST  | 
 | 100 | +        80000000,       // baudrate  | 
 | 101 | +        0,              // polarity  | 
 | 102 | +        0               // phase  | 
 | 103 | +        );  | 
 | 104 | + | 
 | 105 | +    busdisplay_busdisplay_obj_t *display = &allocate_display()->display;  | 
 | 106 | +    display->base.type = &busdisplay_busdisplay_type;  | 
 | 107 | + | 
 | 108 | +    common_hal_busdisplay_busdisplay_construct(  | 
 | 109 | +        display,  | 
 | 110 | +        bus,  | 
 | 111 | +        172,            // width (after rotation)  | 
 | 112 | +        320,            // height (after rotation)  | 
 | 113 | +        34,             // column start  | 
 | 114 | +        0,              // row start  | 
 | 115 | +        0,              // rotation  | 
 | 116 | +        16,             // color depth  | 
 | 117 | +        false,          // grayscale  | 
 | 118 | +        false,          // pixels in a byte share a row. Only valid for depths < 8  | 
 | 119 | +        1,              // bytes per cell. Only valid for depths < 8  | 
 | 120 | +        false,          // reverse_pixels_in_byte. Only valid for depths < 8  | 
 | 121 | +        true,           // reverse_pixels_in_word  | 
 | 122 | +        MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command  | 
 | 123 | +        MIPI_COMMAND_SET_PAGE_ADDRESS,   // set row command  | 
 | 124 | +        MIPI_COMMAND_WRITE_MEMORY_START, // write memory command  | 
 | 125 | +        display_init_sequence,  | 
 | 126 | +        sizeof(display_init_sequence),  | 
 | 127 | +        &pin_GPIO46,    // backlight pin  | 
 | 128 | +        NO_BRIGHTNESS_COMMAND,  | 
 | 129 | +        1.0f,           // brightness  | 
 | 130 | +        false,          // single_byte_bounds  | 
 | 131 | +        false,          // data_as_commands  | 
 | 132 | +        true,           // auto_refresh  | 
 | 133 | +        60,             // native_frames_per_second  | 
 | 134 | +        true,           // backlight_on_high  | 
 | 135 | +        false,          // SH1107_addressing  | 
 | 136 | +        50000           // backlight pwm frequency  | 
 | 137 | +        );  | 
 | 138 | +}  | 
 | 139 | + | 
 | 140 | +void board_init(void) {  | 
 | 141 | +    // Display  | 
 | 142 | +    display_init();  | 
 | 143 | +}  | 
 | 144 | + | 
 | 145 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.  | 
0 commit comments