diff --git a/library.json b/library.json index e7f41f9..37563c1 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Mini Grafx", - "version": "0.0.15", + "version": "0.0.16", "keywords": "embedded, graphics, tft, oled, e-paper", "description": "A generic graphics library containing several drivers for TFT, OLED and e-paper displays", "repository": diff --git a/library.properties b/library.properties index 15e658b..dc983bb 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Mini Grafx -version=0.0.15 +version=0.0.16 author=Daniel Eichhorn maintainer=Daniel Eichhorn sentence=Graphics Library for embedded devices with a framebuffer diff --git a/src/DisplayDriver.h b/src/DisplayDriver.h index 0f2a0d9..2645cd2 100644 --- a/src/DisplayDriver.h +++ b/src/DisplayDriver.h @@ -48,6 +48,7 @@ class DisplayDriver { virtual void setRotation(uint8_t r); virtual void init() = 0; virtual void writeBuffer(uint8_t *buffer, uint8_t bitsPerPixel, uint16_t *palette) = 0; + virtual void setFastRefresh(boolean isEnabled) = 0; int16_t height(void) const; int16_t width(void) const; @@ -60,6 +61,7 @@ class DisplayDriver { WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes int16_t _width, _height; uint8_t rotation; + boolean isFastRefreshEnabled = false; }; diff --git a/src/EPD_WaveShare.cpp b/src/EPD_WaveShare.cpp index 2ad4eac..a235a5d 100644 --- a/src/EPD_WaveShare.cpp +++ b/src/EPD_WaveShare.cpp @@ -148,7 +148,7 @@ void EPD_WaveShare::writeBuffer(uint8_t *buffer, uint8_t bitsPerPixel, uint16_t EPD_SetRamPointer(0x00,(yDot-1)%256,(yDot-1)/256); // set ram //Serial.println(">>>>>>------start send display data!!---------<<<<<<<"); int i = 0,j = 0; - if(XSize%8 != 0){ + if(XSize % 8 != 0){ XSize = XSize+(8-XSize%8); } XSize = XSize/8; @@ -198,6 +198,10 @@ void EPD_WaveShare::writeBuffer(uint8_t *buffer, uint8_t bitsPerPixel, uint16_t } +void EPD_WaveShare::setFastRefresh(boolean isFastRefreshEnabled) { + // Not enabled at the moment +} + uint8_t EPD_WaveShare::getPixel(uint8_t *buffer, uint16_t x, uint16_t y) { uint8_t bitsPerPixel = 1; uint8_t bitMask = (1 << bitsPerPixel) - 1; diff --git a/src/EPD_WaveShare.h b/src/EPD_WaveShare.h index 10735aa..434a84a 100644 --- a/src/EPD_WaveShare.h +++ b/src/EPD_WaveShare.h @@ -116,6 +116,7 @@ class EPD_WaveShare : public DisplayDriver { void EPD_Dis_Full(unsigned char *DisBuffer,unsigned char Label); void EPD_Dis_Part(unsigned char xStart,unsigned char xEnd,unsigned long yStart,unsigned long yEnd,unsigned char *DisBuffer,unsigned char Label); void Dis_Char(char acsii,char size,char mode,char next,unsigned char *buffer); + void setFastRefresh(boolean isFastRefreshEnabled); void driver_delay_xms(unsigned long xms); void SPI_Write(unsigned char value); diff --git a/src/EPD_WaveShare_29.cpp b/src/EPD_WaveShare_29.cpp new file mode 100644 index 0000000..e289f61 --- /dev/null +++ b/src/EPD_WaveShare_29.cpp @@ -0,0 +1,441 @@ + +/** +The MIT License (MIT) +Copyright (c) 2017 by Daniel Eichhorn +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +Please note: I am spending a lot of my free time in developing Software and Hardware +for these projects. Please consider supporting me by +a) Buying my hardware kits from https://blog.squix.org/shop +b) Send a donation: https://www.paypal.me/squix/5USD +c) Or using this affiliate link while shopping: https://www.banggood.com/?p=6R31122484684201508S + +See more at https://blog.squix.org + +This code is based on a driver from http://waveshare.com +*/ + +#include +#include "EPD_WaveShare_29.h" + +EPD_WaveShare29::~EPD_WaveShare29() { +}; + +EPD_WaveShare29::EPD_WaveShare29(uint8_t csPin, uint8_t rstPin, uint8_t dcPin, uint8_t busyPin) : DisplayDriver(EPD_WIDTH, EPD_HEIGHT) { + this->reset_pin = rstPin; + this->dc_pin = dcPin; + this->cs_pin = csPin; + this->busy_pin = busyPin; + width = EPD_WIDTH; + height = EPD_HEIGHT; +}; + +void EPD_WaveShare29::setRotation(uint8_t r) { + this->rotation = r; + switch(r) { + case 0: + bufferWidth = width; + bufferHeight = height; + break; + case 1: + bufferWidth = height; + bufferHeight = width; + break; + case 2: + bufferWidth = width; + bufferHeight = height; + break; + case 3: + bufferWidth = height; + bufferHeight = width; + break; + } +} +void EPD_WaveShare29::init() { + Init(lut_partial_update); +} + +void EPD_WaveShare29::setFastRefresh(boolean isFastRefreshEnabled) { + if (isFastRefreshEnabled != this->isFastRefreshEnabled) { + if (isFastRefreshEnabled) { + Init(lut_partial_update); + } else { + Init(lut_full_update); + } + } + this->isFastRefreshEnabled = isFastRefreshEnabled; + +} + +void EPD_WaveShare29::writeBuffer(uint8_t *buffer, uint8_t bitsPerPixel, uint16_t *palette) { + //SetFrameMemory(buffer, 0, 0, EPD_WIDTH, EPD_HEIGHT); + uint16_t x = 0; + uint16_t y = 0; + int x_end; + int y_end; + uint16_t image_width = width; + uint16_t image_height = height; + uint16_t bufferSize = width * height / 8; + uint16_t xDot = bufferWidth; + uint16_t yDot = bufferHeight; + uint8_t data; + if ( + buffer == NULL || + x < 0 || image_width < 0 || + y < 0 || image_height < 0 + ) { + return; + } + /* x point must be the multiple of 8 or the last 3 bits will be ignored */ + x &= 0xF8; + image_width &= 0xF8; + if (image_width >= this->bufferWidth) { + x_end = this->bufferWidth - 1; + } else { + x_end = image_width - 1; + } + if (image_height >= this->bufferHeight) { + y_end = this->bufferHeight - 1; + } else { + y_end = image_height - 1; + } + SetMemoryArea(0, 0, EPD_WIDTH - 1, EPD_HEIGHT - 1); + SetMemoryPointer(0, 0); + SendCommand(WRITE_RAM); + /* send the image data */ + for (int i = 0; i < EPD_HEIGHT; i++) { + for (int j = 0; j < (EPD_WIDTH) / 8; j++) { + + data = 0; + for (int b = 0; b < 8; b++) { + data = data << 1; + switch (rotation) { + case 0: + x = (j * 8 + b); + y = i; + break; + case 1: + x = bufferWidth - i; + y = (j * 8 + b); + break; + case 2: + x = xDot - (j * 8 + b); + y = yDot - i; + break; + case 3: + x = i; + y = bufferHeight - (j * 8 + b); + break; + } + data = data | (getPixel(buffer, x, y) & 1); + + } + SendData(data); + //SendData(reverse(buffer[(i + j * (image_width / 8))])); + //SendData(i); + yield(); + } + } + + DisplayFrame(); +} + +int EPD_WaveShare29::IfInit(void) { + pinMode(this->cs_pin, OUTPUT); + pinMode(this->reset_pin, OUTPUT); + pinMode(this->dc_pin, OUTPUT); + pinMode(this->busy_pin, INPUT); + SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0)); + SPI.begin(); + return 0; +} + + +void EPD_WaveShare29::DigitalWrite(int pin, int value) { + digitalWrite(pin, value); +} + +int EPD_WaveShare29::DigitalRead(int pin) { + return digitalRead(pin); +} + +void EPD_WaveShare29::DelayMs(unsigned int delaytime) { + delay(delaytime); +} + +void EPD_WaveShare29::SpiTransfer(unsigned char data) { + digitalWrite(this->cs_pin, LOW); + SPI.transfer(data); + digitalWrite(this->cs_pin, HIGH); +} + +int EPD_WaveShare29::Init(const unsigned char* lut) { + /* this calls the peripheral hardware interface, see epdif */ + if (IfInit() != 0) { + return -1; + } + /* EPD hardware init start */ + this->lut = lut; + Reset(); + SendCommand(DRIVER_OUTPUT_CONTROL); + SendData((EPD_HEIGHT - 1) & 0xFF); + SendData(((EPD_HEIGHT - 1) >> 8) & 0xFF); + SendData(0x00); // GD = 0; SM = 0; TB = 0; + SendCommand(BOOSTER_SOFT_START_CONTROL); + SendData(0xD7); + SendData(0xD6); + SendData(0x9D); + SendCommand(WRITE_VCOM_REGISTER); + SendData(0xA8); // VCOM 7C + SendCommand(SET_DUMMY_LINE_PERIOD); + SendData(0x1A); // 4 dummy lines per gate + SendCommand(SET_GATE_TIME); + SendData(0x08); // 2us per line + SendCommand(DATA_ENTRY_MODE_SETTING); + SendData(0x03); // X increment; Y increment + SetLut(this->lut); + /* EPD hardware init end */ + return 0; +} + +/** + * @brief: basic function for sending commands + */ +void EPD_WaveShare29::SendCommand(unsigned char command) { + DigitalWrite(dc_pin, LOW); + SpiTransfer(command); +} + +/** + * @brief: basic function for sending data + */ +void EPD_WaveShare29::SendData(unsigned char data) { + DigitalWrite(dc_pin, HIGH); + SpiTransfer(data); +} + +/** + * @brief: Wait until the busy_pin goes LOW + */ +void EPD_WaveShare29::WaitUntilIdle(void) { + while(DigitalRead(busy_pin) == HIGH) { //LOW: idle, HIGH: busy + DelayMs(100); + } +} + +/** + * @brief: module reset. + * often used to awaken the module in deep sleep, + * see Epd::Sleep(); + */ +void EPD_WaveShare29::Reset(void) { + DigitalWrite(reset_pin, LOW); //module reset + DelayMs(200); + DigitalWrite(reset_pin, HIGH); + DelayMs(200); +} + +/** + * @brief: set the look-up table register + */ +void EPD_WaveShare29::SetLut(const unsigned char* lut) { + this->lut = lut; + SendCommand(WRITE_LUT_REGISTER); + /* the length of look-up table is 30 bytes */ + for (int i = 0; i < 30; i++) { + SendData(this->lut[i]); + } +} + +/** + * @brief: put an image buffer to the frame memory. + * this won't update the display. + */ +void EPD_WaveShare29::SetFrameMemory( + const unsigned char* image_buffer, + int x, + int y, + int image_width, + int image_height +) { + int x_end; + int y_end; + + if ( + image_buffer == NULL || + x < 0 || image_width < 0 || + y < 0 || image_height < 0 + ) { + return; + } + /* x point must be the multiple of 8 or the last 3 bits will be ignored */ + x &= 0xF8; + image_width &= 0xF8; + if (x + image_width >= this->bufferWidth) { + x_end = this->bufferWidth - 1; + } else { + x_end = x + image_width - 1; + } + if (y + image_height >= this->bufferHeight) { + y_end = this->bufferHeight - 1; + } else { + y_end = y + image_height - 1; + } + SetMemoryArea(x, y, x_end, y_end); + SetMemoryPointer(x, y); + SendCommand(WRITE_RAM); + /* send the image data */ + for (int j = 0; j < y_end - y + 1; j++) { + for (int i = 0; i < (x_end - x + 1) / 8; i++) { + SendData(reverse(image_buffer[i + j * (image_width / 8)])); + } + } + +} + +uint8_t EPD_WaveShare29::getPixel(uint8_t *buffer, uint16_t x, uint16_t y) { + uint8_t bitsPerPixel = 1; + uint8_t bitMask = (1 << bitsPerPixel) - 1; + uint8_t pixelsPerByte = 8 / bitsPerPixel; + uint8_t bitShift = 3; + + if (x >= bufferWidth || y >= bufferHeight) return 0; + // bitsPerPixel: 8, pixPerByte: 1, 0 1 = 2^0 + // bitsPerPixel: 4, pixPerByte: 2, 1 2 = 2^1 + // bitsPerPixel 2, pixPerByte: 4, 2 4 = 2^2 + // bitsPerPixel 1, pixPerByte: 8, 3 8 = 2^3 + uint16_t pos = (y * bufferWidth + x) >> bitShift; + + uint8_t shift = (x & (pixelsPerByte - 1)) * bitsPerPixel; + + return (buffer[pos] >> shift) & bitMask; +} + +/** + * @brief: put an image buffer to the frame memory. + * this won't update the display. + * + * Question: When do you use this function instead of + * void SetFrameMemory( + * const unsigned char* image_buffer, + * int x, + * int y, + * int image_width, + * int image_height + * ); + * Answer: SetFrameMemory with parameters only reads image data + * from the RAM but not from the flash in AVR chips (for AVR chips, + * you have to use the function pgm_read_byte to read buffers + * from the flash). + */ +void EPD_WaveShare29::SetFrameMemory(const unsigned char* image_buffer) { + SetMemoryArea(0, 0, this->width - 1, this->height - 1); + SetMemoryPointer(0, 0); + SendCommand(WRITE_RAM); + /* send the image data */ + for (int i = 0; i < this->width / 8 * this->height; i++) { + SendData(pgm_read_byte(&image_buffer[i])); + } +} + +/** + * @brief: clear the frame memory with the specified color. + * this won't update the display. + */ +void EPD_WaveShare29::ClearFrameMemory(unsigned char color) { + SetMemoryArea(0, 0, this->width - 1, this->height - 1); + SetMemoryPointer(0, 0); + SendCommand(WRITE_RAM); + /* send the color data */ + for (int i = 0; i < this->width / 8 * this->height; i++) { + SendData(color); + } +} + +/** + * @brief: update the display + * there are 2 memory areas embedded in the e-paper display + * but once this function is called, + * the the next action of SetFrameMemory or ClearFrame will + * set the other memory area. + */ +void EPD_WaveShare29::DisplayFrame(void) { + SendCommand(DISPLAY_UPDATE_CONTROL_2); + SendData(0xC4); + SendCommand(MASTER_ACTIVATION); + SendCommand(TERMINATE_FRAME_READ_WRITE); + WaitUntilIdle(); +} + +/** + * @brief: private function to specify the memory area for data R/W + */ +void EPD_WaveShare29::SetMemoryArea(int x_start, int y_start, int x_end, int y_end) { + SendCommand(SET_RAM_X_ADDRESS_START_END_POSITION); + /* x point must be the multiple of 8 or the last 3 bits will be ignored */ + SendData((x_start >> 3) & 0xFF); + SendData((x_end >> 3) & 0xFF); + SendCommand(SET_RAM_Y_ADDRESS_START_END_POSITION); + SendData(y_start & 0xFF); + SendData((y_start >> 8) & 0xFF); + SendData(y_end & 0xFF); + SendData((y_end >> 8) & 0xFF); +} + +/** + * @brief: private function to specify the start point for data R/W + */ +void EPD_WaveShare29::SetMemoryPointer(int x, int y) { + SendCommand(SET_RAM_X_ADDRESS_COUNTER); + /* x point must be the multiple of 8 or the last 3 bits will be ignored */ + SendData((x >> 3) & 0xFF); + SendCommand(SET_RAM_Y_ADDRESS_COUNTER); + SendData(y & 0xFF); + SendData((y >> 8) & 0xFF); + WaitUntilIdle(); +} + +uint8_t EPD_WaveShare29::reverse(uint8_t in) +{ + uint8_t out; + out = 0; + if (in & 0x01) out |= 0x80; + if (in & 0x02) out |= 0x40; + if (in & 0x04) out |= 0x20; + if (in & 0x08) out |= 0x10; + if (in & 0x10) out |= 0x08; + if (in & 0x20) out |= 0x04; + if (in & 0x40) out |= 0x02; + if (in & 0x80) out |= 0x01; + + return(out); +} + +/** + * @brief: After this command is transmitted, the chip would enter the + * deep-sleep mode to save power. + * The deep sleep mode would return to standby by hardware reset. + * You can use Epd::Init() to awaken + */ +void EPD_WaveShare29::Sleep() { + SendCommand(DEEP_SLEEP_MODE); + WaitUntilIdle(); +} + + + +/* END OF FILE */ diff --git a/src/EPD_WaveShare_29.h b/src/EPD_WaveShare_29.h new file mode 100644 index 0000000..9da25d7 --- /dev/null +++ b/src/EPD_WaveShare_29.h @@ -0,0 +1,138 @@ +/** +The MIT License (MIT) +Copyright (c) 2017 by Daniel Eichhorn +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +Please note: I am spending a lot of my free time in developing Software and Hardware +for these projects. Please consider supporting me by +a) Buying my hardware kits from https://blog.squix.org/shop +b) Send a donation: https://www.paypal.me/squix/5USD +c) Or using this affiliate link while shopping: https://www.banggood.com/?p=6R31122484684201508S + +See more at https://blog.squix.org + +This code is based on a driver from http://waveshare.com +*/ + +#ifndef EPD2IN9_H +#define EPD2IN9_H + +#include +#include "DisplayDriver.h" + +// Display resolution +#define EPD_WIDTH 128 +#define EPD_HEIGHT 296 + +// EPD2IN9 commands +#define DRIVER_OUTPUT_CONTROL 0x01 +#define BOOSTER_SOFT_START_CONTROL 0x0C +#define GATE_SCAN_START_POSITION 0x0F +#define DEEP_SLEEP_MODE 0x10 +#define DATA_ENTRY_MODE_SETTING 0x11 +#define SW_RESET 0x12 +#define TEMPERATURE_SENSOR_CONTROL 0x1A +#define MASTER_ACTIVATION 0x20 +#define DISPLAY_UPDATE_CONTROL_1 0x21 +#define DISPLAY_UPDATE_CONTROL_2 0x22 +#define WRITE_RAM 0x24 +#define WRITE_VCOM_REGISTER 0x2C +#define WRITE_LUT_REGISTER 0x32 +#define SET_DUMMY_LINE_PERIOD 0x3A +#define SET_GATE_TIME 0x3B +#define BORDER_WAVEFORM_CONTROL 0x3C +#define SET_RAM_X_ADDRESS_START_END_POSITION 0x44 +#define SET_RAM_Y_ADDRESS_START_END_POSITION 0x45 +#define SET_RAM_X_ADDRESS_COUNTER 0x4E +#define SET_RAM_Y_ADDRESS_COUNTER 0x4F +#define TERMINATE_FRAME_READ_WRITE 0xFF + + +const unsigned char lut_full_update[] = +{ + 0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22, + 0x66, 0x69, 0x69, 0x59, 0x58, 0x99, 0x99, 0x88, + 0x00, 0x00, 0x00, 0x00, 0xF8, 0xB4, 0x13, 0x51, + 0x35, 0x51, 0x51, 0x19, 0x01, 0x00 +}; + +const unsigned char lut_partial_update[] = +{ + 0x10, 0x18, 0x18, 0x08, 0x18, 0x18, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x13, 0x14, 0x44, 0x12, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +class EPD_WaveShare29 : public DisplayDriver { +public: + unsigned long width; + unsigned long height; + + EPD_WaveShare29(uint8_t csPin, uint8_t rstPin, uint8_t dcPin, uint8_t busyPin); + ~EPD_WaveShare29(); + + void setRotation(uint8_t r); + void init(); + + void writeBuffer(uint8_t *buffer, uint8_t bitsPerPixel, uint16_t *palette); + + int Init(const unsigned char* lut); + + int IfInit(void); + void DigitalWrite(int pin, int value); + int DigitalRead(int pin); + void DelayMs(unsigned int delaytime); + void SpiTransfer(unsigned char data); + + void SendCommand(unsigned char command); + void SendData(unsigned char data); + void WaitUntilIdle(void); + void Reset(void); + void SetFrameMemory( + const unsigned char* image_buffer, + int x, + int y, + int image_width, + int image_height + ); + void SetFrameMemory(const unsigned char* image_buffer); + void ClearFrameMemory(unsigned char color); + void DisplayFrame(void); + void Sleep(void); + void setFastRefresh(boolean isFastRefreshEnabled); + +private: + uint16_t bufferWidth; + uint16_t bufferHeight; + uint8_t rotation; + unsigned int reset_pin; + unsigned int dc_pin; + unsigned int cs_pin; + unsigned int busy_pin; + const unsigned char* lut; + + uint8_t reverse(uint8_t in); + uint8_t getPixel(uint8_t *buffer, uint16_t x, uint16_t y); + void SetLut(const unsigned char* lut); + void SetMemoryArea(int x_start, int y_start, int x_end, int y_end); + void SetMemoryPointer(int x, int y); +}; + +#endif /* EPD2IN9_H */ + +/* END OF FILE */ diff --git a/examples/EPaper/EPD_WaveShare_2_9/EPD_WaveShare_2_9.ino b/src/EPD_WaveShare_2_9.ino similarity index 78% rename from examples/EPaper/EPD_WaveShare_2_9/EPD_WaveShare_2_9.ino rename to src/EPD_WaveShare_2_9.ino index 1a8faf3..9137f59 100644 --- a/examples/EPaper/EPD_WaveShare_2_9/EPD_WaveShare_2_9.ino +++ b/src/EPD_WaveShare_2_9.ino @@ -29,7 +29,7 @@ Demo for the buffered graphics library. Renders a 3D cube */ #include -#include "EPD_WaveShare.h" +#include "EPD_WaveShare_29.h" #include "MiniGrafx.h" #include "DisplayDriver.h" @@ -45,35 +45,36 @@ Demo for the buffered graphics library. Renders a 3D cube GND GND 3.3V 3V3 */ -#define CS D3 +/*#define CS D3 #define RST D2 #define DC D8 -#define BUSY D1 +#define BUSY D1*/ + +#define CS 15 // D8 +#define RST 2 // D4 +#define DC 5 // D1 +#define BUSY 4 // D2 -#define SCREEN_WIDTH 128 -#define SCREEN_HEIGHT 296 #define BITS_PER_PIXEL 1 uint16_t palette[] = {0, 1}; +boolean isFastRefreshEnabled = false; -EPD_WaveShare epd(EPD2_9, CS, RST, DC, BUSY); +EPD_WaveShare29 epd(CS, RST, DC, BUSY); MiniGrafx gfx = MiniGrafx(&epd, BITS_PER_PIXEL, palette); - +uint8_t counter = 0; void setup() { + Serial.begin(115200); gfx.init(); + gfx.setRotation(0); } -uint8_t rotation = 0; +uint8_t rotation = 2; void loop() { - //epd.Dis_Clear_full(); - //delay(1500); - //epd.EPD_init_Part(); - //delay(1000); - //gfx.init(); gfx.setRotation(rotation); gfx.fillBuffer(1); gfx.setColor(0); @@ -83,8 +84,16 @@ void loop() { gfx.setFont(ArialMT_Plain_16); gfx.drawString(10, 30, "Everything works!"); gfx.setFont(ArialMT_Plain_24); - gfx.drawString(10, 55, "Yes! Millis: " + String(millis())); + gfx.drawString(10, 55, "Yes! Millis: \n" + String(counter)); + long startTime = millis(); gfx.commit(); - delay(5000); + Serial.printf("Time to update screen: %d\n", millis() - startTime); + delay(1000); rotation = (rotation + 1) % 4; + if (rotation == 3) { + isFastRefreshEnabled = !isFastRefreshEnabled; + gfx.setFastRefresh(isFastRefreshEnabled); + } + counter++; + } diff --git a/src/EPD_WaveShare_42.cpp b/src/EPD_WaveShare_42.cpp index 1632cb7..fa5bdce 100644 --- a/src/EPD_WaveShare_42.cpp +++ b/src/EPD_WaveShare_42.cpp @@ -80,6 +80,10 @@ void EPD_WaveShare42::init() { } +void EPD_WaveShare42::setFastRefresh(boolean isFastRefreshEnabled) { + // Not enabled at the moment +} + void EPD_WaveShare42::DigitalWrite(int pin, int value) { digitalWrite(pin, value); } diff --git a/src/EPD_WaveShare_42.h b/src/EPD_WaveShare_42.h index 6fe84dd..d4bcc62 100644 --- a/src/EPD_WaveShare_42.h +++ b/src/EPD_WaveShare_42.h @@ -169,6 +169,7 @@ class EPD_WaveShare42 : public DisplayDriver { void DisplayFrame(void); void ClearFrame(void); void Sleep(void); + void setFastRefresh(boolean isFastRefreshEnabled); uint8_t reverse(uint8_t in); diff --git a/src/EPD_WaveShare_43.cpp b/src/EPD_WaveShare_43.cpp index d0c170a..cb3028c 100644 --- a/src/EPD_WaveShare_43.cpp +++ b/src/EPD_WaveShare_43.cpp @@ -14,6 +14,10 @@ void EPD_WaveShare_43::init(void) { setMemory(MEM_NAND); } +void EPD_WaveShare_43::setFastRefresh(boolean isFastRefreshEnabled) { + // Not enabled at the moment +} + void EPD_WaveShare_43::setRotation(uint8_t r) { } diff --git a/src/EPD_WaveShare_43.h b/src/EPD_WaveShare_43.h index e101b8e..f10c777 100644 --- a/src/EPD_WaveShare_43.h +++ b/src/EPD_WaveShare_43.h @@ -104,7 +104,7 @@ class EPD_WaveShare_43 : public DisplayDriver { void writeBuffer(uint8_t *buffer, uint8_t bitsPerPixel, uint16_t *palette); void setBaud(long baud); - + void setFastRefresh(boolean isFastRefreshEnabled); diff --git a/src/EPaperPervasive.cpp b/src/EPaperPervasive.cpp index 542b625..d79e743 100644 --- a/src/EPaperPervasive.cpp +++ b/src/EPaperPervasive.cpp @@ -48,7 +48,7 @@ EPD_Class::EPD_Class(EPD_size size, int discharge_pin, int reset_pin, int busy_pin, - int chip_select_pin) : + int chip_select_pin) : DisplayDriver(width, height), EPD_Pin_PANEL_ON(panel_on_pin), EPD_Pin_BORDER(border_pin), @@ -106,6 +106,10 @@ EPD_Class::EPD_Class(EPD_size size, } +void EPD_Class::setFastRefresh(boolean isFastRefreshEnabled) { + // Not implemented at the moment +} + void EPD_Class::setFactor(int temperature) { // stage1: repeat, step, block diff --git a/src/EPaperPervasive.h b/src/EPaperPervasive.h index 6f6c26e..d821aae 100644 --- a/src/EPaperPervasive.h +++ b/src/EPaperPervasive.h @@ -127,6 +127,7 @@ class EPD_Class : public DisplayDriver { void frame_data_13(const uint8_t *image_data, EPD_stage stage, bool read_progmem = true); void frame_cb_13(uint32_t address, EPD_reader *reader, EPD_stage stage); void frame_cb_13(uint8_t *buffer, EPD_stage stage); + void setFastRefresh(boolean isFastRefreshEnabled); // single line display - very low-level // also has to handle AVR progmem diff --git a/src/ILI9341_SPI.cpp b/src/ILI9341_SPI.cpp index bab6d22..ad267ed 100644 --- a/src/ILI9341_SPI.cpp +++ b/src/ILI9341_SPI.cpp @@ -125,6 +125,10 @@ void ILI9341_SPI::spiwrite(uint8_t c) { } } +void ILI9341_SPI::setFastRefresh(boolean isFastRefreshEnabled) { + // Not enabled at the moment +} + void ILI9341_SPI::writecommand(uint8_t c) { #if defined (USE_FAST_PINIO) diff --git a/src/ILI9341_SPI.h b/src/ILI9341_SPI.h index 62da675..28175ef 100644 --- a/src/ILI9341_SPI.h +++ b/src/ILI9341_SPI.h @@ -125,9 +125,7 @@ class ILI9341_SPI : public DisplayDriver { void setRotation(uint8_t r); void writeBuffer(uint8_t *buffer, uint8_t bitsPerPixel, uint16_t *palette); - //uint16_t getScreenWidth(); - //uint16_t getScreenHeight(); - + void setFastRefresh(boolean isFastRefreshEnabled); void spiwrite(uint8_t); void writecommand(uint8_t c); diff --git a/src/MiniGrafx.cpp b/src/MiniGrafx.cpp index 58c695b..914077e 100644 --- a/src/MiniGrafx.cpp +++ b/src/MiniGrafx.cpp @@ -571,6 +571,10 @@ void MiniGrafx::commit() { this->driver->writeBuffer(buffer, bitsPerPixel, palette); } +void MiniGrafx::setFastRefresh(boolean isFastRefreshEnabled) { + this->driver->setFastRefresh(isFastRefreshEnabled); +} + void MiniGrafx::drawXbm(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const char *xbm) { int16_t widthInXbm = (width + 7) >> 3; uint8_t data = 0; diff --git a/src/MiniGrafx.h b/src/MiniGrafx.h index 7936e47..83c55d3 100644 --- a/src/MiniGrafx.h +++ b/src/MiniGrafx.h @@ -127,6 +127,7 @@ class MiniGrafx { void inline drawInternal(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const char *data, uint16_t offset, uint16_t bytesInData); void commit(); void clear(); + void setFastRefresh(boolean isFastRefreshEnabled); void fillBuffer(uint8_t pal); static char* utf8ascii(String s); static byte utf8ascii(byte ascii);