|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2021 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/busio/SPI.h" |
| 30 | +#include "shared-bindings/fourwire/FourWire.h" |
| 31 | +#include "shared-module/displayio/__init__.h" |
| 32 | +#include "shared-module/displayio/mipi_constants.h" |
| 33 | +#include "supervisor/shared/board.h" |
| 34 | + |
| 35 | +fourwire_fourwire_obj_t board_display_obj; |
| 36 | + |
| 37 | +#define DELAY 0x80 |
| 38 | + |
| 39 | +uint8_t display_init_sequence[] = { |
| 40 | + 0x01, 0 | DELAY, 150, // SWRESET |
| 41 | + |
| 42 | + 0x36, 1, 0x04, // MADCTL |
| 43 | + 0x35, 1, 0x00, // TEON |
| 44 | + 0xB2, 5, 0x0c, 0x0c, 0x00, 0x33, 0x33, // FRMCTR2 |
| 45 | + 0x3A, 1, 0x05, // COLMOD |
| 46 | + 0xB7, 1, 0x14, // GCTRL |
| 47 | + 0xBB, 1, 0x37, // VCOMS |
| 48 | + 0xC0, 1, 0x2c, // LCMCTRL |
| 49 | + 0xC2, 1, 0x01, // VDVVRHEN |
| 50 | + 0xC3, 1, 0x12, // VRHS |
| 51 | + 0xC4, 1, 0x20, // VDVS |
| 52 | + 0xD0, 2, 0xa4, 0xa1, // PWRCTRL1 |
| 53 | + 0xC6, 1, 0x0f, // FRCTRL2 |
| 54 | + 0xE0, 14, 0xd0, 0x04, 0x0d, 0x11, 0x13, 0x2b, 0x3f, 0x54, 0x4c, 0x18, 0x0d, 0x0b, 0x1f, 0x23, // GMCTRP1 |
| 55 | + 0xE1, 14, 0xd0, 0x04, 0x0c, 0x11, 0x13, 0x2c, 0x3f, 0x44, 0x51, 0x2f, 0x1f, 0x1f, 0x20, 0x23, // GMCTRN1 |
| 56 | + 0x21, 0, // INVON |
| 57 | + |
| 58 | + 0x11, 0 | DELAY, 255, // SLPOUT |
| 59 | + 0x29, 0 | DELAY, 100, // DISPON |
| 60 | + |
| 61 | + 0x2a, 4, 0x00, 0, 0x00, 0xfe, // CASET |
| 62 | + 0x2b, 4, 0x00, 0, 0x00, 0xfe, // RASET |
| 63 | + 0x2c, 0, // RAMWR |
| 64 | +}; |
| 65 | + |
| 66 | +void board_init(void) { |
| 67 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 68 | + busio_spi_obj_t *spi = &bus->inline_bus; |
| 69 | + common_hal_busio_spi_construct(spi, &pin_GPIO14, &pin_GPIO15, NULL, false); |
| 70 | + common_hal_busio_spi_never_reset(spi); |
| 71 | + |
| 72 | + bus->base.type = &fourwire_fourwire_type; |
| 73 | + common_hal_fourwire_fourwire_construct(bus, |
| 74 | + spi, |
| 75 | + &pin_GPIO12, // TFT_DC Command or data |
| 76 | + &pin_GPIO13, // TFT_CS Chip select |
| 77 | + NULL, // TFT_RST Reset |
| 78 | + 62500000, // Baudrate |
| 79 | + 0, // Polarity |
| 80 | + 0); // Phase |
| 81 | + |
| 82 | + busdisplay_busdisplay_obj_t *display = &allocate_display()->display; |
| 83 | + display->base.type = &busdisplay_busdisplay_type; |
| 84 | + common_hal_busdisplay_busdisplay_construct(display, |
| 85 | + bus, |
| 86 | + 240, // Width |
| 87 | + 280, // Height |
| 88 | + 0, // column start |
| 89 | + 20, // row start |
| 90 | + 0, // rotation |
| 91 | + 16, // Color depth |
| 92 | + false, // Grayscale |
| 93 | + false, // pixels in a byte share a row. Only valid for depths < 8 |
| 94 | + 1, // bytes per cell. Only valid for depths < 8 |
| 95 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 96 | + true, // reverse_bytes_in_word |
| 97 | + MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command |
| 98 | + MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command |
| 99 | + MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command |
| 100 | + display_init_sequence, |
| 101 | + sizeof(display_init_sequence), |
| 102 | + NULL, // no backlight pin |
| 103 | + NO_BRIGHTNESS_COMMAND, |
| 104 | + 1.0f, // brightness |
| 105 | + false, // single_byte_bounds |
| 106 | + false, // data_as_commands |
| 107 | + true, // auto_refresh |
| 108 | + 60, // native_frames_per_second |
| 109 | + true, // backlight_on_high |
| 110 | + false, // SH1107_addressing |
| 111 | + 0); // backlight pwm frequency |
| 112 | +} |
| 113 | + |
| 114 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
0 commit comments