Adafruit-GFX porting for mbed

Dependents:   RGB_matrix_Panel RGB_matrix_Panel_modif RGB_matrix_Panel Pmod_OLEDrgb_ALS1_K64F ... more

Committer:
marcpl
Date:
Tue Jun 23 16:47:37 2015 +0000
Revision:
4:ca74c390a0de
Parent:
3:3ffdf181555c
Implement the setRotation() method.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lelect 0:3e9c32359703 1 #ifndef _ADAFRUIT_GFX_H
lelect 0:3e9c32359703 2 #define _ADAFRUIT_GFX_H
lelect 3:3ffdf181555c 3
lelect 3:3ffdf181555c 4 #include "mbed.h"
lelect 3:3ffdf181555c 5 #include "glcdfont.h"
lelect 3:3ffdf181555c 6
lelect 0:3e9c32359703 7 #define BLACK 0
lelect 0:3e9c32359703 8 #define WHITE 1
lelect 0:3e9c32359703 9 #ifndef _BV
lelect 0:3e9c32359703 10 #define _BV(bit) (1<<(bit))
lelect 0:3e9c32359703 11 #endif
lelect 3:3ffdf181555c 12 #define swap(a, b) { int16_t t = a; a = b; b = t; }
lelect 0:3e9c32359703 13
lelect 3:3ffdf181555c 14 /** Adafruit_GFX class. This is the Adafruit_GFX class.\n drawPixel(int16_t x,int16_t y,uint16_t color) needing implementation in derived implementation class
lelect 1:c2715acb7466 15 */
lelect 0:3e9c32359703 16 class Adafruit_GFX : public Stream
lelect 0:3e9c32359703 17 {
lelect 0:3e9c32359703 18 public:
lelect 0:3e9c32359703 19 Adafruit_GFX(int16_t w, int16_t h)
lelect 2:66a3fe0dc83a 20 : _rawWidth(w),_rawHeight(h)
lelect 2:66a3fe0dc83a 21 ,_width(w),_height(h)
lelect 2:66a3fe0dc83a 22 ,cursor_x(0),cursor_y(0)
lelect 2:66a3fe0dc83a 23 ,textcolor(WHITE),textbgcolor(BLACK)
lelect 1:c2715acb7466 24 ,textsize(1)
lelect 1:c2715acb7466 25 ,rotation(0)
lelect 1:c2715acb7466 26 ,wrap(true)
lelect 2:66a3fe0dc83a 27 {};
lelect 0:3e9c32359703 28
lelect 3:3ffdf181555c 29 /** @fn void Adafruit_GFX::drawPixel(int16_t x, int16_t y, uint16_t color) = 0
lelect 2:66a3fe0dc83a 30 * @bref This MUST be defined by the subclass!
lelect 2:66a3fe0dc83a 31 * @param x x
lelect 2:66a3fe0dc83a 32 * @param y y
lelect 2:66a3fe0dc83a 33 * @param color 16bit color
lelect 2:66a3fe0dc83a 34 */
lelect 0:3e9c32359703 35 virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
lelect 3:3ffdf181555c 36 // These are overridden for the Stream subclass
lelect 0:3e9c32359703 37 virtual int _putc(int value) {
lelect 0:3e9c32359703 38 return writeChar(value);
lelect 0:3e9c32359703 39 };
lelect 0:3e9c32359703 40 virtual int _getc() {
lelect 0:3e9c32359703 41 return -1;
lelect 0:3e9c32359703 42 };
lelect 3:3ffdf181555c 43 /** @fn void Adafruit_GFX::invertDisplay(bool i)
lelect 2:66a3fe0dc83a 44 * @bref Do nothing, must be subclassed if supported
lelect 2:66a3fe0dc83a 45 * @param i invert
lelect 2:66a3fe0dc83a 46 */
lelect 0:3e9c32359703 47 virtual void invertDisplay(bool i);
lelect 0:3e9c32359703 48
lelect 2:66a3fe0dc83a 49 // These MAY be overridden by the subclass to provide device-specific
lelect 2:66a3fe0dc83a 50 // optimized code. Otherwise 'generic' versions are used.
lelect 0:3e9c32359703 51 virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
lelect 0:3e9c32359703 52 virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
lelect 0:3e9c32359703 53 virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
lelect 0:3e9c32359703 54 virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
lelect 0:3e9c32359703 55 virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
lelect 0:3e9c32359703 56 virtual void fillScreen(uint16_t color);
lelect 0:3e9c32359703 57
lelect 2:66a3fe0dc83a 58 //These exist only with Adafruit_GFX (no subclass overrides)
lelect 3:3ffdf181555c 59 /** @fn void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
lelect 2:66a3fe0dc83a 60 * @bref draw a circle outline from the coordinates of the center.
lelect 2:66a3fe0dc83a 61 * @param x0 x position
lelect 2:66a3fe0dc83a 62 * @param y0 y position
lelect 2:66a3fe0dc83a 63 * @param r Radius of the circle
lelect 2:66a3fe0dc83a 64 * @param color 16bit color
lelect 2:66a3fe0dc83a 65 */
lelect 0:3e9c32359703 66 void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
lelect 0:3e9c32359703 67 void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
lelect 3:3ffdf181555c 68 /** @fn void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
lelect 2:66a3fe0dc83a 69 * @bref draw a circle from the coordinates of the center.
lelect 2:66a3fe0dc83a 70 * @param x0 x position
lelect 2:66a3fe0dc83a 71 * @param y0 y position
lelect 2:66a3fe0dc83a 72 * @param r Radius of the circle
lelect 2:66a3fe0dc83a 73 * @param color 16bit color
lelect 2:66a3fe0dc83a 74 */
lelect 0:3e9c32359703 75 void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
lelect 0:3e9c32359703 76 void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
lelect 0:3e9c32359703 77
lelect 3:3ffdf181555c 78 /** @fn void Adafruit_GFX::drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
lelect 2:66a3fe0dc83a 79 * @bref draw a triangle outline from the vertex with color.
lelect 2:66a3fe0dc83a 80 * @param x0 first vertex x
lelect 2:66a3fe0dc83a 81 * @param y0 first vertex y
lelect 2:66a3fe0dc83a 82 * @param x1 second vertex x
lelect 2:66a3fe0dc83a 83 * @param y1 second vertex y
lelect 2:66a3fe0dc83a 84 * @param x2 third vertex x
lelect 2:66a3fe0dc83a 85 * @param y2 third vertex y
lelect 2:66a3fe0dc83a 86 * @param color 16bit color
lelect 2:66a3fe0dc83a 87 */
lelect 0:3e9c32359703 88 void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
lelect 3:3ffdf181555c 89 /** @fn void Adafruit_GFX::fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
lelect 2:66a3fe0dc83a 90 * @bref draw a triangle from the vertex with color.
lelect 2:66a3fe0dc83a 91 * @param x0 first vertex x
lelect 2:66a3fe0dc83a 92 * @param y0 first vertex y
lelect 2:66a3fe0dc83a 93 * @param x1 second vertex x
lelect 2:66a3fe0dc83a 94 * @param y1 second vertex y
lelect 2:66a3fe0dc83a 95 * @param x2 third vertex x
lelect 2:66a3fe0dc83a 96 * @param y2 third vertex y
lelect 2:66a3fe0dc83a 97 * @param color 16bit color
lelect 2:66a3fe0dc83a 98 */
lelect 0:3e9c32359703 99 void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
lelect 2:66a3fe0dc83a 100
lelect 3:3ffdf181555c 101 /** @fn void Adafruit_GFX::drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color)
lelect 2:66a3fe0dc83a 102 * @bref draw a round rectangle outline with color.
lelect 2:66a3fe0dc83a 103 * @param x0 first vertex x
lelect 2:66a3fe0dc83a 104 * @param y0 first vertex y
lelect 2:66a3fe0dc83a 105 * @param w width
lelect 2:66a3fe0dc83a 106 * @param h height
lelect 2:66a3fe0dc83a 107 * @param radius radius
lelect 2:66a3fe0dc83a 108 * @param color 16bit color
lelect 2:66a3fe0dc83a 109 */
lelect 0:3e9c32359703 110 void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
lelect 3:3ffdf181555c 111 /** @fn void Adafruit_GFX::drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color)
lelect 2:66a3fe0dc83a 112 * @bref draw a round rectangle with color.
lelect 2:66a3fe0dc83a 113 * @param x0 first vertex x
lelect 2:66a3fe0dc83a 114 * @param y0 first vertex y
lelect 2:66a3fe0dc83a 115 * @param w width
lelect 2:66a3fe0dc83a 116 * @param h height
lelect 2:66a3fe0dc83a 117 * @param radius radius
lelect 2:66a3fe0dc83a 118 * @param color 16bit color
lelect 2:66a3fe0dc83a 119 */
lelect 0:3e9c32359703 120 void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
lelect 0:3e9c32359703 121
lelect 0:3e9c32359703 122 void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
lelect 2:66a3fe0dc83a 123
lelect 0:3e9c32359703 124 void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
lelect 0:3e9c32359703 125
lelect 0:3e9c32359703 126 void setCursor(int16_t x, int16_t y) {
lelect 0:3e9c32359703 127 cursor_x = x;
lelect 0:3e9c32359703 128 cursor_y = y;
lelect 0:3e9c32359703 129 };
lelect 2:66a3fe0dc83a 130
lelect 0:3e9c32359703 131 void setTextSize(uint8_t s) {
lelect 0:3e9c32359703 132 textsize = (s > 0) ? s : 1;
lelect 0:3e9c32359703 133 };
lelect 2:66a3fe0dc83a 134
lelect 0:3e9c32359703 135 void setTextColor(uint16_t c) {
lelect 0:3e9c32359703 136 textcolor = c;
lelect 0:3e9c32359703 137 textbgcolor = c;
lelect 0:3e9c32359703 138 }
lelect 0:3e9c32359703 139 void setTextColor(uint16_t c, uint16_t b) {
lelect 0:3e9c32359703 140 textcolor = c;
lelect 0:3e9c32359703 141 textbgcolor = b;
lelect 0:3e9c32359703 142 };
lelect 0:3e9c32359703 143 void setTextWrap(bool w) {
lelect 0:3e9c32359703 144 wrap = w;
lelect 0:3e9c32359703 145 };
lelect 0:3e9c32359703 146
lelect 0:3e9c32359703 147 virtual size_t writeChar(uint8_t);
lelect 0:3e9c32359703 148
lelect 0:3e9c32359703 149 int16_t height(void) {
lelect 0:3e9c32359703 150 return _height;
lelect 0:3e9c32359703 151 };
lelect 2:66a3fe0dc83a 152
lelect 0:3e9c32359703 153 int16_t width(void) {
lelect 0:3e9c32359703 154 return _width;
lelect 0:3e9c32359703 155 };
marcpl 4:ca74c390a0de 156 void setRotation(uint8_t r) {
marcpl 4:ca74c390a0de 157 rotation = r;
marcpl 4:ca74c390a0de 158 }
lelect 0:3e9c32359703 159
lelect 0:3e9c32359703 160 uint8_t getRotation(void) {
lelect 0:3e9c32359703 161 rotation%=4;
lelect 0:3e9c32359703 162 return rotation;
lelect 0:3e9c32359703 163 };
lelect 0:3e9c32359703 164
lelect 0:3e9c32359703 165 protected:
lelect 0:3e9c32359703 166 int16_t _rawWidth, _rawHeight; // Display w/h as modified by current rotation
lelect 0:3e9c32359703 167 int16_t _width, _height; // Display w/h as modified by current rotation
lelect 0:3e9c32359703 168 int16_t cursor_x, cursor_y;
lelect 0:3e9c32359703 169 uint16_t textcolor, textbgcolor;
lelect 0:3e9c32359703 170 uint8_t textsize,rotation;
lelect 0:3e9c32359703 171 bool wrap; // If set, 'wrap' text at right edge of display
lelect 0:3e9c32359703 172 };
lelect 0:3e9c32359703 173
lelect 0:3e9c32359703 174 #endif // _ADAFRUIT_GFX_H