|
| 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 | + |
| 10 | +#include "shared-bindings/busio/SPI.h" |
| 11 | +#include "shared-bindings/fourwire/FourWire.h" |
| 12 | +#include "shared-bindings/microcontroller/Pin.h" |
| 13 | +#include "shared-module/displayio/__init__.h" |
| 14 | +#include "shared-module/displayio/mipi_constants.h" |
| 15 | +#include "shared-bindings/board/__init__.h" |
| 16 | + |
| 17 | + |
| 18 | +uint8_t display_init_sequence[] = { |
| 19 | + /* |
| 20 | + 0, 0xae, // display off |
| 21 | + 0xd5, 0, 0x80, // set display clock div |
| 22 | + 0, 0xd3, 0, 0x00, // set display offset |
| 23 | + 0, 0x40, // set start line |
| 24 | + 0, 0xa4, // display all on, resume |
| 25 | + 0, 0xa6, // normal display |
| 26 | + 0, 0x8d, 0, 0x14, // charge pump |
| 27 | + 0, 0x20, 0, 0x00, // memory mode |
| 28 | + 0, 0xa0, // segremap |
| 29 | + 0, 0xc0, // com scan increment |
| 30 | + 0, 0x81, 0, 0xff, // set contrast |
| 31 | + 0, 0xd9, 0, 0xf1, // set precharge |
| 32 | + 0, 0xd8, 0, 0x20, // set v com detect |
| 33 | + 0, 0xa8, 0, 40-1, // set multiplex |
| 34 | + 0, 0xda, 0, 0x12, // set com pins |
| 35 | + 0, 0xad, 0, 0x30, |
| 36 | + 0, 0xaf, // on |
| 37 | + */ |
| 38 | + |
| 39 | + 0xae, 0, // sleep |
| 40 | + 0xd5, 1, 0x80, // fOsc divide by 2 |
| 41 | + 0xd3, 1, 0x00, // set display offset |
| 42 | + 0x40, 1, 0x00, // set start line |
| 43 | + 0xa4, 0, // display all on, resume |
| 44 | + 0xa6, 0, // normal display |
| 45 | + 0x8d, 1, 0x14, // charge pump |
| 46 | + 0x20, 1, 0x00, // memory mode |
| 47 | + 0xa0, 0, // segremap |
| 48 | + 0xc0, 0, // com scan increment |
| 49 | + 0x81, 1, 0xff, // set contrast |
| 50 | + 0xd9, 1, 0xf1, // set precharge |
| 51 | + 0xd8, 1, 0x20, // set v com detect |
| 52 | + 0xa8, 1, 40-1, // set multiplex |
| 53 | + 0xda, 1, 0x12, // set com pins |
| 54 | + 0xad, 1, 0x30, |
| 55 | + 0xaf, 0, // on |
| 56 | +}; |
| 57 | + |
| 58 | +void board_init(void) { |
| 59 | + busio_spi_obj_t *spi = common_hal_board_create_spi(0); |
| 60 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 61 | + bus->base.type = &fourwire_fourwire_type; |
| 62 | + common_hal_fourwire_fourwire_construct(bus, |
| 63 | + spi, |
| 64 | + CIRCUITPY_BOARD_OLED_DC, // Command or data |
| 65 | + CIRCUITPY_BOARD_OLED_CS, // Chip select |
| 66 | + CIRCUITPY_BOARD_OLED_RESET, // Reset |
| 67 | + 10000000, // Baudrate |
| 68 | + 0, // Polarity |
| 69 | + 0); // Phase |
| 70 | + |
| 71 | + busdisplay_busdisplay_obj_t *display = &allocate_display()->display; |
| 72 | + display->base.type = &busdisplay_busdisplay_type; |
| 73 | + common_hal_busdisplay_busdisplay_construct( |
| 74 | + display, |
| 75 | + bus, |
| 76 | + 72, // Width (after rotation) |
| 77 | + 40, // Height (after rotation) |
| 78 | + 28, // column start |
| 79 | + 0, // row start |
| 80 | + 0, // rotation |
| 81 | + 1, // Color depth |
| 82 | + true, // grayscale |
| 83 | + false, // pixels in byte share row. only used for depth < 8 |
| 84 | + 1, // bytes per cell. Only valid for depths < 8 |
| 85 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 86 | + true, // reverse_pixels_in_word |
| 87 | + 0, // Set column command |
| 88 | + 0, // Set row command |
| 89 | + 0, // Write memory command |
| 90 | + display_init_sequence, |
| 91 | + sizeof(display_init_sequence), |
| 92 | + NULL, // backlight pin |
| 93 | + 0x81, |
| 94 | + 1.0f, // brightness |
| 95 | + true, // single_byte_bounds |
| 96 | + true, // data_as_commands |
| 97 | + true, // auto_refresh |
| 98 | + 60, // native_frames_per_second |
| 99 | + true, // backlight_on_high |
| 100 | + true, // SH1107_addressing |
| 101 | + 50000); // backlight pwm frequency |
| 102 | +} |
| 103 | + |
| 104 | +void reset_board(void) { |
| 105 | +} |
0 commit comments