|
| 1 | +#include "Adafruit_EK79686.h" |
| 2 | +#include "Adafruit_EPD.h" |
| 3 | + |
| 4 | +#define BUSY_WAIT 500 |
| 5 | + |
| 6 | +// clang-format off |
| 7 | + |
| 8 | +const uint8_t ek79686_default_init_code[] { |
| 9 | + EK79686_PSR, 1, 0x0F, // LUT from OTP 128x296 |
| 10 | + 0x4D, 1, 0xAA, // FITI cmd (???) |
| 11 | + 0x87, 1, 0x28, |
| 12 | + 0x84, 1, 0x00, |
| 13 | + 0x83, 1, 0x05, |
| 14 | + 0xA8, 1, 0xDF, |
| 15 | + 0xA9, 1, 0x05, |
| 16 | + 0xB1, 1, 0xE8, |
| 17 | + 0xAB, 1, 0xA1, |
| 18 | + 0xB9, 1, 0x10, |
| 19 | + 0x88, 1, 0x80, |
| 20 | + 0x90, 1, 0x02, |
| 21 | + 0x86, 1, 0x15, |
| 22 | + 0x91, 1, 0x8D, |
| 23 | + 0xAA, 1, 0x0F, |
| 24 | + EK79686_PON, 0, |
| 25 | + 0xFE}; |
| 26 | + |
| 27 | +// clang-format on |
| 28 | + |
| 29 | +/**************************************************************************/ |
| 30 | +/*! |
| 31 | + @brief constructor if using external SRAM chip and software SPI |
| 32 | + @param width the width of the display in pixels |
| 33 | + @param height the height of the display in pixels |
| 34 | + @param SID the SID pin to use |
| 35 | + @param SCLK the SCLK pin to use |
| 36 | + @param DC the data/command pin to use |
| 37 | + @param RST the reset pin to use |
| 38 | + @param CS the chip select pin to use |
| 39 | + @param SRCS the SRAM chip select pin to use |
| 40 | + @param MISO the MISO pin to use |
| 41 | + @param BUSY the busy pin to use |
| 42 | +*/ |
| 43 | +/**************************************************************************/ |
| 44 | +Adafruit_EK79686::Adafruit_EK79686(int width, int height, int8_t SID, |
| 45 | + int8_t SCLK, int8_t DC, int8_t RST, |
| 46 | + int8_t CS, int8_t SRCS, int8_t MISO, |
| 47 | + int8_t BUSY) |
| 48 | + : Adafruit_EPD(width, height, SID, SCLK, DC, RST, CS, SRCS, MISO, BUSY) { |
| 49 | + |
| 50 | + if ((width % 8) != 0) { |
| 51 | + width += 8 - (width % 8); |
| 52 | + } |
| 53 | + buffer1_size = ((uint32_t)width * (uint32_t)height) / 8; |
| 54 | + buffer2_size = buffer1_size; |
| 55 | + |
| 56 | + if (SRCS >= 0) { |
| 57 | + use_sram = true; |
| 58 | + buffer1_addr = 0; |
| 59 | + buffer2_addr = buffer1_size; |
| 60 | + buffer1 = buffer2 = NULL; |
| 61 | + } else { |
| 62 | + buffer1 = (uint8_t *)malloc(buffer1_size); |
| 63 | + buffer2 = (uint8_t *)malloc(buffer2_size); |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +// constructor for hardware SPI - we indicate DataCommand, ChipSelect, Reset |
| 68 | + |
| 69 | +/**************************************************************************/ |
| 70 | +/*! |
| 71 | + @brief constructor if using on-chip RAM and hardware SPI |
| 72 | + @param width the width of the display in pixels |
| 73 | + @param height the height of the display in pixels |
| 74 | + @param DC the data/command pin to use |
| 75 | + @param RST the reset pin to use |
| 76 | + @param CS the chip select pin to use |
| 77 | + @param SRCS the SRAM chip select pin to use |
| 78 | + @param BUSY the busy pin to use |
| 79 | +*/ |
| 80 | +/**************************************************************************/ |
| 81 | +Adafruit_EK79686::Adafruit_EK79686(int width, int height, int8_t DC, int8_t RST, |
| 82 | + int8_t CS, int8_t SRCS, int8_t BUSY, |
| 83 | + SPIClass *spi) |
| 84 | + : Adafruit_EPD(width, height, DC, RST, CS, SRCS, BUSY, spi) { |
| 85 | + |
| 86 | + if ((height % 8) != 0) { |
| 87 | + height += 8 - (height % 8); |
| 88 | + } |
| 89 | + buffer1_size = (uint16_t)width * (uint16_t)height / 8; |
| 90 | + buffer2_size = buffer1_size; |
| 91 | + |
| 92 | + if (SRCS >= 0) { |
| 93 | + use_sram = true; |
| 94 | + buffer1_addr = 0; |
| 95 | + buffer2_addr = buffer1_size; |
| 96 | + buffer1 = buffer2 = NULL; |
| 97 | + } else { |
| 98 | + buffer1 = (uint8_t *)malloc(buffer1_size); |
| 99 | + buffer2 = (uint8_t *)malloc(buffer2_size); |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +/**************************************************************************/ |
| 104 | +/*! |
| 105 | + @brief wait for busy signal to end |
| 106 | +*/ |
| 107 | +/**************************************************************************/ |
| 108 | +void Adafruit_EK79686::busy_wait(void) { |
| 109 | + if (_busy_pin >= 0) { |
| 110 | + do { |
| 111 | + EPD_command(EK79686_FLG); |
| 112 | + delay(10); |
| 113 | + } while (!digitalRead(_busy_pin)); |
| 114 | + } else { |
| 115 | + delay(BUSY_WAIT); |
| 116 | + } |
| 117 | + delay(200); // additional delay |
| 118 | +} |
| 119 | + |
| 120 | +/**************************************************************************/ |
| 121 | +/*! |
| 122 | + @brief begin communication with and set up the display. |
| 123 | + @param reset if true the reset pin will be toggled. |
| 124 | +*/ |
| 125 | +/**************************************************************************/ |
| 126 | +void Adafruit_EK79686::begin(bool reset) { |
| 127 | + Adafruit_EPD::begin(reset); |
| 128 | + setBlackBuffer(1, true); // black defaults to inverted |
| 129 | + setColorBuffer(0, false); // red defaults to not-inverted |
| 130 | + |
| 131 | + powerDown(); |
| 132 | +} |
| 133 | + |
| 134 | +/**************************************************************************/ |
| 135 | +/*! |
| 136 | + @brief signal the display to update |
| 137 | +*/ |
| 138 | +/**************************************************************************/ |
| 139 | +void Adafruit_EK79686::update() { |
| 140 | + EPD_command(EK79686_DRF); |
| 141 | + delay(10); |
| 142 | + busy_wait(); |
| 143 | +} |
| 144 | + |
| 145 | +/**************************************************************************/ |
| 146 | +/*! |
| 147 | + @brief start up the display |
| 148 | +*/ |
| 149 | +/**************************************************************************/ |
| 150 | +void Adafruit_EK79686::powerUp() { |
| 151 | + uint8_t buf[5]; |
| 152 | + |
| 153 | + hardwareReset(); |
| 154 | + delay(10); |
| 155 | + |
| 156 | + const uint8_t *init_code = ek79686_default_init_code; |
| 157 | + |
| 158 | + if (_epd_init_code != NULL) { |
| 159 | + init_code = _epd_init_code; |
| 160 | + } |
| 161 | + EPD_commandList(init_code); |
| 162 | + |
| 163 | + if (_epd_lut_code) { |
| 164 | + EPD_commandList(_epd_lut_code); |
| 165 | + } |
| 166 | + busy_wait(); |
| 167 | +} |
| 168 | + |
| 169 | +/**************************************************************************/ |
| 170 | +/*! |
| 171 | + @brief wind down the display |
| 172 | +*/ |
| 173 | +/**************************************************************************/ |
| 174 | + |
| 175 | +void Adafruit_EK79686::powerDown(void) { |
| 176 | + uint8_t buf[1]; |
| 177 | + |
| 178 | + EPD_command(EK79686_POF); // power off |
| 179 | + busy_wait(); |
| 180 | + |
| 181 | + buf[0] = 0xA5; |
| 182 | + EPD_command(EK79686_DSLP, buf, 1); |
| 183 | +} |
| 184 | + |
| 185 | +/**************************************************************************/ |
| 186 | +/*! |
| 187 | + @brief Send the specific command to start writing to EPD display RAM |
| 188 | + @param index The index for which buffer to write (0 or 1 or tri-color |
| 189 | + displays) Ignored for monochrome displays. |
| 190 | + @returns The byte that is read from SPI at the same time as sending the |
| 191 | + command |
| 192 | +*/ |
| 193 | +/**************************************************************************/ |
| 194 | +uint8_t Adafruit_EK79686::writeRAMCommand(uint8_t index) { |
| 195 | + if (index == 0) { |
| 196 | + return EPD_command(EK79686_DTM1, false); |
| 197 | + } |
| 198 | + if (index == 1) { |
| 199 | + return EPD_command(EK79686_DTM2, false); |
| 200 | + } |
| 201 | + return 0; |
| 202 | +} |
| 203 | + |
| 204 | +/**************************************************************************/ |
| 205 | +/*! |
| 206 | + @brief Some displays require setting the RAM address pointer |
| 207 | + @param x X address counter value |
| 208 | + @param y Y address counter value |
| 209 | +*/ |
| 210 | +/**************************************************************************/ |
| 211 | +void Adafruit_EK79686::setRAMAddress(uint16_t x, uint16_t y) {} |
0 commit comments