#include "pins_arduino.h"

// Display (E-Ink) ED047TC1 - 8bit parallel
#define EPD_WIDTH 960
#define EPD_HEIGHT 540

#define CANNED_MESSAGE_MODULE_ENABLE 1
#define USE_VIRTUAL_KEYBOARD 1

#if defined(T5_S3_EPAPER_PRO_V1)
#define BOARD_BL_EN 40
#else
#define BOARD_BL_EN 11
#endif

#define I2C_SDA SDA
#define I2C_SCL SCL

#define HAS_TOUCHSCREEN 1
#define TOUCH_POLL_INTERVAL_IDLE 25
#define TOUCH_POLL_INTERVAL_ACTIVE 15
#define TOUCH_POLL_INTERVAL_RELEASE 20
#define TOUCH_POLL_INTERVAL_ACTIVE_FAST 8
#define TOUCH_POLL_INTERVAL_RELEASE_FAST 8
#define GT911_PIN_SDA SDA
#define GT911_PIN_SCL SCL
#if defined(T5_S3_EPAPER_PRO_V1)
#define GT911_PIN_INT 15
#define GT911_PIN_RST 41
#else
#define GT911_PIN_INT 3
#define GT911_PIN_RST 9
#endif
// Do not use touch as a light-sleep wake source on T5-S3.
// Wake should come from physical buttons/radio/timer only.
#define SCREEN_TOUCH_INT GT911_PIN_INT

// Touch control helpers for this variant
bool isTouchInputEnabled();
void setTouchInputEnabled(bool enabled, bool showIndicator);
void toggleTouchInputEnabled();

// Backlight control helpers for this variant (non-latching behavior)
void t5BacklightSetUserEnabled(bool enabled);
bool t5BacklightIsUserEnabled();
void t5BacklightToggleUser();
void t5BacklightSetForcedByTimeout(bool forced);
void t5BacklightSetForcedBySleep(bool forced);
void t5BacklightHandleUserInput();

// Touch timeout/wake helpers for this variant
void t5TouchSetForcedByTimeout(bool forced);
bool t5TouchIsForcedByTimeout();
void t5TouchHandleUserInput();

// Gate GT911 capacitive-home callback delivery until InkHUD startup is complete.
void t5SetHomeCapButtonEventsEnabled(bool enabled);

#define PCF8563_RTC 0x51
#define HAS_RTC 1
#define PCF8563_INT 2

#define USE_POWERSAVE
#define SLEEP_TIME 120

// GPS
#if !defined(T5_S3_EPAPER_PRO_V1)
#define GPS_RX_PIN 44
#define GPS_TX_PIN 43
#endif

#if defined(T5_S3_EPAPER_PRO_V1)
#define BUTTON_PIN 48
#define PIN_BUTTON2 0
#define ALT_BUTTON_PIN PIN_BUTTON2
#else
#define BUTTON_PIN 0
#define BOARD_PCA9535_ADDR 0x20
#define BOARD_PCA9535_INT 38
#define BOARD_PCA9535_BUTTON_MASK 0x04
#endif
// SD card
#define HAS_SDCARD
#define SDCARD_CS SPI_CS
#define SD_SPI_FREQUENCY 75000000U

// battery charger BQ25896
#define HAS_PPM 1
#define XPOWERS_CHIP_BQ25896

// battery quality management BQ27220
#define HAS_BQ27220 1
#define BQ27220_I2C_SDA SDA
#define BQ27220_I2C_SCL SCL
#define BQ27220_DESIGN_CAPACITY 1500

// LoRa
#define USE_SX1262
#define USE_SX1268

#define LORA_SCK SCK
#define LORA_MISO MISO
#define LORA_MOSI MOSI
#define LORA_CS 46

#define LORA_DIO0 -1
#if defined(T5_S3_EPAPER_PRO_V1)
#define LORA_RESET 43
#define LORA_DIO1 3  // SX1262 IRQ
#define LORA_DIO2 44 // SX1262 BUSY
#define LORA_DIO3
#else
#define LORA_RESET 1
#define LORA_DIO1 10 // SX1262 IRQ
#define LORA_DIO2 47 // SX1262 BUSY
#define LORA_DIO3
#endif

#define SX126X_CS LORA_CS
#define SX126X_DIO1 LORA_DIO1
#define SX126X_BUSY LORA_DIO2
#define SX126X_RESET LORA_RESET
#define SX126X_DIO2_AS_RF_SWITCH
#define SX126X_DIO3_TCXO_VOLTAGE 2.4
