SOLVED Atmega1284p and TFT 3.5" Touchscreen Work As Expected.
After several hours of trial and error I actually found out what was the root of the issue.
Firstly, to make pin assignment easy I recommend everyone to switch the pinout for the Atmega1284p to bobuino, which is provided by Mightycore. Using the diagram found on its git hub make the connections MCU to Shield taking into account which pins are the equivalent to the uno (the bobuino arranges everything so the pins on the 1248p are now compatible to most of the common arduino libraries). Having the correct connections will allow you to use the MCUFRIEND and Adafruit GFX, but not adafruit´s touchscreen.
To make touchscreen work it is necessary to modify it. This library expects the analog pins of the 1284p provided by Mightycore to be stated as A0,A1,A2, etc and not as digital pins 24, 25, etc. This generates an error where it is not using correct analog pin constants in the constructor TouchScreen(XP, YP, XM, YM, RX). Which causes USE_FAST_PINIO to have its port pins incorrectly assigned.
At least that´s my theory of the origin of the issue, I´m probably missing something but I´m sure my solutions works.
First, you´ll need the modded version of the library I made with some help of ChatGPT (I know I know, but I ran out of options). They should be attached to this post. The main change is a slight tweak on the header file that allows the identification of the 1284p and in the main file it removes completely the use of FAST PINIO. Some comments on the original library would probably make more sense, but I´m thinking about that just now. I just deleted the original library from my lib folder and pasted the new folder with the two files.
Make sure your hardware is well connected, it is not necessary to power at the same time 3V and 5V. With 5V is enough for both the screen and the touchscreen to work. Also, you can leave the SD pins alone for this purpose. I have tested uploading the code using a USBasp and an Arduino UNO board (without the IC) so i can debug using the serial monitor and both work.
library.properties.txt (334 Bytes)
TouchScreen.cpp (4.0 KB)
TouchScreen.h (804 Bytes)
I´ll add the testing file I used with the two buttons so you can confirm it works.
Cal_Test_Vertical_Working.ino (2.5 KB)
Proof this thing works:
I hope this was not me just going in circles around a problem I made. In the best case someone will find this post usefully and may save themselves a bad headache.