|
| 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 | + |
| 9 | +#include "mpconfigboard.h" |
| 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 "supervisor/shared/board.h" |
| 15 | + |
| 16 | +#include "esp_log.h" |
| 17 | + |
| 18 | +// static const char *TAG = "board"; |
| 19 | + |
| 20 | +#define DELAY 0x80 |
| 21 | + |
| 22 | +// This is an SSD1680 control chip. The display is a 2.9" grayscale EInk. |
| 23 | +const uint8_t display_start_sequence[] = { |
| 24 | + 0x12, DELAY, 0x00, 0x14, // soft reset and wait 20ms |
| 25 | + 0x11, 0x00, 0x01, 0x03, // Ram data entry mode |
| 26 | + 0x3c, 0x00, 0x01, 0x03, // border color |
| 27 | + 0x2c, 0x00, 0x01, 0x28, // Set vcom voltage |
| 28 | + 0x03, 0x00, 0x01, 0x17, // Set gate voltage |
| 29 | + 0x04, 0x00, 0x03, 0x41, 0xae, 0x32, // Set source voltage |
| 30 | + 0x4e, 0x00, 0x01, 0x01, // ram x count |
| 31 | + 0x4f, 0x00, 0x02, 0x00, 0x00, // ram y count |
| 32 | + 0x01, 0x00, 0x03, 0x27, 0x01, 0x00, // set display size |
| 33 | + 0x32, 0x00, 0x99, // Update waveforms |
| 34 | + 0x2a, 0x60, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L0 |
| 35 | + 0x20, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L1 |
| 36 | + 0x28, 0x60, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L2 |
| 37 | + 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L3 |
| 38 | + 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L4 |
| 39 | + 0x00, 0x02, 0x00, 0x05, 0x14, 0x00, 0x00, // TP, SR, RP of Group0 |
| 40 | + 0x1E, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x01, // TP, SR, RP of Group1 |
| 41 | + 0x00, 0x02, 0x00, 0x05, 0x14, 0x00, 0x00, // TP, SR, RP of Group2 |
| 42 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group3 |
| 43 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group4 |
| 44 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group5 |
| 45 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group6 |
| 46 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group7 |
| 47 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group8 |
| 48 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group9 |
| 49 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group10 |
| 50 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group11 |
| 51 | + 0x24, 0x22, 0x22, 0x22, 0x23, 0x32, 0x00, 0x00, 0x00, // FR, XON |
| 52 | + 0x22, 0x00, 0x01, 0xc7 // display update mode |
| 53 | +}; |
| 54 | + |
| 55 | +const uint8_t display_stop_sequence[] = { |
| 56 | + 0x10, DELAY, 0x01, 0x01, 0x64 |
| 57 | +}; |
| 58 | + |
| 59 | +const uint8_t refresh_sequence[] = { |
| 60 | + 0x20, 0x00, 0x00 |
| 61 | +}; |
| 62 | + |
| 63 | +void board_init(void) { |
| 64 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 65 | + busio_spi_obj_t *spi = &bus->inline_bus; |
| 66 | + common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, false); |
| 67 | + common_hal_busio_spi_never_reset(spi); |
| 68 | + |
| 69 | + bus->base.type = &fourwire_fourwire_type; |
| 70 | + common_hal_fourwire_fourwire_construct(bus, |
| 71 | + spi, |
| 72 | + &pin_GPIO7, // EPD_DC Command or data |
| 73 | + &pin_GPIO8, // EPD_CS Chip select |
| 74 | + &pin_GPIO6, // EPD_RST Reset |
| 75 | + 4000000, // Baudrate |
| 76 | + 0, // Polarity |
| 77 | + 0); // Phase |
| 78 | + |
| 79 | + epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; |
| 80 | + display->base.type = &epaperdisplay_epaperdisplay_type; |
| 81 | + common_hal_epaperdisplay_epaperdisplay_construct( |
| 82 | + display, |
| 83 | + bus, |
| 84 | + display_start_sequence, sizeof(display_start_sequence), |
| 85 | + 0, // start up time |
| 86 | + display_stop_sequence, sizeof(display_stop_sequence), |
| 87 | + 296, // width |
| 88 | + 128, // height |
| 89 | + 250, // ram_width |
| 90 | + 296, // ram_height |
| 91 | + 0, // colstart |
| 92 | + 0, // rowstart |
| 93 | + 270, // rotation |
| 94 | + 0x44, // set_column_window_command |
| 95 | + 0x45, // set_row_window_command |
| 96 | + 0x4e, // set_current_column_command |
| 97 | + 0x4f, // set_current_row_command |
| 98 | + 0x24, // write_black_ram_command |
| 99 | + false, // black_bits_inverted |
| 100 | + 0x26, // write_color_ram_command |
| 101 | + false, // color_bits_inverted |
| 102 | + 0x000000, // highlight_color |
| 103 | + refresh_sequence, sizeof(refresh_sequence), |
| 104 | + 1.0, // refresh_time |
| 105 | + &pin_GPIO5, // busy_pin |
| 106 | + true, // busy_state |
| 107 | + 5.0, // seconds_per_frame |
| 108 | + false, // always_toggle_chip_select |
| 109 | + true, // grayscale |
| 110 | + false, // acep |
| 111 | + false, // spectra6 |
| 112 | + true, // two_byte_sequence_length |
| 113 | + true); // address_little_endian |
| 114 | +} |
| 115 | + |
| 116 | +bool espressif_board_reset_pin_number(gpio_num_t pin_number) { |
| 117 | + // Pin 16 is speaker enable and it's pulled down on the board. We don't want |
| 118 | + // to pull it high because then we'll compete with the external pull down. |
| 119 | + // So, reset without any pulls internally. |
| 120 | + if (pin_number == 16) { |
| 121 | + gpio_config_t cfg = { |
| 122 | + .pin_bit_mask = BIT64(16), |
| 123 | + .mode = GPIO_MODE_DISABLE, |
| 124 | + // The pin is externally pulled down, so we don't need to pull it. |
| 125 | + .pull_up_en = false, |
| 126 | + .pull_down_en = false, |
| 127 | + .intr_type = GPIO_INTR_DISABLE, |
| 128 | + }; |
| 129 | + gpio_config(&cfg); |
| 130 | + return true; |
| 131 | + } |
| 132 | + // Pin 4 is used for voltage monitoring, so don't reset |
| 133 | + if (pin_number == 4) { |
| 134 | + return true; |
| 135 | + } |
| 136 | + return false; |
| 137 | +} |
| 138 | + |
| 139 | +void board_deinit(void) { |
| 140 | + epaperdisplay_epaperdisplay_obj_t *display = &displays[0].epaper_display; |
| 141 | + if (display->base.type == &epaperdisplay_epaperdisplay_type) { |
| 142 | + size_t i = 0; |
| 143 | + while (common_hal_epaperdisplay_epaperdisplay_get_busy(display)) { |
| 144 | + RUN_BACKGROUND_TASKS; |
| 145 | + i++; |
| 146 | + } |
| 147 | + } |
| 148 | + common_hal_displayio_release_displays(); |
| 149 | +} |
| 150 | + |
| 151 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
0 commit comments