SparkFun SSD168x Library  v1.0.2
Library for SSD1680 / SSD1681 e-paper displays on SPI
Loading...
Searching...
No Matches
spi_ssd1681.h
Go to the documentation of this file.
1
21#pragma once
22
23#include "spi_ssd1681_defs.h"
24#include "qwiic_grbuffer.h"
25#include "sfe_platform.h"
26#include "sfe_bus.h"
27#include "sfe_debug.h"
28#include "res/qwiic_resdef.h"
29#include "qwiic_grcommon.h"
30
32// Buffer Management
34//
35// SSD1681 supports up to 200 rows and 200 columns
36// Each memory byte contains the pixels for 8 columns
37// (For the SSD1306: each byte contains the pixels for 8 rows / COM lines)
38// The MSB is the left-most pixel
39// By default: white pixels are '1', black are '0', but UpdateCtrl1 can invert this
40// Because this library is hard-wired to expect 'off' pixels to be '0' and 'on' pixels to be '1',
41// it is MUCH easier if we use the inversion...
42// On SSD1681, the 25 'pages' run vertically, not horizontally
43// By default: addresses increase in the X direction: byte 0 is row 0 cols 0-7, byte 1 is row 0 cols 8-15, etc.
44// But Data Entry Mode can select Y-increase instead: byte 0 is row 0 cols 0-7, byte 1 is row 1 cols 0-7
45// Basically, the memory is rotated and flipped compared to the SSD1306, and the pixels are inverted too...
46//
47// The 'pages' are arranged like this:
48//
49// _ _ _ _ _ _ _
50// | || || || || || || | < Row 0
51// | || || || || || || | < Row 1
52// | || || || || || || | < Row 2
53// | || || || || || || |
54// | || || || || || || |
55// | || || || || || || |
56// |_||_||_||_||_||_||_|
57// | FPC |
58//
59// ^- Page 2
60// ^- Page 1
61// ^- Page 0
62//
63// The memory/back buffer of the SSD1681 is based on the concept of pages -
64// each page is a stream of bytes, and - with addresses increasing in Y - is defined as follows:
65//
66// - X pixel position is a bit in a byte, so a page can have 8 X locations
67// - Y pixel position is an offset in a byte array
68//
69// With inversion, a pixel value of 0 is 'off' (white), 1 is 'on' (black)
70//
71// This implementation uses the Page mode for buffer transfer. This is defined by:
72// - A start position is set - a page number and row in that page.
73// - As data is transferred, it is written to the screenbuffer, based on this start
74// position
75// - If the end of the page is reached, the next entry location is the start of the next page
76//
77// >> Implementation <<
78//
79// This implementation uses the concept of "dirty rects" at the page level to minimize data
80// transfers to the device. The min and max Y locations set for each page is recorded as
81// graphics are drawn to the graphics buffer. When transferring the display buffer to
82// the devices screen buffer, the following takes place:
83//
84// For each page:
85// - if page is dirty
86// - Set the screen buffer current location to this page, min dirty value
87// - Write buffer bytes to the device - starting at min for the page, ending at max
88// - Mark the buffer as "clean"
89//
90//
91
93// SpiSsd1681
94// A buffer graphics device to support the SSD1681 graphics hardware
95
97{
98 private:
99 void setupDefaults(void);
100
101 public:
103 {
104 setupDefaults(); // default constructor - always called
105 }
106 SpiSsd1681(uint8_t width, uint8_t height) : SpiSsd1681(0, 0, width, height){};
107
108 // call super class
109 SpiSsd1681(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height) : QwEpGrBufferDevice(x0, y0, width, height)
110 {
111 setupDefaults();
112 };
113
114 // Public draw methods
121 void display(bool partial = false, bool dirtyOnly = true);
125 void erase(void);
126
127 // Device setup
135 virtual bool init(void);
136
142 bool isInitialized(void)
143 {
144 return m_isInitialized;
145 };
151 bool reset(void);
152
160 void setCommBus(SparkFun_SSD168x::SSD168xDeviceBus &theBus, int resetPin, int busyPin);
161
162 // Set the current color/pixel write operation
163 void setColor(uint8_t color);
164
171 {
172 m_rop = rop;
173 }
174
181 {
182 return m_rop;
183 }
184
190 void deepSleep(bool mode2);
191
197 bool isBusy(void);
198
206 bool waitWhileBusy(unsigned long pollInterval_ms = 10, unsigned long timeout_ms = kSsd168xBusyTimeout_ms);
207
208 protected:
209 // Subclasses of this class define the specifics of the device, including size.
210 // Subclass needs to define the graphics buffer array - stack based - and pass in
211 void setBuffer(uint8_t *pBuffer);
212
214 // Internal, fast draw routines - this are used in the overall
215 // draw interface (_QwEpIDraw) for this object/device/system.
216 //
217 // >> Pixels <<
218 void drawPixel(uint8_t x, uint8_t y, uint8_t clr);
219
220 // >> Fast Lines <<
221 void drawLineHorz(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr);
222 void drawLineVert(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr);
223
224 // fast rect fill
225 void drawRectFilled(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr);
226
227 // >> Fast Bitmap <<
228 void drawBitmap(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t *pBitmap, uint8_t bmp_width,
229 uint8_t bmp_height);
230
232 // configuration methods for sub-classes. Settings unique to a device
233
234 private:
235 // Internal buffer management methods
236 bool setScreenBufferAddress(uint8_t page, uint8_t rowStart, uint8_t rowEnd);
237 void initBuffers(void); // clear graphics and screen buffer
238 void clearScreenBuffer(void); // clear screen buffer
239 void setupEpaperDevice(void); // always calls initBuffers
240
241 // device communication methods
242 void sendDevCommand(uint8_t command);
243 void sendDevCommand(uint8_t command, uint8_t value);
244 void sendDevCommand(uint8_t command, uint8_t *values, uint16_t n_values);
245 void sendDevReset(void);
246
248 // instance vars
249
250 // Buffer variables
251 uint8_t *m_pBuffer; // Pointer to the graphics buffer
252 uint8_t m_nPages; // number of pages for current device
253 // m_pageState
254 // The current "dirty" areas of the graphics [local] buffer.
255 // Areas that haven't been sent to the screen/device but are
256 // "dirty" (have been changed)
257 pageStateEp_t m_pageState[kMaxPageNumberSSD1681]; // page state descriptors
258 // m_pageErase
259 // erase() erases all graphics on the device, placing the display in a blank state.
260 // ** The erase update isn't sent to the device until the next display() call
261 // on the device. **
262 // m_pageErase holds the area of each page which need to be erased on the next
263 // call of display()
264 pageStateEp_t m_pageErase[kMaxPageNumberSSD1681]; // keep track of erase boundaries
265 // m_pendingErase
266 // Flags to indicate which of the screen pages need to be erased.
267 // In the original OLED library, this is a single flag which is set
268 // when erase() is called and cleared by the next display().
269 // In this library, m_pendingErase has been expanded to provide
270 // a flag for each screen bank / page.
271 bool m_pendingErase[kMaxPageNumberSSD1681]; // indicates if this page needs erase
272 // The GoodDisplay e-paper displays have ping-pong mode enabled.
273 // When using partial updates, we need to ensure display() always writes
274 // the current "dirty" area(s) _and_ the previous "dirty" area(s) to the
275 // screen. (Otherwise the two SSD168x RAM banks get out of sync and we
276 // get 'flashing' / 'blinking' areas of pixels.)
277 // Thinking through how we need to handle erase():
278 // display() needs to send:
279 // the current "dirty" area stored in m_pageState
280 // expanded to include:
281 // the current erased area stored in m_pageErase (if flagged)
282 // the previous combined "dirty" area in m_pagePrevious
283 pageStateEp_t m_pagePrevious[kMaxPageNumberSSD1681]; // previous page state descriptors
284
285 // display variables
286 uint8_t m_color; // current color (really 0 or 1)
287 grEpRasterOp_t m_rop; // current raster operation code
288
289 // SPI things
290 SparkFun_SSD168x::SSD168xDeviceBus *m_spiBus; // pointer to our SPI bus object
291 int m_pinReset; // the RES# pin. -1 if not connected
292 int m_pinBusy; // the BUSY pin
293
294 // Stash values for settings that are unique to each device.
295
296 bool m_isInitialized; // general init flag
297
298 // Handy helper
299 const uint8_t gfx_byte_bits[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
300};
Definition: qwiic_grbuffer.h:153
uint16_t height(void)
Definition: qwiic_grbuffer.h:189
uint16_t width(void)
Definition: qwiic_grbuffer.h:185
The abstract hardware bus interface used by the SSD168x device classes.
Definition: sfe_bus.h:42
Definition: sfe_debug.h:43
Definition: spi_ssd1681.h:97
void setCommBus(SparkFun_SSD168x::SSD168xDeviceBus &theBus, int resetPin, int busyPin)
Set the communication bus this object should use, plus the RES# and BUSY pins.
Definition: spi_ssd1681.cpp:263
bool isBusy(void)
Read the state of the BUSY pin.
Definition: spi_ssd1681.cpp:356
bool isInitialized(void)
Check if init() has been called successfully.
Definition: spi_ssd1681.h:142
void drawRectFilled(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr)
Definition: spi_ssd1681.cpp:578
void erase(void)
Erase the graphics buffer. The erase is not sent to the device until the next display().
Definition: spi_ssd1681.cpp:397
SpiSsd1681(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height)
Definition: spi_ssd1681.h:109
void deepSleep(bool mode2)
Put the SSD168x into deep sleep. Only a hardware reset can wake it again (display() does this).
Definition: spi_ssd1681.cpp:343
bool waitWhileBusy(unsigned long pollInterval_ms=10, unsigned long timeout_ms=kSsd168xBusyTimeout_ms)
Wait until the SSD168x BUSY pin goes low.
Definition: spi_ssd1681.cpp:370
bool reset(void)
Wake and reset the device: clear the graphics and screen buffers and perform a full update.
Definition: spi_ssd1681.cpp:171
void display(bool partial=false, bool dirtyOnly=true)
Send the changes in the graphics buffer to the device and perform a full or partial update.
Definition: spi_ssd1681.cpp:691
void setRasterOp(grEpRasterOp_t rop)
Set the current raster operation (draw mode).
Definition: spi_ssd1681.h:170
void setColor(uint8_t color)
void setBuffer(uint8_t *pBuffer)
Definition: spi_ssd1681.cpp:280
SpiSsd1681(uint8_t width, uint8_t height)
Definition: spi_ssd1681.h:106
void drawLineVert(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr)
Definition: spi_ssd1681.cpp:460
SpiSsd1681()
Definition: spi_ssd1681.h:102
void drawPixel(uint8_t x, uint8_t y, uint8_t clr)
Definition: spi_ssd1681.cpp:440
void drawLineHorz(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr)
Definition: spi_ssd1681.cpp:500
void drawBitmap(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t *pBitmap, uint8_t bmp_width, uint8_t bmp_height)
Definition: spi_ssd1681.cpp:592
grEpRasterOp_t rasterOp(void)
Get the current raster operation (draw mode).
Definition: spi_ssd1681.h:180
virtual bool init(void)
Initialize the device: reset it, send the initialization sequence, clear it and perform a full update...
Definition: spi_ssd1681.cpp:105
enum gr_ep_op_funcs_ grEpRasterOp_t
#define kSsd168xBusyTimeout_ms
Definition: spi_ssd1680_defs.h:110
#define kMaxPageNumberSSD1681
Definition: spi_ssd1681_defs.h:98
Definition: qwiic_grbuffer.h:147