Port of the Adafruit_GFX library for use in MBED. This is the core graphics library for all Adafruit's displays, providing a common set of graphics primitives (points, lines, circles, strings,bitmaps. etc). Complete details found @ https://github.com/adafruit/Adafruit-GFX-Library Required by Adafruit_PCD8544 Driver. BSD license.

Dependents:   ili9341_test ece495_firmware Adafruit-64x32-PWM-Demo Pong_ILI9163C

Committer:
infotech1
Date:
Sun Nov 02 07:08:28 2014 +0000
Revision:
1:2c772b09cce5
Parent:
0:50ff23c02d57
Initial commit ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
infotech1 0:50ff23c02d57 1 /*
infotech1 0:50ff23c02d57 2 This is the core graphics library for all our displays, providing a common
infotech1 0:50ff23c02d57 3 set of graphics primitives (points, lines, circles, etc.). It needs to be
infotech1 0:50ff23c02d57 4 paired with a hardware-specific library for each display device we carry
infotech1 0:50ff23c02d57 5 (to handle the lower-level functions).
infotech1 0:50ff23c02d57 6
infotech1 0:50ff23c02d57 7 Adafruit invests time and resources providing this open source code, please
infotech1 0:50ff23c02d57 8 support Adafruit & open-source hardware by purchasing products from Adafruit!
infotech1 0:50ff23c02d57 9
infotech1 0:50ff23c02d57 10 Copyright (c) 2013 Adafruit Industries. All rights reserved.
infotech1 0:50ff23c02d57 11
infotech1 0:50ff23c02d57 12 Redistribution and use in source and binary forms, with or without
infotech1 0:50ff23c02d57 13 modification, are permitted provided that the following conditions are met:
infotech1 0:50ff23c02d57 14
infotech1 0:50ff23c02d57 15 - Redistributions of source code must retain the above copyright notice,
infotech1 0:50ff23c02d57 16 this list of conditions and the following disclaimer.
infotech1 0:50ff23c02d57 17 - Redistributions in binary form must reproduce the above copyright notice,
infotech1 0:50ff23c02d57 18 this list of conditions and the following disclaimer in the documentation
infotech1 0:50ff23c02d57 19 and/or other materials provided with the distribution.
infotech1 0:50ff23c02d57 20
infotech1 0:50ff23c02d57 21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
infotech1 0:50ff23c02d57 22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
infotech1 0:50ff23c02d57 23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
infotech1 0:50ff23c02d57 24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
infotech1 0:50ff23c02d57 25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
infotech1 0:50ff23c02d57 26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
infotech1 0:50ff23c02d57 27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
infotech1 0:50ff23c02d57 28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
infotech1 0:50ff23c02d57 29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
infotech1 0:50ff23c02d57 30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
infotech1 0:50ff23c02d57 31 POSSIBILITY OF SUCH DAMAGE.
infotech1 0:50ff23c02d57 32 */
infotech1 0:50ff23c02d57 33
infotech1 0:50ff23c02d57 34 /*Modified for MBED usage and tested with STM32F411RE on a Nucleo board.
infotech1 0:50ff23c02d57 35 Embedded Print methods from Arduino Print.Cpp/Print.h
infotech1 0:50ff23c02d57 36
infotech1 0:50ff23c02d57 37 by James Kidd 2014
infotech1 0:50ff23c02d57 38 * */
infotech1 0:50ff23c02d57 39 #include <stdint.h>
infotech1 0:50ff23c02d57 40 #include <stdbool.h>
infotech1 0:50ff23c02d57 41 #include <stddef.h>
infotech1 0:50ff23c02d57 42 #include <string.h>
infotech1 0:50ff23c02d57 43 #include <stdlib.h>
infotech1 0:50ff23c02d57 44 #ifndef _ADAFRUIT_GFX_H
infotech1 0:50ff23c02d57 45 #define _ADAFRUIT_GFX_H
infotech1 0:50ff23c02d57 46
infotech1 0:50ff23c02d57 47 #define DEC 10
infotech1 0:50ff23c02d57 48
infotech1 0:50ff23c02d57 49 #define swap(a, b) { int16_t t = a; a = b; b = t; }
infotech1 0:50ff23c02d57 50
infotech1 0:50ff23c02d57 51 class Adafruit_GFX {
infotech1 0:50ff23c02d57 52
infotech1 0:50ff23c02d57 53 public:
infotech1 0:50ff23c02d57 54
infotech1 0:50ff23c02d57 55 Adafruit_GFX(int16_t w, int16_t h); // Constructor
infotech1 0:50ff23c02d57 56
infotech1 0:50ff23c02d57 57 // This MUST be defined by the subclass:
infotech1 0:50ff23c02d57 58 virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
infotech1 0:50ff23c02d57 59
infotech1 0:50ff23c02d57 60 // These MAY be overridden by the subclass to provide device-specific
infotech1 0:50ff23c02d57 61 // optimized code. Otherwise 'generic' versions are used.
infotech1 0:50ff23c02d57 62 virtual void
infotech1 0:50ff23c02d57 63 drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
infotech1 0:50ff23c02d57 64 drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
infotech1 0:50ff23c02d57 65 drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
infotech1 0:50ff23c02d57 66 drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
infotech1 0:50ff23c02d57 67 fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
infotech1 0:50ff23c02d57 68 fillScreen(uint16_t color),
infotech1 0:50ff23c02d57 69 invertDisplay(bool i);
infotech1 0:50ff23c02d57 70
infotech1 0:50ff23c02d57 71 // These exist only with Adafruit_GFX (no subclass overrides)
infotech1 0:50ff23c02d57 72 void
infotech1 0:50ff23c02d57 73 drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
infotech1 0:50ff23c02d57 74 drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
infotech1 0:50ff23c02d57 75 uint16_t color),
infotech1 0:50ff23c02d57 76 fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
infotech1 0:50ff23c02d57 77 fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
infotech1 0:50ff23c02d57 78 int16_t delta, uint16_t color),
infotech1 0:50ff23c02d57 79 drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
infotech1 0:50ff23c02d57 80 int16_t x2, int16_t y2, uint16_t color),
infotech1 0:50ff23c02d57 81 fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
infotech1 0:50ff23c02d57 82 int16_t x2, int16_t y2, uint16_t color),
infotech1 0:50ff23c02d57 83 drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
infotech1 0:50ff23c02d57 84 int16_t radius, uint16_t color),
infotech1 0:50ff23c02d57 85 fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
infotech1 0:50ff23c02d57 86 int16_t radius, uint16_t color),
infotech1 0:50ff23c02d57 87 drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
infotech1 0:50ff23c02d57 88 int16_t w, int16_t h, uint16_t color),
infotech1 0:50ff23c02d57 89 drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
infotech1 0:50ff23c02d57 90 int16_t w, int16_t h, uint16_t color, uint16_t bg),
infotech1 0:50ff23c02d57 91 drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
infotech1 0:50ff23c02d57 92 int16_t w, int16_t h, uint16_t color),
infotech1 0:50ff23c02d57 93 drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
infotech1 0:50ff23c02d57 94 uint16_t bg, uint8_t size),
infotech1 0:50ff23c02d57 95 setCursor(int16_t x, int16_t y),
infotech1 0:50ff23c02d57 96 setTextColor(uint16_t c),
infotech1 0:50ff23c02d57 97 setTextColor(uint16_t c, uint16_t bg),
infotech1 0:50ff23c02d57 98 setTextSize(uint8_t s),
infotech1 0:50ff23c02d57 99 setTextWrap(bool w),
infotech1 0:50ff23c02d57 100 setRotation(uint8_t r);
infotech1 0:50ff23c02d57 101
infotech1 0:50ff23c02d57 102
infotech1 0:50ff23c02d57 103 int16_t height(void) const;
infotech1 0:50ff23c02d57 104 int16_t width(void) const;
infotech1 0:50ff23c02d57 105
infotech1 0:50ff23c02d57 106 uint8_t getRotation(void) const;
infotech1 0:50ff23c02d57 107
infotech1 0:50ff23c02d57 108 protected:
infotech1 0:50ff23c02d57 109 const int16_t
infotech1 0:50ff23c02d57 110 WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes
infotech1 0:50ff23c02d57 111 int16_t
infotech1 0:50ff23c02d57 112 _width, _height, // Display w/h as modified by current rotation
infotech1 0:50ff23c02d57 113 cursor_x, cursor_y;
infotech1 0:50ff23c02d57 114 uint16_t
infotech1 0:50ff23c02d57 115 textcolor, textbgcolor;
infotech1 0:50ff23c02d57 116 uint8_t
infotech1 0:50ff23c02d57 117 textsize,
infotech1 0:50ff23c02d57 118 rotation;
infotech1 0:50ff23c02d57 119 bool
infotech1 0:50ff23c02d57 120 wrap; // If set, 'wrap' text at right edge of display
infotech1 0:50ff23c02d57 121
infotech1 0:50ff23c02d57 122
infotech1 0:50ff23c02d57 123 //Print Methods
infotech1 0:50ff23c02d57 124 private:
infotech1 0:50ff23c02d57 125 uint8_t printNumber(unsigned long, uint8_t);
infotech1 0:50ff23c02d57 126 uint8_t printFloat(double, uint8_t);
infotech1 0:50ff23c02d57 127 public:
infotech1 0:50ff23c02d57 128 uint8_t write(uint8_t);
infotech1 0:50ff23c02d57 129 uint8_t write(const char *str) {
infotech1 0:50ff23c02d57 130 if (str == NULL) return 0;
infotech1 0:50ff23c02d57 131 return write((const uint8_t *)str, strlen(str));
infotech1 0:50ff23c02d57 132 }
infotech1 0:50ff23c02d57 133 uint8_t write(const uint8_t *buffer, uint8_t size);
infotech1 0:50ff23c02d57 134 uint8_t write(const char *buffer, uint8_t size) {
infotech1 0:50ff23c02d57 135 return write((const uint8_t *)buffer, size);
infotech1 0:50ff23c02d57 136 }
infotech1 0:50ff23c02d57 137
infotech1 0:50ff23c02d57 138 uint8_t print(const char[]);
infotech1 0:50ff23c02d57 139 uint8_t print(char);
infotech1 0:50ff23c02d57 140 uint8_t print(unsigned char, int = DEC);
infotech1 0:50ff23c02d57 141 uint8_t print(int, int = DEC);
infotech1 0:50ff23c02d57 142 uint8_t print(unsigned int, int = DEC);
infotech1 0:50ff23c02d57 143 uint8_t print(long, int = DEC);
infotech1 0:50ff23c02d57 144 uint8_t print(unsigned long, int = DEC);
infotech1 0:50ff23c02d57 145 uint8_t print(double, int = 2);
infotech1 0:50ff23c02d57 146
infotech1 0:50ff23c02d57 147 uint8_t println(const char[]);
infotech1 0:50ff23c02d57 148 uint8_t println(char);
infotech1 0:50ff23c02d57 149 uint8_t println(unsigned char, int = DEC);
infotech1 0:50ff23c02d57 150 uint8_t println(int, int = DEC);
infotech1 0:50ff23c02d57 151 uint8_t println(unsigned int, int = DEC);
infotech1 0:50ff23c02d57 152 uint8_t println(long, int = DEC);
infotech1 0:50ff23c02d57 153 uint8_t println(unsigned long, int = DEC);
infotech1 0:50ff23c02d57 154 uint8_t println(double, int = 2);
infotech1 0:50ff23c02d57 155
infotech1 0:50ff23c02d57 156 uint8_t println(void);
infotech1 0:50ff23c02d57 157 };
infotech1 0:50ff23c02d57 158
infotech1 0:50ff23c02d57 159 #endif // _ADAFRUIT_GFX_H