---
substitutions:
  device: lvgl-eworkbench
  name: Electronics Workbench Display
  area: Office R
  comment: "${area} | Electronics Workbench"

esphome:
  name: mcu-${device}
  friendly_name: ${name}
  area: ${area}
  comment: ${comment}

esp32:
  variant: esp32s3
  flash_size: 16MB
  framework:
    type: esp-idf

packages:
  common: !include common/common.yaml

# external_components:

i2c:
  sda: 4
  scl: 8
  id: touchscreen_bus

psram:
  mode: octal
  speed: 40MHz

spi:
  id: display_qspi
  type: quad
  clk_pin: 47
  data_pins: [21, 48, 40, 39]

color:
  - id: my_red
    red: 100%
    green: 0%
    blue: 0%
  - id: my_orange
    red: 100%
    green: 50%
    blue: 0%
  - id: my_yellow
    red: 100%
    green: 100%
    blue: 0%
  - id: my_green
    red: 0%
    green: 100%
    blue: 0%
  - id: my_blue
    red: 0%
    green: 0%
    blue: 100%
  - id: my_teal
    red: 0%
    green: 100%
    blue: 100%
  - id: my_gray
    red: 70%
    green: 70%
    blue: 70%
  - id: my_white
    red: 100%
    green: 100%
    blue: 100%

font:
  - file: "gfonts://Roboto"
    id: Roboto_48
    size: 48
  - file: "gfonts://Roboto"
    id: Roboto_36
    size: 36
  - file: "gfonts://Roboto"
    id: Roboto_24
    size: 24
  - file: "gfonts://Roboto"
    id: Roboto_12
    size: 12
  - file: "gfonts://Roboto"
    id: font_std
    size: 40
    glyphs: "!\"%()+=,-_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz/\\[]|&@#'"
  - file: "gfonts://Roboto@700"
    id: font_title
    size: 40
    glyphs: "!\"%()+=,-_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz/\\[]|&@#'"

globals:
  - id: bgcolor
    type: Color
    initial_value: "Color::random_color()"

power_supply:
  id: main_backlight
  pin: 1
  enable_on_boot: true

display:
  - platform: qspi_dbi
    model: axs15231
    data_rate: 40MHz #20mhz is default
    #spi_mode: MODE2
    id: main_display
    spi_id: display_qspi
    dimensions:
      height: 480
      width: 320
    cs_pin: 45
    brightness: 50
    rotation: 90
    auto_clear_enabled: false
    show_test_card: true
    lambda: |-
      it.fill(id(bgcolor));
      it.print(it.get_width()/2, it.get_height()/2-20, id(font_title), TextAlign::CENTER, "ESPHome");
      it.print(it.get_width()/2, it.get_height()/2+20, id(font_std), TextAlign::CENTER, "@UTBDK");

touchscreen:
  - platform: axs15231
    id: main_touch
    display: main_display
    i2c_id: touchscreen_bus
    transform:
      swap_xy: true
    on_touch:
      - lambda: |-
          Color newColor;
          do { newColor =  Color::random_color(); } while (newColor == id(bgcolor));
          id(bgcolor) = newColor;

          ESP_LOGI("cal", "x=%d, y=%d, x_raw=%d, y_raw=%0d",
            touch.x,
            touch.y,
            touch.x_raw,
            touch.y_raw
          );
