Library to control a Graphics TFT connected to 4-wire SPI - revised for the Raio RA8875 Display Controller.

Dependents:   FRDM_RA8875_mPaint RA8875_Demo RA8875_KeyPadDemo SignalGenerator ... more

Fork of SPI_TFT by Peter Drescher

See Components - RA8875 Based Display

Enhanced touch-screen support - where it previous supported both the Resistive Touch and Capacitive Touch based on the FT5206 Touch Controller, now it also has support for the GSL1680 Touch Controller.

Offline Help Manual (Windows chm)

/media/uploads/WiredHome/ra8875.zip.bin (download, rename to .zip and unzip)

Committer:
WiredHome
Date:
Sun Mar 29 18:12:24 2020 +0000
Revision:
201:0b25d24d9bda
Parent:
197:853d08e2fb53
Child:
202:a22cbc04f332
Correct a defect in JPEG Rendering that came in when window() changed to SetWindow();

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 165:695c24cc5197 1
WiredHome 165:695c24cc5197 2
WiredHome 165:695c24cc5197 3 #include "RA8875.h"
WiredHome 165:695c24cc5197 4
WiredHome 165:695c24cc5197 5 //#define DEBUG "RAFT" // RA8875 FT5206
WiredHome 165:695c24cc5197 6 // ...
WiredHome 165:695c24cc5197 7 // INFO("Stuff to show %d", var); // new-line is automatically appended
WiredHome 165:695c24cc5197 8 //
WiredHome 165:695c24cc5197 9 #if (defined(DEBUG) && !defined(TARGET_LPC11U24))
WiredHome 197:853d08e2fb53 10 #define INFO(x, ...) std::printf("[INF %s %4d] " x "\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 197:853d08e2fb53 11 #define WARN(x, ...) std::printf("[WRN %s %4d] " x "\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 197:853d08e2fb53 12 #define ERR(x, ...) std::printf("[ERR %s %4d] " x "\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 165:695c24cc5197 13 static void HexDump(const char * title, const uint8_t * p, int count)
WiredHome 165:695c24cc5197 14 {
WiredHome 165:695c24cc5197 15 int i;
WiredHome 165:695c24cc5197 16 char buf[100] = "0000: ";
WiredHome 165:695c24cc5197 17
WiredHome 165:695c24cc5197 18 if (*title)
WiredHome 165:695c24cc5197 19 INFO("%s", title);
WiredHome 165:695c24cc5197 20 for (i=0; i<count; ) {
WiredHome 165:695c24cc5197 21 sprintf(buf + strlen(buf), "%02X ", *(p+i));
WiredHome 165:695c24cc5197 22 if ((++i & 0x0F) == 0x00) {
WiredHome 165:695c24cc5197 23 INFO("%s", buf);
WiredHome 165:695c24cc5197 24 if (i < count)
WiredHome 165:695c24cc5197 25 sprintf(buf, "%04X: ", i);
WiredHome 165:695c24cc5197 26 else
WiredHome 165:695c24cc5197 27 buf[0] = '\0';
WiredHome 165:695c24cc5197 28 }
WiredHome 165:695c24cc5197 29 }
WiredHome 165:695c24cc5197 30 if (strlen(buf))
WiredHome 165:695c24cc5197 31 INFO("%s", buf);
WiredHome 165:695c24cc5197 32 }
WiredHome 165:695c24cc5197 33 #else
WiredHome 165:695c24cc5197 34 #define INFO(x, ...)
WiredHome 165:695c24cc5197 35 #define WARN(x, ...)
WiredHome 165:695c24cc5197 36 #define ERR(x, ...)
WiredHome 165:695c24cc5197 37 #define HexDump(a, b, c)
WiredHome 165:695c24cc5197 38 #endif
WiredHome 165:695c24cc5197 39
WiredHome 165:695c24cc5197 40
WiredHome 165:695c24cc5197 41
WiredHome 165:695c24cc5197 42 // Translate from FT5206 Event Flag to Touch Code to API-match the
WiredHome 165:695c24cc5197 43 // alternate resistive touch screen driver common in the RA8875
WiredHome 165:695c24cc5197 44 // displays.
WiredHome 165:695c24cc5197 45 static const TouchCode_t FT5206_EventFlagToTouchCode[4] = {
WiredHome 165:695c24cc5197 46 touch, // 00b Put Down
WiredHome 165:695c24cc5197 47 release, // 01b Put Up
WiredHome 165:695c24cc5197 48 held, // 10b Contact
WiredHome 165:695c24cc5197 49 no_touch // 11b Reserved
WiredHome 165:695c24cc5197 50 };
WiredHome 165:695c24cc5197 51
WiredHome 165:695c24cc5197 52
WiredHome 165:695c24cc5197 53 RetCode_t RA8875::FT5206_Init() {
WiredHome 178:ae472eb22740 54 const char data[] = {FT5206_DEVICE_MODE, 0};
WiredHome 178:ae472eb22740 55 //const char data[] = {0xC3, 0x55, 0x11, 0x33, 0xAA};
WiredHome 165:695c24cc5197 56
WiredHome 178:ae472eb22740 57 #ifdef DEBUG
WiredHome 178:ae472eb22740 58 int count = 0;
WiredHome 178:ae472eb22740 59 for (int address=0; address<256; address+=2) {
WiredHome 178:ae472eb22740 60 if (!m_i2c->write(address, NULL, 0)) { // 0 returned is ok
WiredHome 178:ae472eb22740 61 INFO("I2C address 0x%02X", address);
WiredHome 178:ae472eb22740 62 count++;
WiredHome 178:ae472eb22740 63 }
WiredHome 178:ae472eb22740 64 }
WiredHome 178:ae472eb22740 65 INFO("%d devices found", count);
WiredHome 178:ae472eb22740 66 #endif
WiredHome 197:853d08e2fb53 67
WiredHome 197:853d08e2fb53 68
WiredHome 178:ae472eb22740 69 INFO("FT5206_Init: Addr %02X", m_addr);
WiredHome 178:ae472eb22740 70 HexDump("FT5206 Init", (uint8_t *)data, sizeof(data)/sizeof(data[0]));
WiredHome 178:ae472eb22740 71 int err = m_i2c->write(m_addr, data, sizeof(data)/sizeof(data[0]), true);
WiredHome 178:ae472eb22740 72 if (err) {
WiredHome 178:ae472eb22740 73 ERR(" result: %d", err);
WiredHome 178:ae472eb22740 74 }
WiredHome 165:695c24cc5197 75 return noerror;
WiredHome 165:695c24cc5197 76 }
WiredHome 165:695c24cc5197 77
WiredHome 165:695c24cc5197 78 uint8_t RA8875::FT5206_TouchPositions(void) {
WiredHome 165:695c24cc5197 79 uint8_t valXH;
WiredHome 165:695c24cc5197 80 uint8_t valYH;
WiredHome 165:695c24cc5197 81
WiredHome 178:ae472eb22740 82 INFO("FT5206_TouchPositions()");
WiredHome 165:695c24cc5197 83 numberOfTouchPoints = FT5206_ReadRegU8(FT5206_TD_STATUS) & 0xF;
WiredHome 178:ae472eb22740 84 INFO(" numOfTouchPoints %d", numberOfTouchPoints);
WiredHome 165:695c24cc5197 85 gesture = FT5206_ReadRegU8(FT5206_GEST_ID);
WiredHome 178:ae472eb22740 86 INFO(" gesture %d", gesture);
WiredHome 197:853d08e2fb53 87
WiredHome 197:853d08e2fb53 88
WiredHome 166:53fd4a876dac 89 valXH = FT5206_ReadRegU8(FT5206_TOUCH5_XH);
WiredHome 166:53fd4a876dac 90 valYH = FT5206_ReadRegU8(FT5206_TOUCH5_YH);
WiredHome 166:53fd4a876dac 91 touchInfo[4].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 181:0032d1b8f5d4 92 INFO(" touchID %d", touchInfo[4].touchCode);
WiredHome 166:53fd4a876dac 93 touchInfo[4].touchID = (valYH >> 4);
WiredHome 166:53fd4a876dac 94 touchInfo[4].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH5_XL);
WiredHome 166:53fd4a876dac 95 touchInfo[4].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH5_YL);
WiredHome 197:853d08e2fb53 96
WiredHome 197:853d08e2fb53 97
WiredHome 166:53fd4a876dac 98 valXH = FT5206_ReadRegU8(FT5206_TOUCH4_XH);
WiredHome 166:53fd4a876dac 99 valYH = FT5206_ReadRegU8(FT5206_TOUCH4_YH);
WiredHome 166:53fd4a876dac 100 touchInfo[3].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 181:0032d1b8f5d4 101 INFO(" touchID %d", touchInfo[3].touchCode);
WiredHome 166:53fd4a876dac 102 touchInfo[3].touchID = (valYH >> 4);
WiredHome 166:53fd4a876dac 103 touchInfo[3].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH4_XL);
WiredHome 166:53fd4a876dac 104 touchInfo[3].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH4_YL);
WiredHome 197:853d08e2fb53 105
WiredHome 197:853d08e2fb53 106
WiredHome 166:53fd4a876dac 107 valXH = FT5206_ReadRegU8(FT5206_TOUCH3_XH);
WiredHome 166:53fd4a876dac 108 valYH = FT5206_ReadRegU8(FT5206_TOUCH3_YH);
WiredHome 166:53fd4a876dac 109 touchInfo[2].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 181:0032d1b8f5d4 110 INFO(" touchID %d", touchInfo[2].touchCode);
WiredHome 166:53fd4a876dac 111 touchInfo[2].touchID = (valYH >> 4);
WiredHome 166:53fd4a876dac 112 touchInfo[2].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH3_XL);
WiredHome 166:53fd4a876dac 113 touchInfo[2].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH3_YL);
WiredHome 197:853d08e2fb53 114
WiredHome 197:853d08e2fb53 115
WiredHome 166:53fd4a876dac 116 valXH = FT5206_ReadRegU8(FT5206_TOUCH2_XH);
WiredHome 166:53fd4a876dac 117 valYH = FT5206_ReadRegU8(FT5206_TOUCH2_YH);
WiredHome 166:53fd4a876dac 118 touchInfo[1].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 181:0032d1b8f5d4 119 INFO(" touchID %d", touchInfo[1].touchCode);
WiredHome 166:53fd4a876dac 120 touchInfo[1].touchID = (valYH >> 4);
WiredHome 166:53fd4a876dac 121 touchInfo[1].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH2_XL);
WiredHome 166:53fd4a876dac 122 touchInfo[1].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH2_YL);
WiredHome 197:853d08e2fb53 123
WiredHome 197:853d08e2fb53 124
WiredHome 166:53fd4a876dac 125 valXH = FT5206_ReadRegU8(FT5206_TOUCH1_XH);
WiredHome 166:53fd4a876dac 126 valYH = FT5206_ReadRegU8(FT5206_TOUCH1_YH);
WiredHome 166:53fd4a876dac 127 touchInfo[0].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 181:0032d1b8f5d4 128 INFO(" touchID %d", touchInfo[0].touchCode);
WiredHome 166:53fd4a876dac 129 touchInfo[0].touchID = (valYH >> 4);
WiredHome 166:53fd4a876dac 130 touchInfo[0].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH1_XL);
WiredHome 166:53fd4a876dac 131 touchInfo[0].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH1_YL);
WiredHome 166:53fd4a876dac 132
WiredHome 165:695c24cc5197 133 return numberOfTouchPoints;
WiredHome 165:695c24cc5197 134 }