skydarc meneldoll
/
test_TFT_11_v5
test st7735 on lpc1768 with mbed v5. bug with spi frequency...
Diff: ST7735/GFX.h
- Revision:
- 2:2946f9eefcae
diff -r 121b61eeffe7 -r 2946f9eefcae ST7735/GFX.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST7735/GFX.h Wed Apr 08 15:00:13 2020 +0000 @@ -0,0 +1,160 @@ +/* +This is the core graphics library for all our displays, providing a common +set of graphics primitives (points, lines, circles, etc.). It needs to be +paired with a hardware-specific library for each display device we carry +(to handle the lower-level functions). + +Adafruit invests time and resources providing this open source code, please +support Adafruit & open-source hardware by purchasing products from Adafruit! + +Copyright (c) 2013 Adafruit Industries. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +/*Modified for MBED usage and tested with STM32F411RE on a Nucleo board. +Embedded Print methods from Arduino Print.Cpp/Print.h + +by James Kidd 2014 + * */ +#include <stdint.h> +#include <stdbool.h> +#include <stddef.h> +#include <string.h> +#include <stdlib.h> +#ifndef _GFX_H +#define _GFX_H + +#define DEC 10 + +#define swap(a, b) { int16_t t = a; a = b; b = t; } + +class GFX { + + public: + + GFX(int16_t w, int16_t h); // Constructor + + // This MUST be defined by the subclass: + virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; + + // These MAY be overridden by the subclass to provide device-specific + // optimized code. Otherwise 'generic' versions are used. + virtual void + drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color), + drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color), + drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color), + drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color), + fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color), + fillScreen(uint16_t color), + fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), + invertDisplay(bool i); + + // These exist only with GFX (no subclass overrides) + void + drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), + drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, + uint16_t color), + + fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, + int16_t delta, uint16_t color), + drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, + int16_t x2, int16_t y2, uint16_t color), + fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, + int16_t x2, int16_t y2, uint16_t color), + drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, + int16_t radius, uint16_t color), + fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, + int16_t radius, uint16_t color), + drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, + int16_t w, int16_t h, uint16_t color), + drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, + int16_t w, int16_t h, uint16_t color, uint16_t bg), + drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, + int16_t w, int16_t h, uint16_t color), + drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, + uint16_t bg, uint8_t size), + setCursor(int16_t x, int16_t y), + setTextColor(uint16_t c), + setTextColor(uint16_t c, uint16_t bg), + setTextSize(uint8_t s), + setTextWrap(bool w), //retour a la ligne + setRotation(uint8_t r); + + + int16_t height(void) const; + int16_t width(void) const; + + uint8_t getRotation(void) const; + + protected: + const int16_t + WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes + int16_t + _width, _height, // Display w/h as modified by current rotation + cursor_x, cursor_y; + uint16_t + textcolor, textbgcolor; + uint8_t + textsize, + rotation; + bool + wrap; // If set, 'wrap' text at right edge of display + + + //Print Methods + private: + uint8_t printNumber(unsigned long, uint8_t); + uint8_t printFloat(double, uint8_t); +public: + uint8_t write(uint8_t); + uint8_t write(const char *str) { + if (str == NULL) return 0; + return write((const uint8_t *)str, strlen(str)); + } + uint8_t write(const uint8_t *buffer, uint8_t size); + uint8_t write(const char *buffer, uint8_t size) { + return write((const uint8_t *)buffer, size); + } + + uint8_t print(const char[]); + uint8_t print(char); + uint8_t print(unsigned char, int = DEC); + uint8_t print(int, int = DEC); + uint8_t print(unsigned int, int = DEC); + uint8_t print(long, int = DEC); + uint8_t print(unsigned long, int = DEC); + uint8_t print(double, int = 2); + + uint8_t println(const char[]); + uint8_t println(char); + uint8_t println(unsigned char, int = DEC); + uint8_t println(int, int = DEC); + uint8_t println(unsigned int, int = DEC); + uint8_t println(long, int = DEC); + uint8_t println(unsigned long, int = DEC); + uint8_t println(double, int = 2); + + uint8_t println(void); +}; + +#endif // _GFX_H