This is the David Smart RA8875 Library with mods for working with FRDM-K64F
RA8875_Touch_FT5206.cpp@165:695c24cc5197, 2019-02-24 (annotated)
- Committer:
- WiredHome
- Date:
- Sun Feb 24 00:40:00 2019 +0000
- Revision:
- 165:695c24cc5197
- Child:
- 166:53fd4a876dac
Initial refactoring to add support for another Cap Sense touch controller - based on the GSL1680.
Who changed what in which revision?
User | Revision | Line number | New 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 | 165:695c24cc5197 | 70 | // If the switch statement was based only on numberOfTouchPoints, it would not |
WiredHome | 165:695c24cc5197 | 71 | // be able to generate notification for 'release' events (as it is no longer touched). |
WiredHome | 165:695c24cc5197 | 72 | // Therefore, forcing a 5, and it intentionally falls through each lower case. |
WiredHome | 165:695c24cc5197 | 73 | switch (5) { // numberOfTouchPoints |
WiredHome | 165:695c24cc5197 | 74 | case 5: |
WiredHome | 165:695c24cc5197 | 75 | valXH = FT5206_ReadRegU8(FT5206_TOUCH5_XH); |
WiredHome | 165:695c24cc5197 | 76 | valYH = FT5206_ReadRegU8(FT5206_TOUCH5_YH); |
WiredHome | 165:695c24cc5197 | 77 | touchInfo[4].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6]; |
WiredHome | 165:695c24cc5197 | 78 | touchInfo[4].touchID = (valYH >> 4); |
WiredHome | 165:695c24cc5197 | 79 | touchInfo[4].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH5_XL); |
WiredHome | 165:695c24cc5197 | 80 | touchInfo[4].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH5_YL); |
WiredHome | 165:695c24cc5197 | 81 | if (touchInfo[4].touchCode) |
WiredHome | 165:695c24cc5197 | 82 | INFO(" Touch[%d] code %d, id %2d, (%4d,%4d)", |
WiredHome | 165:695c24cc5197 | 83 | 5, |
WiredHome | 165:695c24cc5197 | 84 | touchInfo[4].touchCode, |
WiredHome | 165:695c24cc5197 | 85 | touchInfo[4].touchID, |
WiredHome | 165:695c24cc5197 | 86 | touchInfo[4].coordinates.x, |
WiredHome | 165:695c24cc5197 | 87 | touchInfo[4].coordinates.y); |
WiredHome | 165:695c24cc5197 | 88 | case 4: |
WiredHome | 165:695c24cc5197 | 89 | valXH = FT5206_ReadRegU8(FT5206_TOUCH4_XH); |
WiredHome | 165:695c24cc5197 | 90 | valYH = FT5206_ReadRegU8(FT5206_TOUCH4_YH); |
WiredHome | 165:695c24cc5197 | 91 | touchInfo[3].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6]; |
WiredHome | 165:695c24cc5197 | 92 | touchInfo[3].touchID = (valYH >> 4); |
WiredHome | 165:695c24cc5197 | 93 | touchInfo[3].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH4_XL); |
WiredHome | 165:695c24cc5197 | 94 | touchInfo[3].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH4_YL); |
WiredHome | 165:695c24cc5197 | 95 | if (touchInfo[3].touchCode) |
WiredHome | 165:695c24cc5197 | 96 | INFO(" Touch[%d] code %d, id %2d, (%4d,%4d)", |
WiredHome | 165:695c24cc5197 | 97 | 4, |
WiredHome | 165:695c24cc5197 | 98 | touchInfo[3].touchCode, |
WiredHome | 165:695c24cc5197 | 99 | touchInfo[3].touchID, |
WiredHome | 165:695c24cc5197 | 100 | touchInfo[3].coordinates.x, |
WiredHome | 165:695c24cc5197 | 101 | touchInfo[3].coordinates.y); |
WiredHome | 165:695c24cc5197 | 102 | case 3: |
WiredHome | 165:695c24cc5197 | 103 | valXH = FT5206_ReadRegU8(FT5206_TOUCH3_XH); |
WiredHome | 165:695c24cc5197 | 104 | valYH = FT5206_ReadRegU8(FT5206_TOUCH3_YH); |
WiredHome | 165:695c24cc5197 | 105 | touchInfo[2].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6]; |
WiredHome | 165:695c24cc5197 | 106 | touchInfo[2].touchID = (valYH >> 4); |
WiredHome | 165:695c24cc5197 | 107 | touchInfo[2].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH3_XL); |
WiredHome | 165:695c24cc5197 | 108 | touchInfo[2].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH3_YL); |
WiredHome | 165:695c24cc5197 | 109 | if (touchInfo[2].touchCode) |
WiredHome | 165:695c24cc5197 | 110 | INFO(" Touch[%d] code %d, id %2d, (%4d,%4d)", |
WiredHome | 165:695c24cc5197 | 111 | 3, |
WiredHome | 165:695c24cc5197 | 112 | touchInfo[2].touchCode, |
WiredHome | 165:695c24cc5197 | 113 | touchInfo[2].touchID, |
WiredHome | 165:695c24cc5197 | 114 | touchInfo[2].coordinates.x, |
WiredHome | 165:695c24cc5197 | 115 | touchInfo[2].coordinates.y); |
WiredHome | 165:695c24cc5197 | 116 | case 2: |
WiredHome | 165:695c24cc5197 | 117 | valXH = FT5206_ReadRegU8(FT5206_TOUCH2_XH); |
WiredHome | 165:695c24cc5197 | 118 | valYH = FT5206_ReadRegU8(FT5206_TOUCH2_YH); |
WiredHome | 165:695c24cc5197 | 119 | touchInfo[1].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6]; |
WiredHome | 165:695c24cc5197 | 120 | touchInfo[1].touchID = (valYH >> 4); |
WiredHome | 165:695c24cc5197 | 121 | touchInfo[1].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH2_XL); |
WiredHome | 165:695c24cc5197 | 122 | touchInfo[1].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH2_YL); |
WiredHome | 165:695c24cc5197 | 123 | if (touchInfo[1].touchCode) |
WiredHome | 165:695c24cc5197 | 124 | INFO(" Touch[%d] code %d, id %2d, (%4d,%4d)", |
WiredHome | 165:695c24cc5197 | 125 | 2, |
WiredHome | 165:695c24cc5197 | 126 | touchInfo[1].touchCode, |
WiredHome | 165:695c24cc5197 | 127 | touchInfo[1].touchID, |
WiredHome | 165:695c24cc5197 | 128 | touchInfo[1].coordinates.x, |
WiredHome | 165:695c24cc5197 | 129 | touchInfo[1].coordinates.y); |
WiredHome | 165:695c24cc5197 | 130 | case 1: |
WiredHome | 165:695c24cc5197 | 131 | valXH = FT5206_ReadRegU8(FT5206_TOUCH1_XH); |
WiredHome | 165:695c24cc5197 | 132 | valYH = FT5206_ReadRegU8(FT5206_TOUCH1_YH); |
WiredHome | 165:695c24cc5197 | 133 | touchInfo[0].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6]; |
WiredHome | 165:695c24cc5197 | 134 | touchInfo[0].touchID = (valYH >> 4); |
WiredHome | 165:695c24cc5197 | 135 | touchInfo[0].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH1_XL); |
WiredHome | 165:695c24cc5197 | 136 | touchInfo[0].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH1_YL); |
WiredHome | 165:695c24cc5197 | 137 | if (touchInfo[0].touchCode) |
WiredHome | 165:695c24cc5197 | 138 | INFO(" Touch[%d] code %d, id %2d, (%4d,%4d)", |
WiredHome | 165:695c24cc5197 | 139 | 1, |
WiredHome | 165:695c24cc5197 | 140 | touchInfo[0].touchCode, |
WiredHome | 165:695c24cc5197 | 141 | touchInfo[0].touchID, |
WiredHome | 165:695c24cc5197 | 142 | touchInfo[0].coordinates.x, |
WiredHome | 165:695c24cc5197 | 143 | touchInfo[0].coordinates.y); |
WiredHome | 165:695c24cc5197 | 144 | break; |
WiredHome | 165:695c24cc5197 | 145 | default: |
WiredHome | 165:695c24cc5197 | 146 | break; |
WiredHome | 165:695c24cc5197 | 147 | } |
WiredHome | 165:695c24cc5197 | 148 | return numberOfTouchPoints; |
WiredHome | 165:695c24cc5197 | 149 | } |