test st7735 on lpc1768 with mbed v5. bug with spi frequency...

Committer:
skydarc
Date:
Wed Apr 08 15:00:13 2020 +0000
Revision:
2:2946f9eefcae
v2

Who changed what in which revision?

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