yup

Committer:
peterswanson87
Date:
Tue Nov 18 18:48:49 2014 +0000
Revision:
0:c16f38158e0e
project is compiling with LIS3DH test

Who changed what in which revision?

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