MCUFRIEND_kbv library for MBED depends on ADA_GFX_kbv library
Dependents: TFT_Touch_botao_v1 TFT_Touch_exemplo5_git_touch TESTE_1 TFT_Touch_exemplo6_git_touch_button_3_ ... more
UTFTGLUE.h@3:47aa91940108, 2021-05-14 (annotated)
- Committer:
- davidprentice
- Date:
- Fri May 14 14:45:22 2021 +0000
- Revision:
- 3:47aa91940108
- Parent:
- 0:6f633078852b
conditional MBED and STM32CUBEIDE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
davidprentice | 0:6f633078852b | 1 | /* |
davidprentice | 0:6f633078852b | 2 | * utftglue.h @@@@@@@@@@@@@@@@@@@@@@@@ LIBRARY @@@@@@@@@@@@@@@@@@@@@@@@@ |
davidprentice | 0:6f633078852b | 3 | * |
davidprentice | 0:6f633078852b | 4 | * Created: 12/05/2019 14:25:06 |
davidprentice | 0:6f633078852b | 5 | * Author: David Prentice |
davidprentice | 0:6f633078852b | 6 | * |
davidprentice | 0:6f633078852b | 7 | * 1. replace "UTFT.h" with "UTFTGLUE.h" |
davidprentice | 0:6f633078852b | 8 | * 2. replace UTFT constructor with UTFTGLUE(model_ID, 0,0,0,0,0) |
davidprentice | 0:6f633078852b | 9 | * 3. remove smallFont, BigFont, SeveSegNumFont declarations |
davidprentice | 0:6f633078852b | 10 | * 4. UTFTGLUE uses FreeFonts or NULL (System 5x7) |
davidprentice | 0:6f633078852b | 11 | * |
davidprentice | 0:6f633078852b | 12 | * 5. knows FreeSmallFont, FreeBigFont and FreeSevenSegNumFont |
davidprentice | 0:6f633078852b | 13 | * 6. any other Fonts just need to #include "FreeOtherXXX.h" |
davidprentice | 0:6f633078852b | 14 | * 7. #define OtherXXX &FreeOtherXXX |
davidprentice | 0:6f633078852b | 15 | */ |
davidprentice | 0:6f633078852b | 16 | |
davidprentice | 0:6f633078852b | 17 | #warning @@@@@@@@@@@@@@@@@@@@@@@@@ <UTFTGLUE.h> @@@@@@@@@@@@@@@@@@@@@@@@@@ |
davidprentice | 0:6f633078852b | 18 | |
davidprentice | 0:6f633078852b | 19 | #ifndef UTFTGLUE_H_ |
davidprentice | 0:6f633078852b | 20 | #define UTFTGLUE_H_ |
davidprentice | 0:6f633078852b | 21 | |
davidprentice | 0:6f633078852b | 22 | #define LEFT 0 |
davidprentice | 0:6f633078852b | 23 | #define RIGHT 9999 |
davidprentice | 0:6f633078852b | 24 | #define CENTER 9998 |
davidprentice | 0:6f633078852b | 25 | |
davidprentice | 0:6f633078852b | 26 | #define PORTRAIT 0 |
davidprentice | 0:6f633078852b | 27 | #define LANDSCAPE 1 |
davidprentice | 0:6f633078852b | 28 | |
davidprentice | 0:6f633078852b | 29 | #include <MCUFRIEND_kbv.h> |
davidprentice | 0:6f633078852b | 30 | |
davidprentice | 0:6f633078852b | 31 | #include <Adafruit_GFX.h> |
davidprentice | 0:6f633078852b | 32 | #if defined(__arm__) && !defined(TEENSYDUINO) |
davidprentice | 0:6f633078852b | 33 | #include <avr/dtostrf.h> |
davidprentice | 0:6f633078852b | 34 | #endif |
davidprentice | 0:6f633078852b | 35 | |
davidprentice | 0:6f633078852b | 36 | #include <FreeDefaultFonts.h> |
davidprentice | 0:6f633078852b | 37 | #define SmallFont &FreeSmallFont |
davidprentice | 0:6f633078852b | 38 | #define BigFont &FreeBigFont |
davidprentice | 0:6f633078852b | 39 | #define SevenSegNumFont &FreeSevenSegNumFont |
davidprentice | 0:6f633078852b | 40 | |
davidprentice | 0:6f633078852b | 41 | class UTFTGLUE : public MCUFRIEND_kbv |
davidprentice | 0:6f633078852b | 42 | { |
davidprentice | 0:6f633078852b | 43 | public: |
davidprentice | 0:6f633078852b | 44 | // UTFTGLUE() : MCUFRIEND_kbv() {} |
davidprentice | 0:6f633078852b | 45 | UTFTGLUE(int model_ID, int RS, int WR,int CS, int RST, int RD = A0) |
davidprentice | 0:6f633078852b | 46 | : MCUFRIEND_kbv(CS, RS, WR, RD, RST) { _model_ID = model_ID; } |
davidprentice | 0:6f633078852b | 47 | void InitLCD(byte orientation=LANDSCAPE) { |
davidprentice | 0:6f633078852b | 48 | MCUFRIEND_kbv::reset(); |
davidprentice | 0:6f633078852b | 49 | uint16_t ID = MCUFRIEND_kbv::readID(); |
davidprentice | 0:6f633078852b | 50 | // if (ID == 0) ID = 0x9341; //DealExtreme with EXTC=0 |
davidprentice | 0:6f633078852b | 51 | // if (ID == 0x8989) ID = 0x1289; |
davidprentice | 0:6f633078852b | 52 | // if (ID == 0xD3D3) ID = 0x9481; //write-only controller |
davidprentice | 0:6f633078852b | 53 | // if (ID == 0xD3D3) ID = 0x9486; //write-only controller |
davidprentice | 0:6f633078852b | 54 | if (ID == 0xD3D3) ID = 0x9090; //write-only controller HX8357-D |
davidprentice | 0:6f633078852b | 55 | // if (ID == 0x9327 && orientation == LANDSCAPE) orientation = 3; |
davidprentice | 0:6f633078852b | 56 | MCUFRIEND_kbv::begin(ID); |
davidprentice | 0:6f633078852b | 57 | MCUFRIEND_kbv::setRotation(_orient = orientation); |
davidprentice | 0:6f633078852b | 58 | _radius = 4; |
davidprentice | 0:6f633078852b | 59 | } |
davidprentice | 0:6f633078852b | 60 | void clrScr() { MCUFRIEND_kbv::fillScreen(0x0000);} |
davidprentice | 0:6f633078852b | 61 | void drawPixel(int x, int y) { MCUFRIEND_kbv::drawPixel(x, y, _fcolor);} |
davidprentice | 0:6f633078852b | 62 | void drawLine(int x1, int y1, int x2, int y2) { MCUFRIEND_kbv::drawLine(x1, y1, x2, y2, _fcolor);} |
davidprentice | 0:6f633078852b | 63 | void fillScr(uint16_t color) { MCUFRIEND_kbv::fillScreen(color);} |
davidprentice | 0:6f633078852b | 64 | void fillScr(byte r, byte g, byte b) { MCUFRIEND_kbv::fillScreen(setrgb(r, g, b));} |
davidprentice | 0:6f633078852b | 65 | void drawRect(int x1, int y1, int x2, int y2) { |
davidprentice | 0:6f633078852b | 66 | int w = x2 - x1 + 1, h = y2 - y1 + 1; |
davidprentice | 0:6f633078852b | 67 | if (w < 0) { x1 = x2; w = -w; } |
davidprentice | 0:6f633078852b | 68 | if (h < 0) { y1 = y2; h = -h; } |
davidprentice | 0:6f633078852b | 69 | MCUFRIEND_kbv::drawRect(x1, y1, w, h, _fcolor); |
davidprentice | 0:6f633078852b | 70 | } |
davidprentice | 0:6f633078852b | 71 | void drawRoundRect(int x1, int y1, int x2, int y2) { |
davidprentice | 0:6f633078852b | 72 | int w = x2 - x1 + 1, h = y2 - y1 + 1; |
davidprentice | 0:6f633078852b | 73 | if (w < 0) { x1 = x2; w = -w; } |
davidprentice | 0:6f633078852b | 74 | if (h < 0) { y1 = y2; h = -h; } |
davidprentice | 0:6f633078852b | 75 | MCUFRIEND_kbv::drawRoundRect(x1, y1, w, h, _radius, _fcolor); |
davidprentice | 0:6f633078852b | 76 | } |
davidprentice | 0:6f633078852b | 77 | void fillRect(int x1, int y1, int x2, int y2) { |
davidprentice | 0:6f633078852b | 78 | int w = x2 - x1 + 1, h = y2 - y1 + 1; |
davidprentice | 0:6f633078852b | 79 | if (w < 0) { x1 = x2; w = -w; } |
davidprentice | 0:6f633078852b | 80 | if (h < 0) { y1 = y2; h = -h; } |
davidprentice | 0:6f633078852b | 81 | MCUFRIEND_kbv::fillRect(x1, y1, w, h, _fcolor); |
davidprentice | 0:6f633078852b | 82 | } |
davidprentice | 0:6f633078852b | 83 | void fillRoundRect(int x1, int y1, int x2, int y2) { |
davidprentice | 0:6f633078852b | 84 | int w = x2 - x1 + 1, h = y2 - y1 + 1; |
davidprentice | 0:6f633078852b | 85 | if (w < 0) { x1 = x2; w = -w; } |
davidprentice | 0:6f633078852b | 86 | if (h < 0) { y1 = y2; h = -h; } |
davidprentice | 0:6f633078852b | 87 | MCUFRIEND_kbv::fillRoundRect(x1, y1, w, h, _radius, _fcolor); |
davidprentice | 0:6f633078852b | 88 | } |
davidprentice | 0:6f633078852b | 89 | void drawCircle(int x, int y, int radius) { MCUFRIEND_kbv::drawCircle(x, y, radius, _fcolor);} |
davidprentice | 0:6f633078852b | 90 | void fillCircle(int x, int y, int radius) { MCUFRIEND_kbv::fillCircle(x, y, radius, _fcolor);} |
davidprentice | 0:6f633078852b | 91 | void setColor(byte r, byte g, byte b) { setColor(setrgb(r, g, b));} |
davidprentice | 0:6f633078852b | 92 | void setColor(uint16_t c) { MCUFRIEND_kbv::setTextColor(_fcolor = c, _bcolor); } |
davidprentice | 0:6f633078852b | 93 | void setBackColor(byte r, byte g, byte b) { setBackColor(setrgb(r, g, b)); } |
davidprentice | 0:6f633078852b | 94 | void setBackColor(uint32_t c) { |
davidprentice | 0:6f633078852b | 95 | if (c == 0xFFFFFFFF) _bcolor = _fcolor; |
davidprentice | 0:6f633078852b | 96 | else _bcolor = c; |
davidprentice | 0:6f633078852b | 97 | MCUFRIEND_kbv::setTextColor(_fcolor, _bcolor); |
davidprentice | 0:6f633078852b | 98 | } |
davidprentice | 0:6f633078852b | 99 | void print(const char *st, int x, int y, int deg=0) { |
davidprentice | 0:6f633078852b | 100 | settextcursor((char*)st, x, y); MCUFRIEND_kbv::print(st);} |
davidprentice | 0:6f633078852b | 101 | void print(char *st, int x, int y, int deg=0) { |
davidprentice | 0:6f633078852b | 102 | settextcursor(st, x, y); MCUFRIEND_kbv::print(st);} |
davidprentice | 0:6f633078852b | 103 | void print(String st, int x, int y, int deg=0) { |
davidprentice | 0:6f633078852b | 104 | settextcursor((char*)(st.c_str()), x, y); MCUFRIEND_kbv::print(st);} |
davidprentice | 0:6f633078852b | 105 | void printNumI(long num, int x, int y, int length=0, char filler=' ') { |
davidprentice | 0:6f633078852b | 106 | printNumF(num, 0, x, y, '.', length, filler); |
davidprentice | 0:6f633078852b | 107 | } |
davidprentice | 0:6f633078852b | 108 | void printNumF(double num, byte dec, int x, int y, char divider='.', int length=0, char filler=' ') { |
davidprentice | 0:6f633078852b | 109 | char buf[20]; |
davidprentice | 0:6f633078852b | 110 | dtostrf(num, length, dec, buf); |
davidprentice | 0:6f633078852b | 111 | for (int i = 0; buf[i] == ' '; i++) buf[i] = filler; |
davidprentice | 0:6f633078852b | 112 | settextcursor(buf, x, y, length * _dig_wid * MCUFRIEND_kbv::textsize_x); |
davidprentice | 0:6f633078852b | 113 | MCUFRIEND_kbv::print(buf); |
davidprentice | 0:6f633078852b | 114 | } |
davidprentice | 0:6f633078852b | 115 | void setTextSize(int sz) { MCUFRIEND_kbv::setTextSize(gfxFont == NULL ? sz : 1); } // ####### GFX ######## |
davidprentice | 0:6f633078852b | 116 | void setFont(const GFXfont* font) { |
davidprentice | 0:6f633078852b | 117 | MCUFRIEND_kbv::setFont(font); |
davidprentice | 0:6f633078852b | 118 | _ascend = 8; |
davidprentice | 0:6f633078852b | 119 | _descend = 1; |
davidprentice | 0:6f633078852b | 120 | _dig_wid = 6; |
davidprentice | 0:6f633078852b | 121 | if (font != NULL) { |
davidprentice | 0:6f633078852b | 122 | int16_t x = 0, y = 0, x1, y1 = 0, x2, y2 = 0; |
davidprentice | 0:6f633078852b | 123 | MCUFRIEND_kbv::setTextSize(1); |
davidprentice | 0:6f633078852b | 124 | charBounds('0', &x, &y, &x1, &y1, &x2, &y2); |
davidprentice | 0:6f633078852b | 125 | _ascend = y2 - y1; //yAdvance |
davidprentice | 0:6f633078852b | 126 | _dig_wid = x; //xAdvance |
davidprentice | 0:6f633078852b | 127 | } |
davidprentice | 0:6f633078852b | 128 | } |
davidprentice | 0:6f633078852b | 129 | void drawBitmap(int x, int y, int sx, int sy, const uint16_t *data, int scale=1) { |
davidprentice | 0:6f633078852b | 130 | uint16_t color; |
davidprentice | 0:6f633078852b | 131 | MCUFRIEND_kbv::setAddrWindow(x, y, x + sx*scale - 1, y + sy*scale - 1); |
davidprentice | 0:6f633078852b | 132 | if (scale == 1) MCUFRIEND_kbv::pushColors((const uint8_t*)data, sx * sy, 1); |
davidprentice | 0:6f633078852b | 133 | else { |
davidprentice | 0:6f633078852b | 134 | for (int row = 0; row < sy; row++) { |
davidprentice | 0:6f633078852b | 135 | for (int col = 0; col < sx; col++) { |
davidprentice | 0:6f633078852b | 136 | color = pgm_read_word(data + (row*sx + col)*1); |
davidprentice | 0:6f633078852b | 137 | MCUFRIEND_kbv::fillRect(x+col*scale, y+row*scale, scale, scale, color); |
davidprentice | 0:6f633078852b | 138 | } |
davidprentice | 0:6f633078852b | 139 | } |
davidprentice | 0:6f633078852b | 140 | } |
davidprentice | 0:6f633078852b | 141 | } |
davidprentice | 0:6f633078852b | 142 | // void drawBitmap(int x, int y, int sx, int sy, bitmapdatatype data, int deg, int rox, int roy); |
davidprentice | 0:6f633078852b | 143 | // void lcdOff(); |
davidprentice | 0:6f633078852b | 144 | // void lcdOn(); |
davidprentice | 0:6f633078852b | 145 | void setContrast(char c) {} |
davidprentice | 0:6f633078852b | 146 | int getDisplayXSize() { return MCUFRIEND_kbv::width(); } |
davidprentice | 0:6f633078852b | 147 | int getDisplayYSize() { return MCUFRIEND_kbv::height(); } |
davidprentice | 0:6f633078852b | 148 | void setBrightness(byte br) {} |
davidprentice | 0:6f633078852b | 149 | // void LCD_Write_DATA(char VH,char VL); |
davidprentice | 0:6f633078852b | 150 | // void dispBitmap(File inFile); |
davidprentice | 0:6f633078852b | 151 | uint8_t _ascend, _descend, _dig_wid; |
davidprentice | 0:6f633078852b | 152 | uint16_t _model_ID; |
davidprentice | 0:6f633078852b | 153 | |
davidprentice | 0:6f633078852b | 154 | protected: |
davidprentice | 0:6f633078852b | 155 | uint16_t _fcolor; |
davidprentice | 0:6f633078852b | 156 | uint16_t _bcolor; |
davidprentice | 0:6f633078852b | 157 | // uint8_t _ascend, _descend, _dig_wid; |
davidprentice | 0:6f633078852b | 158 | uint8_t _radius; |
davidprentice | 0:6f633078852b | 159 | uint8_t _orient; |
davidprentice | 0:6f633078852b | 160 | void settextcursor(char *st, int x, int y, int pad = 0) { |
davidprentice | 0:6f633078852b | 161 | int16_t pos, x1, y1; |
davidprentice | 0:6f633078852b | 162 | uint16_t len, w, h; |
davidprentice | 0:6f633078852b | 163 | bool is_gfx = (MCUFRIEND_kbv::gfxFont != NULL); |
davidprentice | 0:6f633078852b | 164 | getTextBounds(st, 0, 0, &x1, &y1, &w, &h); //always |
davidprentice | 0:6f633078852b | 165 | len = x1 + w + 0; // assumes the final right padding = 1. |
davidprentice | 0:6f633078852b | 166 | if (pad >= len) pad = pad - len; |
davidprentice | 0:6f633078852b | 167 | pos = (MCUFRIEND_kbv::width() - len - pad); |
davidprentice | 0:6f633078852b | 168 | if (x == CENTER) x = pos/2; |
davidprentice | 0:6f633078852b | 169 | else if (x == RIGHT) x = pos - 1; |
davidprentice | 0:6f633078852b | 170 | if (is_gfx) { //only GFX fonts need to paint background |
davidprentice | 0:6f633078852b | 171 | h = _ascend + _descend; //pgm_read_byte(&gfxFont->yAdvance); |
davidprentice | 0:6f633078852b | 172 | if (_fcolor != _bcolor) MCUFRIEND_kbv::fillRect(x, y, len + pad + 1, h, _bcolor); |
davidprentice | 0:6f633078852b | 173 | y += h; |
davidprentice | 0:6f633078852b | 174 | } |
davidprentice | 0:6f633078852b | 175 | MCUFRIEND_kbv::setCursor(x + pad, y); |
davidprentice | 0:6f633078852b | 176 | } |
davidprentice | 0:6f633078852b | 177 | uint16_t setrgb(byte r, byte g, byte b) { return ((r&0xF8) << 8) | ((g&0xFC) << 3) | (b>>3);} |
davidprentice | 0:6f633078852b | 178 | }; |
davidprentice | 0:6f633078852b | 179 | |
davidprentice | 0:6f633078852b | 180 | #define VGA_BLACK 0x0000 |
davidprentice | 0:6f633078852b | 181 | #define VGA_WHITE 0xFFFF |
davidprentice | 0:6f633078852b | 182 | #define VGA_RED 0xF800 |
davidprentice | 0:6f633078852b | 183 | #define VGA_GREEN 0x0400 |
davidprentice | 0:6f633078852b | 184 | #define VGA_BLUE 0x001F |
davidprentice | 0:6f633078852b | 185 | #define VGA_SILVER 0xC618 |
davidprentice | 0:6f633078852b | 186 | #define VGA_GRAY 0x8410 |
davidprentice | 0:6f633078852b | 187 | #define VGA_MAROON 0x8000 |
davidprentice | 0:6f633078852b | 188 | #define VGA_YELLOW 0xFFE0 |
davidprentice | 0:6f633078852b | 189 | #define VGA_OLIVE 0x8400 |
davidprentice | 0:6f633078852b | 190 | #define VGA_LIME 0x07E0 |
davidprentice | 0:6f633078852b | 191 | #define VGA_AQUA 0x07FF |
davidprentice | 0:6f633078852b | 192 | #define VGA_TEAL 0x0410 |
davidprentice | 0:6f633078852b | 193 | #define VGA_NAVY 0x0010 |
davidprentice | 0:6f633078852b | 194 | #define VGA_FUCHSIA 0xF81F |
davidprentice | 0:6f633078852b | 195 | #define VGA_PURPLE 0x8010 |
davidprentice | 0:6f633078852b | 196 | #define VGA_TRANSPARENT 0xFFFFFFFF |
davidprentice | 0:6f633078852b | 197 | |
davidprentice | 0:6f633078852b | 198 | #endif /* UTFTGLUE_H_ */ |