|
| 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 | +// SSD1683 EPD Driver chip |
| 18 | +const uint8_t display_start_sequence[] = { |
| 19 | + // Init |
| 20 | + 0x12, 0x80, 0x0a, // Soft reset |
| 21 | + 0x01, 0x03, 0x2b, 0x01, 0x00, // Set MUX as 300 |
| 22 | + 0x21, 0x02, 0x40, 0x00, // Display update control |
| 23 | + 0x3c, 0x01, 0x01, // Border waveform |
| 24 | + 0x11, 0x01, 0x03, // X- mode |
| 25 | + 0x44, 0x02, 0x00, 0x31, // Set RAM X Address Start/End Pos |
| 26 | + 0x45, 0x04, 0x00, 0x00, 0x2b, 0x01, // Set RAM Y Address Start/End Pos |
| 27 | + 0x4e, 0x01, 0x00, // Set RAM X Address counter |
| 28 | + 0x4f, 0x02, 0x00, 0x00, // Set RAM Y Address counter |
| 29 | +}; |
| 30 | + |
| 31 | +const uint8_t display_stop_sequence[] = { |
| 32 | + 0x10, 0x01, 0x32, |
| 33 | +}; |
| 34 | + |
| 35 | +const uint8_t refresh_sequence[] = { |
| 36 | + 0x22, 0x01, 0xf7, // Display update sequence option |
| 37 | + 0x20, 0x80, 0x0a, // Master activation |
| 38 | +}; |
| 39 | + |
| 40 | +void board_init(void) { |
| 41 | + |
| 42 | + // Enable EPD with driver pin |
| 43 | + digitalio_digitalinout_obj_t epd_enable_pin_obj; |
| 44 | + epd_enable_pin_obj.base.type = &digitalio_digitalinout_type; |
| 45 | + common_hal_digitalio_digitalinout_construct(&epd_enable_pin_obj, &pin_GPIO7); |
| 46 | + common_hal_digitalio_digitalinout_switch_to_output(&epd_enable_pin_obj, true, DRIVE_MODE_PUSH_PULL); |
| 47 | + common_hal_digitalio_digitalinout_never_reset(&epd_enable_pin_obj); |
| 48 | + |
| 49 | + // Set up the SPI object used to control the display |
| 50 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 51 | + busio_spi_obj_t *spi = &bus->inline_bus; |
| 52 | + common_hal_busio_spi_construct(spi, &pin_GPIO12, &pin_GPIO11, NULL, false); |
| 53 | + common_hal_busio_spi_never_reset(spi); |
| 54 | + |
| 55 | + // Set up the DisplayIO pin object |
| 56 | + bus->base.type = &fourwire_fourwire_type; |
| 57 | + common_hal_fourwire_fourwire_construct(bus, |
| 58 | + spi, |
| 59 | + &pin_GPIO46, // EPD_DC Command or data |
| 60 | + &pin_GPIO45, // EPD_CS Chip select |
| 61 | + &pin_GPIO47, // EPD_RST Reset |
| 62 | + 1000000, // Baudrate |
| 63 | + 0, // Polarity |
| 64 | + 0); // Phase |
| 65 | + |
| 66 | +// Set up the DisplayIO epaper object |
| 67 | + epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; |
| 68 | + display->base.type = &epaperdisplay_epaperdisplay_type; |
| 69 | + common_hal_epaperdisplay_epaperdisplay_construct( |
| 70 | + display, |
| 71 | + bus, |
| 72 | + display_start_sequence, sizeof(display_start_sequence), |
| 73 | + 1, // start up time |
| 74 | + display_stop_sequence, sizeof(display_stop_sequence), |
| 75 | + 400, // width |
| 76 | + 300, // height |
| 77 | + 400, // ram_width |
| 78 | + 300, // ram_height |
| 79 | + 0, // colstart |
| 80 | + 0, // rowstart |
| 81 | + 0, // rotation |
| 82 | + NO_COMMAND, // set_column_window_command |
| 83 | + NO_COMMAND, // set_row_window_command |
| 84 | + NO_COMMAND, // set_current_column_command |
| 85 | + NO_COMMAND, // set_current_row_command |
| 86 | + 0x24, // write_black_ram_command |
| 87 | + false, // black_bits_inverted |
| 88 | + 0x26, // write_color_ram_command |
| 89 | + false, // color_bits_inverted |
| 90 | + 0x000000, // highlight_color |
| 91 | + refresh_sequence, sizeof(refresh_sequence), // refresh_display_command |
| 92 | + 1.0, // refresh_time |
| 93 | + &pin_GPIO48, // busy_pin |
| 94 | + true, // busy_state |
| 95 | + 2.0, // seconds_per_frame |
| 96 | + false, // always_toggle_chip_select |
| 97 | + false, // grayscale |
| 98 | + false, // acep |
| 99 | + false, // two_byte_sequence_length |
| 100 | + false); // address_little_endian |
| 101 | +} |
| 102 | + |
| 103 | +void board_deinit(void) { |
| 104 | + epaperdisplay_epaperdisplay_obj_t *display = &displays[0].epaper_display; |
| 105 | + if (display->base.type == &epaperdisplay_epaperdisplay_type) { |
| 106 | + while (common_hal_epaperdisplay_epaperdisplay_get_busy(display)) { |
| 107 | + RUN_BACKGROUND_TASKS; |
| 108 | + } |
| 109 | + } |
| 110 | + common_hal_displayio_release_displays(); |
| 111 | +} |
| 112 | + |
| 113 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
0 commit comments