|
| 1 | +// This file is part of the CircuitPython project: https://circuitpython.org |
| 2 | +// |
| 3 | +// SPDX-FileCopyrightText: Copyright (c) 2025 Cooper Dalrymple |
| 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 | + |
| 17 | +#define DELAY 0x80 |
| 18 | + |
| 19 | +// display init sequence according to TinyCircuits-Tiny-Game-Engine |
| 20 | +uint8_t display_init_sequence[] = { |
| 21 | + 0xFE, 0, // inter register enable 1 |
| 22 | + 0xEF, 0, // inter register enable 2 |
| 23 | + 0xB0, 1, 0xC0, |
| 24 | + 0xB1, 1, 0x80, |
| 25 | + 0xB2, 1, 0x2F, |
| 26 | + 0xB3, 1, 0x03, |
| 27 | + 0xB7, 1, 0x01, |
| 28 | + 0xB6, 1, 0x19, |
| 29 | + 0xAC, 1, 0xC8, // Complement Principle of RGB 5, 6, 5 |
| 30 | + 0xAB, 1, 0x0f, // ? |
| 31 | + 0x3A, 1, 0x05, // COLMOD: Pixel Format Set |
| 32 | + 0xB4, 1, 0x04, // ? |
| 33 | + 0xA8, 1, 0x07, // Frame Rate Set |
| 34 | + 0xB8, 1, 0x08, // ? |
| 35 | + 0xE7, 1, 0x5A, // VREG_CTL |
| 36 | + 0xE8, 1, 0x23, // VGH_SET |
| 37 | + 0xE9, 1, 0x47, // VGL_SET |
| 38 | + 0xEA, 1, 0x99, // VGH_VGL_CLK |
| 39 | + 0xC6, 1, 0x30, // ? |
| 40 | + 0xC7, 1, 0x1F, // ? |
| 41 | + 0xF0, 14, 0x05, 0x1D, 0x51, 0x2F, 0x85, 0x2A, 0x11, 0x62, 0x00, 0x07, 0x07, 0x0F, 0x08, 0x1F, // SET_GAMMA1 |
| 42 | + 0xF1, 14, 0x2E, 0x41, 0x62, 0x56, 0xA5, 0x3A, 0x3f, 0x60, 0x0F, 0x07, 0x0A, 0x18, 0x18, 0x1D, // SET_GAMMA2 |
| 43 | + 0x11, 0 | DELAY, 120, |
| 44 | + 0x29, 0 | DELAY, 10, // display on |
| 45 | +}; |
| 46 | + |
| 47 | +void board_init(void) { |
| 48 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 49 | + busio_spi_obj_t *spi = &bus->inline_bus; |
| 50 | + common_hal_busio_spi_construct( |
| 51 | + spi, |
| 52 | + DEFAULT_SPI_BUS_SCK, // CLK |
| 53 | + DEFAULT_SPI_BUS_MOSI, // MOSI |
| 54 | + NULL, // MISO not connected |
| 55 | + false // Not half-duplex |
| 56 | + ); |
| 57 | + |
| 58 | + common_hal_busio_spi_never_reset(spi); |
| 59 | + |
| 60 | + bus->base.type = &fourwire_fourwire_type; |
| 61 | + |
| 62 | + common_hal_fourwire_fourwire_construct( |
| 63 | + bus, |
| 64 | + spi, |
| 65 | + CIRCUITPY_BOARD_LCD_DC, // DC |
| 66 | + CIRCUITPY_BOARD_LCD_CS, // CS |
| 67 | + CIRCUITPY_BOARD_LCD_RESET, // RST |
| 68 | + 80000000, // baudrate |
| 69 | + 0, // polarity |
| 70 | + 0 // phase |
| 71 | + ); |
| 72 | + |
| 73 | + busdisplay_busdisplay_obj_t *display = &allocate_display()->display; |
| 74 | + display->base.type = &busdisplay_busdisplay_type; |
| 75 | + common_hal_busdisplay_busdisplay_construct( |
| 76 | + display, |
| 77 | + bus, |
| 78 | + 128, // width (after rotation) |
| 79 | + 128, // height (after rotation) |
| 80 | + 0, // column start |
| 81 | + 0, // row start |
| 82 | + 0, // rotation |
| 83 | + 16, // color depth |
| 84 | + false, // grayscale |
| 85 | + false, // pixels in a byte share a row. Only valid for depths < 8 |
| 86 | + 1, // bytes per cell. Only valid for depths < 8 |
| 87 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 88 | + true, // reverse_pixels_in_word |
| 89 | + MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command |
| 90 | + MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command |
| 91 | + MIPI_COMMAND_WRITE_MEMORY_START, // write memory command |
| 92 | + display_init_sequence, |
| 93 | + sizeof(display_init_sequence), |
| 94 | + CIRCUITPY_BOARD_LCD_BACKLIGHT, // backlight pin |
| 95 | + NO_BRIGHTNESS_COMMAND, |
| 96 | + 1.0f, // brightness |
| 97 | + false, // single_byte_bounds |
| 98 | + false, // data_as_commands |
| 99 | + true, // auto_refresh |
| 100 | + 60, // native_frames_per_second |
| 101 | + true, // backlight_on_high |
| 102 | + false, // SH1107_addressing |
| 103 | + 50000 // backlight pwm frequency |
| 104 | + ); |
| 105 | +} |
| 106 | + |
| 107 | +void reset_board(void) { |
| 108 | +} |
0 commit comments