Adafruit 3.5" Display with Touchscreen - Touch Library not working with Mega2560

Hello everyone

I purchased this display with touchscreen: 3.5 TFT 320x480 + Touchscreen Breakout Board w/MicroSD Socket [HXD8357D] : ID 2050 : $39.95 : Adafruit Industries, Unique & fun DIY electronics and kits

I downloaded the following library and added it to my Arduino Libraries: GitHub - adafruit/Adafruit_TouchScreen: Arduino library for 4-wire resistive touchscreens

Sidenote: The libraries for the display are working.

When I try to run one of the examples from the library I get the errors like the following:

'RwReg' does not name a type
   volatile RwReg *xp_port, *yp_port, *xm_port, *ym_port;

'RwReg' does not name a type
   RwReg xp_pin, xm_pin, yp_pin, ym_pin;

'xp_port' was not declared in this scope
   *xp_port |= xp_pin;

'xm_pin' was not declared in this scope
   *xm_port &= ~xm_pin;

Has anybody experienced the same problems?

Thanks in advance and cheers.

I'm still waiting for my touchscreen to be delivered, but while doing some initial experimentation in the IDE I'm seeing the same issue. Looking at the TouchScreen.h file, I find the following:

#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega32U4__) || defined(TEENSYDUINO)
typedef volatile uint8_t RwReg;
#if defined(ARDUINO_STM32_FEATHER)
typedef volatile uint32 RwReg;
#if defined(ARDUINO_FEATHER52)
typedef volatile uint32_t RwReg;

I think we just need to add the appropriate "if defined" for the Mega 2560. Now, what exactly that would be, I'm not certain. If the proper data type is the same as a Mega328, then I think adding || defined(__AVR_ATmega2560__) to the end of the existing AVR defined check would work. If it's a different data type, then a separate if defined would need to be added.

From a compiling standpoint, adding the extra bit to the existing code works, no more errors. I'm not sure if it will work from an actual functionality standpoint yet.


I can now confirm that all you have to do to use the Touchcreen library with a Mega2560 is to add the line I described above to the touchscreen.h file. It works perfectly.