// User setup for ChronoDisplay - XIAO ESP32C3 with UC8179 ePaper (7.5 inch)
// This file is included by TFT_eSPI.h before User_Setup_Select.h

#ifndef USER_SETUP_LOADED
#define USER_SETUP_LOADED

// Setup ID
#define USER_SETUP_INFO "ChronoDisplay_XIAO_ESP32C3"
#define USER_SETUP_ID 0x502

// Enable ePaper support
#define EPAPER_ENABLE

// Define the driver
#define UC8179_DRIVER

// Driver ID for getSetup() function
#define TFT_DRIVER 0x8179

// Include driver defines first (must be before Init.h is included)
#include <TFT_Drivers/UC8179_Defines.h>

// Include board-specific pin definitions
#include <User_Setups/EPaper_Board_Pins_Setups.h>

// Use the XIAO_EPAPER_DRIVER_BOARD pin setup
#define USE_XIAO_EPAPER_DRIVER_BOARD

// Fix CHECK_BUSY macro - wait while BUSY is LOW (busy), stop when HIGH (ready)
#undef CHECK_BUSY
#define CHECK_BUSY()               \
    do                             \
    {                              \
        while (!digitalRead(TFT_BUSY)) \
            ;                      \
    } while (0)

// Add delay after update to ensure display completes refresh
#undef EPD_UPDATE
#define EPD_UPDATE()               \
    do                             \
    {                              \
        writecommand(0x12);        \
        CHECK_BUSY();              \
        delay(200);                \
    } while (0)

// Fonts to load - minimal set to save space
#define LOAD_GLCD

// Disable smooth font to save space
// #define SMOOTH_FONT

// SPI frequency
#define SPI_FREQUENCY 10000000
#define SPI_READ_FREQUENCY 4000000

#endif
