[heltec_v4_base] 
extends = esp32s3_base
board = heltec_v4
board_check = true
board_build.partitions = default_16MB.csv
build_flags = 
  ${esp32s3_base.build_flags}
  -D HELTEC_V4
  -D HAS_LORA_FEM=1
  -I variants/esp32s3/heltec_v4


[env:heltec-v4]
custom_meshtastic_hw_model = 110
custom_meshtastic_hw_model_slug = HELTEC_V4
custom_meshtastic_architecture = esp32-s3
custom_meshtastic_actively_supported = true
custom_meshtastic_support_level = 1
custom_meshtastic_display_name = Heltec V4
custom_meshtastic_images = heltec_v4.svg
custom_meshtastic_tags = Heltec
custom_meshtastic_requires_dfu = true
custom_meshtastic_partition_scheme = 16MB
custom_meshtastic_has_mui = true

extends = heltec_v4_base
board_level = pr
build_flags =
  ${heltec_v4_base.build_flags}
  -D HELTEC_V4_OLED
  -D USE_SSD1306 ; Heltec_v4 has an SSD1315 display (compatible with SSD1306 driver)
  -D LED_POWER=35
  -D RESET_OLED=21
  -D I2C_SDA=17
  -D I2C_SCL=18
  -D I2C_SDA1=4
  -D I2C_SCL1=3

[env:heltec-v4-tft]
custom_meshtastic_hw_model = 110
custom_meshtastic_hw_model_slug = HELTEC_V4
custom_meshtastic_architecture = esp32-s3
custom_meshtastic_actively_supported = true
custom_meshtastic_support_level = 1
custom_meshtastic_display_name = Heltec V4 TFT
custom_meshtastic_images = heltec_v4.svg
custom_meshtastic_tags = Heltec
custom_meshtastic_requires_dfu = true
custom_meshtastic_partition_scheme = 16MB

extends = heltec_v4_base
build_flags = 
  ${heltec_v4_base.build_flags} ;-Os
  -D HELTEC_V4_TFT
  -D I2C_SDA=4
  -D I2C_SCL=3
  -D I2C_SDA1=47
  -D I2C_SCL1=48
  -D PIN_BUTTON2=35
  -D PIN_BUZZER=6
  -D USE_PIN_BUZZER=PIN_BUZZER
  -D CONFIG_ARDUHAL_LOG_COLORS
  -D RADIOLIB_DEBUG_SPI=0
  -D RADIOLIB_DEBUG_PROTOCOL=0
  -D RADIOLIB_DEBUG_BASIC=0
  -D RADIOLIB_VERBOSE_ASSERT=0
  -D RADIOLIB_SPI_PARANOID=0
  -D CONFIG_DISABLE_HAL_LOCKS=1
  -D INPUTDRIVER_BUTTON_TYPE=0
  -D HAS_SCREEN=1
  -D HAS_TFT=1
  -D MAP_TILES_GREY ; required for 2MB PSRAM
  -D RAM_SIZE=1432
  -D STBI_ARENA_SIZE=450000
  -D LV_CACHE_DEF_SIZE=0
  -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 USE_PACKET_API
  -D LGFX_DRIVER=LGFX_HELTEC_V4_TFT
  -D GFX_DRIVER_INC=\"graphics/LGFX/LGFX_HELTEC_V4_TFT.h\"
  -D VIEW_240x320
  -D DISPLAY_SET_RESOLUTION
  -D DISPLAY_SIZE=240x320 ; portrait mode
  -D LGFX_SPI_3WIRE=true
  -D LGFX_PIN_SCK=17
  -D LGFX_PIN_MOSI=33
  -D LGFX_PIN_MISO=-1
  -D LGFX_PIN_DC=16
  -D LGFX_PIN_CS=15
  -D LGFX_PIN_BL=21
  -D LGFX_PIN_RST=18
  -D CUSTOM_TOUCH_DRIVER
  -D TOUCH_SDA_PIN=I2C_SDA1
  -D TOUCH_SCL_PIN=I2C_SCL1
  -D TOUCH_INT_PIN=-1  ;45
  -D TOUCH_RST_PIN=44
;base UI
  -D TFT_CS=LGFX_PIN_CS
  -D ST7789_CS=TFT_CS
  -D ST7789_RS=LGFX_PIN_DC
  -D ST7789_SDA=LGFX_PIN_MOSI 
  -D ST7789_SCK=LGFX_PIN_SCK
  -D ST7789_RESET=LGFX_PIN_RST
  -D ST7789_MISO=-1
  -D ST7789_BUSY=-1
  -D ST7789_BL=LGFX_PIN_BL
  -D ST7789_SPI_HOST=SPI3_HOST
  -D TFT_BL=ST7789_BL
  -D SPI_FREQUENCY=40000000
  -D SPI_READ_FREQUENCY=4000000
  -D TFT_HEIGHT=320
  -D TFT_WIDTH=240
  -D TFT_OFFSET_X=0
  -D TFT_OFFSET_Y=0
  -D TFT_OFFSET_ROTATION=0
  -D SCREEN_ROTATE
  -D SCREEN_TRANSITION_FRAMERATE=30
  -D BRIGHTNESS_DEFAULT=130 ; Medium Low Brightness
  -D HAS_TOUCHSCREEN=1
  -D TOUCH_I2C_PORT=1
  -D TOUCH_SLAVE_ADDRESS=0x2E
  -D SCREEN_TOUCH_INT=TOUCH_INT_PIN
  -D SCREEN_TOUCH_RST=TOUCH_RST_PIN

lib_deps = ${heltec_v4_base.lib_deps}
  ${device-ui_base.lib_deps}
  # renovate: datasource=custom.pio depName=LovyanGFX packageName=lovyan03/library/LovyanGFX
  lovyan03/LovyanGFX@1.2.21
  # renovate: datasource=git-refs depName=Quency-D_chsc6x packageName=https://github.com/Quency-D/chsc6x gitBranch=master
  https://github.com/Quency-D/chsc6x/archive/5cbead829d6b432a8d621ed1aafd4eb474fd4f27.zip
