/*
#####################################

void setup() {
  ....
  pinMode(TFT_BL, OUTPUT);
  digitalWrite(TFT_BL, HIGH); // Turn on backlight


#include <SPI.h>
#include <SD.h>

// Define SPI pins (change if needed)
#define SD_SCK  12
#define SD_MISO 15
#define SD_MOSI 11
#define SD_CS   5

void setup() {
  Serial.begin(115200);
  while (!Serial) delay(10);

  Serial.println("Initializing SD card with custom SPI pins...");

  // Initialize SPI with custom pins
  SPI.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);

  // Initialize SD card
  if (!SD.begin(SD_CS)) {
    Serial.println("Card failed, or not present.");
    return;
  }

  Serial.println("Card initialized.");

  // Write test
  File file = SD.open("/test.txt", FILE_WRITE);
  if (file) {
    file.println("Hello from ESP32-S3!");
    file.close();
    Serial.println("File written.");
  } else {
    Serial.println("Failed to open file for writing.");
  }

  // Read test
  file = SD.open("/test.txt");
  if (file) {
    Serial.println("Reading file:");
    while (file.available()) {
      Serial.write(file.read());
    }
    file.close();
  } else {
    Serial.println("Failed to open file for reading.");
  }
}

void loop() {
  // Nothing here
}




#####################################
*/

// /////////////////////////////////////////////////////////////////////////// start WORKS!!!!!!!!
// // Configuration file for ESP32-S3 with ST7789 display
// // Save this as User_Setup.h in the TFT_eSPI library folder

// #define ST7789_DRIVER     // Configure ST7789 display driver

// // Define pins for ESP32-S3
// // #define TFT_MISO -1       // ST7789 doesn't use MISO
// #define SD_MISO 15
// // #define TFT_MOSI 42       // SPI MOSI pin
// // #define TFT_SCLK 38       // SPI Clock pin
// #define TFT_MOSI 11       // Hardware SPI2 MOSI
// #define TFT_SCLK 12       // Hardware SPI2 SCLK
// #define TFT_CS   8        // Chip select control pin
// #define TFT_DC   17       // Data Command control pin
// #define TFT_RST  18       // Reset pin
// #define TFT_BL   16       // LED back-light control pin
// #define SD_CS   5

// // For ESP32-S3, we need to explicitly set the SPI bus
// #define USE_HSPI_PORT

// // Display resolution
// #define TFT_WIDTH  170
// #define TFT_HEIGHT 320

// // Other options - you may need to uncomment based on your specific display
// //#define TFT_RGB_ORDER TFT_RGB  // Color order Red-Green-Blue
// //#define TFT_RGB_ORDER TFT_BGR  // Color order Blue-Green-Red

// // DRAM handling
// #define DISABLE_DEPRECATED_FUNCTIONS

// // Fonts to include
// #define LOAD_GLCD   // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
// #define LOAD_FONT2  // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
// #define LOAD_FONT4  // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
// #define LOAD_FONT6  // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
// #define LOAD_FONT7  // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
// #define LOAD_FONT8  // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
// #define LOAD_GFXFF  // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48

// // Smooth fonts - can use significant RAM
// #define SMOOTH_FONT

// // SPI frequency
// #define SPI_FREQUENCY  40000000  // Maximum for ST7789 is usually 80000000
// /////////////////////////////////////////////////////////////////////////// end WORKS!!!!!!!!



// // ST7789 240 x 240 display with no chip select line
// #define USER_SETUP_ID 24

// #define ST7789_DRIVER     // Configure all registers

// #define TFT_WIDTH  240
// #define TFT_HEIGHT 240

// //#define TFT_RGB_ORDER TFT_RGB  // Colour order Red-Green-Blue
// //#define TFT_RGB_ORDER TFT_BGR  // Colour order Blue-Green-Red

// //#define TFT_INVERSION_ON
// //#define TFT_INVERSION_OFF

// // DSTIKE stepup
// //#define TFT_DC    23
// //#define TFT_RST   32
// //#define TFT_MOSI  26
// //#define TFT_SCLK  27

// // Generic ESP32 setup
// #define TFT_MISO 19
// #define TFT_MOSI 23
// #define TFT_SCLK 18
// #define TFT_CS    -1 // Not connected
// #define TFT_DC    2
// #define TFT_RST   4  // Connect reset to ensure display initialises

// // For NodeMCU - use pin numbers in the form PIN_Dx where Dx is the NodeMCU pin designation
// // #define TFT_CS   -1      // Define as not used
// // #define TFT_DC   PIN_D1  // Data Command control pin
// // #define TFT_RST  PIN_D4  // TFT reset pin (could connect to NodeMCU RST, see next line)
// //#define TFT_RST  -1    // TFT reset pin connect to NodeMCU RST, must also then add 10K pull down to TFT SCK


// #define LOAD_GLCD   // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
// #define LOAD_FONT2  // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
// #define LOAD_FONT4  // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
// #define LOAD_FONT6  // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
// #define LOAD_FONT7  // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
// #define LOAD_FONT8  // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
// //#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
// #define LOAD_GFXFF  // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts

// #define SMOOTH_FONT


// // #define SPI_FREQUENCY  27000000
// #define SPI_FREQUENCY  40000000

// #define SPI_READ_FREQUENCY  20000000

// #define SPI_TOUCH_FREQUENCY  2500000

// // #define SUPPORT_TRANSACTIONS



/////////////////////////////////////////////////////////////////////////// start WORKS!!!!!!!!
// Configuration file for ESP32-S3 with ST7789 display
// Save this as User_Setup.h in the TFT_eSPI library folder

// #define ST7789_DRIVER     // Configure ST7789 display driver

// // Define pins for ESP32-S3
// // #define TFT_MISO -1       // ST7789 doesn't use MISO
// #define SD_MISO 14
// // #define TFT_MOSI 42       // SPI MOSI pin
// // #define TFT_SCLK 38       // SPI Clock pin
// #define TFT_MOSI 11       // Hardware SPI2 MOSI
// #define TFT_SCLK 12       // Hardware SPI2 SCLK
// #define TFT_CS   10        // Chip select control pin
// #define TFT_DC   4       // Data Command control pin
// #define TFT_RST  5       // Reset pin
// #define TFT_BL   6       // LED back-light control pin
// #define SD_CS   7

// // For ESP32-S3, we need to explicitly set the SPI bus
// #define USE_HSPI_PORT

// // Display resolution
// #define TFT_WIDTH  170
// #define TFT_HEIGHT 320

// // Other options - you may need to uncomment based on your specific display
// //#define TFT_RGB_ORDER TFT_RGB  // Color order Red-Green-Blue
// //#define TFT_RGB_ORDER TFT_BGR  // Color order Blue-Green-Red

// // DRAM handling
// #define DISABLE_DEPRECATED_FUNCTIONS

// // Fonts to include
// #define LOAD_GLCD   // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
// #define LOAD_FONT2  // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
// #define LOAD_FONT4  // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
// #define LOAD_FONT6  // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
// #define LOAD_FONT7  // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
// #define LOAD_FONT8  // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
// #define LOAD_GFXFF  // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48

// // Smooth fonts - can use significant RAM
// #define SMOOTH_FONT

// // SPI frequency
// #define SPI_FREQUENCY  40000000  // Maximum for ST7789 is usually 80000000



/*


#include <SPI.h>
#include <SD.h>

// Define SPI pins (change if needed)
#define SD_SCK  12
#define SD_MISO 14
#define SD_MOSI 11
#define SD_CS   7

void setup() {
  Serial.begin(115200);
  while (!Serial) delay(10);

  Serial.println("Initializing SD card with custom SPI pins...");

  // Initialize SPI with custom pins
  SPI.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);

  // Initialize SD card
  if (!SD.begin(SD_CS)) {
    Serial.println("Card failed, or not present.");
    return;
  }

  Serial.println("Card initialized.");

  // Write test
  File file = SD.open("/test.txt", FILE_WRITE);
  if (file) {
    file.println("Hello from ESP32-S3!");
    file.close();
    Serial.println("File written.");
  } else {
    Serial.println("Failed to open file for writing.");
  }

  // Read test
  file = SD.open("/test.txt");
  if (file) {
    Serial.println("Reading file:");
    while (file.available()) {
      Serial.write(file.read());
    }
    file.close();
  } else {
    Serial.println("Failed to open file for reading.");
  }
}

void loop() {
  // Nothing here
}


*/

/////////////////////////////////////////////////////////////////////////// end WORKS!!!!!!!!


#define ST7789_DRIVER     // Configure ST7789 display driver

// Define pins for ESP32-S3
// #define TFT_MISO -1       // ST7789 doesn't use MISO
#define SD_MISO 19
// #define TFT_MOSI 42       // SPI MOSI pin
// #define TFT_SCLK 38       // SPI Clock pin
#define TFT_MOSI 18       // Hardware SPI2 MOSI
#define TFT_SCLK 5       // Hardware SPI2 SCLK
#define TFT_CS   17        // Chip select control pin
#define TFT_DC   21       // Data Command control pin
#define TFT_RST  16       // Reset pin
// #define TFT_BL   6       // LED back-light control pin
// #define SD_CS   7

// For ESP32-S3, we need to explicitly set the SPI bus
// #define USE_HSPI_PORT

// Display resolution
#define TFT_WIDTH  135
#define TFT_HEIGHT 240

// Other options - you may need to uncomment based on your specific display
//#define TFT_RGB_ORDER TFT_RGB  // Color order Red-Green-Blue
//#define TFT_RGB_ORDER TFT_BGR  // Color order Blue-Green-Red

// DRAM handling
#define DISABLE_DEPRECATED_FUNCTIONS

// Fonts to include
#define LOAD_GLCD   // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2  // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4  // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6  // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7  // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
#define LOAD_FONT8  // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
#define LOAD_GFXFF  // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48

// Smooth fonts - can use significant RAM
#define SMOOTH_FONT

// SPI frequency
#define SPI_FREQUENCY  40000000  // Maximum for ST7789 is usually 80000000

