0.95-inch RGB OLED Display library  0.5
Library for the 0.95-inch RGB OLED Display library (Parallax Part #28087)
oledc_.h
Go to the documentation of this file.
1 /*
2  * @file oledc_.h
3  *
4  * @author Matthew Matz
5  *
6  * @version 0.9
7  *
8  * @copyright Copyright (C) Parallax, Inc. 2016. See end of file for
9  * terms of use (MIT License).
10  *
11  * @brief 0.96-inch RGB OLED driver source header file.
12  *
13  * @detail Please submit bug reports, suggestions, and improvements to
14  * this code to editor@parallax.com.
15  */
16 
17 #ifndef OLEDC_H // Prevents duplicate
18 #define OLEDC_H // declarations
19 
20 #if defined(__cplusplus) // If compiling for C++
21 extern "C" { // Compile for C
22 #endif
23 
24 
25 #include <propeller.h>
26 
27 #define WHITE 0xFFFF
28 #define PINK 0xFD59
29 #define MAGENTA 0xF319
30 #define RED 0xC082
31 #define DARKRED 0xA162
32 #define REDORANGE 0xD261
33 #define LIGHTORANGE 0xFEB6
34 #define ORANGE 0xFC00
35 #define YELLOWORANGE 0xFCC0
36 #define GOLD 0xF704
37 #define YELLOW 0xF744
38 #define LEMON 0xF7D3
39 #define YELLOWGREEN 0x5600
40 #define GREEN 0x1C62
41 #define DARKGREEN 0x03CE
42 #define GREENBLUE 0x0C75
43 #define CYAN 0x5E97
44 #define LIGHTBLUE 0x857B
45 #define SKYBLUE 0x0E3E
46 #define BLUE 0x2B16
47 #define NAVYBLUE 0x0007
48 #define VIOLET 0x7A37
49 #define PURPLE 0x7A37
50 #define RASPBERRY 0xA82E
51 #define TAN 0xCC2A
52 #define LIGHTBROWN 0xBB44
53 #define BRONZE 0xA440
54 #define BROWN 0x9201
55 #define DARKBROWN 0x7269
56 #define LIGHTGRAY 0xBDD7
57 #define GRAY 0x8410
58 #define DARKGRAY 0x3186
59 #define BLACK 0x0000
60 
61 
62 #define SMALL 1
63 #define MEDIUM 2
64 #define LARGE 3
65 
66 
67 
85 void oledc_init(char CS, char RS, char SID, char SCLK, char RST, char screen_rotation);
86 
96 unsigned int oledc_color565(char r, char g, char b);
97 
98 //
99 // @name Individual setup calls
100 // @{
101 //
102 
103 //
104 // @}
105 //
106 // @name Drawing Functions
107 // @{
108 
118 void oledc_drawPixel(int x, int y, unsigned int color);
119 
133 void oledc_drawLine(int x0, int y0, int x1, int y1, unsigned int color);
134 
146 void oledc_drawFastVLine(int x, int y, int h, unsigned int color);
147 
159 void oledc_drawFastHLine(int x, int y, int w, unsigned int color);
160 
172 void oledc_drawCircle(int x0, int y0, int r, unsigned int color);
173 
185 void oledc_fillCircle(int x0, int y0, int r, unsigned int color);
186 
200 void oledc_drawRect(int x, int y, int w, int h, unsigned int color);
201 
215 void oledc_fillRect(int x, int y, int w, int h, unsigned int color);
216 
232 void oledc_drawRoundRect(int x, int y, int w, int h, int r, unsigned int color);
233 
249 void oledc_fillRoundRect(int x, int y, int w, int h, int r, unsigned int color);
250 
268 void oledc_drawTriangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color);
269 
287 void oledc_fillTriangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color);
288 
301 void oledc_bitmap(char *imgdir, int x0, int y0);
302 
303 // @}
304 // @Name Text Functions
305 // @{
306 
313 void oledc_setTextSize(char s);
314 
324 void oledc_setTextColor(unsigned int c, unsigned int b);
325 
329 void oledc_setTextWrap(char w);
330 
343 void oledc_setCursor(int x, int y, char size);
344 
348 int oledc_print(const char *fmt, ...);
349 
353 int oledc_getCursorX();
354 
358 int oledc_getCursorY();
359 
360 // @}
361 // @Name Screen Manipulation Functions
362 // @{
363 
375 void oledc_clear(int x0, int y0, int w, int h);
376 
392 void oledc_copy(int x0, int y0, int w, int h, int x2, int y2);
393 
399 char oledc_getRotation();
400 
404 void oledc_setRotation(char x);
405 
409 int oledc_getWidth();
410 
414 int oledc_getHeight();
415 
419 void oledc_invertDisplay();
420 
434 void oledc_scrollStart(char h, char v);
435 
439 void oledc_scrollStop();
440 
444 int oledc_isScrolling();
445 
446 // @}
447 
448 
449 
450 #ifndef DOXYGEN_SHOULD_SKIP_THIS
451 
452 /* =========================================================================== */
453 // PRIVATE FUNCTIONS/MACROS
454 /* =========================================================================== */
455 
461 #define gfx_swap(a, b) { unsigned int t = a; a = b; b = t; }
462 #define absv(x) ((x)<0 ? -(x) : (x))
463 
464 // Timing Delays
465 #define SSD1331_DELAYS_HWFILL 25
466 #define SSD1331_DELAYS_HWLINE 10
467 #define SSD1331_DELAYS_HWPIXEL 10
468 
469 // SSD1331 Commands
470 #define SSD1331_CMD_DRAWLINE 0x21
471 #define SSD1331_CMD_DRAWRECT 0x22
472 #define SSD1331_CMD_COPY 0x23
473 #define SSD1331_CMD_CLEAR 0x25
474 #define SSD1331_CMD_FILL 0x26
475 #define SSD1331_CMD_SCROLLSETUP 0x27
476 #define SSD1331_CMD_SCROLLSTOP 0x2E
477 #define SSD1331_CMD_SCROLLSTART 0x2F
478 #define SSD1331_CMD_SETCOLUMN 0x15
479 #define SSD1331_CMD_SETROW 0x75
480 #define SSD1331_CMD_CONTRASTA 0x81
481 #define SSD1331_CMD_CONTRASTB 0x82
482 #define SSD1331_CMD_CONTRASTC 0x83
483 #define SSD1331_CMD_MASTERCURRENT 0x87
484 #define SSD1331_CMD_SETREMAP 0xA0
485 #define SSD1331_CMD_STARTLINE 0xA1
486 #define SSD1331_CMD_DISPLAYOFFSET 0xA2
487 #define SSD1331_CMD_NORMALDISPLAY 0xA4
488 #define SSD1331_CMD_DISPLAYALLON 0xA5
489 #define SSD1331_CMD_DISPLAYALLOFF 0xA6
490 #define SSD1331_CMD_INVERTDISPLAY 0xA7
491 #define SSD1331_CMD_SETMULTIPLEX 0xA8
492 #define SSD1331_CMD_SETMASTER 0xAD
493 #define SSD1331_CMD_DISPLAYOFF 0xAE
494 #define SSD1331_CMD_DISPLAYON 0xAF
495 #define SSD1331_CMD_POWERMODE 0xB0
496 #define SSD1331_CMD_PRECHARGE 0xB1
497 #define SSD1331_CMD_CLOCKDIV 0xB3
498 #define SSD1331_CMD_PRECHARGEA 0x8A
499 #define SSD1331_CMD_PRECHARGEB 0x8B
500 #define SSD1331_CMD_PRECHARGEC 0x8C
501 #define SSD1331_CMD_PRECHARGELEVEL 0xBB
502 #define SSD1331_CMD_VCOMH 0xBE
503 
504 #define TFTWIDTH 96
505 #define TFTHEIGHT 64
506 
507 extern char font_lg_index[95];
508 extern char font_lg_zeroMap[658];
509 extern char oled_font_lg[3100];
510 extern char oled_font_med[2090];
511 
515 void oledc_spiWrite(char c);
516 
520 void oledc_writeData(char d);
521 
525 void oledc_writeCommand(char c);
526 
530 void oledc_write(char c);
531 
546 void oledc_drawCharSmall(int x, int y, unsigned char c, unsigned int color, unsigned int bg);
547 
562 void oledc_drawCharMedium(int x, int y, unsigned char c, unsigned int color, unsigned int bg);
563 
578 void oledc_drawCharLarge(int x, int y, unsigned char c, unsigned int color, unsigned int bg);
579 
585 void oledc_goTo(int x, int y);
586 
590 void oledc_drawCircleHelper( int x0, int y0, int r, char cornername, unsigned int color);
591 
595 void oledc_fillCircleHelper(int x0, int y0, int r, char cornername, int delta, unsigned int color);
596 
597 
602 #endif // DOXYGEN_SHOULD_SKIP_THIS
603 
604 
605 #if defined(__cplusplus)
606 } // End compile for C block
607 #endif
608 /* __cplusplus */
609 
610 #endif // End prevent duplicate forward
611 /* OLEDC_H */ // declarations block
612 
613 
614 
615 // Parts of this file are from the Adafruit GFX arduino library
616 
617 /***************************************************
618  This is a library for the 0.96" 16-bit Color OLED with SSD1331 driver chip
619  Pick one up today in the adafruit shop!
620  ------> http://www.adafruit.com/products/684
621  These displays use SPI to communicate, 4 or 5 pins are required to
622  interface
623  Adafruit invests time and resources providing this open source code,
624  please support Adafruit and open-source hardware by purchasing
625  products from Adafruit!
626  Written by Limor Fried/Ladyada for Adafruit Industries.
627  BSD license, all text above must be included in any redistribution
628  ****************************************************/
void oledc_setCursor(int x, int y, char size)
Sets the cursor position based on the size parameter.
Definition: oledc_setCursor.c:22
void oledc_drawCharSmall(int x, int y, unsigned char c, unsigned int color, unsigned int bg)
Low-level driver for printing single characters to the screen in the small (5x7) font.
Definition: oledc_drawCharSmall.c:118
char font_lg_index[95]
Definition: oledc_drawCharLarge.c:20
void oledc_scrollStart(char h, char v)
Starts scrolling the entire image on the screen horizontally, vertically, or both.
Definition: oledc_scrollStart.c:24
int oledc_getHeight()
Returns the height of the screen per the screen&#39;s current orientation.
Definition: oledc_getScreenInfo.c:32
void oledc_setTextWrap(char w)
Toggles automatic wrapping of text printed to the screen. (0) turns wrapping off, (1) turning wrappin...
Definition: oledc_setText.c:46
void oledc_clear(int x0, int y0, int w, int h)
Clears (sets to black) a rectangular area of the screen.
Definition: oledc_clear.c:22
void oledc_fillCircle(int x0, int y0, int r, unsigned int color)
Draws a filled circle on the screen in the specified color.
Definition: oledc_fillCircle.c:20
char oled_font_lg[3100]
Definition: oledc_drawCharLarge.c:21
void oledc_writeData(char d)
Sets up the screen to recieve pixel data.
Definition: oledc_spiWrite.c:55
void oledc_spiWrite(char c)
Low-level driver for sending a byte to the OLED screen.
void oledc_init(char CS, char RS, char SID, char SCLK, char RST, char screen_rotation)
Initializes the OLED screen by setting up it&#39;s SPI and control pins.
Definition: oledc_init.c:34
void oledc_fillCircleHelper(int x0, int y0, int r, char cornername, int delta, unsigned int color)
Helper function used to draw filled circles and rectangles with rounded corners.
Definition: oledc_fillCircleHelper.c:21
int oledc_print(const char *fmt,...)
Print format "..." args to the screen. The output is limited to 128 bytes.
Definition: oledc_print.c:21
void oledc_bitmap(char *imgdir, int x0, int y0)
Displays a properly formatted bitmap (.BMP) image on the screen. The image must be saved as a Device ...
Definition: oledc_bitmap.c:26
void oledc_drawCharMedium(int x, int y, unsigned char c, unsigned int color, unsigned int bg)
Low-level driver for printing single characters to the screen in the medium (11x15) font...
Definition: oledc_drawCharMedium.c:22
char font_lg_zeroMap[658]
Definition: oledc_drawCharLarge.c:19
void oledc_goTo(int x, int y)
Low-level function for setting the pixel to be changed.
Definition: oledc_goTo.c:20
void oledc_fillRect(int x, int y, int w, int h, unsigned int color)
Draws a filled rectangle on the screen in the specified color.
Definition: oledc_fillRect.c:23
int oledc_isScrolling()
Returns (1) if the screen is currently scrolling and (0) if it is not.
Definition: oledc_getScreenInfo.c:36
void oledc_drawFastHLine(int x, int y, int w, unsigned int color)
Draws a horizontal line on the screen in the specified color.
Definition: oledc_drawFastLines.c:26
void oledc_drawCircle(int x0, int y0, int r, unsigned int color)
Draws a circle on the screen in the specified color.
Definition: oledc_drawCircle.c:21
void oledc_scrollStop()
Stops scrolling the screen.
Definition: oledc_scrollStop.c:22
int oledc_getWidth()
Returns the width of the screen per the screen&#39;s current orientation.
Definition: oledc_getScreenInfo.c:28
void oledc_setTextColor(unsigned int c, unsigned int b)
Sets the color of the font and the color of the background (highlighting) to be used. Setting the text color and text background to the same color will make the background color transparent.
Definition: oledc_setText.c:41
void oledc_drawTriangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color)
Draws a triangle with on the screen in the specified color.
Definition: oledc_drawTriangle.c:21
void oledc_write(char c)
Prints single ASCII-encoded characters to the screen. Characters 32 (space) to 126 (~) are rendered...
Definition: oledc_write.c:25
void oledc_setTextSize(char s)
Sets the size of the font to be used. Range is from 1 to 3. Size (1) is 5x7 (6x8 spacing) pixels...
Definition: oledc_setText.c:24
void oledc_invertDisplay()
Inverts the screen.
Definition: oledc_invertDisplay.c:22
int oledc_getCursorX()
Returns the current horizontal position of the cursor, measured from the left side of the screen in p...
Definition: oledc_getCursor.c:22
void oledc_drawLine(int x0, int y0, int x1, int y1, unsigned int color)
Draws a line on the screen in the specified color.
Definition: oledc_drawLine.c:24
void oledc_drawPixel(int x, int y, unsigned int color)
Draws a single pixel on the screen in the specified color.
Definition: oledc_drawPixel.c:23
void oledc_writeCommand(char c)
Sets up the screen to recieve commands.
Definition: oledc_spiWrite.c:50
void oledc_drawCharLarge(int x, int y, unsigned char c, unsigned int color, unsigned int bg)
Low-level driver for printing single characters to the screen in the large (17x23) font...
Definition: oledc_drawCharLarge.c:27
void oledc_setRotation(char x)
Low-level function used by the begin function to set up the screen&#39;s orientation. ...
Definition: oledc_setRotation.c:24
void oledc_copy(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: oledc_copy.c:21
void oledc_fillRoundRect(int x, int y, int w, int h, int r, unsigned int color)
Draws a filled rectangle with rounded corners on the screen in the specified color.
Definition: oledc_fillRoundRect.c:21
int oledc_getCursorY()
Returns the current vertical position of the cursor, measured from the top of the screen in pixels...
Definition: oledc_getCursor.c:26
void oledc_drawRect(int x, int y, int w, int h, unsigned int color)
Draws a rectangle on the screen in the specified color.
Definition: oledc_drawRect.c:23
char oled_font_med[2090]
void oledc_fillTriangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color)
Draws a filled triangle with on the screen in the specified color.
Definition: oledc_fillTriangle.c:21
void oledc_drawRoundRect(int x, int y, int w, int h, int r, unsigned int color)
Draws a rectangle with rounded corners on the screen in the specified color.
Definition: oledc_drawRoundRect.c:21
void oledc_drawCircleHelper(int x0, int y0, int r, char cornername, unsigned int color)
Helper function used to draw circles and rectangles with rounded corners.
Definition: oledc_drawCircleHelper.c:20
unsigned int oledc_color565(char r, char g, char b)
Generates a 2-byte (16-bit) color code (RRRRRGGGGGGBBBBB format) for use with the OLED screen...
Definition: oledc_color565.c:19
void oledc_drawFastVLine(int x, int y, int h, unsigned int color)
Draws a vertical line on the screen in the specified color.
Definition: oledc_drawFastLines.c:20
char oledc_getRotation()
Returns the screen&#39;s orientation. (0) means the pins are pointed upwards, (1) means the pins are poin...
Definition: oledc_getScreenInfo.c:24