; Base for Mesh-Tab device (esp32-s3 N16R2 + ra-sh01 lora)
; https://github.com/valzzu/Mesh-Tab
[mesh_tab_base]
extends = esp32s3_base
board = mesh-tab
board_level = extra
board_upload.flash_size = 16MB
board_build.partitions = default_16MB.csv
upload_protocol = esptool
build_flags = ${esp32s3_base.build_flags}
  -D MESH_TAB
  -D CONFIG_ARDUHAL_ESP_LOG
  -D CONFIG_ARDUHAL_LOG_COLORS=1
  -D CONFIG_DISABLE_HAL_LOCKS=1
  -D MESHTASTIC_EXCLUDE_CANNEDMESSAGES=1
  -D MESHTASTIC_EXCLUDE_INPUTBROKER=1
  -D MESHTASTIC_EXCLUDE_BLUETOOTH=1
  -D MESHTASTIC_EXCLUDE_WEBSERVER=1
  -D LV_LVGL_H_INCLUDE_SIMPLE
  -D LV_CONF_INCLUDE_SIMPLE
  -D LV_COMP_CONF_INCLUDE_SIMPLE
  -D LV_USE_SYSMON=0
  -D LV_USE_PROFILER=0
  -D LV_USE_PERF_MONITOR=0
  -D LV_USE_MEM_MONITOR=0
  -D LV_USE_LOG=0
  -D LV_BUILD_TEST=0
  -D USE_LOG_DEBUG
  -D LOG_DEBUG_INC=\"DebugConfiguration.h\"
  -D RADIOLIB_SPI_PARANOID=0
  -D MAX_THREADS=40
  -D HAS_SCREEN=0
  -D HAS_TFT=1
  -D USE_PIN_BUZZER
  -D RAM_SIZE=1024
  -D LGFX_DRIVER_TEMPLATE
  -D LGFX_DRIVER=LGFX_GENERIC
  -D GFX_DRIVER_INC=\"graphics/LGFX/LGFX_GENERIC.h\"
  -D LGFX_PIN_SCK=12
  -D LGFX_PIN_MOSI=13
  -D LGFX_PIN_MISO=11
  -D LGFX_PIN_DC=16
  -D LGFX_PIN_CS=10
  -D LGFX_PIN_RST=-1
  -D LGFX_PIN_BL=42
  -D LGFX_TOUCH_INT=41
  -D VIEW_320x240
  -D USE_PACKET_API
  -I variants/mesh-tab
build_src_filter = ${esp32_base.build_src_filter}
lib_deps =
  ${esp32_base.lib_deps}
  ${device-ui_base.lib_deps}
  lovyan03/LovyanGFX@^1.2.0

[mesh_tab_xpt2046]
extends = mesh_tab_base
build_flags = ${mesh_tab_base.build_flags}
  -D LGFX_TOUCH=XPT2046
  -D LGFX_TOUCH_SPI_FREQ=2500000
  -D LGFX_TOUCH_SPI_HOST=2
  -D LGFX_TOUCH_CS=7
  -D LGFX_TOUCH_CLK=12
  -D LGFX_TOUCH_DO=11
  -D LGFX_TOUCH_DIN=13
  -D LGFX_TOUCH_X_MIN=300
  -D LGFX_TOUCH_X_MAX=3900
  -D LGFX_TOUCH_Y_MIN=400
  -D LGFX_TOUCH_Y_MAX=3900

[mesh_tab_ft5x06]
extends = mesh_tab_base
build_flags = ${mesh_tab_base.build_flags}
  -D LGFX_TOUCH=FT5x06
  -D LGFX_TOUCH_I2C_FREQ=400000
  -D LGFX_TOUCH_I2C_PORT=0
  -D LGFX_TOUCH_I2C_ADDR=0x38
  -D LGFX_TOUCH_I2C_SDA=8
  -D LGFX_TOUCH_I2C_SCL=9
  -D LGFX_TOUCH_RST=7

; 3.2" TN TFT ST7789 / XPT2046: https://vi.aliexpress.com/item/1005005933490544.html
[env:mesh-tab-3-2-TN-resistive]
extends = mesh_tab_base
build_flags = ${mesh_tab_xpt2046.build_flags}
  -D SPI_FREQUENCY=60000000
  -D LGFX_SCREEN_WIDTH=240
  -D LGFX_SCREEN_HEIGHT=320
  -D LGFX_PANEL=ST7789
  -D LGFX_INVERT_COLOR=false
  -D LGFX_ROTATION=3
  -D LGFX_TOUCH_ROTATION=4

; 3.2" IPS TFT ILI9341 / XPT2046: https://www.aliexpress.com/item/1005006258575617.html
[env:mesh-tab-3-2-IPS-resistive]
extends = mesh_tab_base
build_flags = ${mesh_tab_xpt2046.build_flags}
  -D SPI_FREQUENCY=60000000 ; if image is distorted then lower to 40 MHz
  -D LGFX_SCREEN_WIDTH=240
  -D LGFX_SCREEN_HEIGHT=320
  -D LGFX_PANEL=ILI9341
  -D LGFX_ROTATION=1
  -D LGFX_TOUCH_ROTATION=4

; 3.5" IPS TFT ILI9488 / XPT2046: https://vi.aliexpress.com/item/1005006333922639.html
[env:mesh-tab-3-5-IPS-resistive]
extends = mesh_tab_base
build_flags = ${mesh_tab_xpt2046.build_flags}
  -D SPI_FREQUENCY=60000000 ; may go higher upto 40/60/80 MHz
  -D DISPLAY_SET_RESOLUTION
  -D LGFX_SCREEN_WIDTH=320
  -D LGFX_SCREEN_HEIGHT=480
  -D LGFX_PANEL=ILI9488
  -D LGFX_ROTATION=0
  -D LGFX_TOUCH_ROTATION=0

; 3.5" TN TFT ILI9488 / XPT2046: https://vi.aliexpress.com/item/32985467436.html
[env:mesh-tab-3-5-TN-resistive]
extends = mesh_tab_base
build_flags = ${mesh_tab_xpt2046.build_flags}
  -D SPI_FREQUENCY=60000000
  -D DISPLAY_SET_RESOLUTION
  -D LGFX_SCREEN_WIDTH=320
  -D LGFX_SCREEN_HEIGHT=480
  -D LGFX_PANEL=HX8357B
  -D LGFX_INVERT_COLOR=false
  -D LGFX_ROTATION=4
  -D LGFX_TOUCH_ROTATION=2

; 3.2" IPS TFT ILI9341 / FT6236: https://vi.aliexpress.com/item/1005006624072350.html
[env:mesh-tab-3-2-IPS-capacitive]
extends = mesh_tab_base
build_flags = ${mesh_tab_ft5x06.build_flags}
  -D SPI_FREQUENCY=75000000 ; may go higher upto 60/80 MHz
  -D LGFX_SCREEN_WIDTH=240
  -D LGFX_SCREEN_HEIGHT=320
  -D LGFX_PANEL=ILI9341
  -D LGFX_ROTATION=1
  -D LGFX_TOUCH_X_MIN=0
  -D LGFX_TOUCH_X_MAX=239
  -D LGFX_TOUCH_Y_MIN=0
  -D LGFX_TOUCH_Y_MAX=319
  -D LGFX_TOUCH_ROTATION=2

; 3.5" IPS TFT ILI9488 / FT6236: https://vi.aliexpress.com/item/1005006893699919.html
[env:mesh-tab-3-5-IPS-capacitive]
extends = mesh_tab_base
build_flags = ${mesh_tab_ft5x06.build_flags}
  -D SPI_FREQUENCY=75000000 ; may go higher upto 40/60/80 MHz
  -D DISPLAY_SET_RESOLUTION
  -D LGFX_SCREEN_WIDTH=320
  -D LGFX_SCREEN_HEIGHT=480
  -D LGFX_PANEL=ILI9488
  -D LGFX_ROTATION=2
  -D LGFX_TOUCH_X_MIN=0
  -D LGFX_TOUCH_X_MAX=319
  -D LGFX_TOUCH_Y_MIN=0
  -D LGFX_TOUCH_Y_MAX=479
  -D LGFX_TOUCH_ROTATION=0

; 4.0" IPS TFT ILI9488 / FT6236: https://vi.aliexpress.com/item/1005007082906950.html
[env:mesh-tab-4-0-IPS-capacitive]
extends = mesh_tab_base
build_flags = ${mesh_tab_ft5x06.build_flags}
  -D SPI_FREQUENCY=75000000
  -D DISPLAY_SET_RESOLUTION
  -D LGFX_SCREEN_WIDTH=320
  -D LGFX_SCREEN_HEIGHT=480
  -D LGFX_PANEL=HX8357B
  -D LGFX_ROTATION=4
  -D LGFX_TOUCH_X_MIN=0
  -D LGFX_TOUCH_X_MAX=319
  -D LGFX_TOUCH_Y_MIN=0
  -D LGFX_TOUCH_Y_MAX=479
  -D LGFX_TOUCH_ROTATION=6
