|
| 1 | +// This file is part of the CircuitPython project: https://circuitpython.org |
| 2 | +// |
| 3 | +// SPDX-FileCopyrightText: Copyright (c) 2021 microDev |
| 4 | +// SPDX-FileCopyrightText: Copyright (c) 2021 skieast/Bruce Segal |
| 5 | +// |
| 6 | +// SPDX-License-Identifier: MIT |
| 7 | + |
| 8 | +#include "supervisor/board.h" |
| 9 | + |
| 10 | +#include "mpconfigboard.h" |
| 11 | +#include "shared-bindings/busio/SPI.h" |
| 12 | +#include "shared-bindings/fourwire/FourWire.h" |
| 13 | +#include "shared-bindings/microcontroller/Pin.h" |
| 14 | +#include "shared-module/displayio/__init__.h" |
| 15 | +#include "supervisor/shared/board.h" |
| 16 | + |
| 17 | +#define DELAY 0x80 |
| 18 | + |
| 19 | +// SSD1677 controller driving a GDEQ0426T82 4.26" 800x480 E-Ink display. |
| 20 | + |
| 21 | +const uint8_t ssd1677_display_start_sequence[] = { |
| 22 | + // Software Reset |
| 23 | + 0x12, DELAY, 0x00, 0x14, |
| 24 | + |
| 25 | + // Temperature Sensor Control (use internal sensor) |
| 26 | + 0x18, 0x00, 0x01, 0x80, |
| 27 | + |
| 28 | + // Booster Soft Start |
| 29 | + 0x0C, 0x00, 0x05, 0xAE, 0xC7, 0xC3, 0xC0, 0x40, |
| 30 | + |
| 31 | + // Driver Output Control: 480 gates, GD=0, SM=1, TB=0 = 0x02 |
| 32 | + 0x01, 0x00, 0x03, 0xDF, 0x01, 0x02, |
| 33 | + |
| 34 | + // Data Entry Mode: X increment, Y decrement = 0x01 |
| 35 | + 0x11, 0x00, 0x01, 0x01, |
| 36 | + |
| 37 | + // Border Waveform Control |
| 38 | + 0x3C, 0x00, 0x01, 0x01, |
| 39 | + |
| 40 | + // Set RAM X Address Start/End: 0 to 799 |
| 41 | + 0x44, 0x00, 0x04, 0x00, 0x00, 0x1F, 0x03, |
| 42 | + |
| 43 | + // Set RAM Y Address Start/End: 479 down to 0 |
| 44 | + 0x45, 0x00, 0x04, 0xDF, 0x01, 0x00, 0x00, |
| 45 | + |
| 46 | + // Set RAM X Counter to 0 |
| 47 | + 0x4E, 0x00, 0x02, 0x00, 0x00, |
| 48 | + |
| 49 | + // Set RAM Y Counter to 479 |
| 50 | + 0x4F, 0x00, 0x02, 0xDF, 0x01, |
| 51 | + |
| 52 | + // Auto Write BW RAM (clear to white) |
| 53 | + 0x46, DELAY, 0x01, 0xF7, 0xFF, |
| 54 | + |
| 55 | + // Display Update Control 1: bypass RED |
| 56 | + 0x21, 0x00, 0x02, 0x40, 0x00, |
| 57 | + |
| 58 | + // Display Update Control 2: full refresh with OTP LUT |
| 59 | + 0x22, 0x00, 0x01, 0xF7, |
| 60 | +}; |
| 61 | + |
| 62 | +const uint8_t ssd1677_display_stop_sequence[] = { |
| 63 | + 0x22, 0x00, 0x01, 0x83, |
| 64 | + 0x20, 0x00, 0x00, |
| 65 | + 0x10, 0x00, 0x01, 0x01, |
| 66 | +}; |
| 67 | + |
| 68 | +const uint8_t ssd1677_display_refresh_sequence[] = { |
| 69 | + 0x20, 0x00, 0x00, |
| 70 | +}; |
| 71 | + |
| 72 | +void board_init(void) { |
| 73 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 74 | + busio_spi_obj_t *spi = &bus->inline_bus; |
| 75 | + common_hal_busio_spi_construct(spi, &pin_GPIO8, &pin_GPIO10, NULL, false); |
| 76 | + common_hal_busio_spi_never_reset(spi); |
| 77 | + |
| 78 | + bus->base.type = &fourwire_fourwire_type; |
| 79 | + common_hal_fourwire_fourwire_construct(bus, |
| 80 | + spi, |
| 81 | + MP_OBJ_FROM_PTR(&pin_GPIO4), |
| 82 | + MP_OBJ_FROM_PTR(&pin_GPIO21), |
| 83 | + MP_OBJ_FROM_PTR(&pin_GPIO5), |
| 84 | + 40000000, |
| 85 | + 0, |
| 86 | + 0); |
| 87 | + |
| 88 | + epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; |
| 89 | + display->base.type = &epaperdisplay_epaperdisplay_type; |
| 90 | + |
| 91 | + epaperdisplay_construct_args_t args = EPAPERDISPLAY_CONSTRUCT_ARGS_DEFAULTS; |
| 92 | + args.bus = bus; |
| 93 | + args.start_sequence = ssd1677_display_start_sequence; |
| 94 | + args.start_sequence_len = sizeof(ssd1677_display_start_sequence); |
| 95 | + args.stop_sequence = ssd1677_display_stop_sequence; |
| 96 | + args.stop_sequence_len = sizeof(ssd1677_display_stop_sequence); |
| 97 | + args.width = 800; |
| 98 | + args.height = 480; |
| 99 | + args.ram_width = 800; |
| 100 | + args.ram_height = 480; |
| 101 | + args.rotation = 0; |
| 102 | + args.write_black_ram_command = 0x24; |
| 103 | + args.black_bits_inverted = false; |
| 104 | + args.refresh_sequence = ssd1677_display_refresh_sequence; |
| 105 | + args.refresh_sequence_len = sizeof(ssd1677_display_refresh_sequence); |
| 106 | + args.refresh_time = 1.6; |
| 107 | + args.busy_pin = &pin_GPIO6; |
| 108 | + args.busy_state = true; |
| 109 | + args.seconds_per_frame = 5.0; |
| 110 | + args.grayscale = false; |
| 111 | + args.two_byte_sequence_length = true; |
| 112 | + args.address_little_endian = true; |
| 113 | + common_hal_epaperdisplay_epaperdisplay_construct(display, &args); |
| 114 | +} |
| 115 | + |
| 116 | +bool espressif_board_reset_pin_number(gpio_num_t pin_number) { |
| 117 | + return false; |
| 118 | +} |
| 119 | + |
| 120 | +void board_deinit(void) { |
| 121 | + epaperdisplay_epaperdisplay_obj_t *display = &displays[0].epaper_display; |
| 122 | + if (display->base.type == &epaperdisplay_epaperdisplay_type) { |
| 123 | + while (common_hal_epaperdisplay_epaperdisplay_get_busy(display)) { |
| 124 | + RUN_BACKGROUND_TASKS; |
| 125 | + } |
| 126 | + } |
| 127 | + common_hal_displayio_release_displays(); |
| 128 | +} |
| 129 | + |
| 130 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
0 commit comments