A derived version of the BSD licensed Adafrut GFX library for the SSD1306 controller for an OLED 128x32 or 128x64 display using SPI or I2C.

Fork of Adafruit_GFX by Neal Horman

Committer:
nkhorman
Date:
Tue Jul 17 05:54:22 2012 +0000
Revision:
1:9db12505727a
Parent:
0:c3dcd4c4983a
Child:
2:7bcea45e60d8
change the default background color to black

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nkhorman 0:c3dcd4c4983a 1 /***********************************
nkhorman 0:c3dcd4c4983a 2 This is a our graphics core library, for all our displays.
nkhorman 0:c3dcd4c4983a 3 We'll be adapting all the
nkhorman 0:c3dcd4c4983a 4 existing libaries to use this core to make updating, support
nkhorman 0:c3dcd4c4983a 5 and upgrading easier!
nkhorman 0:c3dcd4c4983a 6
nkhorman 0:c3dcd4c4983a 7 Adafruit invests time and resources providing this open source code,
nkhorman 0:c3dcd4c4983a 8 please support Adafruit and open-source hardware by purchasing
nkhorman 0:c3dcd4c4983a 9 products from Adafruit!
nkhorman 0:c3dcd4c4983a 10
nkhorman 0:c3dcd4c4983a 11 Written by Limor Fried/Ladyada for Adafruit Industries.
nkhorman 0:c3dcd4c4983a 12 BSD license, check license.txt for more information
nkhorman 0:c3dcd4c4983a 13 All text above must be included in any redistribution
nkhorman 0:c3dcd4c4983a 14 ****************************************/
nkhorman 0:c3dcd4c4983a 15
nkhorman 0:c3dcd4c4983a 16 /*
nkhorman 0:c3dcd4c4983a 17 * Modified by Neal Horman 7/14/2012 for use in LPC1768
nkhorman 0:c3dcd4c4983a 18 */
nkhorman 0:c3dcd4c4983a 19
nkhorman 0:c3dcd4c4983a 20 #ifndef _ADAFRUIT_GFX_H_
nkhorman 0:c3dcd4c4983a 21 #define _ADAFRUIT_GFX_H_
nkhorman 0:c3dcd4c4983a 22
nkhorman 0:c3dcd4c4983a 23 #ifndef swap
nkhorman 0:c3dcd4c4983a 24 #define swap(a, b) { int16_t t = a; a = b; b = t; }
nkhorman 0:c3dcd4c4983a 25 #endif
nkhorman 0:c3dcd4c4983a 26
nkhorman 0:c3dcd4c4983a 27 #ifndef _BV
nkhorman 0:c3dcd4c4983a 28 #define _BV(bit) (1<<(bit))
nkhorman 0:c3dcd4c4983a 29 #endif
nkhorman 0:c3dcd4c4983a 30
nkhorman 0:c3dcd4c4983a 31 #define BLACK 0
nkhorman 0:c3dcd4c4983a 32 #define WHITE 1
nkhorman 0:c3dcd4c4983a 33
nkhorman 0:c3dcd4c4983a 34 class Adafruit_GFX : public Stream
nkhorman 0:c3dcd4c4983a 35 {
nkhorman 0:c3dcd4c4983a 36 public:
nkhorman 0:c3dcd4c4983a 37 Adafruit_GFX(int16_t w, int16_t h)
nkhorman 0:c3dcd4c4983a 38 : _rawWidth(w)
nkhorman 0:c3dcd4c4983a 39 , _rawHeight(h)
nkhorman 0:c3dcd4c4983a 40 , _width(w)
nkhorman 0:c3dcd4c4983a 41 , _height(h)
nkhorman 0:c3dcd4c4983a 42 , cursor_x(0)
nkhorman 0:c3dcd4c4983a 43 , cursor_y(0)
nkhorman 0:c3dcd4c4983a 44 , textcolor(WHITE)
nkhorman 1:9db12505727a 45 , textbgcolor(BLACK)
nkhorman 0:c3dcd4c4983a 46 , textsize(1)
nkhorman 0:c3dcd4c4983a 47 , rotation(0)
nkhorman 0:c3dcd4c4983a 48 , wrap(true)
nkhorman 0:c3dcd4c4983a 49 {};
nkhorman 0:c3dcd4c4983a 50
nkhorman 0:c3dcd4c4983a 51 // this must be defined by the subclass
nkhorman 0:c3dcd4c4983a 52 virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
nkhorman 0:c3dcd4c4983a 53 // this is optional
nkhorman 0:c3dcd4c4983a 54 virtual void invertDisplay(bool i) {};
nkhorman 0:c3dcd4c4983a 55
nkhorman 0:c3dcd4c4983a 56 // Stream implementation - provides printf() interface
nkhorman 0:c3dcd4c4983a 57 // You would otherwise be forced to use writeChar()
nkhorman 0:c3dcd4c4983a 58 virtual int _putc(int value) { return writeChar(value); };
nkhorman 0:c3dcd4c4983a 59 virtual int _getc() { return -1; };
nkhorman 0:c3dcd4c4983a 60
nkhorman 0:c3dcd4c4983a 61 #ifdef WANT_ABSTRACTS
nkhorman 0:c3dcd4c4983a 62 // these are 'generic' drawing functions, so we can share them!
nkhorman 0:c3dcd4c4983a 63 virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
nkhorman 0:c3dcd4c4983a 64 virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
nkhorman 0:c3dcd4c4983a 65 virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
nkhorman 0:c3dcd4c4983a 66 virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
nkhorman 0:c3dcd4c4983a 67 virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
nkhorman 0:c3dcd4c4983a 68 virtual void fillScreen(uint16_t color);
nkhorman 0:c3dcd4c4983a 69
nkhorman 0:c3dcd4c4983a 70 void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
nkhorman 0:c3dcd4c4983a 71 void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
nkhorman 0:c3dcd4c4983a 72 void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
nkhorman 0:c3dcd4c4983a 73 void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
nkhorman 0:c3dcd4c4983a 74
nkhorman 0:c3dcd4c4983a 75 void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
nkhorman 0:c3dcd4c4983a 76 void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
nkhorman 0:c3dcd4c4983a 77 void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
nkhorman 0:c3dcd4c4983a 78 void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
nkhorman 0:c3dcd4c4983a 79 #endif
nkhorman 0:c3dcd4c4983a 80
nkhorman 0:c3dcd4c4983a 81 void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
nkhorman 0:c3dcd4c4983a 82 void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
nkhorman 0:c3dcd4c4983a 83 size_t writeChar(uint8_t);
nkhorman 0:c3dcd4c4983a 84
nkhorman 0:c3dcd4c4983a 85 int16_t width(void) { return _width; };
nkhorman 0:c3dcd4c4983a 86 int16_t height(void) { return _height; };
nkhorman 0:c3dcd4c4983a 87
nkhorman 0:c3dcd4c4983a 88 void setCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; };
nkhorman 0:c3dcd4c4983a 89 void setTextSize(uint8_t s) { textsize = (s > 0) ? s : 1; };
nkhorman 0:c3dcd4c4983a 90 void setTextColor(uint16_t c) { textcolor = c; textbgcolor = c; }
nkhorman 0:c3dcd4c4983a 91 void setTextColor(uint16_t c, uint16_t b) { textcolor = c; textbgcolor = b; };
nkhorman 0:c3dcd4c4983a 92 void setTextWrap(bool w) { wrap = w; };
nkhorman 0:c3dcd4c4983a 93
nkhorman 0:c3dcd4c4983a 94 void setRotation(uint8_t r);
nkhorman 0:c3dcd4c4983a 95 uint8_t getRotation(void) { rotation %= 4; return rotation; };
nkhorman 0:c3dcd4c4983a 96
nkhorman 0:c3dcd4c4983a 97 protected:
nkhorman 0:c3dcd4c4983a 98 int16_t _rawWidth, _rawHeight; // this is the 'raw' display w/h - never changes
nkhorman 0:c3dcd4c4983a 99 int16_t _width, _height; // dependent on rotation
nkhorman 0:c3dcd4c4983a 100 int16_t cursor_x, cursor_y;
nkhorman 0:c3dcd4c4983a 101 uint16_t textcolor, textbgcolor;
nkhorman 0:c3dcd4c4983a 102 uint8_t textsize;
nkhorman 0:c3dcd4c4983a 103 uint8_t rotation;
nkhorman 0:c3dcd4c4983a 104 bool wrap; // If set, 'wrap' text at right edge of display
nkhorman 0:c3dcd4c4983a 105 };
nkhorman 0:c3dcd4c4983a 106
nkhorman 0:c3dcd4c4983a 107 #endif