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 Feb 24 19:28:26 2019 +0000
Revision:
166:53fd4a876dac
Parent:
165:695c24cc5197
Child:
178:ae472eb22740
Some refactoring, but mostly to improve support for GSL1680 controller to extract the touch id.

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 165:695c24cc5197 54 char data[2] = {FT5206_DEVICE_MODE, 0};
WiredHome 165:695c24cc5197 55
WiredHome 165:695c24cc5197 56 m_i2c->write(m_addr, data, 2);
WiredHome 165:695c24cc5197 57 return noerror;
WiredHome 165:695c24cc5197 58 }
WiredHome 165:695c24cc5197 59
WiredHome 165:695c24cc5197 60 uint8_t RA8875::FT5206_TouchPositions(void) {
WiredHome 165:695c24cc5197 61 uint8_t valXH;
WiredHome 165:695c24cc5197 62 uint8_t valYH;
WiredHome 165:695c24cc5197 63
WiredHome 165:695c24cc5197 64 //INFO("FT5206_TouchPositions()");
WiredHome 165:695c24cc5197 65 numberOfTouchPoints = FT5206_ReadRegU8(FT5206_TD_STATUS) & 0xF;
WiredHome 165:695c24cc5197 66 //INFO(" numOfTouchPoints %d", numberOfTouchPoints);
WiredHome 165:695c24cc5197 67 gesture = FT5206_ReadRegU8(FT5206_GEST_ID);
WiredHome 165:695c24cc5197 68 //INFO(" gesture %d", gesture);
WiredHome 165:695c24cc5197 69
WiredHome 166:53fd4a876dac 70 valXH = FT5206_ReadRegU8(FT5206_TOUCH5_XH);
WiredHome 166:53fd4a876dac 71 valYH = FT5206_ReadRegU8(FT5206_TOUCH5_YH);
WiredHome 166:53fd4a876dac 72 touchInfo[4].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 166:53fd4a876dac 73 touchInfo[4].touchID = (valYH >> 4);
WiredHome 166:53fd4a876dac 74 touchInfo[4].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH5_XL);
WiredHome 166:53fd4a876dac 75 touchInfo[4].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH5_YL);
WiredHome 166:53fd4a876dac 76
WiredHome 166:53fd4a876dac 77 valXH = FT5206_ReadRegU8(FT5206_TOUCH4_XH);
WiredHome 166:53fd4a876dac 78 valYH = FT5206_ReadRegU8(FT5206_TOUCH4_YH);
WiredHome 166:53fd4a876dac 79 touchInfo[3].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 166:53fd4a876dac 80 touchInfo[3].touchID = (valYH >> 4);
WiredHome 166:53fd4a876dac 81 touchInfo[3].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH4_XL);
WiredHome 166:53fd4a876dac 82 touchInfo[3].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH4_YL);
WiredHome 166:53fd4a876dac 83
WiredHome 166:53fd4a876dac 84 valXH = FT5206_ReadRegU8(FT5206_TOUCH3_XH);
WiredHome 166:53fd4a876dac 85 valYH = FT5206_ReadRegU8(FT5206_TOUCH3_YH);
WiredHome 166:53fd4a876dac 86 touchInfo[2].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 166:53fd4a876dac 87 touchInfo[2].touchID = (valYH >> 4);
WiredHome 166:53fd4a876dac 88 touchInfo[2].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH3_XL);
WiredHome 166:53fd4a876dac 89 touchInfo[2].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH3_YL);
WiredHome 166:53fd4a876dac 90
WiredHome 166:53fd4a876dac 91 valXH = FT5206_ReadRegU8(FT5206_TOUCH2_XH);
WiredHome 166:53fd4a876dac 92 valYH = FT5206_ReadRegU8(FT5206_TOUCH2_YH);
WiredHome 166:53fd4a876dac 93 touchInfo[1].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 166:53fd4a876dac 94 touchInfo[1].touchID = (valYH >> 4);
WiredHome 166:53fd4a876dac 95 touchInfo[1].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH2_XL);
WiredHome 166:53fd4a876dac 96 touchInfo[1].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH2_YL);
WiredHome 166:53fd4a876dac 97
WiredHome 166:53fd4a876dac 98 valXH = FT5206_ReadRegU8(FT5206_TOUCH1_XH);
WiredHome 166:53fd4a876dac 99 valYH = FT5206_ReadRegU8(FT5206_TOUCH1_YH);
WiredHome 166:53fd4a876dac 100 touchInfo[0].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
WiredHome 166:53fd4a876dac 101 touchInfo[0].touchID = (valYH >> 4);
WiredHome 166:53fd4a876dac 102 touchInfo[0].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH1_XL);
WiredHome 166:53fd4a876dac 103 touchInfo[0].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH1_YL);
WiredHome 166:53fd4a876dac 104
WiredHome 165:695c24cc5197 105 return numberOfTouchPoints;
WiredHome 165:695c24cc5197 106 }