|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | + * of this software and associated documentation files (the "Software"), to deal |
| 10 | + * in the Software without restriction, including without limitation the rights |
| 11 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | + * copies of the Software, and to permit persons to whom the Software is |
| 13 | + * furnished to do so, subject to the following conditions: |
| 14 | + * |
| 15 | + * The above copyright notice and this permission notice shall be included in |
| 16 | + * all copies or substantial portions of the Software. |
| 17 | + * |
| 18 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | + * THE SOFTWARE. |
| 25 | + */ |
| 26 | + |
| 27 | +#include "supervisor/board.h" |
| 28 | +#include "mpconfigboard.h" |
| 29 | +#include "shared-bindings/board/__init__.h" |
| 30 | +#include "shared-bindings/microcontroller/Pin.h" |
| 31 | +#include "shared-module/displayio/__init__.h" |
| 32 | +#include "shared-module/displayio/mipi_constants.h" |
| 33 | +#include "components/driver/gpio/include/driver/gpio.h" |
| 34 | +#include "components/hal/include/hal/gpio_hal.h" |
| 35 | +#include "common-hal/microcontroller/Pin.h" |
| 36 | + |
| 37 | + |
| 38 | +uint8_t display_init_sequence[] = { |
| 39 | + 0x01, 0x80, 0x80, // # Software reset then delay 0x80 (128ms) |
| 40 | + 0xEF, 0x03, 0x03, 0x80, 0x02, |
| 41 | + 0xCF, 0x03, 0x00, 0xC1, 0x30, |
| 42 | + 0xED, 0x04, 0x64, 0x03, 0x12, 0x81, |
| 43 | + 0xE8, 0x03, 0x85, 0x00, 0x78, |
| 44 | + 0xCB, 0x05, 0x39, 0x2C, 0x00, 0x34, 0x02, |
| 45 | + 0xF7, 0x01, 0x20, |
| 46 | + 0xEA, 0x02, 0x00, 0x00, |
| 47 | + 0xc0, 0x01, 0x23, // # Power control VRH[5:0] |
| 48 | + 0xc1, 0x01, 0x10, // # Power control SAP[2:0];BT[3:0] |
| 49 | + 0xc5, 0x02, 0x3e, 0x28, // # VCM control |
| 50 | + 0xc7, 0x01, 0x86, // # VCM control2 |
| 51 | + 0x36, 0x01, 0x38, // # Memory Access Control |
| 52 | + 0x37, 0x01, 0x00, // # Vertical scroll zero |
| 53 | + 0x3a, 0x01, 0x55, // # COLMOD: Pixel Format Set |
| 54 | + 0xb1, 0x02, 0x00, 0x18, // # Frame Rate Control (In Normal Mode/Full Colors) |
| 55 | + 0xb6, 0x03, 0x08, 0x82, 0x27, // # Display Function Control |
| 56 | + 0xF2, 0x01, 0x00, // # 3Gamma Function Disable |
| 57 | + 0x26, 0x01, 0x01, // # Gamma curve selected |
| 58 | + 0xe0, 0x0f, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00, // # Set Gamma |
| 59 | + 0xe1, 0x0f, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F, // # Set Gamma |
| 60 | + 0x11, 0x80, 0x48, // # Exit Sleep then delay |
| 61 | + 0x29, 0x80, 0x78, // # Display on then delay 0x78 (120ms) |
| 62 | +}; |
| 63 | + |
| 64 | +static void display_init(void) { |
| 65 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 66 | + busio_spi_obj_t *spi = &bus->inline_bus; |
| 67 | + common_hal_busio_spi_construct(spi, &pin_GPIO14, &pin_GPIO13, &pin_GPIO12, false); |
| 68 | + common_hal_busio_spi_never_reset(spi); |
| 69 | + |
| 70 | + bus->base.type = &fourwire_fourwire_type; |
| 71 | + common_hal_fourwire_fourwire_construct(bus, |
| 72 | + spi, |
| 73 | + &pin_GPIO2, // TFT_DC Command or data |
| 74 | + &pin_GPIO15, // TFT_CS Chip select |
| 75 | + NULL, // TFT_RST Reset |
| 76 | + 6000000, // Baudrate |
| 77 | + 0, // Polarity |
| 78 | + 0); // Phase |
| 79 | + |
| 80 | + busdisplay_busdisplay_obj_t *display = &allocate_display()->display; |
| 81 | + display->base.type = &busdisplay_busdisplay_type; |
| 82 | + common_hal_busdisplay_busdisplay_construct(display, |
| 83 | + bus, |
| 84 | + 320, // Width |
| 85 | + 240, // Height |
| 86 | + 0, // column start |
| 87 | + 0, // row start |
| 88 | + 0, // rotation |
| 89 | + 16, // Color depth |
| 90 | + false, // Grayscale |
| 91 | + false, // pixels in a byte share a row. Only valid for depths < 8 |
| 92 | + 1, // bytes per cell. Only valid for depths < 8 |
| 93 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 94 | + true, // reverse_pixels_in_word |
| 95 | + MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command |
| 96 | + MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command |
| 97 | + MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command |
| 98 | + display_init_sequence, |
| 99 | + sizeof(display_init_sequence), |
| 100 | + &pin_GPIO21, // backlight pin |
| 101 | + NO_BRIGHTNESS_COMMAND, |
| 102 | + 1.0f, // brightness |
| 103 | + false, // single_byte_bounds |
| 104 | + false, // data_as_commands |
| 105 | + true, // auto_refresh |
| 106 | + 60, // native_frames_per_second |
| 107 | + true, // backlight_on_high |
| 108 | + false, // SH1107_addressing |
| 109 | + 50000); // backlight pwm frequency |
| 110 | +} |
| 111 | + |
| 112 | +void board_init(void) { |
| 113 | + display_init(); |
| 114 | +} |
| 115 | + |
| 116 | +bool espressif_board_reset_pin_number(gpio_num_t pin_number) { |
| 117 | + // Pull the speaker pin low to reduce noise on reset |
| 118 | + if (pin_number == 26) { |
| 119 | + // Turn on TFT |
| 120 | + gpio_set_direction(pin_number, GPIO_MODE_DEF_OUTPUT); |
| 121 | + gpio_set_level(pin_number, false); |
| 122 | + return true; |
| 123 | + } |
| 124 | + return false; |
| 125 | +} |
| 126 | + |
| 127 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
0 commit comments