Problemas com LCD TFT 7783 (778x) + TouchScreen com tela revertida

O universo se abre de possibilidades quando usamos uma tela grande, touch screen, com ótima qualidade de renderização. Quanto maior a tela, maior o custo, fato. Uma tela barata, de fácil acesso e fácil utilização, são as telas com chip 778x. Estas telas são encontradas em forma de shield para Arduíno, como também como parte isolada. Porem, com toda essa facilidade aparecem os problemas. Drivers 7783 em especial, causam um reverso na tela, fazendo com que as libs disponíveis trabalhem de forma inconsistente.

Os shields com telas com drive 778x, na sua maioria, já possuem cartão micro SD, o que torna fácil a ligação e utilização deste equipamento. Com 2.4", regulador 3.3v embutido, resolução 240x320, 18Bits de cor (262K cores), e a preço de aproximadamente R$ 30,00 reais, torna-se um shield de ótimo custo beneficio.

Acontece que pela quantidade de drivers e a quantidade de shields existentes (o que diferencia pela forma que ele foi construído), nem todas as libs funcionam corretamente. Sempre vejo problemas relacionados ao touch deste modelo em questão (modelo 7783 da mcu friend), pois o touch não corresponde ao screen. Acontece que algumas libs tomam como ponto de partida 0x0 pixel com o shield deitado, quando outros tomam como em pé, e assim por diante. Vale lembrar que a posição deste shield é em pé, com os botões touch para baixo:
Partindo deste ponto, a posição X e Y inicial (0x0) é do topo esquerdo. Após alguns testes, notei que cada lib tratava isso de uma forma diferente.

A resposta mais precisa que consegui, foi com a lib TFT-Shield, que é baseada no Adafruit_GFX. A lib do touch, foi usada a TouchScreen, lib mais completa para esta função, com controle de pressão e ótima precisão.
p.x = map(p.x, TS_MAXX, TS_MINX, 0, tft.height());
p.y = map(p.y, TS_MAXY, TS_MINY, 0, tft.width());
2 - Invertemos o X para o Y, e Y para o X, pois a lib trabalha horizontalmente, e ja que nossa tela é vertical, precisamos modificar as posições:
int a = p.x;
p.x = p.y;
p.y = a;
Com isso temos a posição X e Y correta.
#include <Adafruit_GFX.h>    // Core graphics library
#include <SWTFT.h> // Hardware-specific library
#include <TouchScreen.h>

#define YP A1  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 7  // can be a digital pin
#define XP 6  // can be a digital pin

#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

// Assign human-readable names to some common 16-bit color values:
#define BLACK  0x0000
#define BLUE    0x001F
#define RED    0xF800
#define GREEN  0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE  0xFFFF

SWTFT tft;

#define BOXSIZE 40
#define PENRADIUS 1

int oldcolor, currentcolor;

void setup(void) {
  tft.reset();

  uint16_t identifier = tft.readID();

  tft.setRotation(0);

  tft.begin(identifier);

  tft.fillScreen(BLACK);

  tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED);
  tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW);
  tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN);
  tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN);
  tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE);
  tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA);
  // tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, WHITE);
  tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE);

  currentcolor = RED;

  pinMode(13, OUTPUT);
}

#define MINPRESSURE 10
#define MAXPRESSURE 1000

void loop()
{
  digitalWrite(13, HIGH);

  // Recently Point was renamed TSPoint in the TouchScreen library
  // If you are using an older version of the library, use the
  // commented definition instead.
  // Point p = ts.getPoint();
  TSPoint p = ts.getPoint();
  //digitalWrite(13, LOW);

  // if sharing pins, you'll need to fix the directions of the touchscreen pins
  //pinMode(XP, OUTPUT);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  //pinMode(YM, OUTPUT);

/**
* Modificação para telas 7783 rotacionada
* @author Bruno P. Gonçalves
* @site http://blog.andor.com.br
* @publisher And Or
*/
p.x = map(p.x, TS_MAXX, TS_MINX, 0, tft.height());
p.y = map(p.y, TS_MAXY, TS_MINY, 0, tft.width());

int a = p.x;
p.x = p.y;
p.y = a;

  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    /*
    Serial.print("X = "); Serial.print(p.x);
    Serial.print("\tY = "); Serial.print(p.y);
    Serial.print("\tPressure = "); Serial.println(p.z);
    */

    if (p.y > (320)) {
      // press the bottom of the screen to erase
      tft.fillRect(0, BOXSIZE, tft.width(), tft.height()-BOXSIZE, BLACK);
    }

    // scale from 0->1023 to tft.width
    //p.x = tft.width()-(map(p.x, TS_MINX, TS_MAXX, tft.width(), 0));
    //p.y = tft.height()-(map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));

    if (p.y < BOXSIZE) {
      oldcolor = currentcolor;

      if (p.x < BOXSIZE) {
        currentcolor = RED;
        tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE);
      } else if (p.x < BOXSIZE*2) {
        currentcolor = YELLOW;
        tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, WHITE);
      } else if (p.x < BOXSIZE*3) {
        currentcolor = GREEN;
        tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, WHITE);
      } else if (p.x < BOXSIZE*4) {
        currentcolor = CYAN;
        tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, WHITE);
      } else if (p.x < BOXSIZE*5) {
        currentcolor = BLUE;
        tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, WHITE);
      } else if (p.x < BOXSIZE*6) {
        currentcolor = MAGENTA;
        tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, WHITE);
      }

      if (oldcolor != currentcolor) {
          if (oldcolor == RED) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED);
          if (oldcolor == YELLOW) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW);
          if (oldcolor == GREEN) tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN);
          if (oldcolor == CYAN) tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN);
          if (oldcolor == BLUE) tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE);
          if (oldcolor == MAGENTA) tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA);
      }
    }

    if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) {
      tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
    }
  }
}
Veja funcionando:
 
 
Espero que esta dica ajude a resolverem este problema. Tivemos conhecimento que muitas pessoas até desistiram de testar suas telas, pois não encontravam uma solução para isso.