|
| 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/busio/SPI.h" |
| 30 | +#include "shared-bindings/displayio/FourWire.h" |
| 31 | +#include "shared-bindings/microcontroller/Pin.h" |
| 32 | +#include "shared-module/displayio/__init__.h" |
| 33 | +#include "shared-module/displayio/mipi_constants.h" |
| 34 | + |
| 35 | +displayio_fourwire_obj_t board_display_obj; |
| 36 | + |
| 37 | +#define DELAY 0x80 |
| 38 | + |
| 39 | +// display init sequence according to LilyGO example app |
| 40 | +uint8_t display_init_sequence[] = { |
| 41 | + // sw reset |
| 42 | + 0x01, 0 | DELAY, 150, |
| 43 | + // sleep out |
| 44 | + 0x11, 0 | DELAY, 255, |
| 45 | + // normal display mode on |
| 46 | + 0x13, 0, |
| 47 | + // display and color format settings |
| 48 | + 0x36, 1, 0x08, |
| 49 | + 0xB6, 2, 0x0A, 0x82, |
| 50 | + 0x3A, 1 | DELAY, 0x55, 10, |
| 51 | + // ST7789V frame rate setting |
| 52 | + 0xB2, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33, |
| 53 | + // voltages: VGH / VGL |
| 54 | + 0xB7, 1, 0x35, |
| 55 | + // ST7789V power setting |
| 56 | + 0xBB, 1, 0x28, |
| 57 | + 0xC0, 1, 0x0C, |
| 58 | + 0xC2, 2, 0x01, 0xFF, |
| 59 | + 0xC3, 1, 0x10, |
| 60 | + 0xC4, 1, 0x20, |
| 61 | + 0xC6, 1, 0x0F, |
| 62 | + 0xD0, 2, 0xA4, 0xA1, |
| 63 | + // ST7789V gamma setting |
| 64 | + 0xE0, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x32, 0x44, 0x42, 0x06, 0x0E, 0x12, 0x14, 0x17, |
| 65 | + 0xE1, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x31, 0x54, 0x47, 0x0E, 0x1C, 0x17, 0x1B, 0x1E, |
| 66 | + 0x21, 0, |
| 67 | + // display on |
| 68 | + 0x29, 0 | DELAY, 255, |
| 69 | +}; |
| 70 | + |
| 71 | + |
| 72 | +void board_init(void) { |
| 73 | + // USB |
| 74 | + common_hal_never_reset_pin(&pin_GPIO19); |
| 75 | + common_hal_never_reset_pin(&pin_GPIO20); |
| 76 | + |
| 77 | + |
| 78 | + busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; |
| 79 | + |
| 80 | + common_hal_busio_spi_construct( |
| 81 | + spi, |
| 82 | + &pin_GPIO36, // CLK |
| 83 | + &pin_GPIO35, // MOSI |
| 84 | + NULL // MISO not connected |
| 85 | + ); |
| 86 | + |
| 87 | + common_hal_busio_spi_never_reset(spi); |
| 88 | + |
| 89 | + displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; |
| 90 | + bus->base.type = &displayio_fourwire_type; |
| 91 | + |
| 92 | + common_hal_displayio_fourwire_construct( |
| 93 | + bus, |
| 94 | + spi, |
| 95 | + &pin_GPIO39, // DC |
| 96 | + &pin_GPIO21, // CS |
| 97 | + &pin_GPIO40, // RST |
| 98 | + 40000000, // baudrate |
| 99 | + 0, // polarity |
| 100 | + 0 // phase |
| 101 | + ); |
| 102 | + displayio_display_obj_t* display = &displays[0].display; |
| 103 | + display->base.type = &displayio_display_type; |
| 104 | + |
| 105 | + // workaround as board_init() is called before reset_port() in main.c |
| 106 | + pwmout_reset(); |
| 107 | + |
| 108 | + |
| 109 | + common_hal_displayio_display_construct( |
| 110 | + display, |
| 111 | + bus, |
| 112 | + 240, // width (after rotation) |
| 113 | + 135, // height (after rotation) |
| 114 | + 52, // column start |
| 115 | + 40, // row start |
| 116 | + 90, // rotation |
| 117 | + 16, // color depth |
| 118 | + false, // grayscale |
| 119 | + false, // pixels in a byte share a row. Only valid for depths < 8 |
| 120 | + 1, // bytes per cell. Only valid for depths < 8 |
| 121 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 122 | + true, // reverse_pixels_in_word |
| 123 | + MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command |
| 124 | + MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command |
| 125 | + MIPI_COMMAND_WRITE_MEMORY_START, // write memory command |
| 126 | + display_init_sequence, |
| 127 | + sizeof(display_init_sequence), |
| 128 | + &pin_GPIO45, // backlight pin |
| 129 | + NO_BRIGHTNESS_COMMAND, |
| 130 | + 1.0f, // brightness (ignored) |
| 131 | + false, // auto_brightness |
| 132 | + false, // single_byte_bounds |
| 133 | + false, // data_as_commands |
| 134 | + true, // auto_refresh |
| 135 | + 60, // native_frames_per_second |
| 136 | + true, // backlight_on_high |
| 137 | + false // SH1107_addressing |
| 138 | + ); |
| 139 | + |
| 140 | + common_hal_never_reset_pin(&pin_GPIO45); // backlight pin |
| 141 | +} |
| 142 | + |
| 143 | +bool board_requests_safe_mode(void) { |
| 144 | + return false; |
| 145 | +} |
| 146 | + |
| 147 | +void reset_board(void) { |
| 148 | + |
| 149 | +} |
| 150 | + |
| 151 | +void board_deinit(void) { |
| 152 | +} |
0 commit comments