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:
Mon May 25 16:08:50 2020 +0000
Revision:
206:83edda283d90
Parent:
202:a22cbc04f332
Child:
209:08fc22dea762
Pick up a change in the touch ISR to pick up the final release.

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 // Translate from FT5206 Event Flag to Touch Code to API-match the
WiredHome 165:695c24cc5197 42 // alternate resistive touch screen driver common in the RA8875
WiredHome 165:695c24cc5197 43 // displays.
WiredHome 165:695c24cc5197 44 static const TouchCode_t FT5206_EventFlagToTouchCode[4] = {
WiredHome 165:695c24cc5197 45 touch, // 00b Put Down
WiredHome 165:695c24cc5197 46 release, // 01b Put Up
WiredHome 165:695c24cc5197 47 held, // 10b Contact
WiredHome 165:695c24cc5197 48 no_touch // 11b Reserved
WiredHome 165:695c24cc5197 49 };
WiredHome 165:695c24cc5197 50
WiredHome 165:695c24cc5197 51
WiredHome 165:695c24cc5197 52 RetCode_t RA8875::FT5206_Init() {
WiredHome 178:ae472eb22740 53 const char data[] = {FT5206_DEVICE_MODE, 0};
WiredHome 178:ae472eb22740 54 //const char data[] = {0xC3, 0x55, 0x11, 0x33, 0xAA};
WiredHome 165:695c24cc5197 55
WiredHome 178:ae472eb22740 56 #ifdef DEBUG
WiredHome 178:ae472eb22740 57 int count = 0;
WiredHome 178:ae472eb22740 58 for (int address=0; address<256; address+=2) {
WiredHome 178:ae472eb22740 59 if (!m_i2c->write(address, NULL, 0)) { // 0 returned is ok
WiredHome 178:ae472eb22740 60 INFO("I2C address 0x%02X", address);
WiredHome 178:ae472eb22740 61 count++;
WiredHome 178:ae472eb22740 62 }
WiredHome 178:ae472eb22740 63 }
WiredHome 178:ae472eb22740 64 INFO("%d devices found", count);
WiredHome 178:ae472eb22740 65 #endif
WiredHome 197:853d08e2fb53 66
WiredHome 197:853d08e2fb53 67
WiredHome 178:ae472eb22740 68 INFO("FT5206_Init: Addr %02X", m_addr);
WiredHome 178:ae472eb22740 69 HexDump("FT5206 Init", (uint8_t *)data, sizeof(data)/sizeof(data[0]));
WiredHome 178:ae472eb22740 70 int err = m_i2c->write(m_addr, data, sizeof(data)/sizeof(data[0]), true);
WiredHome 178:ae472eb22740 71 if (err) {
WiredHome 178:ae472eb22740 72 ERR(" result: %d", err);
WiredHome 178:ae472eb22740 73 }
WiredHome 165:695c24cc5197 74 return noerror;
WiredHome 165:695c24cc5197 75 }
WiredHome 165:695c24cc5197 76
WiredHome 165:695c24cc5197 77 uint8_t RA8875::FT5206_TouchPositions(void) {
WiredHome 165:695c24cc5197 78 uint8_t valXH;
WiredHome 165:695c24cc5197 79 uint8_t valYH;
WiredHome 165:695c24cc5197 80
WiredHome 178:ae472eb22740 81 INFO("FT5206_TouchPositions()");
WiredHome 165:695c24cc5197 82 numberOfTouchPoints = FT5206_ReadRegU8(FT5206_TD_STATUS) & 0xF;
WiredHome 178:ae472eb22740 83 INFO(" numOfTouchPoints %d", numberOfTouchPoints);
WiredHome 165:695c24cc5197 84 gesture = FT5206_ReadRegU8(FT5206_GEST_ID);
WiredHome 178:ae472eb22740 85 INFO(" gesture %d", gesture);
WiredHome 197:853d08e2fb53 86
WiredHome 197:853d08e2fb53 87
WiredHome 166:53fd4a876dac 88 valXH = FT5206_ReadRegU8(FT5206_TOUCH5_XH);
WiredHome 166:53fd4a876dac 89 valYH = FT5206_ReadRegU8(FT5206_TOUCH5_YH);
WiredHome 166:53fd4a876dac 90 touchInfo[4].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 181:0032d1b8f5d4 91 INFO(" touchID %d", touchInfo[4].touchCode);
WiredHome 166:53fd4a876dac 92 touchInfo[4].touchID = (valYH >> 4);
WiredHome 202:a22cbc04f332 93 touchInfo[4].coordinates = TranslateOrientation(
WiredHome 202:a22cbc04f332 94 (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH5_XL),
WiredHome 202:a22cbc04f332 95 (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 202:a22cbc04f332 103 touchInfo[3].coordinates = TranslateOrientation(
WiredHome 202:a22cbc04f332 104 (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH4_XL),
WiredHome 202:a22cbc04f332 105 (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH4_YL) );
WiredHome 202:a22cbc04f332 106
WiredHome 197:853d08e2fb53 107
WiredHome 166:53fd4a876dac 108 valXH = FT5206_ReadRegU8(FT5206_TOUCH3_XH);
WiredHome 166:53fd4a876dac 109 valYH = FT5206_ReadRegU8(FT5206_TOUCH3_YH);
WiredHome 166:53fd4a876dac 110 touchInfo[2].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 181:0032d1b8f5d4 111 INFO(" touchID %d", touchInfo[2].touchCode);
WiredHome 166:53fd4a876dac 112 touchInfo[2].touchID = (valYH >> 4);
WiredHome 202:a22cbc04f332 113 touchInfo[2].coordinates = TranslateOrientation(
WiredHome 202:a22cbc04f332 114 (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH3_XL),
WiredHome 202:a22cbc04f332 115 (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH3_YL) );
WiredHome 197:853d08e2fb53 116
WiredHome 197:853d08e2fb53 117
WiredHome 166:53fd4a876dac 118 valXH = FT5206_ReadRegU8(FT5206_TOUCH2_XH);
WiredHome 166:53fd4a876dac 119 valYH = FT5206_ReadRegU8(FT5206_TOUCH2_YH);
WiredHome 166:53fd4a876dac 120 touchInfo[1].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 181:0032d1b8f5d4 121 INFO(" touchID %d", touchInfo[1].touchCode);
WiredHome 166:53fd4a876dac 122 touchInfo[1].touchID = (valYH >> 4);
WiredHome 202:a22cbc04f332 123 touchInfo[1].coordinates = TranslateOrientation(
WiredHome 202:a22cbc04f332 124 (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH2_XL),
WiredHome 202:a22cbc04f332 125 (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH2_YL) );
WiredHome 197:853d08e2fb53 126
WiredHome 197:853d08e2fb53 127
WiredHome 166:53fd4a876dac 128 valXH = FT5206_ReadRegU8(FT5206_TOUCH1_XH);
WiredHome 166:53fd4a876dac 129 valYH = FT5206_ReadRegU8(FT5206_TOUCH1_YH);
WiredHome 166:53fd4a876dac 130 touchInfo[0].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 181:0032d1b8f5d4 131 INFO(" touchID %d", touchInfo[0].touchCode);
WiredHome 166:53fd4a876dac 132 touchInfo[0].touchID = (valYH >> 4);
WiredHome 202:a22cbc04f332 133 touchInfo[0].coordinates = TranslateOrientation(
WiredHome 202:a22cbc04f332 134 (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH1_XL),
WiredHome 202:a22cbc04f332 135 (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH1_YL) );
WiredHome 166:53fd4a876dac 136
WiredHome 165:695c24cc5197 137 return numberOfTouchPoints;
WiredHome 165:695c24cc5197 138 }