Adafruit OLED Libary

Dependents:   SSD1306_LCD-HelloWorld WizFi250-Geolocation_NTP Tweeting_Machine_HelloWorld_WIZwiki-W7500 display_irita ... more

Fork of Adafruit_GFX by Neal Horman

Committer:
kaizen
Date:
Tue Jun 23 09:49:01 2015 +0000
Revision:
18:3112550cc6a3
Parent:
13:8f03f908f22a
Fixed display function bug

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nkhorman9:ddb97c9850a2 1/***********************************
nkhorman9:ddb97c9850a2 2This is a our graphics core library, for all our displays.
nkhorman9:ddb97c9850a2 3We'll be adapting all the
nkhorman9:ddb97c9850a2 4existing libaries to use this core to make updating, support
nkhorman9:ddb97c9850a2 5and upgrading easier!
nkhorman9:ddb97c9850a2 6
nkhorman9:ddb97c9850a2 7Adafruit invests time and resources providing this open source code,
nkhorman9:ddb97c9850a2 8please support Adafruit and open-source hardware by purchasing
nkhorman9:ddb97c9850a2 9products from Adafruit!
nkhorman9:ddb97c9850a2 10
nkhorman9:ddb97c9850a2 11Written by Limor Fried/Ladyada for Adafruit Industries.
nkhorman9:ddb97c9850a2 12BSD license, check license.txt for more information
nkhorman9:ddb97c9850a2 13All text above must be included in any redistribution
nkhorman9:ddb97c9850a2 14****************************************/
nkhorman9:ddb97c9850a2 15
nkhorman9:ddb97c9850a2 16/*
nkhorman9:ddb97c9850a2 17 * Modified by Neal Horman 7/14/2012 for use in mbed
nkhorman9:ddb97c9850a2 18 */
nkhorman9:ddb97c9850a2 19
nkhorman9:ddb97c9850a2 20#ifndef _ADAFRUIT_GFX_H_
nkhorman9:ddb97c9850a2 21#define _ADAFRUIT_GFX_H_
nkhorman9:ddb97c9850a2 22
nkhorman13:8f03f908f22a 23#include "Adafruit_GFX_Config.h"
nkhorman9:ddb97c9850a2 24
nkhorman9:ddb97c9850a2 25static inline void swap(int16_t &a, int16_t &b)
nkhorman9:ddb97c9850a2 26{
nkhorman9:ddb97c9850a2 27 int16_t t = a;
nkhorman9:ddb97c9850a2 28
nkhorman9:ddb97c9850a2 29 a = b;
nkhorman9:ddb97c9850a2 30 b = t;
nkhorman9:ddb97c9850a2 31}
nkhorman9:ddb97c9850a2 32
nkhorman9:ddb97c9850a2 33#ifndef _BV
nkhorman9:ddb97c9850a2 34#define _BV(bit) (1<<(bit))
nkhorman9:ddb97c9850a2 35#endif
nkhorman9:ddb97c9850a2 36
nkhorman9:ddb97c9850a2 37#define BLACK 0
nkhorman9:ddb97c9850a2 38#define WHITE 1
nkhorman9:ddb97c9850a2 39
nkhorman11:86909e6db3c8 40/**
nkhorman11:86909e6db3c8 41 * This is a Text and Graphics element drawing class.
nkhorman11:86909e6db3c8 42 * These functions draw to the display buffer.
nkhorman11:86909e6db3c8 43 *
nkhorman11:86909e6db3c8 44 * Display drivers should be derived from here.
nkhorman11:86909e6db3c8 45 * The Display drivers push the display buffer to the
nkhorman11:86909e6db3c8 46 * hardware based on application control.
nkhorman11:86909e6db3c8 47 *
nkhorman11:86909e6db3c8 48 */
nkhorman9:ddb97c9850a2 49class Adafruit_GFX : public Stream
nkhorman9:ddb97c9850a2 50{
nkhorman9:ddb97c9850a2 51 public:
nkhorman9:ddb97c9850a2 52 Adafruit_GFX(int16_t w, int16_t h)
nkhorman9:ddb97c9850a2 53 : _rawWidth(w)
nkhorman9:ddb97c9850a2 54 , _rawHeight(h)
nkhorman9:ddb97c9850a2 55 , _width(w)
nkhorman9:ddb97c9850a2 56 , _height(h)
nkhorman9:ddb97c9850a2 57 , cursor_x(0)
nkhorman9:ddb97c9850a2 58 , cursor_y(0)
nkhorman9:ddb97c9850a2 59 , textcolor(WHITE)
nkhorman9:ddb97c9850a2 60 , textbgcolor(BLACK)
nkhorman9:ddb97c9850a2 61 , textsize(1)
nkhorman9:ddb97c9850a2 62 , rotation(0)
nkhorman9:ddb97c9850a2 63 , wrap(true)
nkhorman9:ddb97c9850a2 64 {};
nkhorman9:ddb97c9850a2 65
nkhorman11:86909e6db3c8 66 /// Paint one BLACK or WHITE pixel in the display buffer
nkhorman9:ddb97c9850a2 67 // this must be defined by the subclass
nkhorman9:ddb97c9850a2 68 virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
nkhorman9:ddb97c9850a2 69 // this is optional
nkhorman9:ddb97c9850a2 70 virtual void invertDisplay(bool i) {};
nkhorman9:ddb97c9850a2 71
nkhorman9:ddb97c9850a2 72 // Stream implementation - provides printf() interface
nkhorman9:ddb97c9850a2 73 // You would otherwise be forced to use writeChar()
nkhorman9:ddb97c9850a2 74 virtual int _putc(int value) { return writeChar(value); };
nkhorman9:ddb97c9850a2 75 virtual int _getc() { return -1; };
nkhorman9:ddb97c9850a2 76
nkhorman9:ddb97c9850a2 77#ifdef GFX_WANT_ABSTRACTS
nkhorman9:ddb97c9850a2 78 // these are 'generic' drawing functions, so we can share them!
nkhorman11:86909e6db3c8 79
nkhorman11:86909e6db3c8 80 /** Draw a Horizontal Line
nkhorman11:86909e6db3c8 81 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman11:86909e6db3c8 82 */
nkhorman9:ddb97c9850a2 83 virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
nkhorman11:86909e6db3c8 84 /** Draw a rectangle
nkhorman11:86909e6db3c8 85 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman11:86909e6db3c8 86 */
nkhorman9:ddb97c9850a2 87 virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
nkhorman11:86909e6db3c8 88 /** Fill the entire display
nkhorman11:86909e6db3c8 89 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman11:86909e6db3c8 90 */
nkhorman9:ddb97c9850a2 91 virtual void fillScreen(uint16_t color);
nkhorman9:ddb97c9850a2 92
nkhorman11:86909e6db3c8 93 /** Draw a circle
nkhorman11:86909e6db3c8 94 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman11:86909e6db3c8 95 */
nkhorman9:ddb97c9850a2 96 void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
nkhorman9:ddb97c9850a2 97 void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
nkhorman11:86909e6db3c8 98
nkhorman11:86909e6db3c8 99 /** Draw and fill a circle
nkhorman11:86909e6db3c8 100 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman11:86909e6db3c8 101 */
nkhorman9:ddb97c9850a2 102 void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
nkhorman9:ddb97c9850a2 103 void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
nkhorman9:ddb97c9850a2 104
nkhorman11:86909e6db3c8 105 /** Draw a triangle
nkhorman11:86909e6db3c8 106 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman11:86909e6db3c8 107 */
nkhorman9:ddb97c9850a2 108 void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
nkhorman11:86909e6db3c8 109 /** Draw and fill a triangle
nkhorman11:86909e6db3c8 110 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman11:86909e6db3c8 111 */
nkhorman9:ddb97c9850a2 112 void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
nkhorman11:86909e6db3c8 113
nkhorman11:86909e6db3c8 114 /** Draw a rounded rectangle
nkhorman11:86909e6db3c8 115 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman11:86909e6db3c8 116 */
nkhorman9:ddb97c9850a2 117 void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
nkhorman11:86909e6db3c8 118 /** Draw and fill a rounded rectangle
nkhorman11:86909e6db3c8 119 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman11:86909e6db3c8 120 */
nkhorman9:ddb97c9850a2 121 void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
nkhorman14:edb3c36aa1a7 122 /** Draw a bitmap
nkhorman14:edb3c36aa1a7 123 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
nkhorman14:edb3c36aa1a7 124 */
nkhorman14:edb3c36aa1a7 125 void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
nkhorman9:ddb97c9850a2 126#endif
nkhorman9:ddb97c9850a2 127
nkhorman9:ddb97c9850a2 128#if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
nkhorman11:86909e6db3c8 129 /** Draw a line
nkhorman11:86909e6db3c8 130 * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
nkhorman11:86909e6db3c8 131 */
nkhorman9:ddb97c9850a2 132 virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
nkhorman11:86909e6db3c8 133 /** Draw a vertical line
nkhorman11:86909e6db3c8 134 * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
nkhorman11:86909e6db3c8 135 */
nkhorman9:ddb97c9850a2 136 virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
nkhorman11:86909e6db3c8 137 /** Draw and fill a rectangle
nkhorman11:86909e6db3c8 138 * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
nkhorman11:86909e6db3c8 139 */
nkhorman9:ddb97c9850a2 140 virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
nkhorman9:ddb97c9850a2 141#endif
nkhorman9:ddb97c9850a2 142
nkhorman11:86909e6db3c8 143 /// Draw a text character at a specified pixel location
nkhorman9:ddb97c9850a2 144 void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
nkhorman11:86909e6db3c8 145 /// Draw a text character at the text cursor location
nkhorman9:ddb97c9850a2 146 size_t writeChar(uint8_t);
nkhorman9:ddb97c9850a2 147
nkhorman11:86909e6db3c8 148 /// Get the width of the display in pixels
nkhorman14:edb3c36aa1a7 149 inline int16_t width(void) { return _width; };
nkhorman11:86909e6db3c8 150 /// Get the height of the display in pixels
nkhorman14:edb3c36aa1a7 151 inline int16_t height(void) { return _height; };
nkhorman9:ddb97c9850a2 152
nkhorman11:86909e6db3c8 153 /// Set the text cursor location, based on the size of the text
nkhorman14:edb3c36aa1a7 154 inline void setTextCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; };
nkhorman14:edb3c36aa1a7 155#if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
nkhorman11:86909e6db3c8 156 /** Set the size of the text to be drawn
nkhorman11:86909e6db3c8 157 * @note Make sure to enable either GFX_SIZEABLE_TEXT or GFX_WANT_ABSTRACTS
nkhorman11:86909e6db3c8 158 */
nkhorman14:edb3c36aa1a7 159 inline void setTextSize(uint8_t s) { textsize = (s > 0) ? s : 1; };
nkhorman9:ddb97c9850a2 160#endif
nkhorman11:86909e6db3c8 161 /// Set the text foreground and background colors to be the same
nkhorman14:edb3c36aa1a7 162 inline void setTextColor(uint16_t c) { textcolor = c; textbgcolor = c; }
nkhorman11:86909e6db3c8 163 /// Set the text foreground and background colors independantly
nkhorman14:edb3c36aa1a7 164 inline void setTextColor(uint16_t c, uint16_t b) { textcolor = c; textbgcolor = b; };
nkhorman11:86909e6db3c8 165 /// Set text wraping mode true or false
nkhorman14:edb3c36aa1a7 166 inline void setTextWrap(bool w) { wrap = w; };
nkhorman9:ddb97c9850a2 167
nkhorman11:86909e6db3c8 168 /// Set the display rotation, 1, 2, 3, or 4
nkhorman9:ddb97c9850a2 169 void setRotation(uint8_t r);
nkhorman11:86909e6db3c8 170 /// Get the current rotation
nkhorman14:edb3c36aa1a7 171 inline uint8_t getRotation(void) { rotation %= 4; return rotation; };
nkhorman9:ddb97c9850a2 172
nkhorman9:ddb97c9850a2 173protected:
nkhorman9:ddb97c9850a2 174 int16_t _rawWidth, _rawHeight; // this is the 'raw' display w/h - never changes
nkhorman9:ddb97c9850a2 175 int16_t _width, _height; // dependent on rotation
nkhorman9:ddb97c9850a2 176 int16_t cursor_x, cursor_y;
nkhorman9:ddb97c9850a2 177 uint16_t textcolor, textbgcolor;
nkhorman9:ddb97c9850a2 178 uint8_t textsize;
nkhorman9:ddb97c9850a2 179 uint8_t rotation;
nkhorman9:ddb97c9850a2 180 bool wrap; // If set, 'wrap' text at right edge of display
nkhorman9:ddb97c9850a2 181};
nkhorman9:ddb97c9850a2 182
nkhorman9:ddb97c9850a2 183#endif