Paperd.Ink Library 0.0.5
Library for interacting with Paperd.Ink devices.
Loading...
Searching...
No Matches
GxEPD2_EPD.h
Go to the documentation of this file.
1// Display Library for SPI e-paper panels from Dalian Good Display and boards from Waveshare.
2// Requires HW SPI and Adafruit_GFX. Caution: these e-papers require 3.3V supply AND data lines!
3//
4// based on Demo Example from Good Display: http://www.e-paper-display.com/download_list/downloadcategoryid=34&isMode=false.html
5//
6// Author: Jean-Marc Zingg
7//
8// Version: see library.properties
9//
10// Library: https://github.com/ZinggJM/GxEPD2
11
12#ifndef _GxEPD2_EPD_H_
13#define _GxEPD2_EPD_H_
14
15#include <Arduino.h>
16#include <SPI.h>
17
18#include "GxEPD2.h"
19
20#pragma GCC diagnostic ignored "-Wunused-parameter"
21//#pragma GCC diagnostic ignored "-Wsign-compare"
22
24{
25 public:
26 // attributes
27 const uint16_t WIDTH;
28 const uint16_t HEIGHT;
30 const bool hasColor;
31 const bool hasPartialUpdate;
33 // constructor
34 GxEPD2_EPD(int16_t cs, int16_t dc, int16_t rst, int16_t busy, int16_t busy_level, uint32_t busy_timeout,
35 uint16_t w, uint16_t h, GxEPD2::Panel p, bool c, bool pu, bool fpu);
36 virtual void init(uint32_t serial_diag_bitrate = 0); // serial_diag_bitrate = 0 : disabled
37 virtual void init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration = 10, bool pulldown_rst_mode = false);
38 // Support for Bitmaps (Sprites) to Controller Buffer and to Screen
39 virtual void clearScreen(uint8_t value) = 0; // init controller memory and screen (default white)
40 virtual void writeScreenBuffer(uint8_t value) = 0; // init controller memory (default white)
41 // write to controller memory, without screen refresh; x and w should be multiple of 8
42 virtual void writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
43 virtual void writeImageForFullRefresh(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false)
44 {
45 // writeImage is independent from refresh mode for most controllers, exception e.g. SSD1681
46 writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
47 }
48 //virtual void writeImage_4G(const uint8_t bitmap[], uint8_t bpp, int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
49 virtual void writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
50 int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
51 // virtual void writeImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
52 // virtual void writeImagePart(const uint8_t* black, const uint8_t* color, int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
53 // int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
54 // write sprite of native data to controller memory, without screen refresh; x and w should be multiple of 8
55 // virtual void writeNative(const uint8_t* data1, const uint8_t* data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
56 // for differential update: set current and previous buffers equal (for fast partial update to work correctly)
57 virtual void writeScreenBufferAgain(uint8_t value = 0xFF) // init controller memory (default white)
58 {
59 // most controllers with differential update do switch buffers on refresh, can use:
60 writeScreenBuffer(value);
61 }
62 virtual void writeImageAgain(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false)
63 {
64 // most controllers with differential update do switch buffers on refresh, can use:
65 writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
66 }
67 virtual void writeImagePartAgain(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
68 int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false)
69 {
70 // most controllers with differential update do switch buffers on refresh, can use:
71 writeImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
72 }
73 // write to controller memory, with screen refresh; x and w should be multiple of 8
74 // virtual void drawImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
75 // virtual void drawImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
76 // int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
77 // virtual void drawImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
78 // virtual void drawImagePart(const uint8_t* black, const uint8_t* color, int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
79 // int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
80 // write sprite of native data to controller memory, with screen refresh; x and w should be multiple of 8
81 // virtual void drawNative(const uint8_t* data1, const uint8_t* data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
82 virtual void refresh(bool partial_update_mode = false) = 0; // screen refresh from controller memory to full screen
83 virtual void refresh(int16_t x, int16_t y, int16_t w, int16_t h) = 0; // screen refresh from controller memory, partial screen
84 virtual void powerOff() = 0; // turns off generation of panel driving voltages, avoids screen fading over time
85 virtual void hibernate() = 0; // turns powerOff() and sets controller to deep sleep for minimum power use, ONLY if wakeable by RST (rst >= 0)
86 virtual void setPaged() {}; // for GxEPD2_154c paged workaround
87 // register a callback function to be called during _waitWhileBusy continuously.
88 void setBusyCallback(void (*busyCallback)(const void*), const void* busy_callback_parameter = 0);
89 static inline uint16_t gx_uint16_min(uint16_t a, uint16_t b)
90 {
91 return (a < b ? a : b);
92 };
93 static inline uint16_t gx_uint16_max(uint16_t a, uint16_t b)
94 {
95 return (a > b ? a : b);
96 };
97 void selectSPI(SPIClass& spi, SPISettings spi_settings);
98 protected:
99 void _reset();
100 void _waitWhileBusy(const char* comment = 0, uint16_t busy_time = 5000);
101 void _writeCommand(uint8_t c);
102 void _writeData(uint8_t d);
103 void _writeData(const uint8_t* data, uint16_t n);
104 void _writeDataPGM(const uint8_t* data, uint16_t n, int16_t fill_with_zeroes = 0);
105 void _writeDataPGM_sCS(const uint8_t* data, uint16_t n, int16_t fill_with_zeroes = 0);
106 void _writeCommandData(const uint8_t* pCommandData, uint8_t datalen);
107 void _writeCommandDataPGM(const uint8_t* pCommandData, uint8_t datalen);
108 void _startTransfer();
109 void _transfer(uint8_t value);
110 void _endTransfer();
111 protected:
115 SPIClass* _pSPIx;
116 SPISettings _spi_settings;
120 void (*_busy_callback)(const void*);
122};
123
124#endif
bool _pulldown_rst_mode
Definition GxEPD2_EPD.h:114
bool _diag_enabled
Definition GxEPD2_EPD.h:114
void _endTransfer()
const uint16_t HEIGHT
Definition GxEPD2_EPD.h:28
void _writeCommand(uint8_t c)
void _writeData(uint8_t d)
static uint16_t gx_uint16_max(uint16_t a, uint16_t b)
Definition GxEPD2_EPD.h:93
int16_t _busy_level
Definition GxEPD2_EPD.h:112
virtual void refresh(int16_t x, int16_t y, int16_t w, int16_t h)=0
virtual void writeScreenBuffer(uint8_t value)=0
bool _using_partial_mode
Definition GxEPD2_EPD.h:118
virtual void init(uint32_t serial_diag_bitrate=0)
virtual void writeImageAgain(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert=false, bool mirror_y=false, bool pgm=false)
Definition GxEPD2_EPD.h:62
void _waitWhileBusy(const char *comment=0, uint16_t busy_time=5000)
void(* _busy_callback)(const void *)
Definition GxEPD2_EPD.h:120
bool _power_is_on
Definition GxEPD2_EPD.h:118
bool _initial_refresh
Definition GxEPD2_EPD.h:117
virtual void powerOff()=0
const uint16_t WIDTH
Definition GxEPD2_EPD.h:27
virtual void writeImagePartAgain(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap, int16_t x, int16_t y, int16_t w, int16_t h, bool invert=false, bool mirror_y=false, bool pgm=false)
Definition GxEPD2_EPD.h:67
void _startTransfer()
void _writeCommandDataPGM(const uint8_t *pCommandData, uint8_t datalen)
virtual void writeImageForFullRefresh(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert=false, bool mirror_y=false, bool pgm=false)
Definition GxEPD2_EPD.h:43
virtual void clearScreen(uint8_t value)=0
void selectSPI(SPIClass &spi, SPISettings spi_settings)
void _transfer(uint8_t value)
uint16_t _reset_duration
Definition GxEPD2_EPD.h:119
int16_t _dc
Definition GxEPD2_EPD.h:112
GxEPD2_EPD(int16_t cs, int16_t dc, int16_t rst, int16_t busy, int16_t busy_level, uint32_t busy_timeout, uint16_t w, uint16_t h, GxEPD2::Panel p, bool c, bool pu, bool fpu)
void _reset()
void _writeDataPGM_sCS(const uint8_t *data, uint16_t n, int16_t fill_with_zeroes=0)
const bool hasColor
Definition GxEPD2_EPD.h:30
virtual void hibernate()=0
bool _initial_write
Definition GxEPD2_EPD.h:117
const void * _busy_callback_parameter
Definition GxEPD2_EPD.h:121
virtual void writeScreenBufferAgain(uint8_t value=0xFF)
Definition GxEPD2_EPD.h:57
const bool hasFastPartialUpdate
Definition GxEPD2_EPD.h:32
virtual void refresh(bool partial_update_mode=false)=0
virtual void writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert=false, bool mirror_y=false, bool pgm=false)=0
uint32_t _busy_timeout
Definition GxEPD2_EPD.h:113
void _writeCommandData(const uint8_t *pCommandData, uint8_t datalen)
int16_t _rst
Definition GxEPD2_EPD.h:112
const GxEPD2::Panel panel
Definition GxEPD2_EPD.h:29
virtual void writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap, int16_t x, int16_t y, int16_t w, int16_t h, bool invert=false, bool mirror_y=false, bool pgm=false)=0
SPISettings _spi_settings
Definition GxEPD2_EPD.h:116
static uint16_t gx_uint16_min(uint16_t a, uint16_t b)
Definition GxEPD2_EPD.h:89
int16_t _busy
Definition GxEPD2_EPD.h:112
bool _hibernating
Definition GxEPD2_EPD.h:118
void _writeDataPGM(const uint8_t *data, uint16_t n, int16_t fill_with_zeroes=0)
SPIClass * _pSPIx
Definition GxEPD2_EPD.h:115
void setBusyCallback(void(*busyCallback)(const void *), const void *busy_callback_parameter=0)
const bool hasPartialUpdate
Definition GxEPD2_EPD.h:31
virtual void setPaged()
Definition GxEPD2_EPD.h:86
int16_t _cs
Definition GxEPD2_EPD.h:112
Panel
Definition GxEPD2.h:37