vit petrik / Mbed 2 deprecated OLEDMag

Dependencies:   mbed

Committer:
vitpetrik
Date:
Thu Apr 21 13:19:41 2022 +0000
Revision:
4:3618abce1646
Share for Stepan Oslejsek

Who changed what in which revision?

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