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