|
| 1 | +// This file is part of the CircuitPython project: https://circuitpython.org |
| 2 | +// |
| 3 | +// SPDX-FileCopyrightText: Copyright (c) 2024 Olav Schettler |
| 4 | +// |
| 5 | +// SPDX-License-Identifier: MIT |
| 6 | + |
| 7 | +#include "supervisor/board.h" |
| 8 | +#include "mpconfigboard.h" |
| 9 | +#include "shared-bindings/board/__init__.h" |
| 10 | +#include "shared-bindings/microcontroller/Pin.h" |
| 11 | +#include "shared-module/displayio/__init__.h" |
| 12 | +#include "shared-module/displayio/mipi_constants.h" |
| 13 | +#include "driver/gpio.h" |
| 14 | +#include "common-hal/microcontroller/Pin.h" |
| 15 | +#include "shared-module/os/__init__.h" |
| 16 | + |
| 17 | +uint8_t display_init_sequence[] = { |
| 18 | + 0x01, 0x80, 0x80, // # Software reset then delay 0x80 (128ms) |
| 19 | + 0xEF, 0x03, 0x03, 0x80, 0x02, |
| 20 | + 0xCF, 0x03, 0x00, 0xC1, 0x30, |
| 21 | + 0xED, 0x04, 0x64, 0x03, 0x12, 0x81, |
| 22 | + 0xE8, 0x03, 0x85, 0x00, 0x78, |
| 23 | + 0xCB, 0x05, 0x39, 0x2C, 0x00, 0x34, 0x02, |
| 24 | + 0xF7, 0x01, 0x20, |
| 25 | + 0xEA, 0x02, 0x00, 0x00, |
| 26 | + 0xc0, 0x01, 0x23, // # Power control VRH[5:0] |
| 27 | + 0xc1, 0x01, 0x10, // # Power control SAP[2:0];BT[3:0] |
| 28 | + 0xc5, 0x02, 0x3e, 0x28, // # VCM control |
| 29 | + 0xc7, 0x01, 0x86, // # VCM control2 |
| 30 | + 0x36, 0x01, 0x38, // # Memory Access Control |
| 31 | + 0x37, 0x01, 0x00, // # Vertical scroll zero |
| 32 | + 0x3a, 0x01, 0x55, // # COLMOD: Pixel Format Set |
| 33 | + 0xb1, 0x02, 0x00, 0x18, // # Frame Rate Control (In Normal Mode/Full Colors) |
| 34 | + 0xb6, 0x03, 0x08, 0x82, 0x27, // # Display Function Control |
| 35 | + 0xF2, 0x01, 0x00, // # 3Gamma Function Disable |
| 36 | + 0x26, 0x01, 0x01, // # Gamma curve selected |
| 37 | + 0xe0, 0x0f, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00, // # Set Gamma |
| 38 | + 0xe1, 0x0f, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F, // # Set Gamma |
| 39 | + 0x11, 0x80, 0x48, // # Exit Sleep then delay |
| 40 | + 0x29, 0x80, 0x78, // # Display on then delay 0x78 (120ms) |
| 41 | +}; |
| 42 | + |
| 43 | +static void display_init(void) { |
| 44 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 45 | + busio_spi_obj_t *spi = &bus->inline_bus; |
| 46 | + mp_int_t rotation; |
| 47 | + common_hal_busio_spi_construct(spi, &pin_GPIO14, &pin_GPIO13, &pin_GPIO12, false); |
| 48 | + common_hal_busio_spi_never_reset(spi); |
| 49 | + |
| 50 | + bus->base.type = &fourwire_fourwire_type; |
| 51 | + common_hal_fourwire_fourwire_construct(bus, |
| 52 | + spi, |
| 53 | + &pin_GPIO2, // TFT_DC Command or data |
| 54 | + &pin_GPIO15, // TFT_CS Chip select |
| 55 | + NULL, // TFT_RST Reset |
| 56 | + 6000000, // Baudrate |
| 57 | + 0, // Polarity |
| 58 | + 0); // Phase |
| 59 | + |
| 60 | + busdisplay_busdisplay_obj_t *display = &allocate_display()->display; |
| 61 | + display->base.type = &busdisplay_busdisplay_type; |
| 62 | + os_getenv_err_t result = common_hal_os_getenv_int("CIRCUITPY_DISPLAY_ROTATION", &rotation); |
| 63 | + if (result != GETENV_OK) { |
| 64 | + rotation = 0; |
| 65 | + } |
| 66 | + |
| 67 | + common_hal_busdisplay_busdisplay_construct(display, |
| 68 | + bus, |
| 69 | + 320, // Width |
| 70 | + 240, // Height |
| 71 | + 0, // column start |
| 72 | + 0, // row start |
| 73 | + rotation, // rotation |
| 74 | + 16, // Color depth |
| 75 | + false, // Grayscale |
| 76 | + false, // pixels in a byte share a row. Only valid for depths < 8 |
| 77 | + 1, // bytes per cell. Only valid for depths < 8 |
| 78 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 79 | + true, // reverse_pixels_in_word |
| 80 | + MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command |
| 81 | + MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command |
| 82 | + MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command |
| 83 | + display_init_sequence, |
| 84 | + sizeof(display_init_sequence), |
| 85 | + &pin_GPIO27, // backlight pin |
| 86 | + NO_BRIGHTNESS_COMMAND, |
| 87 | + 1.0f, // brightness |
| 88 | + false, // single_byte_bounds |
| 89 | + false, // data_as_commands |
| 90 | + true, // auto_refresh |
| 91 | + 60, // native_frames_per_second |
| 92 | + true, // backlight_on_high |
| 93 | + false, // SH1107_addressing |
| 94 | + 50000); // backlight pwm frequency |
| 95 | +} |
| 96 | + |
| 97 | +void board_init(void) { |
| 98 | + display_init(); |
| 99 | +} |
| 100 | + |
| 101 | +bool espressif_board_reset_pin_number(gpio_num_t pin_number) { |
| 102 | + // Pull the speaker pin low to reduce noise on reset |
| 103 | + if (pin_number == 26) { |
| 104 | + // Turn on TFT |
| 105 | + config_pin_as_output_with_level(pin_number, false); |
| 106 | + return true; |
| 107 | + } |
| 108 | + return false; |
| 109 | +} |
| 110 | + |
| 111 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
0 commit comments