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:
Thu Aug 08 11:29:48 2019 +0000
Revision:
183:808f272e481e
Parent:
181:0032d1b8f5d4
Child:
197:853d08e2fb53
Minor code-cleanup

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 165:695c24cc5197 10 #define INFO(x, ...) std::printf("[INF %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 165:695c24cc5197 11 #define WARN(x, ...) std::printf("[WRN %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 165:695c24cc5197 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 178:ae472eb22740 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 165:695c24cc5197 86
WiredHome 166:53fd4a876dac 87 valXH = FT5206_ReadRegU8(FT5206_TOUCH5_XH);
WiredHome 166:53fd4a876dac 88 valYH = FT5206_ReadRegU8(FT5206_TOUCH5_YH);
WiredHome 166:53fd4a876dac 89 touchInfo[4].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 181:0032d1b8f5d4 90 INFO(" touchID %d", touchInfo[4].touchCode);
WiredHome 166:53fd4a876dac 91 touchInfo[4].touchID = (valYH >> 4);
WiredHome 166:53fd4a876dac 92 touchInfo[4].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH5_XL);
WiredHome 166:53fd4a876dac 93 touchInfo[4].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH5_YL);
WiredHome 166:53fd4a876dac 94
WiredHome 166:53fd4a876dac 95 valXH = FT5206_ReadRegU8(FT5206_TOUCH4_XH);
WiredHome 166:53fd4a876dac 96 valYH = FT5206_ReadRegU8(FT5206_TOUCH4_YH);
WiredHome 166:53fd4a876dac 97 touchInfo[3].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 181:0032d1b8f5d4 98 INFO(" touchID %d", touchInfo[3].touchCode);
WiredHome 166:53fd4a876dac 99 touchInfo[3].touchID = (valYH >> 4);
WiredHome 166:53fd4a876dac 100 touchInfo[3].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH4_XL);
WiredHome 166:53fd4a876dac 101 touchInfo[3].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH4_YL);
WiredHome 166:53fd4a876dac 102
WiredHome 166:53fd4a876dac 103 valXH = FT5206_ReadRegU8(FT5206_TOUCH3_XH);
WiredHome 166:53fd4a876dac 104 valYH = FT5206_ReadRegU8(FT5206_TOUCH3_YH);
WiredHome 166:53fd4a876dac 105 touchInfo[2].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 181:0032d1b8f5d4 106 INFO(" touchID %d", touchInfo[2].touchCode);
WiredHome 166:53fd4a876dac 107 touchInfo[2].touchID = (valYH >> 4);
WiredHome 166:53fd4a876dac 108 touchInfo[2].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH3_XL);
WiredHome 166:53fd4a876dac 109 touchInfo[2].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH3_YL);
WiredHome 166:53fd4a876dac 110
WiredHome 166:53fd4a876dac 111 valXH = FT5206_ReadRegU8(FT5206_TOUCH2_XH);
WiredHome 166:53fd4a876dac 112 valYH = FT5206_ReadRegU8(FT5206_TOUCH2_YH);
WiredHome 166:53fd4a876dac 113 touchInfo[1].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 181:0032d1b8f5d4 114 INFO(" touchID %d", touchInfo[1].touchCode);
WiredHome 166:53fd4a876dac 115 touchInfo[1].touchID = (valYH >> 4);
WiredHome 166:53fd4a876dac 116 touchInfo[1].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH2_XL);
WiredHome 166:53fd4a876dac 117 touchInfo[1].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH2_YL);
WiredHome 166:53fd4a876dac 118
WiredHome 166:53fd4a876dac 119 valXH = FT5206_ReadRegU8(FT5206_TOUCH1_XH);
WiredHome 166:53fd4a876dac 120 valYH = FT5206_ReadRegU8(FT5206_TOUCH1_YH);
WiredHome 166:53fd4a876dac 121 touchInfo[0].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 181:0032d1b8f5d4 122 INFO(" touchID %d", touchInfo[0].touchCode);
WiredHome 166:53fd4a876dac 123 touchInfo[0].touchID = (valYH >> 4);
WiredHome 166:53fd4a876dac 124 touchInfo[0].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH1_XL);
WiredHome 166:53fd4a876dac 125 touchInfo[0].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH1_YL);
WiredHome 166:53fd4a876dac 126
WiredHome 165:695c24cc5197 127 return numberOfTouchPoints;
WiredHome 165:695c24cc5197 128 }