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
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)
Revision 181:0032d1b8f5d4, committed 2019-08-02
- Comitter:
- WiredHome
- Date:
- Fri Aug 02 02:12:26 2019 +0000
- Parent:
- 180:d8abf2e70b88
- Child:
- 182:8832d03a2a29
- Commit message:
- A bit of experimenting on rotation.
Changed in this revision
--- a/RA8875.cpp Thu Aug 01 22:35:29 2019 +0000 +++ b/RA8875.cpp Fri Aug 02 02:12:26 2019 +0000 @@ -247,7 +247,7 @@ #if MBED_VERSION >= MBED_ENCODE_VERSION(5,8,0) eventThread.start(callback(&queue, &EventQueue::dispatch_forever)); m_irq->fall(queue.event(callback(this, &RA8875::TouchPanelISR))); - #elif (MBED_MAJOR_VERSION >= 5) || (MBED_LIBRARY_VERSION > 128) // Is this the right version? + #elif (MBED_MAJOR_VERSION >= 5) || (MBED_LIBRARY_VERSION > 127) m_irq->fall(callback(this, &RA8875::TouchPanelISR)); #else m_irq->fall(this, &RA8875::TouchPanelISR); @@ -295,7 +295,7 @@ #if MBED_VERSION >= MBED_ENCODE_VERSION(5,8,0) eventThread.start(callback(&queue, &EventQueue::dispatch_forever)); m_irq->fall(queue.event(callback(this, &RA8875::TouchPanelISR))); - #elif (MBED_MAJOR_VERSION >= 5) || (MBED_LIBRARY_VERSION > 128) // Is this the right version? + #elif (MBED_MAJOR_VERSION >= 5) || (MBED_LIBRARY_VERSION > 127) m_irq->fall(callback(this, &RA8875::TouchPanelISR)); #else m_irq->fall(this, &RA8875::TouchPanelISR); @@ -1110,7 +1110,9 @@ { uint8_t fncr1Val = ReadCommand(0x22); uint8_t dpcrVal = ReadCommand(0x20); + RetCode_t r; + screen_orientation = angle; fncr1Val &= ~0x10; // remove the old direction bit dpcrVal &= ~0x0C; // remove the old scan direction bits switch (angle) { @@ -1138,8 +1140,9 @@ return bad_parameter; } INFO("Orientation: %d, %d", angle, portraitmode); - WriteCommand(RA8875_FNCR1, fncr1Val); - return WriteCommand(RA8875_DPCR, dpcrVal); + r = WriteCommand(RA8875_FNCR1, fncr1Val); + r = WriteCommand(RA8875_DPCR, dpcrVal); + return r; } @@ -1940,11 +1943,31 @@ RetCode_t RA8875::circle(loc_t x, loc_t y, dim_t radius, fill_t fillit) { RetCode_t ret = noerror; - + INFO("circle"); PERFORMANCE_RESET; - if (radius <= 0 || (x - radius) < 0 || (x + radius) > screenwidth - || (y - radius) < 0 || (y + radius) > screenheight) { + #if 0 + loc_t t; + SetTextCursor(0,10); + printf("Circle(%3d,%3d) => ", x,y); + switch (screen_orientation) { + default: + case rotate_0: + break; + case rotate_90: + t = x; + x = y; + y = t; + break; + case rotate_180: + break; + case rotate_270: + break; + } + printf(" => (%3d,%3d)\r\n", x,y); + #endif + if (radius <= 0 || (x - radius) < 0 || (x + radius) > width() + || (y - radius) < 0 || (y + radius) > height()) { ret = bad_parameter; } else if (radius == 1) { pixel(x,y);
--- a/RA8875.h Thu Aug 01 22:35:29 2019 +0000 +++ b/RA8875.h Fri Aug 02 02:12:26 2019 +0000 @@ -278,6 +278,9 @@ #define RA8875_DEFAULT_SPI_FREQ 5000000 #ifndef MBED_ENCODE_VERSION +#define MBED_MAJOR_VERSION 2 +#define MBED_MINOR_VERSION 0 +#define MBED_PATCH_VERSION MBED_LIBRARY_VERSION #define MBED_ENCODE_VERSION(major, minor, patch) ((major)*10000 + (minor)*100 + (patch)) #endif @@ -3340,6 +3343,9 @@ FPointerDummy *obj_callback; RetCode_t (FPointerDummy::*method_callback)(filecmd_t cmd, uint8_t * buffer, uint16_t size); RetCode_t (* idle_callback)(IdleReason_T reason, uint16_t param); + + orientation_t screen_orientation; + point_t TranslateOrientation(point_t rawPoint); };
--- a/RA8875_Touch.cpp Thu Aug 01 22:35:29 2019 +0000 +++ b/RA8875_Touch.cpp Fri Aug 02 02:12:26 2019 +0000 @@ -69,7 +69,7 @@ touchSample = 0; touchState = no_cal; //touchTicker.attach_us(callback(this, &RA8875::_TouchTicker), TOUCH_TICKER_uS); - #if (MBED_MAJOR_VERSION >= 5) || (MBED_LIBRARY_VERSION > 128) // Is this the right version? + #if (MBED_MAJOR_VERSION >= 5) || (MBED_LIBRARY_VERSION > 127) touchTicker.attach_us(callback(this, &RA8875::_TouchTicker), TOUCH_TICKER_uS); #else touchTicker.attach_us(this, &RA8875::_TouchTicker, TOUCH_TICKER_uS); @@ -113,7 +113,7 @@ touchState = no_cal; if (bTpEnable == TP_ENABLE) { //touchTicker.attach_us(callback(this, &RA8875::_TouchTicker), TOUCH_TICKER_uS); - #if (MBED_MAJOR_VERSION >= 5) || (MBED_LIBRARY_VERSION > 128) // Is this the right version? + #if (MBED_MAJOR_VERSION >= 5) || (MBED_LIBRARY_VERSION > 127) touchTicker.attach_us(callback(this, &RA8875::_TouchTicker), TOUCH_TICKER_uS); #else touchTicker.attach_us(this, &RA8875::_TouchTicker, TOUCH_TICKER_uS); @@ -334,7 +334,7 @@ if (panelTouched == true) { panelTouched = false; if (TouchPoint) { - *TouchPoint = touchInfo[0].coordinates; + *TouchPoint = TranslateOrientation(touchInfo[0].coordinates); ts = touchInfo[0].touchCode; INFO("Touch[0] %2d (%4d,%4d)", touchInfo[0].touchCode, touchInfo[0].coordinates.x, touchInfo[0].coordinates.y); @@ -356,14 +356,15 @@ { if (channel >= TouchChannels()) channel = 0; - return touchInfo[channel].touchCode; + INFO("TouchCode[%d] = %d", channel, touchInfo[channel].touchCode); + return touchInfo[channel].touchCode; } point_t RA8875::TouchCoordinates(uint8_t channel) { if (channel >= TouchChannels()) channel = 0; - return touchInfo[channel].coordinates; + return TranslateOrientation(touchInfo[channel].coordinates); } TouchCode_t RA8875::TouchPanelGet(point_t * TouchPoint) @@ -383,6 +384,35 @@ return t; } +point_t RA8875::TranslateOrientation(point_t rawPoint) +{ + point_t newPoint = rawPoint; + + #if 0 + switch (screen_orientation) { + default: + case rotate_0: + newPoint = rawPoint; + break; + case rotate_90: + newPoint.x = rawPoint.y; + newPoint.y = height() - rawPoint.x; + break; + case rotate_180: + newPoint.x = width() - rawPoint.x; + newPoint.y = height() - rawPoint.y; + break; + case rotate_270: + newPoint.x = height() - rawPoint.y; + newPoint.y = rawPoint.x; + break; + } + INFO("Translate(%3d x %3d) => (%3d x %3d)", rawPoint.x, rawPoint.y, newPoint.x, newPoint.y); + #endif + return newPoint; +} + + // Below here are primarily "helper" functions. While many are accessible // to the user code, they usually don't need to be called. @@ -784,7 +814,7 @@ m_i2c->write(m_addr, (const char *)®, 1); m_i2c->read(m_addr, &val, 1); - HexDump("FT5206_Read", (uint8_t *)&val, 1); + //INFO("ReadReg %02X, Val %02X", reg, val); return (uint8_t)val; }
--- a/RA8875_Touch_FT5206.cpp Thu Aug 01 22:35:29 2019 +0000 +++ b/RA8875_Touch_FT5206.cpp Fri Aug 02 02:12:26 2019 +0000 @@ -87,6 +87,7 @@ valXH = FT5206_ReadRegU8(FT5206_TOUCH5_XH); valYH = FT5206_ReadRegU8(FT5206_TOUCH5_YH); touchInfo[4].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6]; + INFO(" touchID %d", touchInfo[4].touchCode); touchInfo[4].touchID = (valYH >> 4); touchInfo[4].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH5_XL); touchInfo[4].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH5_YL); @@ -94,6 +95,7 @@ valXH = FT5206_ReadRegU8(FT5206_TOUCH4_XH); valYH = FT5206_ReadRegU8(FT5206_TOUCH4_YH); touchInfo[3].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6]; + INFO(" touchID %d", touchInfo[3].touchCode); touchInfo[3].touchID = (valYH >> 4); touchInfo[3].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH4_XL); touchInfo[3].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH4_YL); @@ -101,6 +103,7 @@ valXH = FT5206_ReadRegU8(FT5206_TOUCH3_XH); valYH = FT5206_ReadRegU8(FT5206_TOUCH3_YH); touchInfo[2].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6]; + INFO(" touchID %d", touchInfo[2].touchCode); touchInfo[2].touchID = (valYH >> 4); touchInfo[2].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH3_XL); touchInfo[2].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH3_YL); @@ -108,6 +111,7 @@ valXH = FT5206_ReadRegU8(FT5206_TOUCH2_XH); valYH = FT5206_ReadRegU8(FT5206_TOUCH2_YH); touchInfo[1].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6]; + INFO(" touchID %d", touchInfo[1].touchCode); touchInfo[1].touchID = (valYH >> 4); touchInfo[1].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH2_XL); touchInfo[1].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH2_YL); @@ -115,6 +119,7 @@ valXH = FT5206_ReadRegU8(FT5206_TOUCH1_XH); valYH = FT5206_ReadRegU8(FT5206_TOUCH1_YH); touchInfo[0].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6]; + INFO(" touchID %d", touchInfo[0].touchCode); touchInfo[0].touchID = (valYH >> 4); touchInfo[0].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH1_XL); touchInfo[0].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH1_YL);