|
| 1 | +// This file is part of the CircuitPython project: https://circuitpython.org |
| 2 | +// |
| 3 | +// SPDX-FileCopyrightText: Copyright (c) 2020 Joey Castillo |
| 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 | +#define HEIGHT 300 |
| 18 | +#define WIDTH 400 |
| 19 | + |
| 20 | +// Sequences pulled from InkyWhat driver (https://github.com/alanta/CircuitPython_InkyWhat) |
| 21 | +uint8_t start_sequence[] = { |
| 22 | + 0x12, 0x80, 0x80, // Software reset ✅ TODO wait for busy instead of fixed delay |
| 23 | + 0x12, 0x80, 0x80, // Software reset ✅ TODO wait for busy instead of fixed delay |
| 24 | + 0x74, 0x01, 0x54, // set analog block control ✅ |
| 25 | + 0x7e, 0x01, 0x3b, // set digital block control ✅ |
| 26 | + 0x01, 0x03, 0x2b, 0x01, 0x00, // driver output control |
| 27 | + 0x03, 0x01, 0x17, // Gate driving voltage ✅ |
| 28 | + 0x04, 0x03, 0x07, 0xac, 0x32, // Source Driving voltage ✅ |
| 29 | + 0x3a, 0x01, 0x07, // Dummy line period ✅ |
| 30 | + 0x3b, 0x01, 0x04, // Gate line width ✅ |
| 31 | + 0x3c, 0x01, 0x00, // Border color |
| 32 | + 0x2c, 0x01, 0x3c, // VCOM Register, 0x3c = -1.5v? ✅ |
| 33 | + 0x22, 0x01, 0xc7, // Display update sequence ✅ |
| 34 | + // 0x04, 0x03, 0x07, 0xac, 0x32, // Set voltage of VSH and VSL (yellow) |
| 35 | + // LUT (yellow) |
| 36 | + // 0x32, 0x46, |
| 37 | + // 0xfa, 0x94, 0x8c, 0xc0, 0xd0, 0x00, 0x00, |
| 38 | + // 0xfa, 0x94, 0x2c, 0x80, 0xe0, 0x00, 0x00, |
| 39 | + // 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 40 | + // 0xfa, 0x94, 0xf8, 0x80, 0x50, 0x00, 0xcc, |
| 41 | + // 0xbf, 0x58, 0xfc, 0x80, 0xd0, 0x00, 0x11, |
| 42 | + // 0x40, 0x10, 0x40, 0x10, 0x08, |
| 43 | + // 0x08, 0x10, 0x04, 0x04, 0x10, |
| 44 | + // 0x08, 0x08, 0x03, 0x08, 0x20, |
| 45 | + // 0x08, 0x04, 0x00, 0x00, 0x10, |
| 46 | + // 0x10, 0x08, 0x08, 0x00, 0x20, |
| 47 | + // 0x00, 0x00, 0x00, 0x00, 0x00, |
| 48 | + // 0x00, 0x00, 0x00, 0x00, 0x00, |
| 49 | + 0x11, 0x01, 0x03, // Data entry mode setting 0x03 = X/Y increment ✅ |
| 50 | + // self._send_command(0x44, [0x00, (self.cols // 8) - 1]) # Set RAM X Start/End |
| 51 | + 0x44, 0x02, 0x00, 0x31, // Set RAM X Start/End |
| 52 | + // self._send_command(0x45, [0x00, 0x00] + packed_height) # Set RAM Y Start/End |
| 53 | + 0x45, 0x04, 0x00, 0x00, 0x2b, 0x01, // Set RAM Y Start/End |
| 54 | +}; |
| 55 | + |
| 56 | +uint8_t stop_sequence[] = { |
| 57 | + 0x10, 0x01, 0x01 // Enter Deep Sleep |
| 58 | +}; |
| 59 | + |
| 60 | +uint8_t refresh_sequence[] = { |
| 61 | + 0x20, 0x00 |
| 62 | +}; |
| 63 | + |
| 64 | +void board_init(void) { |
| 65 | + |
| 66 | + // Pull EPD Enable pin high |
| 67 | + digitalio_digitalinout_obj_t vext_pin_obj; |
| 68 | + vext_pin_obj.base.type = &digitalio_digitalinout_type; |
| 69 | + common_hal_digitalio_digitalinout_construct(&vext_pin_obj, &pin_GPIO7); |
| 70 | + common_hal_digitalio_digitalinout_switch_to_output(&vext_pin_obj, true, DRIVE_MODE_PUSH_PULL); |
| 71 | + common_hal_digitalio_digitalinout_never_reset(&vext_pin_obj); |
| 72 | + |
| 73 | + // Set up SPI bus |
| 74 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 75 | + busio_spi_obj_t *spi = &bus->inline_bus; |
| 76 | + common_hal_busio_spi_construct(spi, &pin_GPIO12, &pin_GPIO11, NULL, false); |
| 77 | + common_hal_busio_spi_never_reset(spi); |
| 78 | + |
| 79 | + bus->base.type = &fourwire_fourwire_type; |
| 80 | + common_hal_fourwire_fourwire_construct(bus, |
| 81 | + spi, |
| 82 | + &pin_GPIO46, // EPD_DC Command or data |
| 83 | + &pin_GPIO45, // EPD_CS Chip select |
| 84 | + &pin_GPIO47, // EPD_RST Reset |
| 85 | + 1000000, // Baudrate |
| 86 | + 0, // Polarity |
| 87 | + 0); // Phase |
| 88 | + |
| 89 | + // Set up EPD object |
| 90 | + epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; |
| 91 | + display->base.type = &epaperdisplay_epaperdisplay_type; |
| 92 | + common_hal_epaperdisplay_epaperdisplay_construct(display, |
| 93 | + bus, |
| 94 | + start_sequence, |
| 95 | + sizeof(start_sequence), |
| 96 | + 0, // start up time |
| 97 | + stop_sequence, |
| 98 | + sizeof(stop_sequence), |
| 99 | + WIDTH, // width |
| 100 | + HEIGHT, // height |
| 101 | + 300, // RAM width |
| 102 | + 400, // RAM height |
| 103 | + 0, // colstart |
| 104 | + 0, // rowstart |
| 105 | + 90, // rotation |
| 106 | + NO_COMMAND, // set_column_window_command |
| 107 | + NO_COMMAND, // set_row_window_command |
| 108 | + 0x4E, // set_current_column_command |
| 109 | + 0x4F, // set_current_row_command |
| 110 | + 0x24, // write_black_ram_command |
| 111 | + false, // black_bits_inverted |
| 112 | + 0x26, // write_color_ram_command (can add this for grayscale eventually) |
| 113 | + false, // color_bits_inverted |
| 114 | + 0x000000, // highlight_color |
| 115 | + refresh_sequence, // refresh_display_sequence |
| 116 | + sizeof(refresh_sequence), |
| 117 | + 40, // refresh_time |
| 118 | + &pin_GPIO48, // busy_pin |
| 119 | + false, // busy_state |
| 120 | + 5, // seconds_per_frame |
| 121 | + false, // chip_select (don't always toggle chip select) |
| 122 | + false, // grayscale |
| 123 | + false, // acep |
| 124 | + false, // two_byte_sequence_length |
| 125 | + false); // address_little_endian |
| 126 | +} |
| 127 | + |
| 128 | +void board_deinit(void) { |
| 129 | + epaperdisplay_epaperdisplay_obj_t *display = &displays[0].epaper_display; |
| 130 | + if (display->base.type == &epaperdisplay_epaperdisplay_type) { |
| 131 | + while (common_hal_epaperdisplay_epaperdisplay_get_busy(display)) { |
| 132 | + RUN_BACKGROUND_TASKS; |
| 133 | + } |
| 134 | + } |
| 135 | + common_hal_displayio_release_displays(); |
| 136 | +} |
| 137 | + |
| 138 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
0 commit comments