ImpulseAdventure / GUIslice

GUIslice drag & drop embedded GUI in C for touchscreen TFT on Arduino, Raspberry Pi, ARM, ESP8266 / ESP32 / M5stack using Adafruit-GFX / TFT_eSPI / UTFT / SDL
https://www.impulseadventure.com/elec/guislice-gui.html
MIT License
1.16k stars 209 forks source link

Touchscreen support with 9341 8-bit parallel on ESP32 #130

Closed benton-anderson closed 5 years ago

benton-anderson commented 5 years ago

I'm trying to get touchscreen support on the ESP32 on my 9341 8-bit parallel UNO shield with your GUI builder. I can get the GUI to display, but touch doesn't work. These three issues make it ambiguous to me whether parallel will work with TFT_eSPI and your library:

https://github.com/ImpulseAdventure/GUIslice/issues/61 https://github.com/Bodmer/TFT_eSPI/issues/106 https://github.com/Bodmer/TFT_eSPI/issues/245

I'm looking through GUIslice_config_ard.h and it has the 9341 8-bit parallel option, but nowhere to define the digital pins. How do you use the GUIslice_config_ard.h instead of the GUIslice_config.h in your examples? Is it as simple as adding _ard and everything works?

This is the shield: shield I confirmed that the touchscreen works on a MEGA.

ImpulseAdventure commented 5 years ago

Hi Ben —

Thanks for providing the details and a link to the shield; that’s very helpful!

It looks like your shield will use a 4-wire (simple/analog) touch driver. To your point, I see now that we are missing an example config (listed in GUIslice_config.h) for the TFT_eSPI display driver with the 4-wire touch driver. I will add this as “esp-tftespi-default-simple” and notify when it is ready.

If you are able to use Bodmer’s TFT_eSPI library with your 8-bit ILI9341 then we should be able to get GUIslice also working with it and also add the 4-wire resistive touch. The 8bit data interface will be defined by the TFT_D0...TFT_D7 defines in the TFT_eSPI library’s User_Setup.

To ensure I have the details correct, I had a couple questions:

Thanks!

ImpulseAdventure commented 5 years ago

Hi @benton-anderson -- I have now added an example config for TFT_eSPI + 4-wire touch: Example config: esp-tftespi-default-simple

Notes:

In this update, I also altered the touch initialization for ESP32 to reduce the ADC resolution to 10-bit in order to provide compatibility with the Adafruit_Touchscreen library (thanks to @lukasfischer83 identifying this in https://github.com/adafruit/Adafruit_TouchScreen/issues/15 ). I haven't attempted to test this yet, so would be interested in hearing if this change enables us to use Adafruit_Touchscreen on the ESP32 (by default, it is normally not compatible).

thx

benton-anderson commented 5 years ago

Thank you for the prompt reply! I will update and answer your questions ASAP. I'm very excited to hear I can use your amazing GUI builder. EDIT:

To answer your questions: Yes, I confirmed ex02 as displaying on my screen, but I can't touch the Quit button. I've tested the touch function using the Touch_shield_new from mcufriend_kbv and, interestingly, a thin slice near the edge of my screen responds to touch (I haven't yet used your update) while the rest of the screen does not respond. However, this thin slice doesn't overlap with the button in ex02. Yes, I used esp-notouch config file and Setup14_ILI9341_Parallel.h.

While there is a ESP32 in the UNO form factor that would work (lTTGO ESP32 UNO board), I'm using a ESP32 DevKit DOIT, so I connected the shield's pins to the same DOIT pins as if I had the UNO form factor board, bearing in mind that the hardware mod that Bodmer has on the TFT eSPI page changes three of the pins. This gives XP=12, XM=15, YP=33, YM=13.

With your update, I received this error message on ex02:


In file included from C:\Users\ben\Documents\Arduino\libraries\TFT_eSPI-master/TFT_eSPI.h:101:0,

from C:\Users\ben\Documents\Arduino\libraries\GUIslice-master\src\GUIslice_drv_tft_espi.cpp:47:

C:\Users\ben\Documents\Arduino\libraries\GUIslice-master\src\GUIslice_drv_tft_espi.cpp: In function 'int gslc_TDrvGetPinMode(uint8_t)':

C:\Users\ben\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.1\cores\esp32/Arduino.h:113:99: error: cannot convert 'volatile uint32_t* {aka volatile unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in initialization

 #define portModeRegister(port)      ((volatile uint32_t*)((port)?GPIO_ENABLE1_REG:GPIO_ENABLE_REG))

C:\Users\ben\Documents\Arduino\libraries\GUIslice-master\src\GUIslice_drv_tft_espi.cpp:1075:31: note: in expansion of macro 'portModeRegister'

     volatile uint8_t *nReg  = portModeRegister(nPort);

C:\Users\ben\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.1\cores\esp32/Arduino.h:111:93: error: cannot convert 'volatile uint32_t* {aka volatile unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in initialization

 #define portOutputRegister(port)    ((volatile uint32_t*)((port)?GPIO_OUT1_REG:GPIO_OUT_REG))

C:\Users\ben\Documents\Arduino\libraries\GUIslice-master\src\GUIslice_drv_tft_espi.cpp:1081:31: note: in expansion of macro 'portOutputRegister'

     volatile  uint8_t *nOut = portOutputRegister(nPort);

exit status 1
Error compiling for board ESP32 Dev Module.

I changed line 1075 and line 1081 to use uint32_t instead and it compiled, but leads to a whitescreen. Because I don't see the Quit button appear anymore means that I may have done something else to make ex02 work previously, but I can't recall right now.

Edit(Cal): Added code format tags

ImpulseAdventure commented 5 years ago

Thank you Ben for the update.

ESP32 + 4-wire fix

The fix for the ESP32 + Adafruit_Touchscreen (4-wire) mode has been pushed to the repo -- thanks for catching this! That combination was only just added but still not in the test regression hence it was overlooked; now it has been included. The latest GUIslice should not require mods to lines 1075 & 1081.

Touch testing

You had mentioned that the mcufriend_kbv library's Touch_shield_new (ie. without using GUIslice) is not properly responding to touch on your display. Ideally, that should be resolved before attempting to use any touch functionality in GUIslice. Did you mean that your display correctly tracks touch presses in the right side of the display, but nowhere else (ie. a broken touch overlay), or that touch presses seem to map only to the right side of the display? (ie. a calibration issue)

Putting aside touch for the moment, let's focus on using the display-only esp-tftespi-default-notouch mode.

Display testing

I assume your current TFT_eSPI Setup14_ILI9341_Parallel.h is working on your DOIT Esp32 DevKit + display with TFT_eSPI's TFT_graphicstest_one_lib example?

With regards to ex02, let's start by confirming ex01 first (as it doesn't depend on touch).

thanks!

benton-anderson commented 5 years ago

The touch functions worked on my Mega a few days ago and I doubt it has broken since then (I will retest on the mega to be sure). I calibrated the display on the Mega using the mcufriend calibrate sketch, and I copied over the same 130-ish/900-ish values into the ESP32-connected setup because I assumed the calibration values were screen-specific. And because the touches mapped only to the one side of the screen, I assumed that meant it was a voltage issue, because the Mega does 5V and the ESP pins do 3.3V.

But now that I think of it, when testing the working side of the screen with the mcufriend touch_shield_new sketch, the read-out of x= and y= values goes from x=~200 to x=~580, and y=~800 to y=~2500 (those values appear when using the values of ~130/~900 entered into the sketch). Based on those odd numbers, this also strikes me as a voltage level issue, not something that calibration can fix...? I'm unsure.

I understand that this question is outside of the scope of your software, so I'd be happy to post this on the Arduino forums or on the relevant tft_eSPI/mcufriend/adafruit_touchscreen github pages. I just need to find out which one because I'm not even sure what library uses which dependencies anymore!

I will work on your display tests as soon as possible. Thanks for your help!

ImpulseAdventure commented 5 years ago

Thanks for the extra details.

I suspect the difference you observed in the mcufriend_kbv library’s calibration utility touch handling between the ATmega2560 and the ESP32 is probably to do with the ESP’s default 12-bit ADC resolution versus the AVR’s 10-bit. The Adafruit_Touchscreen depends on the MCU’s ADC sampling of the 4-wire resistive overlay and assumes a 10-bit range.

To prove this out, I would suggest adding the following line in the setup() for your mcufriend_kbv calibration test (when running on your ESP32): analogReadResolution(10);

DETAILS

If you simply ported the ATmega calibration values to the ESP32 and didn’t change the ESP’s ADC resolution, then I would expect the combination of the Adafruit_Touchscreen library and the calibration remapping logic to result in a compressed & clipped remapping output, leading to a relatively small region in one corner of the display (though I think you mentioned one side). So, the mapping function that previously saw an input range of 130..900 may now see an input range of 520..3600.

The Adafruit_Touchscreen library (latest release 1.0.1) doesn’t naturally support ESP32, in part due to this difference in ADC resolution. When adding support for this hardware combination, I had added an override for the ESP32 ADC resolution to 10-bit to address this specifically.

So, if you were to use the latest GUIslice (eg. diag_ard_touch_test) with your ATmega-derived calibration values on the ESP32, you might be able to see a more complete mapping range (though it sounds like you also have a display issue that would need to be addressed first).

Hope that helps!

benton-anderson commented 5 years ago

TFT_graphicstest_one_lib works. Ex02 and ex01 both confirmed to work using default-notouch. Changing to default-simple and running ex01 makes it compile and upload just fine, but the screen is white.

The mcufriend touch_shield_new sketch works perfectly with analogReadResolution(10). The mcufriend Touchscreen_Calbr_native sketch does not detect any touches with analogReadResolution(10).

default-simple and diag_ard_touch_test compiles and uploads but displays a white screen.

ImpulseAdventure commented 5 years ago

Thanks for the data points. Good to see esp-tftespi-default-notouch is working and that the mcufriend_kbv/touch_shield_new works with the analogReadResolution(10) update.

As mentioned earlier, the 4-wire Adafruit_Touchscreen library doesn't natively support ESP32, but I still think we should be able to get it working.

I plan to wire up a similar display setup to double-check the config myself, but in order to rule out an initialization error, could you paste in the output from the Serial Monitor when you run ex01 with tft-tftespi-default-simple on your ESP32?

thx

benton-anderson commented 5 years ago

GUIslice version [0.11.2.45]:

ImpulseAdventure commented 5 years ago

I have wired up a SparkFun ESP32 Thing and selected the esp-tftespi-default-simple config, but haven't managed to reproduce the white screen issue yet. Usually that occurs if the display driver failed to initialize, but we already confirmed in esp-tftespi-default-notouch that the display init can be successful.

Can you confirm for me:

If the above are confirmed, then it would be helpful to try the following two tests: (quitting the Arduino IDE before each test)

To get you up and running faster, it may be easiest to just send me a quick email to guislice@gmail.com so I can attach a revised build for you. thx!

benton-anderson commented 5 years ago

Confirmed the ADATOUCHPIN*, and found no TOUCH_CS in Setup14.

Restarted Arduino IDE and ran Test 1) and touched the screen in opposite corners to get this:

 GUIslice version [0.11.2.45]:
- Initialized display handler [TFT_eSPI] OK
- Initialized touch handler [SIMPLE(Analog)] OK
DBG: remapX: (829,120,923,0,239)
DBG: remapY: (136,37,904,0,319)
DBG: PreRotate: x=211 y=36
DBG: RotateCfg: remap=1 nSwapXY=1 nFlipX=0 nFlipY=1
DBG: Touch Press=1893 Raw[829,136] Out[36,28]
Trk:                                           (36,28) P=1893 : TouchDown
DBG: Touch End  =0 Raw[829,136] *****
DBG: remapX: (829,120,923,0,239)
DBG: remapY: (136,37,904,0,319)
DBG: PreRotate: x=211 y=36
DBG: RotateCfg: remap=1 nSwapXY=1 nFlipX=0 nFlipY=1
DBG: Touch Press=0 Raw[829,136] Out[36,28]
Trk:                                           (36,28) P=0 : TouchUp
DBG: remapX: (259,120,923,0,239)
DBG: remapY: (847,37,904,0,319)
DBG: PreRotate: x=41 y=298
DBG: RotateCfg: remap=1 nSwapXY=1 nFlipX=0 nFlipY=1
DBG: Touch Press=3497 Raw[259,847] Out[298,198]
Trk:                                           (298,198) P=3497 : TouchDown
DBG: Touch End  =0 Raw[259,847] *****
DBG: remapX: (259,120,923,0,239)
DBG: remapY: (847,37,904,0,319)
DBG: PreRotate: x=41 y=298
DBG: RotateCfg: remap=1 nSwapXY=1 nFlipX=0 nFlipY=1
DBG: Touch Press=0 Raw[259,847] Out[298,198]
Trk:                                           (298,198) P=0 : TouchUp 

Restarted Arduino IDE and ran test 2) with your new .cpp file and it displays the ex02 successfully (touch doesn't work). Serial monitor reports:

GUIslice version [0.11.2.45]:
- Initialized display handler [TFT_eSPI] OK
- Initialized touch handler [SIMPLE(Analog)-skip] OK
ImpulseAdventure commented 5 years ago

Update:

Previously, we had marked the Adafruit_TouchScreen as not being compatible with ESP32 mode. With this investigation, I am hoping that we might be able to offer this combination successfully.

ImpulseAdventure commented 5 years ago

Some followup details:

As the original problem exists outside of GUIslice, I will close the issue. My recent updates to provide some compatibility workarounds currently exists in a test branch (WIP130-ESP_4wire) and will be merged soon into the master.

hemangjoshi37a commented 3 months ago

has this been solved yet ? please help me with white screen someone.