|
| 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 | +#include "shared-bindings/digitalio/DigitalInOut.h" |
| 16 | + |
| 17 | +const uint8_t display_start_sequence[] = { |
| 18 | + 0x12, 0x80, 0x14, // Soft reset and wait 20ms |
| 19 | + 0x11, 0x01, 0x03, // Ram data entry mode |
| 20 | + 0x3c, 0x01, 0x05, // border color |
| 21 | + 0x2c, 0x01, 0x36, // set vcom voltage |
| 22 | + 0x03, 0x01, 0x17, // Set gate voltage |
| 23 | + 0x04, 0x03, 0x41, 0x00, 0x32, // Set source voltage |
| 24 | + 0x4e, 0x01, 0x01, // ram x count |
| 25 | + 0x4f, 0x02, 0x00, 0x00, // ram y count |
| 26 | + 0x01, 0x03, 0x27, 0x01, 0x00, // set display size |
| 27 | + 0x22, 0x01, 0xf4, // display update mode |
| 28 | +}; |
| 29 | + |
| 30 | +const uint8_t display_stop_sequence[] = { |
| 31 | + 0x10, 0x81, 0x01, 0x64, // Deep sleep |
| 32 | +}; |
| 33 | + |
| 34 | +const uint8_t refresh_sequence[] = { |
| 35 | + 0x20, |
| 36 | +}; |
| 37 | + |
| 38 | +void board_init(void) { |
| 39 | + |
| 40 | + // Set vext high to enable EPD |
| 41 | + digitalio_digitalinout_obj_t vext_pin_obj; |
| 42 | + vext_pin_obj.base.type = &digitalio_digitalinout_type; |
| 43 | + common_hal_digitalio_digitalinout_construct(&vext_pin_obj, &pin_GPIO18); |
| 44 | + common_hal_digitalio_digitalinout_switch_to_output(&vext_pin_obj, true, DRIVE_MODE_PUSH_PULL); |
| 45 | + common_hal_digitalio_digitalinout_never_reset(&vext_pin_obj); |
| 46 | + |
| 47 | + // Set up the SPI object used to control the display |
| 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(spi, &pin_GPIO2, &pin_GPIO1, NULL, false); |
| 51 | + common_hal_busio_spi_never_reset(spi); |
| 52 | + |
| 53 | + // Set up the DisplayIO pin object |
| 54 | + bus->base.type = &fourwire_fourwire_type; |
| 55 | + common_hal_fourwire_fourwire_construct(bus, |
| 56 | + spi, |
| 57 | + &pin_GPIO4, // EPD_DC Command or data |
| 58 | + &pin_GPIO3, // EPD_CS Chip select |
| 59 | + &pin_GPIO5, // EPD_RST Reset |
| 60 | + 1000000, // Baudrate |
| 61 | + 0, // Polarity |
| 62 | + 0); // Phase |
| 63 | + |
| 64 | +// Set up the DisplayIO epaper object |
| 65 | + epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; |
| 66 | + display->base.type = &epaperdisplay_epaperdisplay_type; |
| 67 | + common_hal_epaperdisplay_epaperdisplay_construct( |
| 68 | + display, |
| 69 | + bus, |
| 70 | + display_start_sequence, sizeof(display_start_sequence), |
| 71 | + 0, // start up time |
| 72 | + display_stop_sequence, sizeof(display_stop_sequence), |
| 73 | + 296, // width |
| 74 | + 128, // height |
| 75 | + 250, // ram_width |
| 76 | + 296, // ram_height |
| 77 | + 8, // colstart |
| 78 | + 0, // rowstart |
| 79 | + 90, // rotation |
| 80 | + 0x44, // set_column_window_command |
| 81 | + 0x45, // set_row_window_command |
| 82 | + 0x4E, // set_current_column_command |
| 83 | + 0x4F, // set_current_row_command |
| 84 | + 0x24, // write_black_ram_command |
| 85 | + false, // black_bits_inverted |
| 86 | + 0x26, // write_color_ram_command |
| 87 | + false, // color_bits_inverted |
| 88 | + 0xFF0000, // highlight_color |
| 89 | + refresh_sequence, sizeof(refresh_sequence), // refresh_display_command |
| 90 | + 1.0, // refresh_time |
| 91 | + &pin_GPIO6, // busy_pin |
| 92 | + true, // busy_state |
| 93 | + 2.0, // seconds_per_frame |
| 94 | + false, // always_toggle_chip_select |
| 95 | + false, // grayscale |
| 96 | + false, // acep |
| 97 | + false, // two_byte_sequence_length |
| 98 | + true); // address_little_endian |
| 99 | +} |
| 100 | + |
| 101 | +void board_deinit(void) { |
| 102 | + epaperdisplay_epaperdisplay_obj_t *display = &displays[0].epaper_display; |
| 103 | + if (display->base.type == &epaperdisplay_epaperdisplay_type) { |
| 104 | + while (common_hal_epaperdisplay_epaperdisplay_get_busy(display)) { |
| 105 | + RUN_BACKGROUND_TASKS; |
| 106 | + } |
| 107 | + } |
| 108 | + common_hal_displayio_release_displays(); |
| 109 | +} |
| 110 | + |
| 111 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
0 commit comments