|
| 1 | +// This file is part of the CircuitPython project: https://circuitpython.org |
| 2 | +// |
| 3 | +// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries |
| 4 | +// |
| 5 | +// SPDX-License-Identifier: MIT |
| 6 | + |
| 7 | +#include "supervisor/board.h" |
| 8 | +#include "mpconfigboard.h" |
| 9 | +#include "shared-bindings/microcontroller/Pin.h" |
| 10 | +#include "shared-module/displayio/__init__.h" |
| 11 | +#include "shared-module/displayio/mipi_constants.h" |
| 12 | + |
| 13 | +#define DELAY 0x80 |
| 14 | + |
| 15 | +// display init sequence according to Adafruit_CircuitPython_ST7735R |
| 16 | +// https://github.com/adafruit/Adafruit_CircuitPython_ST7735R |
| 17 | +uint8_t display_init_sequence[] = { |
| 18 | + // sw reset |
| 19 | + 0x01, 0 | DELAY, 0x96, |
| 20 | + // SLPOUT and Delay |
| 21 | + 0x11, 0 | DELAY, 0xFF, |
| 22 | + 0xB1, 0x03, 0x01, 0x2C, 0x2D, // _FRMCTR1 |
| 23 | + 0xB3, 0x06, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D, // _FRMCTR3 |
| 24 | + 0xB4, 0x01, 0x07, // _INVCTR line inversion |
| 25 | + 0xC0, 0x03, 0xA2, 0x02, 0x84, // _PWCTR1 GVDD = 4.7V, 1.0uA |
| 26 | + 0xC1, 0x01, 0xC5, // _PWCTR2 VGH=14.7V, VGL=-7.35V |
| 27 | + 0xC2, 0x02, 0x0A, 0x00, // _PWCTR3 Opamp current small, Boost frequency |
| 28 | + 0xC3, 0x02, 0x8A, 0x2A, |
| 29 | + 0xC4, 0x02, 0x8A, 0xEE, |
| 30 | + 0xC5, 0x01, 0x0E, // _VMCTR1 VCOMH = 4V, VOML = -1.1V |
| 31 | + 0x20, 0x00, // _INVOFF |
| 32 | + 0x36, 0x01, 0x18, // _MADCTL bottom to top refresh |
| 33 | + // 1 clk cycle nonoverlap, 2 cycle gate rise, 3 cycle osc equalie, |
| 34 | + // fix on VTL |
| 35 | + 0x3A, 0x01, 0x05, // COLMOD - 16bit color |
| 36 | + 0xE0, 0x10, 0x02, 0x1C, 0x07, 0x12, 0x37, 0x32, 0x29, 0x2D, 0x29, 0x25, 0x2B, 0x39, 0x00, 0x01, 0x03, 0x10, // _GMCTRP1 Gamma |
| 37 | + 0xE1, 0x10, 0x03, 0x1D, 0x07, 0x06, 0x2E, 0x2C, 0x29, 0x2D, 0x2E, 0x2E, 0x37, 0x3F, 0x00, 0x00, 0x02, 0x10, // _GMCTRN1 |
| 38 | + 0x13, 0 | DELAY, 0x0A, // _NORON |
| 39 | + 0x29, 0 | DELAY, 0x64, // _DISPON |
| 40 | + // 0x36, 0x01, 0xC0, // _MADCTL Default rotation plus BGR encoding |
| 41 | + 0x36, 0x01, 0xC8, // _MADCTL Default rotation plus RGB encoding |
| 42 | + 0x21, 0x00, // _INVON |
| 43 | +}; |
| 44 | + |
| 45 | +static void display_init(void) { |
| 46 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 47 | + busio_spi_obj_t *spi = &bus->inline_bus; |
| 48 | + |
| 49 | + common_hal_busio_spi_construct( |
| 50 | + spi, |
| 51 | + &pin_GPIO5, // CLK |
| 52 | + &pin_GPIO3, // MOSI |
| 53 | + NULL, // MISO not connected |
| 54 | + false); // Not half-duplex |
| 55 | + |
| 56 | + common_hal_busio_spi_never_reset(spi); |
| 57 | + |
| 58 | + bus->base.type = &fourwire_fourwire_type; |
| 59 | + |
| 60 | + common_hal_fourwire_fourwire_construct( |
| 61 | + bus, |
| 62 | + spi, |
| 63 | + &pin_GPIO2, // DC |
| 64 | + &pin_GPIO4, // CS |
| 65 | + &pin_GPIO1, // RST |
| 66 | + 10000000, // baudrate |
| 67 | + 0, // polarity |
| 68 | + 0 // phase |
| 69 | + ); |
| 70 | + |
| 71 | + busdisplay_busdisplay_obj_t *display = &allocate_display()->display; |
| 72 | + display->base.type = &busdisplay_busdisplay_type; |
| 73 | + |
| 74 | + common_hal_busdisplay_busdisplay_construct( |
| 75 | + display, |
| 76 | + bus, |
| 77 | + 160, // width (after rotation) |
| 78 | + 80, // height (after rotation) |
| 79 | + 26, // column start |
| 80 | + 1, // row start |
| 81 | + 90, // rotation |
| 82 | + 16, // color depth |
| 83 | + false, // grayscale |
| 84 | + false, // pixels in a byte share a row. Only valid for depths < 8 |
| 85 | + 1, // bytes per cell. Only valid for depths < 8 |
| 86 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 87 | + true, // reverse_pixels_in_word |
| 88 | + MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command |
| 89 | + MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command |
| 90 | + MIPI_COMMAND_WRITE_MEMORY_START, // write memory command |
| 91 | + display_init_sequence, |
| 92 | + sizeof(display_init_sequence), |
| 93 | + &pin_GPIO38, // backlight pin |
| 94 | + NO_BRIGHTNESS_COMMAND, |
| 95 | + 1.0f, // brightness |
| 96 | + false, // single_byte_bounds |
| 97 | + false, // data_as_commands |
| 98 | + true, // auto_refresh |
| 99 | + 60, // native_frames_per_second |
| 100 | + true, // backlight_on_high |
| 101 | + false, // SH1107_addressing |
| 102 | + 50000 // backlight pwm frequency |
| 103 | + ); |
| 104 | +} |
| 105 | + |
| 106 | +void board_init(void) { |
| 107 | + // Display |
| 108 | + display_init(); |
| 109 | +} |
| 110 | + |
| 111 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
0 commit comments