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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Adafruit_GFX.h Source File

Adafruit_GFX.h

00001 /*
00002 This is the core graphics library for all our displays, providing a common
00003 set of graphics primitives (points, lines, circles, etc.).  It needs to be
00004 paired with a hardware-specific library for each display device we carry
00005 (to handle the lower-level functions).
00006 
00007 Adafruit invests time and resources providing this open source code, please
00008 support Adafruit & open-source hardware by purchasing products from Adafruit!
00009 
00010 Copyright (c) 2013 Adafruit Industries.  All rights reserved.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014 
00015 - Redistributions of source code must retain the above copyright notice,
00016   this list of conditions and the following disclaimer.
00017 - Redistributions in binary form must reproduce the above copyright notice,
00018   this list of conditions and the following disclaimer in the documentation
00019   and/or other materials provided with the distribution.
00020 
00021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00022 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00025 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00026 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00027 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00028 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00029 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00030 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 POSSIBILITY OF SUCH DAMAGE.
00032 */
00033 
00034 /*Modified for MBED usage and tested with STM32F411RE on a Nucleo board.
00035 Embedded Print methods from Arduino Print.Cpp/Print.h
00036 
00037 by James Kidd 2014
00038  * */
00039 #include <stdint.h>
00040 #include <stdbool.h>
00041 #include <stddef.h>
00042 #include <string.h>
00043 #include <stdlib.h>
00044 #ifndef _ADAFRUIT_GFX_H
00045 #define _ADAFRUIT_GFX_H
00046 
00047 #define DEC 10
00048 
00049 #define swap(a, b) { int16_t t = a; a = b; b = t; }
00050 
00051 class Adafruit_GFX  {
00052 
00053  public:
00054 
00055   Adafruit_GFX(int16_t w, int16_t h); // Constructor
00056 
00057   // This MUST be defined by the subclass:
00058   virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
00059 
00060   // These MAY be overridden by the subclass to provide device-specific
00061   // optimized code.  Otherwise 'generic' versions are used.
00062   virtual void
00063     drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
00064     drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
00065     drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
00066     drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
00067     fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
00068     fillScreen(uint16_t color),
00069     invertDisplay(bool i);
00070 
00071   // These exist only with Adafruit_GFX (no subclass overrides)
00072   void
00073     drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
00074     drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
00075       uint16_t color),
00076     fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
00077     fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
00078       int16_t delta, uint16_t color),
00079     drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
00080       int16_t x2, int16_t y2, uint16_t color),
00081     fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
00082       int16_t x2, int16_t y2, uint16_t color),
00083     drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
00084       int16_t radius, uint16_t color),
00085     fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
00086       int16_t radius, uint16_t color),
00087     drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
00088       int16_t w, int16_t h, uint16_t color),
00089     drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
00090       int16_t w, int16_t h, uint16_t color, uint16_t bg),
00091     drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, 
00092       int16_t w, int16_t h, uint16_t color),
00093     drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
00094       uint16_t bg, uint8_t size),
00095     setCursor(int16_t x, int16_t y),
00096     setTextColor(uint16_t c),
00097     setTextColor(uint16_t c, uint16_t bg),
00098     setTextSize(uint8_t s),
00099     setTextWrap(bool w),
00100     setRotation(uint8_t r);
00101 
00102 
00103   int16_t height(void) const;
00104   int16_t width(void) const;
00105 
00106   uint8_t getRotation(void) const;
00107 
00108  protected:
00109   const int16_t
00110     WIDTH, HEIGHT;   // This is the 'raw' display w/h - never changes
00111   int16_t
00112     _width, _height, // Display w/h as modified by current rotation
00113     cursor_x, cursor_y;
00114   uint16_t
00115     textcolor, textbgcolor;
00116   uint8_t
00117     textsize,
00118     rotation;
00119   bool
00120     wrap; // If set, 'wrap' text at right edge of display
00121 
00122 
00123   //Print Methods
00124  private:
00125   uint8_t printNumber(unsigned long, uint8_t);
00126   uint8_t printFloat(double, uint8_t);
00127 public:
00128   uint8_t write(uint8_t);
00129   uint8_t write(const char *str) {
00130         if (str == NULL) return 0;
00131         return write((const uint8_t *)str, strlen(str));
00132       }
00133   uint8_t write(const uint8_t *buffer, uint8_t size);
00134   uint8_t write(const char *buffer, uint8_t size) {
00135         return write((const uint8_t *)buffer, size);
00136       }
00137 
00138      uint8_t print(const char[]);
00139      uint8_t print(char);
00140      uint8_t print(unsigned char, int = DEC);
00141      uint8_t print(int, int = DEC);
00142      uint8_t print(unsigned int, int = DEC);
00143      uint8_t print(long, int = DEC);
00144      uint8_t print(unsigned long, int = DEC);
00145      uint8_t print(double, int = 2);
00146 
00147      uint8_t println(const char[]);
00148      uint8_t println(char);
00149      uint8_t println(unsigned char, int = DEC);
00150      uint8_t println(int, int = DEC);
00151      uint8_t println(unsigned int, int = DEC);
00152      uint8_t println(long, int = DEC);
00153      uint8_t println(unsigned long, int = DEC);
00154      uint8_t println(double, int = 2);
00155 
00156      uint8_t println(void);
00157 };
00158 
00159 #endif // _ADAFRUIT_GFX_H