|
| 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/busio/SPI.h" |
| 10 | +#include "shared-bindings/fourwire/FourWire.h" |
| 11 | +#include "shared-bindings/microcontroller/Pin.h" |
| 12 | +#include "shared-module/displayio/__init__.h" |
| 13 | +#include "shared-module/displayio/mipi_constants.h" |
| 14 | +#include "shared-bindings/board/__init__.h" |
| 15 | + |
| 16 | +#define DELAY 0x80 |
| 17 | + |
| 18 | +// display init sequence according to LilyGO example app |
| 19 | +uint8_t display_init_sequence[] = { |
| 20 | + 0x01, DELAY, 0x96, // _SWRESET and Delay 150ms |
| 21 | + 0x11, DELAY, 0xFF, // _SLPOUT and Delay 500ms |
| 22 | + 0x3A, DELAY | 1, 0x55, 0x0A, // _COLMOD and Delay 10ms |
| 23 | + 0x21, DELAY, 0x0A, // _INVON Hack and Delay 10ms |
| 24 | + 0x13, DELAY, 0x0A, // _NORON and Delay 10ms |
| 25 | + 0x36, 0x01, 0x60, // _MADCTL |
| 26 | + 0x29, DELAY, 0xFF, // _DISPON and Delay 500ms |
| 27 | +}; |
| 28 | + |
| 29 | +void board_init(void) { |
| 30 | + busio_spi_obj_t *spi = common_hal_board_create_spi(0); |
| 31 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 32 | + bus->base.type = &fourwire_fourwire_type; |
| 33 | + |
| 34 | + common_hal_fourwire_fourwire_construct( |
| 35 | + bus, |
| 36 | + spi, |
| 37 | + &pin_GPIO42, // DC |
| 38 | + &pin_GPIO45, // CS |
| 39 | + &pin_GPIO0, // RST |
| 40 | + // 24000000, |
| 41 | + 40000000, // baudrate |
| 42 | + 0, // polarity |
| 43 | + 0 // phase |
| 44 | + ); |
| 45 | + busdisplay_busdisplay_obj_t *display = &allocate_display()->display; |
| 46 | + display->base.type = &busdisplay_busdisplay_type; |
| 47 | + |
| 48 | + common_hal_busdisplay_busdisplay_construct( |
| 49 | + display, |
| 50 | + bus, |
| 51 | + 320, // width (after rotation) |
| 52 | + 240, // height (after rotation) |
| 53 | + 0, // column start |
| 54 | + 0, // row start |
| 55 | + 0, // rotation |
| 56 | + 16, // color depth |
| 57 | + false, // grayscale |
| 58 | + false, // pixels in a byte share a row. Only valid for depths < 8 |
| 59 | + 1, // bytes per cell. Only valid for depths < 8 |
| 60 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 61 | + true, // reverse_pixels_in_word |
| 62 | + MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command |
| 63 | + MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command |
| 64 | + MIPI_COMMAND_WRITE_MEMORY_START, // write memory command |
| 65 | + display_init_sequence, |
| 66 | + sizeof(display_init_sequence), |
| 67 | + &pin_GPIO1, // backlight pin |
| 68 | + NO_BRIGHTNESS_COMMAND, |
| 69 | + 1.0f, // brightness |
| 70 | + false, // single_byte_bounds |
| 71 | + false, // data_as_commands |
| 72 | + true, // auto_refresh |
| 73 | + 60, // native_frames_per_second |
| 74 | + true, // backlight_on_high |
| 75 | + false, // SH1107_addressing |
| 76 | + 50000 // backlight pwm frequency |
| 77 | + ); |
| 78 | +} |
0 commit comments