|
| 1 | +#include "Adafruit_SSD1680.h" |
| 2 | +#include "Adafruit_EPD.h" |
| 3 | + |
| 4 | +#define BUSY_WAIT 500 |
| 5 | + |
| 6 | +/**************************************************************************/ |
| 7 | +/*! |
| 8 | + @brief constructor if using external SRAM chip and software SPI |
| 9 | + @param width the width of the display in pixels |
| 10 | + @param height the height of the display in pixels |
| 11 | + @param SID the SID pin to use |
| 12 | + @param SCLK the SCLK pin to use |
| 13 | + @param DC the data/command pin to use |
| 14 | + @param RST the reset pin to use |
| 15 | + @param CS the chip select pin to use |
| 16 | + @param SRCS the SRAM chip select pin to use |
| 17 | + @param MISO the MISO pin to use |
| 18 | + @param BUSY the busy pin to use |
| 19 | +*/ |
| 20 | +/**************************************************************************/ |
| 21 | +Adafruit_SSD1680::Adafruit_SSD1680(int width, int height, int8_t SID, |
| 22 | + int8_t SCLK, int8_t DC, int8_t RST, |
| 23 | + int8_t CS, int8_t SRCS, int8_t MISO, |
| 24 | + int8_t BUSY) |
| 25 | + : Adafruit_EPD(width, height, SID, SCLK, DC, RST, CS, SRCS, MISO, BUSY) { |
| 26 | + if ((height % 8) != 0) { |
| 27 | + height += 8 - (height % 8); |
| 28 | + } |
| 29 | + |
| 30 | + buffer1_size = width * height / 8; |
| 31 | + buffer2_size = buffer1_size; |
| 32 | + |
| 33 | + if (SRCS >= 0) { |
| 34 | + use_sram = true; |
| 35 | + buffer1_addr = 0; |
| 36 | + buffer2_addr = buffer1_size; |
| 37 | + buffer1 = buffer2 = NULL; |
| 38 | + } else { |
| 39 | + buffer1 = (uint8_t *)malloc(buffer1_size); |
| 40 | + buffer2 = (uint8_t *)malloc(buffer2_size); |
| 41 | + } |
| 42 | + |
| 43 | + singleByteTxns = true; |
| 44 | +} |
| 45 | + |
| 46 | +// constructor for hardware SPI - we indicate DataCommand, ChipSelect, Reset |
| 47 | + |
| 48 | +/**************************************************************************/ |
| 49 | +/*! |
| 50 | + @brief constructor if using on-chip RAM and hardware SPI |
| 51 | + @param width the width of the display in pixels |
| 52 | + @param height the height of the display in pixels |
| 53 | + @param DC the data/command pin to use |
| 54 | + @param RST the reset pin to use |
| 55 | + @param CS the chip select pin to use |
| 56 | + @param SRCS the SRAM chip select pin to use |
| 57 | + @param BUSY the busy pin to use |
| 58 | +*/ |
| 59 | +/**************************************************************************/ |
| 60 | +Adafruit_SSD1680::Adafruit_SSD1680(int width, int height, int8_t DC, int8_t RST, |
| 61 | + int8_t CS, int8_t SRCS, int8_t BUSY) |
| 62 | + : Adafruit_EPD(width, height, DC, RST, CS, SRCS, BUSY) { |
| 63 | + if ((height % 8) != 0) { |
| 64 | + height += 8 - (height % 8); |
| 65 | + } |
| 66 | + |
| 67 | + buffer1_size = width * height / 8; |
| 68 | + buffer2_size = buffer1_size; |
| 69 | + |
| 70 | + if (SRCS >= 0) { |
| 71 | + use_sram = true; |
| 72 | + buffer1_addr = 0; |
| 73 | + buffer2_addr = buffer1_size; |
| 74 | + buffer1 = buffer2 = NULL; |
| 75 | + } else { |
| 76 | + buffer1 = (uint8_t *)malloc(buffer1_size); |
| 77 | + buffer2 = (uint8_t *)malloc(buffer2_size); |
| 78 | + } |
| 79 | + |
| 80 | + singleByteTxns = true; |
| 81 | +} |
| 82 | + |
| 83 | +/**************************************************************************/ |
| 84 | +/*! |
| 85 | + @brief wait for busy signal to end |
| 86 | +*/ |
| 87 | +/**************************************************************************/ |
| 88 | +void Adafruit_SSD1680::busy_wait(void) { |
| 89 | + if (_busy_pin >= 0) { |
| 90 | + while (digitalRead(_busy_pin)) { // wait for busy low |
| 91 | + delay(10); |
| 92 | + } |
| 93 | + } else { |
| 94 | + delay(BUSY_WAIT); |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +/**************************************************************************/ |
| 99 | +/*! |
| 100 | + @brief begin communication with and set up the display. |
| 101 | + @param reset if true the reset pin will be toggled. |
| 102 | +*/ |
| 103 | +/**************************************************************************/ |
| 104 | +void Adafruit_SSD1680::begin(bool reset) { |
| 105 | + Adafruit_EPD::begin(reset); |
| 106 | + setBlackBuffer(0, true); // black defaults to inverted |
| 107 | + setColorBuffer(1, false); // red defaults to un inverted |
| 108 | + powerDown(); |
| 109 | +} |
| 110 | + |
| 111 | +/**************************************************************************/ |
| 112 | +/*! |
| 113 | + @brief signal the display to update |
| 114 | +*/ |
| 115 | +/**************************************************************************/ |
| 116 | +void Adafruit_SSD1680::update() { |
| 117 | + uint8_t buf[1]; |
| 118 | + |
| 119 | + // display update sequence |
| 120 | + buf[0] = 0xF4; |
| 121 | + EPD_command(SSD1680_DISP_CTRL2, buf, 1); |
| 122 | + |
| 123 | + EPD_command(SSD1680_MASTER_ACTIVATE); |
| 124 | + busy_wait(); |
| 125 | + |
| 126 | + if (_busy_pin <= -1) { |
| 127 | + delay(1000); |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +/**************************************************************************/ |
| 132 | +/*! |
| 133 | + @brief start up the display |
| 134 | +*/ |
| 135 | +/**************************************************************************/ |
| 136 | +void Adafruit_SSD1680::powerUp() { |
| 137 | + uint8_t buf[5]; |
| 138 | + |
| 139 | + hardwareReset(); |
| 140 | + delay(100); |
| 141 | + busy_wait(); |
| 142 | + |
| 143 | + // soft reset |
| 144 | + EPD_command(SSD1680_SW_RESET); |
| 145 | + busy_wait(); |
| 146 | + |
| 147 | + // Set display size and driver output control |
| 148 | + buf[0] = (WIDTH - 1); |
| 149 | + buf[1] = (WIDTH - 1) >> 8; |
| 150 | + buf[2] = 0x00; |
| 151 | + EPD_command(SSD1680_DRIVER_CONTROL, buf, 3); |
| 152 | + |
| 153 | + // Ram data entry mode |
| 154 | + buf[0] = 0x03; |
| 155 | + EPD_command(SSD1680_DATA_MODE, buf, 1); |
| 156 | + |
| 157 | + // Set ram X start/end postion |
| 158 | + buf[0] = 0x01; |
| 159 | + buf[1] = HEIGHT / 8; |
| 160 | + EPD_command(SSD1680_SET_RAMXPOS, buf, 2); |
| 161 | + |
| 162 | + // Set ram Y start/end postion |
| 163 | + buf[2] = (WIDTH - 1); |
| 164 | + buf[3] = (WIDTH - 1) >> 8; |
| 165 | + buf[0] = 0x00; |
| 166 | + buf[1] = 0x00; |
| 167 | + EPD_command(SSD1680_SET_RAMYPOS, buf, 4); |
| 168 | + |
| 169 | + // border color |
| 170 | + buf[0] = 0x05; |
| 171 | + EPD_command(SSD1680_WRITE_BORDER, buf, 1); |
| 172 | + |
| 173 | + // Vcom Voltage |
| 174 | + buf[0] = 0x36; |
| 175 | + EPD_command(SSD1680_WRITE_VCOM, buf, 1); |
| 176 | + |
| 177 | + // Set gate voltage |
| 178 | + buf[0] = 0x17; |
| 179 | + EPD_command(SSD1680_GATE_VOLTAGE, buf, 1); |
| 180 | + |
| 181 | + // Set source voltage |
| 182 | + buf[0] = 0x41; |
| 183 | + buf[1] = 0x00; |
| 184 | + buf[2] = 0x32; |
| 185 | + EPD_command(SSD1680_SOURCE_VOLTAGE, buf, 3); |
| 186 | + |
| 187 | + // Set LUT |
| 188 | + /* |
| 189 | + buf[0] = LUT_DATA[74]; |
| 190 | + EPD_command(SSD1680_WRITE_LUT, buf, 1); |
| 191 | + EPD_command(SSD1680_WRITE_LUT, LUT_DATA, 70); |
| 192 | + */ |
| 193 | + |
| 194 | + // set RAM x address count |
| 195 | + buf[0] = 1; |
| 196 | + EPD_command(SSD1680_SET_RAMXCOUNT, buf, 1); |
| 197 | + |
| 198 | + // set RAM y address count |
| 199 | + buf[0] = 0; |
| 200 | + buf[1] = 0; |
| 201 | + EPD_command(SSD1680_SET_RAMYCOUNT, buf, 2); |
| 202 | +} |
| 203 | + |
| 204 | +/**************************************************************************/ |
| 205 | +/*! |
| 206 | + @brief wind down the display |
| 207 | +*/ |
| 208 | +/**************************************************************************/ |
| 209 | +void Adafruit_SSD1680::powerDown() { |
| 210 | + uint8_t buf[1]; |
| 211 | + // Only deep sleep if we can get out of it |
| 212 | + if (_reset_pin >= 0) { |
| 213 | + // deep sleep |
| 214 | + buf[0] = 0x01; |
| 215 | + EPD_command(SSD1680_DEEP_SLEEP, buf, 1); |
| 216 | + delay(100); |
| 217 | + } else { |
| 218 | + EPD_command(SSD1680_SW_RESET); |
| 219 | + busy_wait(); |
| 220 | + } |
| 221 | +} |
| 222 | + |
| 223 | +/**************************************************************************/ |
| 224 | +/*! |
| 225 | + @brief Send the specific command to start writing to EPD display RAM |
| 226 | + @param index The index for which buffer to write (0 or 1 or tri-color |
| 227 | + displays) Ignored for monochrome displays. |
| 228 | + @returns The byte that is read from SPI at the same time as sending the |
| 229 | + command |
| 230 | +*/ |
| 231 | +/**************************************************************************/ |
| 232 | +uint8_t Adafruit_SSD1680::writeRAMCommand(uint8_t index) { |
| 233 | + if (index == 0) { |
| 234 | + return EPD_command(SSD1680_WRITE_RAM1, false); |
| 235 | + } |
| 236 | + if (index == 1) { |
| 237 | + return EPD_command(SSD1680_WRITE_RAM2, false); |
| 238 | + } |
| 239 | + return 0; |
| 240 | +} |
| 241 | + |
| 242 | +/**************************************************************************/ |
| 243 | +/*! |
| 244 | + @brief Some displays require setting the RAM address pointer |
| 245 | + @param x X address counter value |
| 246 | + @param y Y address counter value |
| 247 | +*/ |
| 248 | +/**************************************************************************/ |
| 249 | +void Adafruit_SSD1680::setRAMAddress(uint16_t x, uint16_t y) { |
| 250 | + uint8_t buf[2]; |
| 251 | + |
| 252 | + // set RAM x address count |
| 253 | + buf[0] = 1; |
| 254 | + EPD_command(SSD1680_SET_RAMXCOUNT, buf, 1); |
| 255 | + |
| 256 | + // set RAM y address count |
| 257 | + buf[0] = 0; |
| 258 | + buf[1] = 0; |
| 259 | + EPD_command(SSD1680_SET_RAMYCOUNT, buf, 2); |
| 260 | +} |
0 commit comments