Color OLED module library  v0.5
Library for the WaveShare 0.96-inch color OLED (SSD1331) module
ssd1331.h
Go to the documentation of this file.
1 /*
2  * @file libssd1331.c
3  *
4  * @author Matthew Matz
5  *
6  * @version 0.5
7  *
8  * @copyright Copyright (C) Parallax, Inc. 2018. See end of file for
9  * terms of use (MIT License).
10  *
11  * @brief Waveshare ePaper driver source, see wsc.h for documentation.
12  *
13  * @detail Please submit bug reports, suggestions, and improvements to
14  * this code to editor@parallax.com.
15  */
16 
17 
18 
19 #include "simplegfx.h"
20 #include "simpletools.h"
21 
22 
23 #ifndef WHITE
24  #define WHITE 0xFFFF
25 #endif
26 
27 #ifndef PINK
28  #define PINK 0xFD59
29 #endif
30 
31 #ifndef MAGENTA
32  #define MAGENTA 0xC9D4
33 #endif
34 
35 #ifndef RED
36  #define RED 0xC082
37 #endif
38 
39 #ifndef DARKRED
40  #define DARKRED 0xA000
41 #endif
42 
43 #ifndef REDORANGE
44  #define REDORANGE 0xD261
45 #endif
46 
47 #ifndef LIGHTORANGE
48  #define LIGHTORANGE 0xDDB2
49 #endif
50 
51 #ifndef ORANGE
52  #define ORANGE 0xFC00
53 #endif
54 
55 #ifndef YELLOWORANGE
56  #define YELLOWORANGE 0xFCE0
57 #endif
58 
59 #ifndef GOLD
60  #define GOLD 0xF704
61 #endif
62 
63 #ifndef YELLOW
64  #define YELLOW 0xF744
65 #endif
66 
67 #ifndef LEMON
68  #define LEMON 0xD6CF
69 #endif
70 
71 #ifndef YELLOWGREEN
72  #define YELLOWGREEN 0x5600
73 #endif
74 
75 #ifndef GREEN
76  #define GREEN 0x1C62
77 #endif
78 
79 #ifndef DARKGREEN
80  #define DARKGREEN 0x02C0
81 #endif
82 
83 #ifndef GREENBLUE
84  #define GREENBLUE 0x0C75
85 #endif
86 
87 #ifndef CYAN
88  #define CYAN 0x5E97
89 #endif
90 
91 #ifndef LIGHTBLUE
92  #define LIGHTBLUE 0x857B
93 #endif
94 
95 #ifndef SKYBLUE
96  #define SKYBLUE 0x0E3E
97 #endif
98 
99 #ifndef BLUE
100  #define BLUE 0x2B16
101 #endif
102 
103 #ifndef NAVYBLUE
104  #define NAVYBLUE 0x0009
105 #endif
106 
107 #ifndef VIOLET
108  #define VIOLET 0x7817
109 #endif
110 
111 #ifndef PURPLE
112  #define PURPLE 0xA017
113 #endif
114 
115 #ifndef RASPBERRY
116  #define RASPBERRY 0x902A
117 #endif
118 
119 #ifndef TAN
120  #define TAN 0xCC2A
121 #endif
122 
123 #ifndef LIGHTBROWN
124  #define LIGHTBROWN 0xBB44
125 #endif
126 
127 #ifndef BRONZE
128  #define BRONZE 0xA440
129 #endif
130 
131 #ifndef BROWN
132  #define BROWN 0x9201
133 #endif
134 
135 #ifndef DARKBROWN
136  #define DARKBROWN 0x51E7
137 #endif
138 
139 #ifndef LIGHTGRAY
140  #define LIGHTGRAY 0xBDD7
141 #endif
142 
143 #ifndef GRAY
144  #define GRAY 0x8410
145 #endif
146 
147 #ifndef DARKGRAY
148  #define DARKGRAY 0x3186
149 #endif
150 
151 #ifndef BLACK
152  #define BLACK 0x0000
153 #endif
154 
155 
156 
157 
158 // SSD1331 Commands
159 #ifndef SSD1331_CMD_DRAWLINE
160  #define SSD1331_CMD_DRAWLINE 0x21
161 #endif
162 
163 #ifndef SSD1331_CMD_DRAWRECT
164  #define SSD1331_CMD_DRAWRECT 0x22
165 #endif
166 
167 #ifndef SSD1331_CMD_COPY
168  #define SSD1331_CMD_COPY 0x23
169 #endif
170 
171 #ifndef SSD1331_CMD_CLEAR
172  #define SSD1331_CMD_CLEAR 0x25
173 #endif
174 
175 #ifndef SSD1331_CMD_FILL
176  #define SSD1331_CMD_FILL 0x26
177 #endif
178 
179 #ifndef SSD1331_CMD_SCROLLSETUP
180  #define SSD1331_CMD_SCROLLSETUP 0x27
181 #endif
182 
183 #ifndef SSD1331_CMD_SCROLLSTOP
184  #define SSD1331_CMD_SCROLLSTOP 0x2E
185 #endif
186 
187 #ifndef SSD1331_CMD_SCROLLSTART
188  #define SSD1331_CMD_SCROLLSTART 0x2F
189 #endif
190 
191 #ifndef SSD1331_CMD_SETCOLUMN
192  #define SSD1331_CMD_SETCOLUMN 0x15
193 #endif
194 
195 #ifndef SSD1331_CMD_SETROW
196  #define SSD1331_CMD_SETROW 0x75
197 #endif
198 
199 #ifndef SSD1331_CMD_CONTRASTA
200  #define SSD1331_CMD_CONTRASTA 0x81
201 #endif
202 
203 #ifndef SSD1331_CMD_CONTRASTB
204  #define SSD1331_CMD_CONTRASTB 0x82
205 #endif
206 
207 #ifndef SSD1331_CMD_CONTRASTC
208  #define SSD1331_CMD_CONTRASTC 0x83
209 #endif
210 
211 #ifndef SSD1331_CMD_MASTERCURRENT
212  #define SSD1331_CMD_MASTERCURRENT 0x87
213 #endif
214 
215 #ifndef SSD1331_CMD_SETREMAP
216  #define SSD1331_CMD_SETREMAP 0xA0
217 #endif
218 
219 #ifndef SSD1331_CMD_STARTLINE
220  #define SSD1331_CMD_STARTLINE 0xA1
221 #endif
222 
223 #ifndef SSD1331_CMD_DISPLAYOFFSET
224  #define SSD1331_CMD_DISPLAYOFFSET 0xA2
225 #endif
226 
227 #ifndef SSD1331_CMD_NORMALDISPLAY
228  #define SSD1331_CMD_NORMALDISPLAY 0xA4
229 #endif
230 
231 #ifndef SSD1331_CMD_DISPLAYALLON
232  #define SSD1331_CMD_DISPLAYALLON 0xA5
233 #endif
234 
235 #ifndef SSD1331_CMD_DISPLAYALLOFF
236  #define SSD1331_CMD_DISPLAYALLOFF 0xA6
237 #endif
238 
239 #ifndef SSD1331_CMD_INVERTDISPLAY
240  #define SSD1331_CMD_INVERTDISPLAY 0xA7
241 #endif
242 
243 #ifndef SSD1331_CMD_SETMULTIPLEX
244  #define SSD1331_CMD_SETMULTIPLEX 0xA8
245 #endif
246 
247 #ifndef SSD1331_CMD_SETMASTER
248  #define SSD1331_CMD_SETMASTER 0xAD
249 #endif
250 
251 #ifndef SSD1331_CMD_DISPLAYOFF
252  #define SSD1331_CMD_DISPLAYOFF 0xAE
253 #endif
254 
255 #ifndef SSD1331_CMD_DISPLAYON
256  #define SSD1331_CMD_DISPLAYON 0xAF
257 #endif
258 
259 #ifndef SSD1331_CMD_POWERMODE
260  #define SSD1331_CMD_POWERMODE 0xB0
261 #endif
262 
263 #ifndef SSD1331_CMD_PRECHARGE
264  #define SSD1331_CMD_PRECHARGE 0xB1
265 #endif
266 
267 #ifndef SSD1331_CMD_CLOCKDIV
268  #define SSD1331_CMD_CLOCKDIV 0xB3
269 #endif
270 
271 #ifndef SSD1331_CMD_PRECHARGEA
272  #define SSD1331_CMD_PRECHARGEA 0x8A
273 #endif
274 
275 #ifndef SSD1331_CMD_PRECHARGEB
276  #define SSD1331_CMD_PRECHARGEB 0x8B
277 #endif
278 
279 #ifndef SSD1331_CMD_PRECHARGEC
280  #define SSD1331_CMD_PRECHARGEC 0x8C
281 #endif
282 
283 #ifndef SSD1331_CMD_PRECHARGELEVEL
284  #define SSD1331_CMD_PRECHARGELEVEL 0xBB
285 #endif
286 
287 #ifndef SSD1331_CMD_VCOMH
288  #define SSD1331_CMD_VCOMH 0xBE
289 #endif
290 
291 
292 
293 
294 
295 
296 
297 
298 
299 screen_t* ssd1331_init(char sdi, char sclk, char cs, char rs, char rst, int _width, int _height);
300 
312 void ssd1331_drawPixel(screen_t* dev, int x, int y, int color);
313 
329 void ssd1331_drawLine(screen_t* dev, int x0, int y0, int x1, int y1, int color);
330 
344 void ssd1331_drawFastVLine(screen_t* dev, int x, int y, int w, int color);
345 
359 void ssd1331_drawFastHLine(screen_t* dev, int x, int y, int h, int color);
360 
376 void ssd1331_fillRect(screen_t* dev, int x0, int y0, int x1, int y1, int color);
377 
383 void ssd1331_clearDisplay(screen_t* dev);
384 
390 void ssd1331_resetDisplay(screen_t* dev);
391 
407 void ssd1331_writeByte(int mask_cs, int mask_sdi, int mask_clk, int mask_dc, char c, char dc);
408 
412 char ssd1331_writeLock();
413 
419 void ssd1331_writeLockSet(char devId);
420 
426 void ssd1331_writeLockClear(char devId);
427 
445 void ssd1331_copy(screen_t* dev, int x0, int y0, int w, int h, int x2, int y2);
446 
463 void ssd1331_scrollDisplay(screen_t* dev, int h, int v);
464 
473 void ssd1331_invertDisplay(screen_t *dev, char i);
474 
482 void ssd1331_sleepWakeDisplay(screen_t *dev, char i);
void ssd1331_drawFastVLine(screen_t *dev, int x, int y, int w, int color)
Draws a vertical line on the screen in the specified color. No bounds checking (used by other functio...
Definition: ssd1331_drawLine.c:46
void ssd1331_sleepWakeDisplay(screen_t *dev, char i)
Sleeps or Wakes the display.
Definition: ssd1331_sleepWake.c:6
void ssd1331_clearDisplay(screen_t *dev)
Clears the screen by setting the full area of the display to black.
Definition: ssd1331_fillRect.c:53
void ssd1331_invertDisplay(screen_t *dev, char i)
Inverts the screen.
Definition: ssd1331_invertDisplay.c:7
void ssd1331_copy(screen_t *dev, int x0, int y0, int w, int h, int x2, int y2)
Creates a copy a rectangular area of the screen at another position on the screen.
Definition: ssd1331_copy.c:5
char ssd1331_writeLock()
Returns the status of the SPI communication lockout so multiple cogs don't try to write to it at the ...
Definition: ssd1331_spiWrite.c:44
void ssd1331_fillRect(screen_t *dev, int x0, int y0, int x1, int y1, int color)
Draws a filled rectangle on the screen in the specified color.
Definition: ssd1331_fillRect.c:21
void ssd1331_writeByte(int mask_cs, int mask_sdi, int mask_clk, int mask_dc, char c, char dc)
Low level function that transfers bytes to the screen.
void ssd1331_drawPixel(screen_t *dev, int x, int y, int color)
Draws a single pixel on the screen in the specified color. No checking.
Definition: ssd1331_drawPixel.c:21
void ssd1331_scrollDisplay(screen_t *dev, int h, int v)
Starts scrolling the entire image on the screen horizontally, vertically, or both.
Definition: ssd1331_scroll.c:6
void ssd1331_drawFastHLine(screen_t *dev, int x, int y, int h, int color)
Draws a horizontal line on the screen in the specified color. No bounds checking (used by other funct...
Definition: ssd1331_drawLine.c:50
void ssd1331_drawLine(screen_t *dev, int x0, int y0, int x1, int y1, int color)
Draws a line on the screen in the specified color.
Definition: ssd1331_drawLine.c:21
void ssd1331_writeLockSet(char devId)
Sets the SPI communication lockout.
Definition: ssd1331_spiWrite.c:48
screen_t * ssd1331_init(char sdi, char sclk, char cs, char rs, char rst, int _width, int _height)
Definition: ssd1331_init.c:23
void ssd1331_writeLockClear(char devId)
Clears the SPI communication lockout.
Definition: ssd1331_spiWrite.c:53
void ssd1331_resetDisplay(screen_t *dev)
Resets the display.
Definition: ssd1331_init.c:136