#define CYD_TFT_CONTROLLER_ILI9341 1
#define CYD_TFT_CONTROLLER_ST7789  2

#ifndef CYD_TFT_CONTROLLER
  #define CYD_TFT_CONTROLLER CYD_TFT_CONTROLLER_ST7789
#endif

#ifndef CYD_ILI9341_V2
  #define CYD_ILI9341_V2 0
#endif

#if CYD_TFT_CONTROLLER == CYD_TFT_CONTROLLER_ST7789
  #define USER_SETUP_INFO "ESP32-2432S028R-ST7789"

  #define ST7789_DRIVER
  #define TFT_WIDTH  240
  #define TFT_HEIGHT 320

  #define TFT_RGB_ORDER TFT_BGR
  #define TFT_INVERSION_OFF

  #ifndef CYD_TOUCH_SWAP_XY
    #define CYD_TOUCH_SWAP_XY 0
  #endif
  #ifndef CYD_TOUCH_FLIP_X
    #define CYD_TOUCH_FLIP_X 0
  #endif
  #ifndef CYD_TOUCH_FLIP_Y
    #define CYD_TOUCH_FLIP_Y 0
  #endif
#elif CYD_TFT_CONTROLLER == CYD_TFT_CONTROLLER_ILI9341
  #define USER_SETUP_INFO "ESP32-2432S028R-ILI9341"

  #if CYD_ILI9341_V2
    #define ILI9341_2_DRIVER
    #define TFT_INVERSION_ON
  #else
    #define ILI9341_DRIVER
    #define TFT_INVERSION_OFF
  #endif

  #ifndef CYD_TOUCH_SWAP_XY
    #define CYD_TOUCH_SWAP_XY 0
  #endif
  #ifndef CYD_TOUCH_FLIP_X
    #define CYD_TOUCH_FLIP_X 0
  #endif
  #ifndef CYD_TOUCH_FLIP_Y
    #define CYD_TOUCH_FLIP_Y 0
  #endif
#else
  #error "Unsupported CYD_TFT_CONTROLLER. Use CYD_TFT_CONTROLLER_ILI9341 or CYD_TFT_CONTROLLER_ST7789."
#endif

#ifndef CYD_TOUCH_MIN_X
  #define CYD_TOUCH_MIN_X 200
#endif
#ifndef CYD_TOUCH_MAX_X
  #define CYD_TOUCH_MAX_X 3700
#endif
#ifndef CYD_TOUCH_MIN_Y
  #define CYD_TOUCH_MIN_Y 240
#endif
#ifndef CYD_TOUCH_MAX_Y
  #define CYD_TOUCH_MAX_Y 3800
#endif

#define TFT_MISO 12
#define TFT_MOSI 13
#define TFT_SCLK 14
#define TFT_CS   15
#define TFT_DC   2
#define TFT_RST  -1

#define TOUCH_IRQ  36
#define TOUCH_MOSI 32
#define TOUCH_MISO 39
#define TOUCH_CLK  25
#define TOUCH_CS   33

#define TFT_BL 21
#define TFT_BACKLIGHT_ON HIGH

#define LOAD_GLCD
#define LOAD_FONT2
#define LOAD_FONT4
#define LOAD_FONT6
#define LOAD_FONT7
#define LOAD_FONT8
#define LOAD_GFXFF
#define SMOOTH_FONT

#define SD_CS   5
#define SD_MISO 19
#define SD_MOSI 23
#define SD_SCLK 18

#define SPI_FREQUENCY       27000000
#define SPI_READ_FREQUENCY  20000000
#define SPI_TOUCH_FREQUENCY 2500000

#define SUPPORT_TRANSACTIONS
