Uses the same fonts as the SPI_TFT_ILI9341 Library (I have many, and a html/php font editor for that)
Diff: SPI_TFT_ILI9225.cpp
- Revision:
- 3:41e8d7dc279a
- Parent:
- 2:e213811335ac
- Child:
- 4:44a66bd8c16c
--- a/SPI_TFT_ILI9225.cpp Wed Nov 23 01:25:19 2016 +0000 +++ b/SPI_TFT_ILI9225.cpp Wed Nov 23 09:39:54 2016 +0000 @@ -183,7 +183,7 @@ cls(); linespacing(0); setBacklight(1.0f); - setOrientation(ILI9225_LANDSCAPE_B); + setOrientation(ILI9225_PORTRAIT_L); foreground(COLOR_WHITE); background(COLOR_BLACK); } @@ -245,25 +245,43 @@ void TFT_22_ILI9225::setOrientation(uint8_t orientation) { _orientation = orientation % 4; - + // Entry Mode (R03h) + // 0x1000 AM = 0: Horizontal, I/D[1:0] = 00: Horizontal: decrement, Vertical: decrement - ILI9225_PORTRAIT_R + // 0x1010 AM = 0: Horizontal, I/D[1:0] = 01: Horizontal: increment, Vertical: decrement + // 0x1020 AM = 0: Horizontal, I/D[1:0] = 10: Horizontal: decrement, Vertical: increment + // 0x1030 AM = 0: Horizontal, I/D[1:0] = 11: Horizontal: increment, Vertical: increment - ILI9225_PORTRAIT_L + // 0x1008 AM = 1: Vertical, I/D[1:0] = 00: Horizontal: decrement, Vertical: decrement + // 0x1018 AM = 1: Vertical, I/D[1:0] = 01: Horizontal: increment, Vertical: decrement - ILI9225_LANDSCAPE_T + // 0x1028 AM = 1: Vertical, I/D[1:0] = 10: Horizontal: decrement, Vertical: increment - ILI9225_LANDSCAPE_B + // 0x1038 AM = 1: Vertical, I/D[1:0] = 11: Horizontal: increment, Vertical: increment + uint16_t entryMode; switch (_orientation) { - case 0: - _maxX = ILI9225_LCD_WIDTH; - _maxY = ILI9225_LCD_HEIGHT; - break; - case 1: - _maxX = ILI9225_LCD_HEIGHT; - _maxY = ILI9225_LCD_WIDTH; - break; - case 2: - _maxX = ILI9225_LCD_WIDTH; - _maxY = ILI9225_LCD_HEIGHT; - break; - case 3: - _maxX = ILI9225_LCD_HEIGHT; - _maxY = ILI9225_LCD_WIDTH; - break; + case ILI9225_PORTRAIT_L: + // 0x1030 AM = 0: Horizontal, I/D[1:0] = 11: Horizontal: increment, Vertical: increment + entryMode = 0x1030; + _maxX = ILI9225_LCD_WIDTH; + _maxY = ILI9225_LCD_HEIGHT; + break; + case ILI9225_LANDSCAPE_B: + // 0x1028 AM = 1: Vertical, I/D[1:0] = 10: Horizontal: decrement, Vertical: increment + entryMode = 0x1028; + _maxX = ILI9225_LCD_HEIGHT; + _maxY = ILI9225_LCD_WIDTH; + break; + case ILI9225_PORTRAIT_R: + // 0x1000 AM = 0: Horizontal, I/D[1:0] = 00: Horizontal: decrement, Vertical: decrement + entryMode = 0x1000; + _maxX = ILI9225_LCD_WIDTH; + _maxY = ILI9225_LCD_HEIGHT; + break; + case ILI9225_LANDSCAPE_T: + // 0x1018 AM = 1: Vertical, I/D[1:0] = 01: Horizontal: increment, Vertical: decrement + entryMode = 0x1018; + _maxX = ILI9225_LCD_HEIGHT; + _maxY = ILI9225_LCD_WIDTH; + break; } + _writeRegister(ILI9225_ENTRY_MODE, entryMode); // set GRAM write direction and BGR=1. } uint8_t TFT_22_ILI9225::getOrientation() { @@ -391,9 +409,11 @@ _setWindow(x1, y1, x1 + 1, y1 + 1); _orientCoordinates(x1, y1); - _startData(); - _writeData(color); - _endData(); + _rs = 1; + _cs = 0; + spi.write(color >> 8); + spi.write(color & 0xff); + _cs = 1; } uint16_t TFT_22_ILI9225::maxX(void) { @@ -566,7 +586,7 @@ void TFT_22_ILI9225::character(int x, int y, int c) { - unsigned int hor, vert, offset, bpl, b; + unsigned int hor, vert, offset, bpl, i, j, b; unsigned char* zeichen; unsigned char z,w; @@ -591,27 +611,9 @@ w = zeichen[0]; // width of actual char _startData(); - switch (_orientation) { - case 0: // Portrait - for (int j=0; j < vert; j++) { // vert line - for (int i=0; i<hor; i++) { // horz line - z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; - b = 1 << (j & 0x07); - if (( z & b ) == 0x00) { - spi.write(_background >> 8); - spi.write(_background & 0xff); - } else { - spi.write(_foreground >> 8); - spi.write(_foreground & 0xff); - } - } - } - break; - case 1: - // Landscape - for (int i=0; i<hor; i++) { // horz line - for (int j=vert-1; j>=0; j--) { // vert line + for (j = 0; j < vert; j++) { // vert line + for (i = 0; i < hor; i++) { // horz line z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; b = 1 << (j & 0x07); if (( z & b ) == 0x00) { @@ -623,40 +625,73 @@ } } } - break; - case 2: - // Portrait - for (int j=vert-1; j>=0; j--) { // vert line - for (int i=hor-1; i>=0; i--) { // horz line - z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; - b = 1 << (j & 0x07); - if (( z & b ) == 0x00) { - spi.write(_background >> 8); - spi.write(_background & 0xff); - } else { - spi.write(_foreground >> 8); - spi.write(_foreground & 0xff); - } - } - } - break; - case 3: - // Landscape - for (int i=hor-1; i>= 0; i--) { // horz line - for (int j=0; j<vert; j++) { // vert line - z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; - b = 1 << (j & 0x07); - if (( z & b ) == 0x00) { - spi.write(_background >> 8); - spi.write(_background & 0xff); - } else { - spi.write(_foreground >> 8); - spi.write(_foreground & 0xff); - } - } - } - break; - } + +// switch (_orientation) { +// case 0: +// // Portrait +// for (j = 0; j < vert; j++) { // vert line +// for (i = 0; i < hor; i++) { // horz line +// z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; +// b = 1 << (j & 0x07); +// if (( z & b ) == 0x00) { +// spi.write(_background >> 8); +// spi.write(_background & 0xff); +// } else { +// spi.write(_foreground >> 8); +// spi.write(_foreground & 0xff); +// } +// } +// } +// break; +// case 1: +// // Landscape +// for (int i=0; i<hor; i++) { // horz line +// for (int j=vert-1; j>=0; j--) { // vert line +// z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; +// b = 1 << (j & 0x07); +// if (( z & b ) == 0x00) { +// spi.write(_background >> 8); +// spi.write(_background & 0xff); +// } else { +// spi.write(_foreground >> 8); +// spi.write(_foreground & 0xff); +// } +// } +// } +// break; +// case 2: +// // Portrait +// for (int j=vert-1; j>=0; j--) { // vert line +// for (int i=hor-1; i>=0; i--) { // horz line +// z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; +// b = 1 << (j & 0x07); +// if (( z & b ) == 0x00) { +// spi.write(_background >> 8); +// spi.write(_background & 0xff); +// } else { +// spi.write(_foreground >> 8); +// spi.write(_foreground & 0xff); +// } +// } +// } +// break; +// case 3: +// // Landscape +// for (int i=hor-1; i>= 0; i--) { // horz line +// for (int j=0; j<vert; j++) { // vert line +// z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; +// b = 1 << (j & 0x07); +// if (( z & b ) == 0x00) { +// spi.write(_background >> 8); +// spi.write(_background & 0xff); +// } else { +// spi.write(_foreground >> 8); +// spi.write(_foreground & 0xff); +// } +// } +// } +// break; +// } _endData(); _setWindowMax();