Skip to content

Commit

Permalink
Add driver and sample for 7.5"
Browse files Browse the repository at this point in the history
  • Loading branch information
squix78 committed Jan 24, 2018
1 parent 3c3772a commit 215201a
Show file tree
Hide file tree
Showing 7 changed files with 2,172 additions and 7 deletions.
6 changes: 4 additions & 2 deletions examples/EPaper/EPD_WaveShare_42/EPD_WaveShare_42.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ MiniGrafx gfx = MiniGrafx(&epd, BITS_PER_PIXEL, palette);
void setup() {
Serial.begin(115200);
gfx.init();

gfx.setRotation(1);
}

uint8_t rotation = 0;

void loop() {


gfx.setRotation(rotation);
gfx.fillBuffer(1);
gfx.setColor(0);
gfx.setFont(ArialMT_Plain_10);
Expand All @@ -86,6 +87,7 @@ void loop() {
gfx.setFont(ArialMT_Plain_24);
gfx.drawString(10, 55, "Yes! Millis: " + String(millis()));
gfx.commit();
delay(15000);
rotation = (rotation + 1) % 4;
delay(5000);

}
95 changes: 95 additions & 0 deletions examples/EPaper/EPD_WaveShare_7_5/EPD_WaveShare_75.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
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
Demo for the buffered graphics library. Renders a 3D cube
*/

#include <SPI.h>
#include "EPD_WaveShare_75.h"
#include "MiniGrafx.h"
#include "DisplayDriver.h"
#include "image.h"

/*
Connect the following pins:
Display NodeMCU
BUSY D1
RST D2
DC D8
CS D3
CLK D5
DIN D7
GND GND
3.3V 3V3
*/
/*#define CS D3
#define RST D2
#define DC D8
#define BUSY D1*/

#define CS 15 // D8
#define RST 2 // D4
#define DC 5 // D1
#define BUSY 4 // D2

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 384
#define BITS_PER_PIXEL 1


uint16_t palette[] = {0, 1};

EPD_WaveShare75 epd(CS, RST, DC, BUSY);
MiniGrafx gfx = MiniGrafx(&epd, BITS_PER_PIXEL, palette);

void setup() {
Serial.begin(115200);
gfx.init();
gfx.setRotation(1);
}

uint8_t rotation = 0;

void loop() {


gfx.setRotation(rotation);
gfx.fillBuffer(1);
/*gfx.setColor(0);
gfx.setFont(ArialMT_Plain_10);
gfx.drawLine(0, 0, gfx.getWidth(), gfx.getHeight());
gfx.drawString(10, 10, "Hello World");
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.drawPalettedBitmapFromPgm(0, 0, miniCalendar);
gfx.commit();
rotation = (rotation + 1) % 4;
delay(5000);

}
1,544 changes: 1,544 additions & 0 deletions examples/EPaper/EPD_WaveShare_7_5/image.h

Large diffs are not rendered by default.

92 changes: 87 additions & 5 deletions src/EPD_WaveShare_42.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,27 @@ int EPD_WaveShare42::getHeight() {
}

void EPD_WaveShare42::setRotation(uint8_t r) {
// Currently not supported
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_WaveShare42::init() {
/* this calls the peripheral hardware interface, see epdif */
if (IfInit() != 0) {
Expand Down Expand Up @@ -219,6 +238,17 @@ void EPD_WaveShare42::SetLut(void) {
* @brief: refresh and displays the frame
*/
void EPD_WaveShare42::DisplayFrame(const unsigned char* frame_buffer) {
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;

SendCommand(RESOLUTION_SETTING);
SendData(width >> 8);
SendData(width & 0xff);
Expand All @@ -232,16 +262,50 @@ void EPD_WaveShare42::DisplayFrame(const unsigned char* frame_buffer) {
SendCommand(0x97); //VBDF 17|D7 VBDW 97 VBDB 57 VBDF F7 VBDW 77 VBDB 37 VBDR B7

if (frame_buffer != NULL) {
SendCommand(DATA_START_TRANSMISSION_1);
/*SendCommand(DATA_START_TRANSMISSION_1);
for(int i = 0; i < width / 8 * height; i++) {
SendData(0xFF); // bit set: white, bit reset: black
}
DelayMs(2);
SendCommand(DATA_START_TRANSMISSION_2);
DelayMs(2);*/
/*SendCommand(DATA_START_TRANSMISSION_2);
for(int i = 0; i < width / 8 * height; i++) {
SendData(reverse(frame_buffer[i]));
}
DelayMs(2);
DelayMs(2);*/
SendCommand(DATA_START_TRANSMISSION_2);
for (int i = 0; i < height; i++) {
for (int j = 0; j < (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(frame_buffer, x, y) & 1);

}
SendData(data);
//SendData(reverse(buffer[(i + j * (image_width / 8))]));
//SendData(i);
yield();
}
}
}

SetLut();
Expand All @@ -251,6 +315,24 @@ void EPD_WaveShare42::DisplayFrame(const unsigned char* frame_buffer) {
WaitUntilIdle();
}

uint8_t EPD_WaveShare42::getPixel(const unsigned char *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;
}

uint8_t EPD_WaveShare42::reverse(uint8_t in)
{
uint8_t out;
Expand Down
3 changes: 3 additions & 0 deletions src/EPD_WaveShare_42.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class EPD_WaveShare42 : public DisplayDriver {
void ClearFrame(void);
void Sleep(void);
void setFastRefresh(boolean isFastRefreshEnabled);
uint8_t getPixel(const unsigned char* buffer, uint16_t x, uint16_t y);

uint8_t reverse(uint8_t in);

Expand All @@ -181,6 +182,8 @@ class EPD_WaveShare42 : public DisplayDriver {
uint8_t rotation;
uint16_t delaytime;
uint16_t height, width;
uint16_t bufferWidth;
uint16_t bufferHeight;


};
Expand Down
Loading

0 comments on commit 215201a

Please sign in to comment.