# Lisael Box — main component.
#
# Audio uses NO ESP-ADF: playback/decoding is done with the managed components
# chmorgan/esp-audio-player (MP3) and espressif/esp_audio_codec (AAC/M4A), with
# PCM handed to the BSP ES8311 codec via esp_codec_dev. See idf_component.yml.

set(srcs
    "app_main.c"
    "net/wifi.c"
    "net/wifi_portal.c"
    "net/file_server.c"
    "net/box_register.c"
    "net/sntp_time.c"
    "net/weather.c"
    "net/udp_log.c"
    "ui/ui.c"
    "ui/fr_date.c"
    "ui/icons.c"
    "modes/home.c"
    "modes/radio.c"
    "modes/calm.c"
    "modes/clock.c"
    "modes/games.c"
    "modes/balloons.c"
    "modes/maze.c"
    "modes/histoires.c"
    "modes/wifi_setup.c"
    "modes/lire.c"
    "modes/routine.c"
    "audio/audio_player.c"
    "audio/radio_pipeline.c"
    "audio/sd_player.c"
    "audio/aac_player.c"
    "audio/calm_tone.c"
    "audio/podcast_manifest.c"
    "audio/routine_manifest.c"
    "net/podcast.c"
)

# Generated colour icon image descriptors (ui/assets/*.c, Twemoji -> LVGL).
file(GLOB lisael_icon_srcs "${CMAKE_CURRENT_SOURCE_DIR}/ui/assets/*.c")
list(APPEND srcs ${lisael_icon_srcs})

# Generated Fredoka fonts with French accents (ui/fonts/*.c).
file(GLOB lisael_font_srcs "${CMAKE_CURRENT_SOURCE_DIR}/ui/fonts/*.c")
list(APPEND srcs ${lisael_font_srcs})

set(reqs
    nvs_flash
    esp_wifi
    esp_event
    esp_netif
    lwip              # lwip/sockets.h for the UDP log sink
    esp-tls
    esp_http_client
    esp_http_server   # SoftAP captive provisioning portal
    mbedtls          # esp_crt_bundle_attach (CA bundle for HTTPS)
    esp-box-3        # BSP: display, touch, codec, sdcard, sensors
    espressif__icm42670  # IMU accelerometer (tilt maze game)
    json             # IDF built-in cJSON component (provides cJSON.h)
    fatfs
    esp_driver_i2c
    esp_driver_tsens  # driver/temperature_sensor.h (internal die temp)
    esp_driver_i2s    # i2s_slot_mode_t in the audio-player clock callback
    chmorgan__esp-audio-player  # MP3 -> PCM player (SD playback, no ESP-ADF)
    espressif__esp_audio_codec  # AAC/M4A simple decoder (podcast self-test)
)

idf_component_register(
    SRCS ${srcs}
    INCLUDE_DIRS "."
    REQUIRES ${reqs}
)

# GCC 14 (-Werror=array-bounds) émet un faux positif sur l'indexation gardée
# de s_screens[mode] dans ui.c (la garde (unsigned)mode < COUNT est ignorée par
# l'analyse de plage). On désarme l'erreur pour ce composant uniquement.
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-error=array-bounds)

# The generated icon descriptors (ui/assets/*.c) pick their LVGL header via
# LV_LVGL_H_INCLUDE_* macros; without one they fall back to "lvgl/lvgl.h"
# which isn't on the include path. Force the simple "lvgl.h" include.
target_compile_definitions(${COMPONENT_LIB} PRIVATE LV_LVGL_H_INCLUDE_SIMPLE=1)
