|
| 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-module/displayio/__init__.h" |
| 30 | +#include "shared-module/displayio/mipi_constants.h" |
| 31 | + |
| 32 | +#define DELAY 0x80 |
| 33 | + |
| 34 | + |
| 35 | +// display init sequence according to Adafruit_CircuitPython_ST7735R |
| 36 | +// https://github.com/adafruit/Adafruit_CircuitPython_ST7735R |
| 37 | +uint8_t display_init_sequence[] = { |
| 38 | + // sw reset |
| 39 | + 0x01, 0 | DELAY, 0x96, |
| 40 | + // SLPOUT and Delay |
| 41 | + 0x11, 0 | DELAY, 0xFF, |
| 42 | + 0xB1, 0x03, 0x01, 0x2C, 0x2D, // _FRMCTR1 |
| 43 | + 0xB3, 0x06, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D, // _FRMCTR3 |
| 44 | + 0xB4, 0x01, 0x07, // _INVCTR line inversion |
| 45 | + 0xC0, 0x03, 0xA2, 0x02, 0x84, // _PWCTR1 GVDD = 4.7V, 1.0uA |
| 46 | + 0xC1, 0x01, 0xC5, // _PWCTR2 VGH=14.7V, VGL=-7.35V |
| 47 | + 0xC2, 0x02, 0x0A, 0x00, // _PWCTR3 Opamp current small, Boost frequency |
| 48 | + 0xC3, 0x02, 0x8A, 0x2A, |
| 49 | + 0xC4, 0x02, 0x8A, 0xEE, |
| 50 | + 0xC5, 0x01, 0x0E, // _VMCTR1 VCOMH = 4V, VOML = -1.1V |
| 51 | + 0x20, 0x00, // _INVOFF |
| 52 | + 0x36, 0x01, 0x18, // _MADCTL bottom to top refresh |
| 53 | + // 1 clk cycle nonoverlap, 2 cycle gate rise, 3 cycle osc equalie, |
| 54 | + // fix on VTL |
| 55 | + 0x3A, 0x01, 0x05, // COLMOD - 16bit color |
| 56 | + 0xE0, 0x10, 0x02, 0x1C, 0x07, 0x12, 0x37, 0x32, 0x29, 0x2D, 0x29, 0x25, 0x2B, 0x39, 0x00, 0x01, 0x03, 0x10, // _GMCTRP1 Gamma |
| 57 | + 0xE1, 0x10, 0x03, 0x1D, 0x07, 0x06, 0x2E, 0x2C, 0x29, 0x2D, 0x2E, 0x2E, 0x37, 0x3F, 0x00, 0x00, 0x02, 0x10, // _GMCTRN1 |
| 58 | + 0x13, 0 | DELAY, 0x0A, // _NORON |
| 59 | + 0x29, 0 | DELAY, 0x64, // _DISPON |
| 60 | + // 0x36, 0x01, 0xC0, // _MADCTL Default rotation plus BGR encoding |
| 61 | + 0x36, 0x01, 0xC8, // _MADCTL Default rotation plus RGB encoding |
| 62 | + 0x21, 0x00, // _INVON |
| 63 | +}; |
| 64 | + |
| 65 | +static void display_init(void) { |
| 66 | + busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; |
| 67 | + common_hal_busio_spi_construct( |
| 68 | + spi, |
| 69 | + &pin_GPIO10, // CLK |
| 70 | + &pin_GPIO11, // MOSI |
| 71 | + NULL, // MISO not connected |
| 72 | + false // Not half-duplex |
| 73 | + ); |
| 74 | + |
| 75 | + common_hal_busio_spi_never_reset(spi); |
| 76 | + |
| 77 | + displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; |
| 78 | + bus->base.type = &displayio_fourwire_type; |
| 79 | + |
| 80 | + common_hal_displayio_fourwire_construct( |
| 81 | + bus, |
| 82 | + spi, |
| 83 | + &pin_GPIO8, // DC |
| 84 | + &pin_GPIO9, // CS |
| 85 | + &pin_GPIO12, // RST |
| 86 | + 40000000, // baudrate |
| 87 | + 0, // polarity |
| 88 | + 0 // phase |
| 89 | + ); |
| 90 | + |
| 91 | + displayio_display_obj_t *display = &displays[0].display; |
| 92 | + display->base.type = &displayio_display_type; |
| 93 | + common_hal_displayio_display_construct( |
| 94 | + display, |
| 95 | + bus, |
| 96 | + 160, // width (after rotation) |
| 97 | + 80, // height (after rotation) |
| 98 | + 26, // column start |
| 99 | + 1, // row start |
| 100 | + 90, // rotation |
| 101 | + 16, // color depth |
| 102 | + false, // grayscale |
| 103 | + false, // pixels in a byte share a row. Only valid for depths < 8 |
| 104 | + 1, // bytes per cell. Only valid for depths < 8 |
| 105 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 106 | + true, // reverse_pixels_in_word |
| 107 | + MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command |
| 108 | + MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command |
| 109 | + MIPI_COMMAND_WRITE_MEMORY_START, // write memory command |
| 110 | + display_init_sequence, |
| 111 | + sizeof(display_init_sequence), |
| 112 | + &pin_GPIO25, // backlight pin |
| 113 | + NO_BRIGHTNESS_COMMAND, |
| 114 | + 1.0f, // brightness |
| 115 | + false, // single_byte_bounds |
| 116 | + false, // data_as_commands |
| 117 | + true, // auto_refresh |
| 118 | + 60, // native_frames_per_second |
| 119 | + true, // backlight_on_high |
| 120 | + false, // SH1107_addressing |
| 121 | + 50000 // backlight pwm frequency |
| 122 | + ); |
| 123 | +} |
| 124 | + |
| 125 | +void board_init(void) { |
| 126 | + // Display |
| 127 | + display_init(); |
| 128 | +} |
| 129 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
0 commit comments