SparkFun SSD168x Library  v1.0.2
Library for SSD1680 / SSD1681 e-paper displays on SPI
Loading...
Searching...
No Matches
spi_ssd1680_rotated.h
Go to the documentation of this file.
1
21#pragma once
22
23#include "spi_ssd1680_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// SSD1680 supports up to 296 rows and 176 columns
36// Here, everything is rotated, becoming similar to the SSD1306
37// Each memory byte contains the pixels for 8 'rows'
38// The MSB is the top-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// To make life easier for ourselves, we use:
43// Y decrement, X increment mode
44// with the address counter updating in the Y direction
45// This places 'Page' 0 at the top of the page
46// In our memory buffer, we can use standard X,Y coordinates
47// When we write to the display, X becomes Y
48// We just need to remember to set the Y RAM Counter to (e.g.) 183 initially
49//
50// The 'pages' are arranged like this:
51// This corner is 0,0 in display coordinates
52// __________/
53// _|__________| < Page 0 ('Rows' 0-7)
54// F|__________| < Page 1 ('Rows' 8-15)
55// P|__________| < Page 2 ('Rows' 16-23)
56// C|__________|
57// -|__________|
58// |__________|
59// ^- 'Column' 0
60// ^- 'Column' 295
61//
62// The memory/back buffer of the SSD1680 is based on the concept of pages -
63// each page is a stream of bytes, and - with addresses increasing in Y - is defined as follows:
64//
65// - Y pixel position is a bit in a byte, so a page can have 8 Y locations
66// - X pixel position is an offset in a byte array. The first byte is right-most
67//
68// With inversion, a pixel value of 0 is 'off' (white), 1 is 'on' (black)
69//
70// This implementation uses the Page mode for buffer transfer. This is defined by:
71// - A start position is set - a page number and 'column' in that page.
72// - As data is transferred, it is written to the screenbuffer, based on this start
73// position
74// - If the end of the page is reached, the next entry location is the start of the next page
75//
76// ** Note: **
77// Because we are rotated, with the FPC to the left, X coordinates need to be flipped:
78// If the X coordinate is 0, the pixel is in 'column' 183 (on 184x88 displays)
79//
80// >> Implementation <<
81//
82// This implementation uses the concept of "dirty rects" at the page level to minimize data
83// transfers to the device. The min and max Y locations set for each page is recorded as
84// graphics are drawn to the graphics buffer. When transferring the display buffer to
85// the devices screen buffer, the following takes place:
86//
87// For each page:
88// - if page is dirty
89// - Set the screen buffer current location to this page, min dirty value
90// - Write buffer bytes to the device - starting at min for the page, ending at max
91// - Mark the buffer as "clean"
92//
93//
94
96// SpiSsd1680Rotated
97// A buffer graphics device to support the SSD1680 graphics hardware
98
100{
101 private:
102 void setupDefaults(void);
103
104 public:
106 {
107 setupDefaults(); // default constructor - always called
108 }
110
111 // call super class
112 SpiSsd1680Rotated(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height) : QwEpGrBufferDevice(x0, y0, width, height)
113 {
114 setupDefaults();
115 };
116
117 // Public draw methods
124 void display(bool partial = false, bool dirtyOnly = true);
128 void erase(void);
129
130 // Device setup
138 virtual bool init(void);
139
145 bool isInitialized(void)
146 {
147 return m_isInitialized;
148 };
154 bool reset(void);
155
163 void setCommBus(SparkFun_SSD168x::SSD168xDeviceBus &theBus, int resetPin, int busyPin);
164
165 // Set the current color/pixel write operation
166 void setColor(uint8_t color);
167
174 {
175 m_rop = rop;
176 }
177
184 {
185 return m_rop;
186 }
187
193 void deepSleep(bool mode2);
194
200 bool isBusy(void);
201
209 bool waitWhileBusy(unsigned long pollInterval_ms = 10, unsigned long timeout_ms = kSsd168xBusyTimeout_ms);
210
211 protected:
212 // Subclasses of this class define the specifics of the device, including size.
213 // Subclass needs to define the graphics buffer array - stack based - and pass in
214 void setBuffer(uint8_t *pBuffer);
215
217 // Internal, fast draw routines - this are used in the overall
218 // draw interface (_QwEpIDraw) for this object/device/system.
219 //
220 // >> Pixels <<
221 void drawPixel(uint8_t x, uint8_t y, uint8_t clr);
222
223 // >> Fast Lines <<
224 void drawLineHorz(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr);
225 void drawLineVert(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr);
226
227 // fast rect fill
228 void drawRectFilled(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr);
229
230 // >> Fast Bitmap <<
231 void drawBitmap(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t *pBitmap, uint8_t bmp_width,
232 uint8_t bmp_height);
233
235 // configuration methods for sub-classes. Settings unique to a device
236
237 private:
238 // Internal buffer management methods
239 bool setScreenBufferAddress(uint8_t page, uint8_t columnStart, uint8_t columnEnd);
240 void initBuffers(void); // clear graphics and screen buffer
241 void clearScreenBuffer(void); // clear screen buffer
242 void setupEpaperDevice(void); // always calls initBuffers
243
244 // device communication methods
245 void sendDevCommand(uint8_t command);
246 void sendDevCommand(uint8_t command, uint8_t value);
247 void sendDevCommand(uint8_t command, uint8_t *values, uint16_t n_values);
248 void sendDevReset(void);
249
251 // instance vars
252
253 // Buffer variables
254 uint8_t *m_pBuffer; // Pointer to the graphics buffer
255 uint8_t m_nPages; // number of pages for current device
256 // m_pageState
257 // The current "dirty" areas of the graphics [local] buffer.
258 // Areas that haven't been sent to the screen/device but are
259 // "dirty" (have been changed)
260 pageStateEp_t m_pageState[kMaxPageNumberSSD1680]; // page state descriptors
261 // m_pageErase
262 // erase() erases all graphics on the device, placing the display in a blank state.
263 // ** The erase update isn't sent to the device until the next display() call
264 // on the device. **
265 // m_pageErase holds the area of each page which need to be erased on the next
266 // call of display()
267 pageStateEp_t m_pageErase[kMaxPageNumberSSD1680]; // keep track of erase boundaries
268 // m_pendingErase
269 // Flags to indicate which of the screen pages need to be erased.
270 // In the original OLED library, this is a single flag which is set
271 // when erase() is called and cleared by the next display().
272 // In this library, m_pendingErase has been expanded to provide
273 // a flag for each screen bank / page.
274 bool m_pendingErase[kMaxPageNumberSSD1680]; // indicates if this page needs erase
275 // The GoodDisplay e-paper displays have ping-pong mode enabled.
276 // When using partial updates, we need to ensure display() always writes
277 // the current "dirty" area(s) _and_ the previous "dirty" area(s) to the
278 // screen. (Otherwise the two SSD168x RAM banks get out of sync and we
279 // get 'flashing' / 'blinking' areas of pixels.)
280 // Thinking through how we need to handle erase():
281 // display() needs to send:
282 // the current "dirty" area stored in m_pageState
283 // expanded to include:
284 // the current erased area stored in m_pageErase (if flagged)
285 // the previous combined "dirty" area in m_pagePrevious
286 pageStateEp_t m_pagePrevious[kMaxPageNumberSSD1680]; // previous page state descriptors
287
288 // display variables
289 uint8_t m_color; // current color (really 0 or 1)
290 grEpRasterOp_t m_rop; // current raster operation code
291
292 // SPI things
293 SparkFun_SSD168x::SSD168xDeviceBus *m_spiBus; // pointer to our SPI bus object
294 int m_pinReset; // the RES# pin. -1 if not connected
295 int m_pinBusy; // the BUSY pin
296
297 // Stash values for settings that are unique to each device.
298
299 bool m_isInitialized; // general init flag
300
301 // Handy helper
302 const uint8_t gfx_byte_bits[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
303};
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_ssd1680_rotated.h:100
bool waitWhileBusy(unsigned long pollInterval_ms=10, unsigned long timeout_ms=kSsd168xBusyTimeout_ms)
Wait until the SSD168x BUSY pin goes low.
Definition: spi_ssd1680_rotated.cpp:413
void drawLineVert(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr)
Definition: spi_ssd1680_rotated.cpp:546
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_ssd1680_rotated.cpp:640
SpiSsd1680Rotated()
Definition: spi_ssd1680_rotated.h:105
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_ssd1680_rotated.cpp:756
virtual bool init(void)
Initialize the device: reset it, send the initialization sequence, clear it and perform a full update...
Definition: spi_ssd1680_rotated.cpp:105
void setColor(uint8_t color)
void drawLineHorz(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr)
Definition: spi_ssd1680_rotated.cpp:505
bool isBusy(void)
Read the state of the BUSY pin.
Definition: spi_ssd1680_rotated.cpp:399
void drawRectFilled(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr)
Definition: spi_ssd1680_rotated.cpp:625
void erase(void)
Erase the graphics buffer. The erase is not sent to the device until the next display().
Definition: spi_ssd1680_rotated.cpp:440
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_ssd1680_rotated.cpp:276
bool reset(void)
Wake and reset the device: clear the graphics and screen buffers and perform a full update.
Definition: spi_ssd1680_rotated.cpp:172
void drawPixel(uint8_t x, uint8_t y, uint8_t clr)
Definition: spi_ssd1680_rotated.cpp:485
bool isInitialized(void)
Check if init() has been called successfully.
Definition: spi_ssd1680_rotated.h:145
SpiSsd1680Rotated(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height)
Definition: spi_ssd1680_rotated.h:112
void deepSleep(bool mode2)
Put the SSD168x into deep sleep. Only a hardware reset can wake it again (display() does this).
Definition: spi_ssd1680_rotated.cpp:386
grEpRasterOp_t rasterOp(void)
Get the current raster operation (draw mode).
Definition: spi_ssd1680_rotated.h:183
SpiSsd1680Rotated(uint8_t width, uint8_t height)
Definition: spi_ssd1680_rotated.h:109
void setRasterOp(grEpRasterOp_t rop)
Set the current raster operation (draw mode).
Definition: spi_ssd1680_rotated.h:173
void setBuffer(uint8_t *pBuffer)
Definition: spi_ssd1680_rotated.cpp:293
enum gr_ep_op_funcs_ grEpRasterOp_t
#define kSsd168xBusyTimeout_ms
Definition: spi_ssd1680_defs.h:110
#define kMaxPageNumberSSD1680
Definition: spi_ssd1680_defs.h:107
Definition: qwiic_grbuffer.h:147