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

Revision:
13:9e6589dc8864
Parent:
12:64165e7ad897
Child:
14:a7640e7e9f80
--- a/SPI_TFT_ILI9225.cpp	Wed Nov 23 12:56:39 2016 +0000
+++ b/SPI_TFT_ILI9225.cpp	Wed Nov 23 13:30:20 2016 +0000
@@ -19,20 +19,12 @@
 
 #include "SPI_TFT_ILI9225.h"
 
-int font_color, x_font, y_font;
-char highlight, fa_num;
-int effect = 0, italic = 0;
-unsigned int highlight_color;
-/* Global Variables */
-int x_text = 0, y_text = 0;
-int x_base = 0;
-
 // Constructor when using software SPI.  All output pins are configurable.
 TFT_22_ILI9225::TFT_22_ILI9225(PinName sdi, PinName clk, PinName cs, PinName rs, PinName rst, PinName led, const char *name) :
-    spi(sdi, NC, clk), _cs(cs), _rs(rs), _rst(rst), _led(led), Stream(name)
+    _spi(sdi, NC, clk), _cs(cs), _rs(rs), _rst(rst), _led(led), Stream(name)
 {
-    spi.frequency(24000000); 
-    spi.format(8, 0);
+    _spi.frequency(24000000); 
+    _spi.format(8, 0);
 
     // PWM output to control backlight
     _led.period_ms(10);
@@ -51,66 +43,6 @@
     init();
 }
 
-bool TFT_22_ILI9225::claim (FILE *stream)
-{
-    if ( _path == NULL) {
-        fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n");
-        return false;
-    }
-    if (freopen(_path, "w", stream) == NULL) {
-        // Failed, should not happen
-        return false;
-    }
-    // make sure we use line buffering
-    setvbuf(stdout, NULL, _IOLBF, ILI9225_CHARS_PER_LINE);
-    return true;
-} 
-
-void TFT_22_ILI9225::_orientCoordinates(uint16_t &x, uint16_t &y)
-{
-    switch (_orientation) {
-        case 0:  // ok
-            break;
-        case 1: // ok
-            y = _maxY - y - 1;
-            _swap(x, y);
-            break;
-        case 2: // ok
-            x = _maxX - x - 1;
-            y = _maxY - y - 1;
-            break;
-        case 3: // ok
-            x = _maxX - x - 1;
-            _swap(x, y);
-            break;
-    }
-}
-
-void TFT_22_ILI9225::_setWindowMax(void)
-{
-    _setWindow(0, 0, maxX(), maxY());
-}
-
-void TFT_22_ILI9225::_setWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
-{
-    _orientCoordinates(x0, y0);
-    _orientCoordinates(x1, y1);
-
-    if (x1 < x0) _swap(x0, x1);
-    if (y1 < y0) _swap(y0, y1);
-
-    _writeRegister(ILI9225_HORIZONTAL_WINDOW_ADDR1, x1);
-    _writeRegister(ILI9225_HORIZONTAL_WINDOW_ADDR2, x0);
-
-    _writeRegister(ILI9225_VERTICAL_WINDOW_ADDR1, y1);
-    _writeRegister(ILI9225_VERTICAL_WINDOW_ADDR2, y0);
-
-    _writeRegister(ILI9225_RAM_ADDR_SET1, x0);
-    _writeRegister(ILI9225_RAM_ADDR_SET2, y0);
-
-    _writeCommand(0x00, 0x22);
-}
-
 void TFT_22_ILI9225::init()
 {
     // Turn off backlight
@@ -196,8 +128,8 @@
     _rs = 1;
     _cs = 0;
     for (uint16_t i = width() * height(); i > 0; i--) {
-        spi.write(0x00);
-        spi.write(0x00);
+        _spi.write(0x00);
+        _spi.write(0x00);
     }
     _cs = 1;
     setBacklightOn();
@@ -296,6 +228,7 @@
     return _orientation;
 }
 
+
 // Graphics functions
 
 void TFT_22_ILI9225::pixel(uint16_t x1, uint16_t y1, uint16_t color)
@@ -306,8 +239,8 @@
     _orientCoordinates(x1, y1);
     _rs = 1;
     _cs = 0;
-    spi.write(color >> 8);
-    spi.write(color & 0xff);
+    _spi.write(color >> 8);
+    _spi.write(color & 0xff);
     _cs = 1;
 }
 
@@ -359,8 +292,8 @@
     _rs = 1;
     _cs = 0;
     for (uint16_t x = x1; x <= x2; x++) {
-        spi.write(color >> 8);
-        spi.write(color & 0xff);
+        _spi.write(color >> 8);
+        _spi.write(color & 0xff);
     } 
     _cs = 1;
     _writeRegister(ILI9225_ENTRY_MODE, _entryMode); // set GRAM write direction and BGR=1.
@@ -376,8 +309,8 @@
     _rs = 1;
     _cs = 0;
     for (uint16_t y = y1; y <= y2; y++) {
-        spi.write(color >> 8);
-        spi.write(color & 0xff);
+        _spi.write(color >> 8);
+        _spi.write(color & 0xff);
     } 
     _cs = 1;
     _writeRegister(ILI9225_ENTRY_MODE, _entryMode); // set GRAM write direction and BGR=1.
@@ -597,16 +530,6 @@
     }
 }
 
-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;
@@ -642,55 +565,24 @@
     blue = (rgb & 0x1F) << 3;
 }
 
-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)
-{
-    _rs = 0;
-    _cs = 0;
-    spi.write(HI);
-    spi.write(LO);
-    _cs = 1;
-}
-
-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)
-{
-    _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)
-{
-    _cs = 1;
-//    spi.format(8, 0);
-}
-
-void TFT_22_ILI9225::_writeRegister(uint16_t reg, uint16_t data)
-{
-    _writeCommand(reg >> 8, reg & 0xff);
-    _startData();
-    _writeData(data);
-    _endData();
-}
+// Text functions
 
 void TFT_22_ILI9225::setFont(unsigned char* f)
 {
     font = f;
 }
 
+uint8_t TFT_22_ILI9225::fontX(void)
+{
+    return font[FONT_HORZ];
+}
+
+uint8_t TFT_22_ILI9225::fontY(void)
+{
+    return font[FONT_VERT];
+}
+
 int TFT_22_ILI9225::putc(int value)
 {
     if (value == '\n') {    // new line
@@ -741,11 +633,11 @@
             z =  zeichen[bpl * i + ((j & 0xF8) >> 3)+1];
             b = 1 << (j & 0x07);
             if (( z & b ) == 0x00) {
-                spi.write(_background >> 8);
-                spi.write(_background & 0xff);
+                _spi.write(_background >> 8);
+                _spi.write(_background & 0xff);
             } else {
-                spi.write(_foreground >> 8);
-                spi.write(_foreground & 0xff);
+                _spi.write(_foreground >> 8);
+                _spi.write(_foreground & 0xff);
             }
         }
     }
@@ -854,3 +746,105 @@
     *(ascii_str + counter) = NULL;
 }
 
+bool TFT_22_ILI9225::claim (FILE *stream)
+{
+    if ( _path == NULL) {
+        fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n");
+        return false;
+    }
+    if (freopen(_path, "w", stream) == NULL) {
+        // Failed, should not happen
+        return false;
+    }
+    // make sure we use line buffering
+    setvbuf(stdout, NULL, _IOLBF, ILI9225_CHARS_PER_LINE);
+    return true;
+} 
+
+// Private functions
+
+void TFT_22_ILI9225::_swap(uint16_t &a, uint16_t &b)
+{
+    uint16_t w = a;
+    a = b;
+    b = w;
+}
+
+void TFT_22_ILI9225::_setWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
+{
+    _orientCoordinates(x0, y0);
+    _orientCoordinates(x1, y1);
+
+    if (x1 < x0) _swap(x0, x1);
+    if (y1 < y0) _swap(y0, y1);
+
+    _writeRegister(ILI9225_HORIZONTAL_WINDOW_ADDR1, x1);
+    _writeRegister(ILI9225_HORIZONTAL_WINDOW_ADDR2, x0);
+
+    _writeRegister(ILI9225_VERTICAL_WINDOW_ADDR1, y1);
+    _writeRegister(ILI9225_VERTICAL_WINDOW_ADDR2, y0);
+
+    _writeRegister(ILI9225_RAM_ADDR_SET1, x0);
+    _writeRegister(ILI9225_RAM_ADDR_SET2, y0);
+
+    _writeCommand(0x00, 0x22);
+}
+
+void TFT_22_ILI9225::_setWindowMax(void)
+{
+    _setWindow(0, 0, maxX(), maxY());
+}
+
+void TFT_22_ILI9225::_orientCoordinates(uint16_t &x, uint16_t &y)
+{
+    switch (_orientation) {
+        case 0:  // ok
+            break;
+        case 1: // ok
+            y = _maxY - y - 1;
+            _swap(x, y);
+            break;
+        case 2: // ok
+            x = _maxX - x - 1;
+            y = _maxY - y - 1;
+            break;
+        case 3: // ok
+            x = _maxX - x - 1;
+            _swap(x, y);
+            break;
+    }
+}
+
+void TFT_22_ILI9225::_writeRegister(uint16_t reg, uint16_t data)
+{
+    _writeCommand(reg >> 8, reg & 0xff);
+    _startData();
+    _writeData(data);
+    _endData();
+}
+
+void TFT_22_ILI9225::_writeCommand(uint8_t HI, uint8_t LO)
+{
+    _rs = 0;
+    _cs = 0;
+    _spi.write(HI);
+    _spi.write(LO);
+    _cs = 1;
+}
+
+void TFT_22_ILI9225::_startData(void)
+{
+    _rs = 1;
+    _cs = 0;
+}
+
+void TFT_22_ILI9225::_writeData(uint16_t data)
+{
+    _spi.write(data >> 8);
+    _spi.write(data & 0xff);
+}
+
+void TFT_22_ILI9225::_endData(void)
+{
+    _cs = 1;
+}