SEPS114A Driver

SEPS114A SPI Driver

class SPIPreInit : public SPI { public: SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) { format(8,3); frequency(12000000); }; };

SPIPreInit gSpi(PB_15,NC,PB_13); PinName mosi(sda), PinName miso, PinName clk(scl) Adafruit_SEPS114A_Spi oled(gSpi,PB_14,PB_1,PB_2); PinName DC, PinName RST, PinName CS

You can print russian cyrilic

Committer:
Dzhafarkhanov
Date:
Tue May 10 06:19:10 2016 +0000
Revision:
1:a37035f55af3
Parent:
0:f7b7f71865d1
add rotation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Dzhafarkhanov 0:f7b7f71865d1 1 /***********************************
Dzhafarkhanov 0:f7b7f71865d1 2 This is a our graphics core library, for all our displays.
Dzhafarkhanov 0:f7b7f71865d1 3 We'll be adapting all the
Dzhafarkhanov 0:f7b7f71865d1 4 existing libaries to use this core to make updating, support
Dzhafarkhanov 0:f7b7f71865d1 5 and upgrading easier!
Dzhafarkhanov 0:f7b7f71865d1 6
Dzhafarkhanov 0:f7b7f71865d1 7 Adafruit invests time and resources providing this open source code,
Dzhafarkhanov 0:f7b7f71865d1 8 please support Adafruit and open-source hardware by purchasing
Dzhafarkhanov 0:f7b7f71865d1 9 products from Adafruit!
Dzhafarkhanov 0:f7b7f71865d1 10
Dzhafarkhanov 0:f7b7f71865d1 11 Written by Limor Fried/Ladyada for Adafruit Industries.
Dzhafarkhanov 0:f7b7f71865d1 12 BSD license, check license.txt for more information
Dzhafarkhanov 0:f7b7f71865d1 13 All text above must be included in any redistribution
Dzhafarkhanov 0:f7b7f71865d1 14 ****************************************/
Dzhafarkhanov 0:f7b7f71865d1 15
Dzhafarkhanov 0:f7b7f71865d1 16 /*
Dzhafarkhanov 0:f7b7f71865d1 17 * Modified by Neal Horman 7/14/2012 for use in mbed
Dzhafarkhanov 0:f7b7f71865d1 18 */
Dzhafarkhanov 0:f7b7f71865d1 19
Dzhafarkhanov 0:f7b7f71865d1 20 #include "mbed.h"
Dzhafarkhanov 0:f7b7f71865d1 21
Dzhafarkhanov 0:f7b7f71865d1 22 #include "Adafruit_GFX.h"
Dzhafarkhanov 0:f7b7f71865d1 23 #include "glcdfont.h"
Dzhafarkhanov 0:f7b7f71865d1 24
Dzhafarkhanov 0:f7b7f71865d1 25 #if defined(GFX_WANT_ABSTRACTS)
Dzhafarkhanov 0:f7b7f71865d1 26 // draw a circle outline
Dzhafarkhanov 0:f7b7f71865d1 27 void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Dzhafarkhanov 0:f7b7f71865d1 28 {
Dzhafarkhanov 0:f7b7f71865d1 29 int16_t f = 1 - r;
Dzhafarkhanov 0:f7b7f71865d1 30 int16_t ddF_x = 1;
Dzhafarkhanov 0:f7b7f71865d1 31 int16_t ddF_y = -2 * r;
Dzhafarkhanov 0:f7b7f71865d1 32 int16_t x = 0;
Dzhafarkhanov 0:f7b7f71865d1 33 int16_t y = r;
Dzhafarkhanov 0:f7b7f71865d1 34
Dzhafarkhanov 0:f7b7f71865d1 35 drawPixel(x0, y0+r, color);
Dzhafarkhanov 0:f7b7f71865d1 36 drawPixel(x0, y0-r, color);
Dzhafarkhanov 0:f7b7f71865d1 37 drawPixel(x0+r, y0, color);
Dzhafarkhanov 0:f7b7f71865d1 38 drawPixel(x0-r, y0, color);
Dzhafarkhanov 0:f7b7f71865d1 39
Dzhafarkhanov 0:f7b7f71865d1 40 while (x<y)
Dzhafarkhanov 0:f7b7f71865d1 41 {
Dzhafarkhanov 0:f7b7f71865d1 42 if (f >= 0)
Dzhafarkhanov 0:f7b7f71865d1 43 {
Dzhafarkhanov 0:f7b7f71865d1 44 y--;
Dzhafarkhanov 0:f7b7f71865d1 45 ddF_y += 2;
Dzhafarkhanov 0:f7b7f71865d1 46 f += ddF_y;
Dzhafarkhanov 0:f7b7f71865d1 47 }
Dzhafarkhanov 0:f7b7f71865d1 48 x++;
Dzhafarkhanov 0:f7b7f71865d1 49 ddF_x += 2;
Dzhafarkhanov 0:f7b7f71865d1 50 f += ddF_x;
Dzhafarkhanov 0:f7b7f71865d1 51
Dzhafarkhanov 0:f7b7f71865d1 52 drawPixel(x0 + x, y0 + y, color);
Dzhafarkhanov 0:f7b7f71865d1 53 drawPixel(x0 - x, y0 + y, color);
Dzhafarkhanov 0:f7b7f71865d1 54 drawPixel(x0 + x, y0 - y, color);
Dzhafarkhanov 0:f7b7f71865d1 55 drawPixel(x0 - x, y0 - y, color);
Dzhafarkhanov 0:f7b7f71865d1 56 drawPixel(x0 + y, y0 + x, color);
Dzhafarkhanov 0:f7b7f71865d1 57 drawPixel(x0 - y, y0 + x, color);
Dzhafarkhanov 0:f7b7f71865d1 58 drawPixel(x0 + y, y0 - x, color);
Dzhafarkhanov 0:f7b7f71865d1 59 drawPixel(x0 - y, y0 - x, color);
Dzhafarkhanov 0:f7b7f71865d1 60 }
Dzhafarkhanov 0:f7b7f71865d1 61 }
Dzhafarkhanov 0:f7b7f71865d1 62
Dzhafarkhanov 0:f7b7f71865d1 63 void Adafruit_GFX::drawCircleHelper( int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color)
Dzhafarkhanov 0:f7b7f71865d1 64 {
Dzhafarkhanov 0:f7b7f71865d1 65 int16_t f = 1 - r;
Dzhafarkhanov 0:f7b7f71865d1 66 int16_t ddF_x = 1;
Dzhafarkhanov 0:f7b7f71865d1 67 int16_t ddF_y = -2 * r;
Dzhafarkhanov 0:f7b7f71865d1 68 int16_t x = 0;
Dzhafarkhanov 0:f7b7f71865d1 69 int16_t y = r;
Dzhafarkhanov 0:f7b7f71865d1 70
Dzhafarkhanov 0:f7b7f71865d1 71 while (x<y)
Dzhafarkhanov 0:f7b7f71865d1 72 {
Dzhafarkhanov 0:f7b7f71865d1 73 if (f >= 0)
Dzhafarkhanov 0:f7b7f71865d1 74 {
Dzhafarkhanov 0:f7b7f71865d1 75 y--;
Dzhafarkhanov 0:f7b7f71865d1 76 ddF_y += 2;
Dzhafarkhanov 0:f7b7f71865d1 77 f += ddF_y;
Dzhafarkhanov 0:f7b7f71865d1 78 }
Dzhafarkhanov 0:f7b7f71865d1 79 x++;
Dzhafarkhanov 0:f7b7f71865d1 80 ddF_x += 2;
Dzhafarkhanov 0:f7b7f71865d1 81 f += ddF_x;
Dzhafarkhanov 0:f7b7f71865d1 82
Dzhafarkhanov 0:f7b7f71865d1 83 if (cornername & 0x4)
Dzhafarkhanov 0:f7b7f71865d1 84 {
Dzhafarkhanov 0:f7b7f71865d1 85 drawPixel(x0 + x, y0 + y, color);
Dzhafarkhanov 0:f7b7f71865d1 86 drawPixel(x0 + y, y0 + x, color);
Dzhafarkhanov 0:f7b7f71865d1 87 }
Dzhafarkhanov 0:f7b7f71865d1 88
Dzhafarkhanov 0:f7b7f71865d1 89 if (cornername & 0x2)
Dzhafarkhanov 0:f7b7f71865d1 90 {
Dzhafarkhanov 0:f7b7f71865d1 91 drawPixel(x0 + x, y0 - y, color);
Dzhafarkhanov 0:f7b7f71865d1 92 drawPixel(x0 + y, y0 - x, color);
Dzhafarkhanov 0:f7b7f71865d1 93 }
Dzhafarkhanov 0:f7b7f71865d1 94
Dzhafarkhanov 0:f7b7f71865d1 95 if (cornername & 0x8)
Dzhafarkhanov 0:f7b7f71865d1 96 {
Dzhafarkhanov 0:f7b7f71865d1 97 drawPixel(x0 - y, y0 + x, color);
Dzhafarkhanov 0:f7b7f71865d1 98 drawPixel(x0 - x, y0 + y, color);
Dzhafarkhanov 0:f7b7f71865d1 99 }
Dzhafarkhanov 0:f7b7f71865d1 100
Dzhafarkhanov 0:f7b7f71865d1 101 if (cornername & 0x1)
Dzhafarkhanov 0:f7b7f71865d1 102 {
Dzhafarkhanov 0:f7b7f71865d1 103 drawPixel(x0 - y, y0 - x, color);
Dzhafarkhanov 0:f7b7f71865d1 104 drawPixel(x0 - x, y0 - y, color);
Dzhafarkhanov 0:f7b7f71865d1 105 }
Dzhafarkhanov 0:f7b7f71865d1 106 }
Dzhafarkhanov 0:f7b7f71865d1 107 }
Dzhafarkhanov 0:f7b7f71865d1 108
Dzhafarkhanov 0:f7b7f71865d1 109 void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Dzhafarkhanov 0:f7b7f71865d1 110 {
Dzhafarkhanov 0:f7b7f71865d1 111 drawFastVLine(x0, y0-r, 2*r+1, color);
Dzhafarkhanov 0:f7b7f71865d1 112 fillCircleHelper(x0, y0, r, 3, 0, color);
Dzhafarkhanov 0:f7b7f71865d1 113 }
Dzhafarkhanov 0:f7b7f71865d1 114
Dzhafarkhanov 0:f7b7f71865d1 115 // used to do circles and roundrects!
Dzhafarkhanov 0:f7b7f71865d1 116 void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color)
Dzhafarkhanov 0:f7b7f71865d1 117 {
Dzhafarkhanov 0:f7b7f71865d1 118 int16_t f = 1 - r;
Dzhafarkhanov 0:f7b7f71865d1 119 int16_t ddF_x = 1;
Dzhafarkhanov 0:f7b7f71865d1 120 int16_t ddF_y = -2 * r;
Dzhafarkhanov 0:f7b7f71865d1 121 int16_t x = 0;
Dzhafarkhanov 0:f7b7f71865d1 122 int16_t y = r;
Dzhafarkhanov 0:f7b7f71865d1 123
Dzhafarkhanov 0:f7b7f71865d1 124 while (x<y)
Dzhafarkhanov 0:f7b7f71865d1 125 {
Dzhafarkhanov 0:f7b7f71865d1 126 if (f >= 0)
Dzhafarkhanov 0:f7b7f71865d1 127 {
Dzhafarkhanov 0:f7b7f71865d1 128 y--;
Dzhafarkhanov 0:f7b7f71865d1 129 ddF_y += 2;
Dzhafarkhanov 0:f7b7f71865d1 130 f += ddF_y;
Dzhafarkhanov 0:f7b7f71865d1 131 }
Dzhafarkhanov 0:f7b7f71865d1 132 x++;
Dzhafarkhanov 0:f7b7f71865d1 133 ddF_x += 2;
Dzhafarkhanov 0:f7b7f71865d1 134 f += ddF_x;
Dzhafarkhanov 0:f7b7f71865d1 135
Dzhafarkhanov 0:f7b7f71865d1 136 if (cornername & 0x1)
Dzhafarkhanov 0:f7b7f71865d1 137 {
Dzhafarkhanov 0:f7b7f71865d1 138 drawFastVLine(x0+x, y0-y, 2*y+1+delta, color);
Dzhafarkhanov 0:f7b7f71865d1 139 drawFastVLine(x0+y, y0-x, 2*x+1+delta, color);
Dzhafarkhanov 0:f7b7f71865d1 140 }
Dzhafarkhanov 0:f7b7f71865d1 141
Dzhafarkhanov 0:f7b7f71865d1 142 if (cornername & 0x2)
Dzhafarkhanov 0:f7b7f71865d1 143 {
Dzhafarkhanov 0:f7b7f71865d1 144 drawFastVLine(x0-x, y0-y, 2*y+1+delta, color);
Dzhafarkhanov 0:f7b7f71865d1 145 drawFastVLine(x0-y, y0-x, 2*x+1+delta, color);
Dzhafarkhanov 0:f7b7f71865d1 146 }
Dzhafarkhanov 0:f7b7f71865d1 147 }
Dzhafarkhanov 0:f7b7f71865d1 148 }
Dzhafarkhanov 0:f7b7f71865d1 149 #endif
Dzhafarkhanov 0:f7b7f71865d1 150
Dzhafarkhanov 0:f7b7f71865d1 151 #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
Dzhafarkhanov 0:f7b7f71865d1 152 // bresenham's algorithm - thx wikpedia
Dzhafarkhanov 0:f7b7f71865d1 153 void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
Dzhafarkhanov 0:f7b7f71865d1 154 {
Dzhafarkhanov 0:f7b7f71865d1 155 int16_t steep = abs(y1 - y0) > abs(x1 - x0);
Dzhafarkhanov 0:f7b7f71865d1 156
Dzhafarkhanov 0:f7b7f71865d1 157 if (steep)
Dzhafarkhanov 0:f7b7f71865d1 158 {
Dzhafarkhanov 0:f7b7f71865d1 159 swap(x0, y0);
Dzhafarkhanov 0:f7b7f71865d1 160 swap(x1, y1);
Dzhafarkhanov 0:f7b7f71865d1 161 }
Dzhafarkhanov 0:f7b7f71865d1 162
Dzhafarkhanov 0:f7b7f71865d1 163 if (x0 > x1)
Dzhafarkhanov 0:f7b7f71865d1 164 {
Dzhafarkhanov 0:f7b7f71865d1 165 swap(x0, x1);
Dzhafarkhanov 0:f7b7f71865d1 166 swap(y0, y1);
Dzhafarkhanov 0:f7b7f71865d1 167 }
Dzhafarkhanov 0:f7b7f71865d1 168
Dzhafarkhanov 0:f7b7f71865d1 169 int16_t dx, dy;
Dzhafarkhanov 0:f7b7f71865d1 170 dx = x1 - x0;
Dzhafarkhanov 0:f7b7f71865d1 171 dy = abs(y1 - y0);
Dzhafarkhanov 0:f7b7f71865d1 172
Dzhafarkhanov 0:f7b7f71865d1 173 int16_t err = dx / 2;
Dzhafarkhanov 0:f7b7f71865d1 174 int16_t ystep;
Dzhafarkhanov 0:f7b7f71865d1 175
Dzhafarkhanov 0:f7b7f71865d1 176 if (y0 < y1)
Dzhafarkhanov 0:f7b7f71865d1 177 ystep = 1;
Dzhafarkhanov 0:f7b7f71865d1 178 else
Dzhafarkhanov 0:f7b7f71865d1 179 ystep = -1;
Dzhafarkhanov 0:f7b7f71865d1 180
Dzhafarkhanov 0:f7b7f71865d1 181 for (; x0<=x1; x0++)
Dzhafarkhanov 0:f7b7f71865d1 182 {
Dzhafarkhanov 0:f7b7f71865d1 183 if (steep)
Dzhafarkhanov 0:f7b7f71865d1 184 drawPixel(y0, x0, color);
Dzhafarkhanov 0:f7b7f71865d1 185 else
Dzhafarkhanov 0:f7b7f71865d1 186 drawPixel(x0, y0, color);
Dzhafarkhanov 0:f7b7f71865d1 187
Dzhafarkhanov 0:f7b7f71865d1 188 err -= dy;
Dzhafarkhanov 0:f7b7f71865d1 189 if (err < 0)
Dzhafarkhanov 0:f7b7f71865d1 190 {
Dzhafarkhanov 0:f7b7f71865d1 191 y0 += ystep;
Dzhafarkhanov 0:f7b7f71865d1 192 err += dx;
Dzhafarkhanov 0:f7b7f71865d1 193 }
Dzhafarkhanov 0:f7b7f71865d1 194 }
Dzhafarkhanov 0:f7b7f71865d1 195 }
Dzhafarkhanov 0:f7b7f71865d1 196
Dzhafarkhanov 0:f7b7f71865d1 197 void Adafruit_GFX::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Dzhafarkhanov 0:f7b7f71865d1 198 {
Dzhafarkhanov 0:f7b7f71865d1 199 // stupidest version - update in subclasses if desired!
Dzhafarkhanov 0:f7b7f71865d1 200 drawLine(x, y, x, y+h-1, color);
Dzhafarkhanov 0:f7b7f71865d1 201 }
Dzhafarkhanov 0:f7b7f71865d1 202
Dzhafarkhanov 0:f7b7f71865d1 203 void Adafruit_GFX::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Dzhafarkhanov 0:f7b7f71865d1 204 {
Dzhafarkhanov 0:f7b7f71865d1 205 // stupidest version - update in subclasses if desired!
Dzhafarkhanov 0:f7b7f71865d1 206 for (int16_t i=x; i<x+w; i++)
Dzhafarkhanov 0:f7b7f71865d1 207 drawFastVLine(i, y, h, color);
Dzhafarkhanov 0:f7b7f71865d1 208 }
Dzhafarkhanov 0:f7b7f71865d1 209 #endif
Dzhafarkhanov 0:f7b7f71865d1 210
Dzhafarkhanov 0:f7b7f71865d1 211 #if defined(GFX_WANT_ABSTRACTS)
Dzhafarkhanov 0:f7b7f71865d1 212 // draw a rectangle
Dzhafarkhanov 0:f7b7f71865d1 213 void Adafruit_GFX::drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Dzhafarkhanov 0:f7b7f71865d1 214 {
Dzhafarkhanov 0:f7b7f71865d1 215 drawFastHLine(x, y, w, color);
Dzhafarkhanov 0:f7b7f71865d1 216 drawFastHLine(x, y+h-1, w, color);
Dzhafarkhanov 0:f7b7f71865d1 217 drawFastVLine(x, y, h, color);
Dzhafarkhanov 0:f7b7f71865d1 218 drawFastVLine(x+w-1, y, h, color);
Dzhafarkhanov 0:f7b7f71865d1 219 }
Dzhafarkhanov 0:f7b7f71865d1 220
Dzhafarkhanov 0:f7b7f71865d1 221 void Adafruit_GFX::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
Dzhafarkhanov 0:f7b7f71865d1 222 {
Dzhafarkhanov 0:f7b7f71865d1 223 // stupidest version - update in subclasses if desired!
Dzhafarkhanov 0:f7b7f71865d1 224 drawLine(x, y, x+w-1, y, color);
Dzhafarkhanov 0:f7b7f71865d1 225 }
Dzhafarkhanov 0:f7b7f71865d1 226
Dzhafarkhanov 0:f7b7f71865d1 227 void Adafruit_GFX::fillScreen(uint16_t color)
Dzhafarkhanov 0:f7b7f71865d1 228 {
Dzhafarkhanov 0:f7b7f71865d1 229 fillRect(0, 0, _width, _height, color);
Dzhafarkhanov 0:f7b7f71865d1 230 }
Dzhafarkhanov 0:f7b7f71865d1 231
Dzhafarkhanov 0:f7b7f71865d1 232 // draw a rounded rectangle!
Dzhafarkhanov 0:f7b7f71865d1 233 void Adafruit_GFX::drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color)
Dzhafarkhanov 0:f7b7f71865d1 234 {
Dzhafarkhanov 0:f7b7f71865d1 235 // smarter version
Dzhafarkhanov 0:f7b7f71865d1 236 drawFastHLine(x+r , y , w-2*r, color); // Top
Dzhafarkhanov 0:f7b7f71865d1 237 drawFastHLine(x+r , y+h-1, w-2*r, color); // Bottom
Dzhafarkhanov 0:f7b7f71865d1 238 drawFastVLine( x , y+r , h-2*r, color); // Left
Dzhafarkhanov 0:f7b7f71865d1 239 drawFastVLine( x+w-1, y+r , h-2*r, color); // Right
Dzhafarkhanov 0:f7b7f71865d1 240 // draw four corners
Dzhafarkhanov 0:f7b7f71865d1 241 drawCircleHelper(x+r , y+r , r, 1, color);
Dzhafarkhanov 0:f7b7f71865d1 242 drawCircleHelper(x+w-r-1, y+r , r, 2, color);
Dzhafarkhanov 0:f7b7f71865d1 243 drawCircleHelper(x+w-r-1, y+h-r-1, r, 4, color);
Dzhafarkhanov 0:f7b7f71865d1 244 drawCircleHelper(x+r , y+h-r-1, r, 8, color);
Dzhafarkhanov 0:f7b7f71865d1 245 }
Dzhafarkhanov 0:f7b7f71865d1 246
Dzhafarkhanov 0:f7b7f71865d1 247 // fill a rounded rectangle!
Dzhafarkhanov 0:f7b7f71865d1 248 void Adafruit_GFX::fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color)
Dzhafarkhanov 0:f7b7f71865d1 249 {
Dzhafarkhanov 0:f7b7f71865d1 250 // smarter version
Dzhafarkhanov 0:f7b7f71865d1 251 fillRect(x+r, y, w-2*r, h, color);
Dzhafarkhanov 0:f7b7f71865d1 252
Dzhafarkhanov 0:f7b7f71865d1 253 // draw four corners
Dzhafarkhanov 0:f7b7f71865d1 254 fillCircleHelper(x+w-r-1, y+r, r, 1, h-2*r-1, color);
Dzhafarkhanov 0:f7b7f71865d1 255 fillCircleHelper(x+r , y+r, r, 2, h-2*r-1, color);
Dzhafarkhanov 0:f7b7f71865d1 256 }
Dzhafarkhanov 0:f7b7f71865d1 257
Dzhafarkhanov 0:f7b7f71865d1 258 // draw a triangle!
Dzhafarkhanov 0:f7b7f71865d1 259 void Adafruit_GFX::drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
Dzhafarkhanov 0:f7b7f71865d1 260 {
Dzhafarkhanov 0:f7b7f71865d1 261 drawLine(x0, y0, x1, y1, color);
Dzhafarkhanov 0:f7b7f71865d1 262 drawLine(x1, y1, x2, y2, color);
Dzhafarkhanov 0:f7b7f71865d1 263 drawLine(x2, y2, x0, y0, color);
Dzhafarkhanov 0:f7b7f71865d1 264 }
Dzhafarkhanov 0:f7b7f71865d1 265
Dzhafarkhanov 0:f7b7f71865d1 266 // fill a triangle!
Dzhafarkhanov 0:f7b7f71865d1 267 void Adafruit_GFX::fillTriangle ( int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
Dzhafarkhanov 0:f7b7f71865d1 268 {
Dzhafarkhanov 0:f7b7f71865d1 269 int16_t a, b, y, last;
Dzhafarkhanov 0:f7b7f71865d1 270
Dzhafarkhanov 0:f7b7f71865d1 271 // Sort coordinates by Y order (y2 >= y1 >= y0)
Dzhafarkhanov 0:f7b7f71865d1 272 if (y0 > y1) {
Dzhafarkhanov 0:f7b7f71865d1 273 swap(y0, y1); swap(x0, x1);
Dzhafarkhanov 0:f7b7f71865d1 274 }
Dzhafarkhanov 0:f7b7f71865d1 275 if (y1 > y2) {
Dzhafarkhanov 0:f7b7f71865d1 276 swap(y2, y1); swap(x2, x1);
Dzhafarkhanov 0:f7b7f71865d1 277 }
Dzhafarkhanov 0:f7b7f71865d1 278 if (y0 > y1) {
Dzhafarkhanov 0:f7b7f71865d1 279 swap(y0, y1); swap(x0, x1);
Dzhafarkhanov 0:f7b7f71865d1 280 }
Dzhafarkhanov 0:f7b7f71865d1 281
Dzhafarkhanov 0:f7b7f71865d1 282 if(y0 == y2) { // Handle awkward all-on-same-line case as its own thing
Dzhafarkhanov 0:f7b7f71865d1 283 a = b = x0;
Dzhafarkhanov 0:f7b7f71865d1 284 if(x1 < a) a = x1;
Dzhafarkhanov 0:f7b7f71865d1 285 else if(x1 > b) b = x1;
Dzhafarkhanov 0:f7b7f71865d1 286 if(x2 < a) a = x2;
Dzhafarkhanov 0:f7b7f71865d1 287 else if(x2 > b) b = x2;
Dzhafarkhanov 0:f7b7f71865d1 288 drawFastHLine(a, y0, b-a+1, color);
Dzhafarkhanov 0:f7b7f71865d1 289 return;
Dzhafarkhanov 0:f7b7f71865d1 290 }
Dzhafarkhanov 0:f7b7f71865d1 291
Dzhafarkhanov 0:f7b7f71865d1 292 int16_t
Dzhafarkhanov 0:f7b7f71865d1 293 dx01 = x1 - x0,
Dzhafarkhanov 0:f7b7f71865d1 294 dy01 = y1 - y0,
Dzhafarkhanov 0:f7b7f71865d1 295 dx02 = x2 - x0,
Dzhafarkhanov 0:f7b7f71865d1 296 dy02 = y2 - y0,
Dzhafarkhanov 0:f7b7f71865d1 297 dx12 = x2 - x1,
Dzhafarkhanov 0:f7b7f71865d1 298 dy12 = y2 - y1;
Dzhafarkhanov 0:f7b7f71865d1 299 int32_t
Dzhafarkhanov 0:f7b7f71865d1 300 sa = 0,
Dzhafarkhanov 0:f7b7f71865d1 301 sb = 0;
Dzhafarkhanov 0:f7b7f71865d1 302
Dzhafarkhanov 0:f7b7f71865d1 303 // For upper part of triangle, find scanline crossings for segments
Dzhafarkhanov 0:f7b7f71865d1 304 // 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
Dzhafarkhanov 0:f7b7f71865d1 305 // is included here (and second loop will be skipped, avoiding a /0
Dzhafarkhanov 0:f7b7f71865d1 306 // error there), otherwise scanline y1 is skipped here and handled
Dzhafarkhanov 0:f7b7f71865d1 307 // in the second loop...which also avoids a /0 error here if y0=y1
Dzhafarkhanov 0:f7b7f71865d1 308 // (flat-topped triangle).
Dzhafarkhanov 0:f7b7f71865d1 309 if(y1 == y2) last = y1; // Include y1 scanline
Dzhafarkhanov 0:f7b7f71865d1 310 else last = y1-1; // Skip it
Dzhafarkhanov 0:f7b7f71865d1 311
Dzhafarkhanov 0:f7b7f71865d1 312 for(y=y0; y<=last; y++) {
Dzhafarkhanov 0:f7b7f71865d1 313 a = x0 + sa / dy01;
Dzhafarkhanov 0:f7b7f71865d1 314 b = x0 + sb / dy02;
Dzhafarkhanov 0:f7b7f71865d1 315 sa += dx01;
Dzhafarkhanov 0:f7b7f71865d1 316 sb += dx02;
Dzhafarkhanov 0:f7b7f71865d1 317 /* longhand:
Dzhafarkhanov 0:f7b7f71865d1 318 a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
Dzhafarkhanov 0:f7b7f71865d1 319 b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
Dzhafarkhanov 0:f7b7f71865d1 320 */
Dzhafarkhanov 0:f7b7f71865d1 321 if(a > b) swap(a,b);
Dzhafarkhanov 0:f7b7f71865d1 322 drawFastHLine(a, y, b-a+1, color);
Dzhafarkhanov 0:f7b7f71865d1 323 }
Dzhafarkhanov 0:f7b7f71865d1 324
Dzhafarkhanov 0:f7b7f71865d1 325 // For lower part of triangle, find scanline crossings for segments
Dzhafarkhanov 0:f7b7f71865d1 326 // 0-2 and 1-2. This loop is skipped if y1=y2.
Dzhafarkhanov 0:f7b7f71865d1 327 sa = dx12 * (y - y1);
Dzhafarkhanov 0:f7b7f71865d1 328 sb = dx02 * (y - y0);
Dzhafarkhanov 0:f7b7f71865d1 329 for(; y<=y2; y++) {
Dzhafarkhanov 0:f7b7f71865d1 330 a = x1 + sa / dy12;
Dzhafarkhanov 0:f7b7f71865d1 331 b = x0 + sb / dy02;
Dzhafarkhanov 0:f7b7f71865d1 332 sa += dx12;
Dzhafarkhanov 0:f7b7f71865d1 333 sb += dx02;
Dzhafarkhanov 0:f7b7f71865d1 334 /* longhand:
Dzhafarkhanov 0:f7b7f71865d1 335 a = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
Dzhafarkhanov 0:f7b7f71865d1 336 b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
Dzhafarkhanov 0:f7b7f71865d1 337 */
Dzhafarkhanov 0:f7b7f71865d1 338 if(a > b) swap(a,b);
Dzhafarkhanov 0:f7b7f71865d1 339 drawFastHLine(a, y, b-a+1, color);
Dzhafarkhanov 0:f7b7f71865d1 340 }
Dzhafarkhanov 0:f7b7f71865d1 341
Dzhafarkhanov 0:f7b7f71865d1 342 }
Dzhafarkhanov 0:f7b7f71865d1 343
Dzhafarkhanov 0:f7b7f71865d1 344 void Adafruit_GFX::drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)
Dzhafarkhanov 0:f7b7f71865d1 345 {
Dzhafarkhanov 0:f7b7f71865d1 346 for (int16_t j=0; j<h; j++)
Dzhafarkhanov 0:f7b7f71865d1 347 {
Dzhafarkhanov 0:f7b7f71865d1 348 for (int16_t i=0; i<w; i++ )
Dzhafarkhanov 0:f7b7f71865d1 349 {
Dzhafarkhanov 0:f7b7f71865d1 350 if (bitmap[i + (j/8)*w] & _BV(j%8))
Dzhafarkhanov 0:f7b7f71865d1 351 drawPixel(x+i, y+j, color);
Dzhafarkhanov 0:f7b7f71865d1 352 }
Dzhafarkhanov 0:f7b7f71865d1 353 }
Dzhafarkhanov 0:f7b7f71865d1 354 }
Dzhafarkhanov 0:f7b7f71865d1 355 #endif
Dzhafarkhanov 0:f7b7f71865d1 356
Dzhafarkhanov 0:f7b7f71865d1 357 size_t Adafruit_GFX::writeChar(uint8_t c)
Dzhafarkhanov 0:f7b7f71865d1 358 {
Dzhafarkhanov 0:f7b7f71865d1 359 if (( c == 0xD0 ) || ( c == 0xD1 )){ // Проверяем на соответствие utf8 и игнорируем если это начальный символ UTF8.
Dzhafarkhanov 0:f7b7f71865d1 360 return;}
Dzhafarkhanov 0:f7b7f71865d1 361 if (c == '\n')
Dzhafarkhanov 0:f7b7f71865d1 362 {
Dzhafarkhanov 0:f7b7f71865d1 363 cursor_y += textsize*8;
Dzhafarkhanov 0:f7b7f71865d1 364 cursor_x = 0;
Dzhafarkhanov 0:f7b7f71865d1 365 }
Dzhafarkhanov 0:f7b7f71865d1 366 else if (c == '\r')
Dzhafarkhanov 0:f7b7f71865d1 367 cursor_x = 0;
Dzhafarkhanov 0:f7b7f71865d1 368 else
Dzhafarkhanov 0:f7b7f71865d1 369 {
Dzhafarkhanov 0:f7b7f71865d1 370 drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize);
Dzhafarkhanov 0:f7b7f71865d1 371 cursor_x += textsize*6;
Dzhafarkhanov 0:f7b7f71865d1 372 if (wrap && (cursor_x > (_width - textsize*6)))
Dzhafarkhanov 0:f7b7f71865d1 373 {
Dzhafarkhanov 0:f7b7f71865d1 374 cursor_y += textsize*8;
Dzhafarkhanov 0:f7b7f71865d1 375 cursor_x = 0;
Dzhafarkhanov 0:f7b7f71865d1 376 }
Dzhafarkhanov 0:f7b7f71865d1 377 }
Dzhafarkhanov 0:f7b7f71865d1 378 return 1;
Dzhafarkhanov 0:f7b7f71865d1 379 }
Dzhafarkhanov 0:f7b7f71865d1 380
Dzhafarkhanov 0:f7b7f71865d1 381 // draw a character
Dzhafarkhanov 0:f7b7f71865d1 382 void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size)
Dzhafarkhanov 0:f7b7f71865d1 383 {
Dzhafarkhanov 0:f7b7f71865d1 384 if (( c == 0xD0 ) || ( c == 0xD1 )){ // Проверяем на соответствие utf8 и игнорируем если это начальный символ UTF8.
Dzhafarkhanov 0:f7b7f71865d1 385 return;}
Dzhafarkhanov 0:f7b7f71865d1 386 if(
Dzhafarkhanov 0:f7b7f71865d1 387 (x >= _width) || // Clip right
Dzhafarkhanov 0:f7b7f71865d1 388 (y >= _height) || // Clip bottom
Dzhafarkhanov 0:f7b7f71865d1 389 ((x + 5 * size - 1) < 0) || // Clip left
Dzhafarkhanov 0:f7b7f71865d1 390 ((y + 8 * size - 1) < 0) // Clip top
Dzhafarkhanov 0:f7b7f71865d1 391 )
Dzhafarkhanov 0:f7b7f71865d1 392 return;
Dzhafarkhanov 0:f7b7f71865d1 393
Dzhafarkhanov 0:f7b7f71865d1 394 for (int8_t i=0; i<6; i++ )
Dzhafarkhanov 0:f7b7f71865d1 395 {
Dzhafarkhanov 0:f7b7f71865d1 396 uint8_t line = 0;
Dzhafarkhanov 0:f7b7f71865d1 397
Dzhafarkhanov 0:f7b7f71865d1 398 if (i == 5)
Dzhafarkhanov 0:f7b7f71865d1 399 line = 0x0;
Dzhafarkhanov 0:f7b7f71865d1 400 else
Dzhafarkhanov 0:f7b7f71865d1 401 line = font[(c*5)+i];
Dzhafarkhanov 0:f7b7f71865d1 402
Dzhafarkhanov 0:f7b7f71865d1 403 for (int8_t j = 0; j<8; j++)
Dzhafarkhanov 0:f7b7f71865d1 404 {
Dzhafarkhanov 0:f7b7f71865d1 405 if (line & 0x1)
Dzhafarkhanov 0:f7b7f71865d1 406 {
Dzhafarkhanov 0:f7b7f71865d1 407 #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
Dzhafarkhanov 0:f7b7f71865d1 408 if (size == 1) // default size
Dzhafarkhanov 0:f7b7f71865d1 409 drawPixel(x+i, y+j, color);
Dzhafarkhanov 0:f7b7f71865d1 410 else // big size
Dzhafarkhanov 0:f7b7f71865d1 411 fillRect(x+(i*size), y+(j*size), size, size, color);
Dzhafarkhanov 0:f7b7f71865d1 412 #else
Dzhafarkhanov 0:f7b7f71865d1 413 drawPixel(x+i, y+j, color);
Dzhafarkhanov 0:f7b7f71865d1 414 #endif
Dzhafarkhanov 0:f7b7f71865d1 415 }
Dzhafarkhanov 0:f7b7f71865d1 416 else if (bg != color)
Dzhafarkhanov 0:f7b7f71865d1 417 {
Dzhafarkhanov 0:f7b7f71865d1 418 #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
Dzhafarkhanov 0:f7b7f71865d1 419 if (size == 1) // default size
Dzhafarkhanov 0:f7b7f71865d1 420 drawPixel(x+i, y+j, bg);
Dzhafarkhanov 0:f7b7f71865d1 421 else // big size
Dzhafarkhanov 0:f7b7f71865d1 422 fillRect(x+i*size, y+j*size, size, size, bg);
Dzhafarkhanov 0:f7b7f71865d1 423 #else
Dzhafarkhanov 0:f7b7f71865d1 424 drawPixel(x+i, y+j, bg);
Dzhafarkhanov 0:f7b7f71865d1 425 #endif
Dzhafarkhanov 0:f7b7f71865d1 426 }
Dzhafarkhanov 0:f7b7f71865d1 427 line >>= 1;
Dzhafarkhanov 0:f7b7f71865d1 428 }
Dzhafarkhanov 0:f7b7f71865d1 429 }
Dzhafarkhanov 0:f7b7f71865d1 430 }
Dzhafarkhanov 0:f7b7f71865d1 431
Dzhafarkhanov 0:f7b7f71865d1 432 void Adafruit_GFX::setRotation(uint8_t x)
Dzhafarkhanov 0:f7b7f71865d1 433 {
Dzhafarkhanov 0:f7b7f71865d1 434 x %= 4; // cant be higher than 3
Dzhafarkhanov 0:f7b7f71865d1 435 rotation = x;
Dzhafarkhanov 0:f7b7f71865d1 436 switch (x)
Dzhafarkhanov 0:f7b7f71865d1 437 {
Dzhafarkhanov 0:f7b7f71865d1 438 case 0:
Dzhafarkhanov 0:f7b7f71865d1 439 case 2:
Dzhafarkhanov 0:f7b7f71865d1 440 _width = _rawWidth;
Dzhafarkhanov 0:f7b7f71865d1 441 _height = _rawHeight;
Dzhafarkhanov 0:f7b7f71865d1 442 break;
Dzhafarkhanov 0:f7b7f71865d1 443 case 1:
Dzhafarkhanov 0:f7b7f71865d1 444 case 3:
Dzhafarkhanov 0:f7b7f71865d1 445 _width = _rawHeight;
Dzhafarkhanov 0:f7b7f71865d1 446 _height = _rawWidth;
Dzhafarkhanov 0:f7b7f71865d1 447 break;
Dzhafarkhanov 0:f7b7f71865d1 448 }
Dzhafarkhanov 0:f7b7f71865d1 449 }