|
| 1 | +// This file is part of the CircuitPython project: https://circuitpython.org |
| 2 | +// |
| 3 | +// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries |
| 4 | +// |
| 5 | +// SPDX-License-Identifier: MIT |
| 6 | + |
| 7 | +#include "supervisor/board.h" |
| 8 | +#include "mpconfigboard.h" |
| 9 | +#include "shared-bindings/busio/SPI.h" |
| 10 | +#include "shared-bindings/fourwire/FourWire.h" |
| 11 | +#include "shared-bindings/microcontroller/Pin.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 | + |
| 17 | +#define DELAY 0x80 |
| 18 | + |
| 19 | +// display init sequence according to LilyGO example app |
| 20 | +uint8_t display_init_sequence[] = { |
| 21 | + // sw reset |
| 22 | + 0x01, 0 | DELAY, 150, |
| 23 | + // sleep out |
| 24 | + 0x11, 0 | DELAY, 255, |
| 25 | + // normal display mode on |
| 26 | + 0x13, 0, |
| 27 | + // display and color format settings |
| 28 | + 0x36, 1, 0x68, |
| 29 | + 0xB6, 2, 0x0A, 0x82, |
| 30 | + 0x3A, 1 | DELAY, 0x55, 10, |
| 31 | + // ST7789V frame rate setting |
| 32 | + 0xB2, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33, |
| 33 | + // voltages: VGH / VGL |
| 34 | + 0xB7, 1, 0x35, |
| 35 | + // ST7789V power setting |
| 36 | + 0xBB, 1, 0x28, |
| 37 | + 0xC0, 1, 0x0C, |
| 38 | + 0xC2, 2, 0x01, 0xFF, |
| 39 | + 0xC3, 1, 0x10, |
| 40 | + 0xC4, 1, 0x20, |
| 41 | + 0xC6, 1, 0x0F, |
| 42 | + 0xD0, 2, 0xA4, 0xA1, |
| 43 | + // ST7789V gamma setting |
| 44 | + 0xE0, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x32, 0x44, 0x42, 0x06, 0x0E, 0x12, 0x14, 0x17, |
| 45 | + 0xE1, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x31, 0x54, 0x47, 0x0E, 0x1C, 0x17, 0x1B, 0x1E, |
| 46 | + 0x21, 0, |
| 47 | + // display on |
| 48 | + 0x29, 0 | DELAY, 255, |
| 49 | +}; |
| 50 | + |
| 51 | + |
| 52 | +void board_init(void) { |
| 53 | + busio_spi_obj_t *spi = common_hal_board_create_spi(0); |
| 54 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 55 | + bus->base.type = &fourwire_fourwire_type; |
| 56 | + |
| 57 | + common_hal_fourwire_fourwire_construct( |
| 58 | + bus, |
| 59 | + spi, |
| 60 | + &pin_GPIO6, // DC |
| 61 | + &pin_GPIO5, // CS |
| 62 | + &pin_GPIO1, // RST |
| 63 | + 40000000, // baudrate |
| 64 | + 0, // polarity |
| 65 | + 0 // phase |
| 66 | + ); |
| 67 | + busdisplay_busdisplay_obj_t *display = &allocate_display()->display; |
| 68 | + display->base.type = &busdisplay_busdisplay_type; |
| 69 | + |
| 70 | + common_hal_busdisplay_busdisplay_construct( |
| 71 | + display, |
| 72 | + bus, |
| 73 | + 128, // width (after rotation) |
| 74 | + 128, // height (after rotation) |
| 75 | + 1, // column start |
| 76 | + 2, // row start |
| 77 | + 90, // rotation |
| 78 | + 16, // color depth |
| 79 | + false, // grayscale |
| 80 | + false, // pixels in a byte share a row. Only valid for depths < 8 |
| 81 | + 1, // bytes per cell. Only valid for depths < 8 |
| 82 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 83 | + true, // reverse_pixels_in_word |
| 84 | + MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command |
| 85 | + MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command |
| 86 | + MIPI_COMMAND_WRITE_MEMORY_START, // write memory command |
| 87 | + display_init_sequence, |
| 88 | + sizeof(display_init_sequence), |
| 89 | + &pin_GPIO10, // backlight pin |
| 90 | + NO_BRIGHTNESS_COMMAND, |
| 91 | + 1.0f, // brightness |
| 92 | + false, // single_byte_bounds |
| 93 | + false, // data_as_commands |
| 94 | + true, // auto_refresh |
| 95 | + 60, // native_frames_per_second |
| 96 | + false, // backlight_on_high |
| 97 | + false, // SH1107_addressing |
| 98 | + 50000 // backlight pwm frequency |
| 99 | + ); |
| 100 | +} |
0 commit comments