|
| 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 | + |
| 29 | +#include "mpconfigboard.h" |
| 30 | +#include "common-hal/paralleldisplay/ParallelBus.h" |
| 31 | +#include "shared-module/displayio/__init__.h" |
| 32 | +#include "supervisor/shared/board.h" |
| 33 | + |
| 34 | +#define DELAY 0x80 |
| 35 | + |
| 36 | +enum reg { |
| 37 | + SWRESET = 0x01, |
| 38 | + TEOFF = 0x34, |
| 39 | + TEON = 0x35, |
| 40 | + MADCTL = 0x36, |
| 41 | + COLMOD = 0x3A, |
| 42 | + GCTRL = 0xB7, |
| 43 | + VCOMS = 0xBB, |
| 44 | + LCMCTRL = 0xC0, |
| 45 | + VDVVRHEN = 0xC2, |
| 46 | + VRHS = 0xC3, |
| 47 | + VDVS = 0xC4, |
| 48 | + FRCTRL2 = 0xC6, |
| 49 | + PWCTRL1 = 0xD0, |
| 50 | + PORCTRL = 0xB2, |
| 51 | + GMCTRP1 = 0xE0, |
| 52 | + GMCTRN1 = 0xE1, |
| 53 | + INVOFF = 0x20, |
| 54 | + SLPOUT = 0x11, |
| 55 | + DISPON = 0x29, |
| 56 | + GAMSET = 0x26, |
| 57 | + DISPOFF = 0x28, |
| 58 | + RAMWR = 0x2C, |
| 59 | + INVON = 0x21, |
| 60 | + CASET = 0x2A, |
| 61 | + RASET = 0x2B, |
| 62 | + PWMFRSEL = 0xCC |
| 63 | +}; |
| 64 | + |
| 65 | +enum MADCTL { |
| 66 | + ROW_ORDER = 0b10000000, |
| 67 | + COL_ORDER = 0b01000000, |
| 68 | + SWAP_XY = 0b00100000, // AKA "MV" |
| 69 | + SCAN_ORDER = 0b00010000, |
| 70 | + RGB_BGR = 0b00001000, |
| 71 | + HORIZ_ORDER = 0b00000100 |
| 72 | +}; |
| 73 | + |
| 74 | +uint8_t display_init_sequence[] = { |
| 75 | + SWRESET, DELAY, 0x64, // 100ms delay |
| 76 | + TEON, DELAY, 0x64, |
| 77 | + COLMOD, 1, 0x05, |
| 78 | + PORCTRL, 5, 0x0c, 0x0c, 0x00, 0x33, 0x33, |
| 79 | + LCMCTRL, 1, 0x2c, |
| 80 | + VDVVRHEN, 1, 0x01, |
| 81 | + VRHS, 1, 0x12, |
| 82 | + VDVS, 1, 0x20, |
| 83 | + PWCTRL1, 2, 0xa4, 0xa1, |
| 84 | + FRCTRL2, 1, 0x0f, |
| 85 | + GCTRL, 1, 0x35, |
| 86 | + VCOMS, 1, 0x1f, |
| 87 | + 0xd6, 1, 0xa1, |
| 88 | + GMCTRP1, 14, 0xd0, 0x08, 0x11, 0x08, 0x0c, 0x15, 0x39, 0x33, 0x50, 0x36, 0x13, 0x14, 0x29, 0x2D, |
| 89 | + GMCTRN1, 14, 0xd0, 0x08, 0x10, 0x08, 0x06, 0x06, 0x39, 0x44, 0x51, 0x0b, 0x16, 0x14, 0x2f, 0x31, |
| 90 | + INVON, DELAY, 0x64, |
| 91 | + SLPOUT, DELAY, 0x64, |
| 92 | + DISPON, DELAY, 0x64, |
| 93 | + CASET, 4, 0x00, 0x00, 0x01, 0x3F, |
| 94 | + RASET, 4, 0x00, 0x00, 0x00, 0xEF, |
| 95 | + MADCTL, 1, ROW_ORDER | SWAP_XY | SCAN_ORDER, |
| 96 | +}; |
| 97 | + |
| 98 | + |
| 99 | +void board_init(void) { |
| 100 | + paralleldisplay_parallelbus_obj_t *bus = &allocate_display_bus()->parallel_bus; |
| 101 | + bus->base.type = ¶lleldisplay_parallelbus_type; |
| 102 | + common_hal_paralleldisplay_parallelbus_construct(bus, |
| 103 | + &pin_GPIO14, // Data0 |
| 104 | + &pin_GPIO11, // Command or data |
| 105 | + &pin_GPIO10, // Chip select |
| 106 | + &pin_GPIO12, // Write |
| 107 | + &pin_GPIO13, // Read |
| 108 | + NULL, // Reset |
| 109 | + 2500000); // Frequency (not fast enough to hit 60Hz, but seems to avoid the ghosting issue) |
| 110 | + |
| 111 | + displayio_display_obj_t *display = &allocate_display()->display; |
| 112 | + display->base.type = &displayio_display_type; |
| 113 | + common_hal_displayio_display_construct(display, |
| 114 | + bus, |
| 115 | + 320, // Width |
| 116 | + 240, // Height |
| 117 | + 0, // column start |
| 118 | + 0, // row start |
| 119 | + 0, // rotation |
| 120 | + 16, // Color depth |
| 121 | + false, // grayscale |
| 122 | + false, // pixels_in_byte_share_row (unused for depths > 8) |
| 123 | + 1, // bytes per cell. Only valid for depths < 8 |
| 124 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 125 | + true, // reverse_pixels_in_word |
| 126 | + CASET, // Set column command |
| 127 | + RASET, // Set row command |
| 128 | + RAMWR, // Write memory command |
| 129 | + display_init_sequence, |
| 130 | + sizeof(display_init_sequence), |
| 131 | + &pin_GPIO2, // Backlight pin |
| 132 | + NO_BRIGHTNESS_COMMAND, |
| 133 | + 1.0f, // brightness (ignored) |
| 134 | + false, // single_byte_bounds |
| 135 | + false, // data_as_commands |
| 136 | + true, // auto_refresh |
| 137 | + 60, // native_frames_per_second |
| 138 | + true, // backlight_on_high |
| 139 | + false, // SH1107_addressing |
| 140 | + 250); // backlight pwm frequency (highest that will result 0.01 displaying an image) |
| 141 | + common_hal_never_reset_pin(&pin_GPIO2); // backlight pin |
| 142 | +} |
| 143 | + |
| 144 | +bool board_requests_safe_mode(void) { |
| 145 | + return false; |
| 146 | +} |
| 147 | + |
| 148 | +void reset_board(void) { |
| 149 | +} |
| 150 | + |
| 151 | +void board_deinit(void) { |
| 152 | + common_hal_displayio_release_displays(); |
| 153 | +} |
0 commit comments