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