Leon Wehmeier / Mbed OS fiasco_max32630

Dependencies:   SoftSerial MAX14690 Buffer

Fork of rtos_threading_with_callback by mbed_example

Committer:
lwehmeier
Date:
Sun Feb 25 16:40:28 2018 +0000
Revision:
2:bf699e054b34
changed to modular design; rtos support; BMI160, BMP180, SSD1306, MPU6050, DHT11, SD support implemented; bit stuffing for link layer implemented; priority queue for data transmission; high-priority SPI link layer output thread

Who changed what in which revision?

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