Added Second SPI option for Touchpad driver

This commit is contained in:
Hamid Saffari 2020-03-27 17:17:56 +04:30 committed by GitHub
parent e9d940a2ce
commit cdcfaf9b43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 32 deletions

View File

@ -16,14 +16,19 @@
***************************************************************************************/ ***************************************************************************************/
// The touch controller has a low SPI clock rate // The touch controller has a low SPI clock rate
inline void TFT_eSPI::begin_touch_read_write(void){ inline void TFT_eSPI::begin_touch_read_write(void){
DMA_BUSY_CHECK; #if !defined(SPI2_for_TOUCH_PORT)
CS_H; // Just in case it has been left low DMA_BUSY_CHECK;
#if defined (SPI_HAS_TRANSACTION) && defined (SUPPORT_TRANSACTIONS) #endif
if (locked) {locked = false; spi.beginTransaction(SPISettings(SPI_TOUCH_FREQUENCY, MSBFIRST, SPI_MODE0));} CS_H; // Just in case it has been left low
#else #if defined (SPI_HAS_TRANSACTION) && defined (SUPPORT_TRANSACTIONS) && !defined(SPI2_for_TOUCH_PORT)
spi.setFrequency(SPI_TOUCH_FREQUENCY); if (locked) {locked = false; spi_touch.beginTransaction(SPISettings(SPI_TOUCH_FREQUENCY, MSBFIRST, SPI_MODE0));}
#elif !defined(SPI2_for_TOUCH_PORT)
spi_touch.setFrequency(SPI_TOUCH_FREQUENCY);
#endif
#if !defined(SPI2_for_TOUCH_PORT)
SET_BUS_READ_MODE;
#endif #endif
SET_BUS_READ_MODE;
T_CS_L; T_CS_L;
} }
@ -33,12 +38,15 @@ inline void TFT_eSPI::begin_touch_read_write(void){
***************************************************************************************/ ***************************************************************************************/
inline void TFT_eSPI::end_touch_read_write(void){ inline void TFT_eSPI::end_touch_read_write(void){
T_CS_H; T_CS_H;
#if defined (SPI_HAS_TRANSACTION) && defined (SUPPORT_TRANSACTIONS) #if defined (SPI_HAS_TRANSACTION) && defined (SUPPORT_TRANSACTIONS) && !defined(SPI2_for_TOUCH_PORT)
if(!inTransaction) {if (!locked) {locked = true; spi.endTransaction();}} if(!inTransaction) {if (!locked) {locked = true; spi_touch.endTransaction();}}
#else #elif !defined(SPI2_for_TOUCH_PORT)
spi.setFrequency(SPI_FREQUENCY); spi_touch.setFrequency(SPI_FREQUENCY);
#endif
#if !defined(SPI2_for_TOUCH_PORT)
SET_BUS_WRITE_MODE;
#endif #endif
SET_BUS_WRITE_MODE;
} }
/*************************************************************************************** /***************************************************************************************
@ -58,31 +66,31 @@ uint8_t TFT_eSPI::getTouchRaw(uint16_t *x, uint16_t *y){
begin_touch_read_write(); begin_touch_read_write();
// Start YP sample request for x position, read 4 times and keep last sample // Start YP sample request for x position, read 4 times and keep last sample
spi.transfer(0xd0); // Start new YP conversion spi_touch.transfer(0xd0); // Start new YP conversion
spi.transfer(0); // Read first 8 bits spi_touch.transfer(0); // Read first 8 bits
spi.transfer(0xd0); // Read last 8 bits and start new YP conversion spi_touch.transfer(0xd0); // Read last 8 bits and start new YP conversion
spi.transfer(0); // Read first 8 bits spi_touch.transfer(0); // Read first 8 bits
spi.transfer(0xd0); // Read last 8 bits and start new YP conversion spi_touch.transfer(0xd0); // Read last 8 bits and start new YP conversion
spi.transfer(0); // Read first 8 bits spi_touch.transfer(0); // Read first 8 bits
spi.transfer(0xd0); // Read last 8 bits and start new YP conversion spi_touch.transfer(0xd0); // Read last 8 bits and start new YP conversion
tmp = spi.transfer(0); // Read first 8 bits tmp = spi_touch.transfer(0); // Read first 8 bits
tmp = tmp <<5; tmp = tmp <<5;
tmp |= 0x1f & (spi.transfer(0x90)>>3); // Read last 8 bits and start new XP conversion tmp |= 0x1f & (spi_touch.transfer(0x90)>>3); // Read last 8 bits and start new XP conversion
*x = tmp; *x = tmp;
// Start XP sample request for y position, read 4 times and keep last sample // Start XP sample request for y position, read 4 times and keep last sample
spi.transfer(0); // Read first 8 bits spi_touch.transfer(0); // Read first 8 bits
spi.transfer(0x90); // Read last 8 bits and start new XP conversion spi_touch.transfer(0x90); // Read last 8 bits and start new XP conversion
spi.transfer(0); // Read first 8 bits spi_touch.transfer(0); // Read first 8 bits
spi.transfer(0x90); // Read last 8 bits and start new XP conversion spi_touch.transfer(0x90); // Read last 8 bits and start new XP conversion
spi.transfer(0); // Read first 8 bits spi_touch.transfer(0); // Read first 8 bits
spi.transfer(0x90); // Read last 8 bits and start new XP conversion spi_touch.transfer(0x90); // Read last 8 bits and start new XP conversion
tmp = spi.transfer(0); // Read first 8 bits tmp = spi_touch.transfer(0); // Read first 8 bits
tmp = tmp <<5; tmp = tmp <<5;
tmp |= 0x1f & (spi.transfer(0)>>3); // Read last 8 bits tmp |= 0x1f & (spi_touch.transfer(0)>>3); // Read last 8 bits
*y = tmp; *y = tmp;
@ -101,9 +109,9 @@ uint16_t TFT_eSPI::getTouchRawZ(void){
// Z sample request // Z sample request
int16_t tz = 0xFFF; int16_t tz = 0xFFF;
spi.transfer(0xb0); // Start new Z1 conversion spi_touch.transfer(0xb0); // Start new Z1 conversion
tz += spi.transfer16(0xc0) >> 3; // Read Z1 and start Z2 conversion tz += spi_touch.transfer16(0xc0) >> 3; // Read Z1 and start Z2 conversion
tz -= spi.transfer16(0x00) >> 3; // Read Z2 tz -= spi_touch.transfer16(0x00) >> 3; // Read Z2
end_touch_read_write(); end_touch_read_write();