Uses the same fonts as the SPI_TFT_ILI9341 Library (I have many, and a html/php font editor for that)

Revision:
10:a640680b5309
Parent:
9:680f6c9940b3
Child:
11:70409b34b74d
diff -r 680f6c9940b3 -r a640680b5309 SPI_TFT_ILI9225.cpp
--- a/SPI_TFT_ILI9225.cpp	Wed Nov 23 11:57:11 2016 +0000
+++ b/SPI_TFT_ILI9225.cpp	Wed Nov 23 12:35:40 2016 +0000
@@ -68,22 +68,22 @@
     return true;
 } 
 
-void TFT_22_ILI9225::_orientCoordinates(uint16_t &x1, uint16_t &y1)
+void TFT_22_ILI9225::_orientCoordinates(uint16_t &x, uint16_t &y)
 {
     switch (_orientation) {
         case 0:  // ok
             break;
         case 1: // ok
-            y1 = _maxY - y1 - 1;
-            _swap(x1, y1);
+            y = _maxY - y - 1;
+            _swap(x, y);
             break;
         case 2: // ok
-            x1 = _maxX - x1 - 1;
-            y1 = _maxY - y1 - 1;
+            x = _maxX - x - 1;
+            y = _maxY - y - 1;
             break;
         case 3: // ok
-            x1 = _maxX - x1 - 1;
-            _swap(x1, y1);
+            x = _maxX - x - 1;
+            _swap(x, y);
             break;
     }
 }
@@ -233,7 +233,8 @@
     setBacklight(_brightness);
 }
 
-void TFT_22_ILI9225::setDisplay(bool flag) {
+void TFT_22_ILI9225::setDisplay(bool flag)
+{
     if (flag) {
         _writeRegister(0x00ff, 0x0000);
         _writeRegister(ILI9225_POWER_CTRL1, 0x0000);
@@ -292,14 +293,15 @@
     _writeRegister(ILI9225_ENTRY_MODE, _entryMode); // set GRAM write direction and BGR=1.
 }
 
-uint8_t TFT_22_ILI9225::getOrientation() {
+uint8_t TFT_22_ILI9225::getOrientation()
+{
     return _orientation;
 }
 
 // Graphics functions
 
-void TFT_22_ILI9225::pixel(uint16_t x1, uint16_t y1, uint16_t color) {
-
+void TFT_22_ILI9225::pixel(uint16_t x1, uint16_t y1, uint16_t color)
+{
     if ((x1 >= _maxX) || (y1 >= _maxY)) return;
 
     _setWindow(x1, y1, x1 + 1, y1 + 1);
@@ -311,8 +313,8 @@
     _cs = 1;
 }
 
-void TFT_22_ILI9225::line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) {
-
+void TFT_22_ILI9225::line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
+{
     // Classic Bresenham algorithm
     int16_t steep = abs(y2 - y1) > abs(x2 - x1);
     int16_t dx, dy;
@@ -391,8 +393,8 @@
     vline(x2, y1, y2, color);
 }
 
-void TFT_22_ILI9225::fillrect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) {
-    
+void TFT_22_ILI9225::fillrect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
+{
     _setWindow(x1, y1, x2, y2);
     _startData();
     for (uint16_t t = (y2 - y1 + 1) * (x2 - x1 + 1); t > 0; t--) {
@@ -401,8 +403,8 @@
     _endData();
 }
 
-void TFT_22_ILI9225::circle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color) {
-
+void TFT_22_ILI9225::circle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color)
+{
     int16_t f = 1 - r;
     int16_t ddF_x = 1;
     int16_t ddF_y = -2 * r;
@@ -435,8 +437,8 @@
     }
 }
 
-void TFT_22_ILI9225::fillcircle(uint8_t x0, uint8_t y0, uint8_t radius, uint16_t color) {
-
+void TFT_22_ILI9225::fillcircle(uint8_t x0, uint8_t y0, uint8_t radius, uint16_t color)
+{
     int16_t f = 1 - radius;
     int16_t ddF_x = 1;
     int16_t ddF_y = -2 * radius;
@@ -461,14 +463,15 @@
     fillrect(x0 - x, y0 - y, x0 + x, y0 + y, color);
 }
 
-void TFT_22_ILI9225::triangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color) {
+void TFT_22_ILI9225::triangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color)
+{
     line(x1, y1, x2, y2, color);
     line(x2, y2, x3, y3, color);
     line(x3, y3, x1, y1, color);
 }
 
-void TFT_22_ILI9225::filltriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color) {
-
+void TFT_22_ILI9225::filltriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color)
+{
     uint16_t a, b, y, last;
 
     // Sort coordinates by Y order (y3 >= y2 >= y1)
@@ -596,28 +599,44 @@
     }
 }
 
-uint16_t TFT_22_ILI9225::maxX(void) {
+uint8_t TFT_22_ILI9225::fontX(void)
+{
+    return font[FONT_HORZ];
+}
+
+uint8_t TFT_22_ILI9225::fontY(void)
+{
+    return font[FONT_VERT];
+}
+
+uint16_t TFT_22_ILI9225::maxX(void)
+{
     return _maxX - 1;
 }
 
-uint16_t TFT_22_ILI9225::maxY(void) {
+uint16_t TFT_22_ILI9225::maxY(void)
+{
     return _maxY - 1;
 }
 
-uint16_t TFT_22_ILI9225::width(void) {
+uint16_t TFT_22_ILI9225::width(void)
+{
     return _maxX;
 }
 
-uint16_t TFT_22_ILI9225::height(void) {
+uint16_t TFT_22_ILI9225::height(void)
+{
     return _maxY;
 }
 
-uint16_t TFT_22_ILI9225::setColor(uint8_t red8, uint8_t green8, uint8_t blue8) {
+uint16_t TFT_22_ILI9225::setColor(uint8_t red8, uint8_t green8, uint8_t blue8)
+{
     // rgb16 = red5 green6 blue5
     return (red8 >> 3) << 11 | (green8 >> 2) << 5 | (blue8 >> 3);
 }
 
-void TFT_22_ILI9225::splitColor(uint16_t rgb, uint8_t &red, uint8_t &green, uint8_t &blue) {
+void TFT_22_ILI9225::splitColor(uint16_t rgb, uint8_t &red, uint8_t &green, uint8_t &blue)
+{
     // rgb16 = red5 green6 blue5
     
     red = (rgb & 0xF800) >> 11 << 3;
@@ -625,13 +644,15 @@
     blue = (rgb & 0x1F) << 3;
 }
 
-void TFT_22_ILI9225::_swap(uint16_t &a, uint16_t &b) {
+void TFT_22_ILI9225::_swap(uint16_t &a, uint16_t &b)
+{
     uint16_t w = a;
     a = b;
     b = w;
 }
 
-void TFT_22_ILI9225::_writeCommand(uint8_t HI, uint8_t LO) {
+void TFT_22_ILI9225::_writeCommand(uint8_t HI, uint8_t LO)
+{
     _rs = 0;
     _cs = 0;
     spi.write(HI);
@@ -639,31 +660,36 @@
     _cs = 1;
 }
 
-void TFT_22_ILI9225::_writeData(uint16_t data) {
+void TFT_22_ILI9225::_writeData(uint16_t data)
+{
     spi.write(data >> 8);
     spi.write(data & 0xff);
 //    spi.write(data);
 }
 
-void TFT_22_ILI9225::_startData(void) {
+void TFT_22_ILI9225::_startData(void)
+{
     _rs = 1;
     _cs = 0;
 //    spi.format(16, 0);    // New mbed library can't use 16 bit spi anymore on this platform
 }
 
-void TFT_22_ILI9225::_endData(void) {
+void TFT_22_ILI9225::_endData(void)
+{
     _cs = 1;
 //    spi.format(8, 0);
 }
 
-void TFT_22_ILI9225::_writeRegister(uint16_t reg, uint16_t data) {
+void TFT_22_ILI9225::_writeRegister(uint16_t reg, uint16_t data)
+{
     _writeCommand(reg >> 8, reg & 0xff);
     _startData();
     _writeData(data);
     _endData();
 }
 
-void TFT_22_ILI9225::setFont(unsigned char* f) {
+void TFT_22_ILI9225::setFont(unsigned char* f)
+{
     font = f;
 }
 
@@ -733,12 +759,14 @@
     } else char_x += hor;
 }
         
-void TFT_22_ILI9225::foreground(uint16_t colour) {
-    _foreground = colour;
+void TFT_22_ILI9225::foreground(uint16_t color)
+{
+    _foreground = color;
 }
 
-void TFT_22_ILI9225::background(uint16_t colour) {
-    _background = colour;
+void TFT_22_ILI9225::background(uint16_t color)
+{
+    _background = color;
 }
 
 void TFT_22_ILI9225::locate(int x, int y)
@@ -773,12 +801,6 @@
     return height() / font[FONT_VERT];
 }
 
-//----------------------------------------------------------------------------------------------------
-//************************************* ECA 2.8 inch LCD Module **************************************
-//----------------------------------------------------------------------------------------------------
-// Make an ascii string from an unicode string 
-//----------------------------------------------------------------------------------------------------
-
 void TFT_22_ILI9225::unicode2ascii(char *uni_str, char *ascii_str)
 {
     int counter = 0;
@@ -832,6 +854,5 @@
 
     }
     *(ascii_str + counter) = NULL;
-
 }