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