if(${IDF_VERSION_MAJOR} LESS 6)
    set(priv_requires esp_timer driver hal usb)
else()
    set(priv_requires
        esp_timer
        esp_driver_gpio
        esp_driver_i2c
        esp_driver_i2s
        esp_driver_rmt
        esp_driver_uart
        esp_hal_usb
        esp_hw_support
        vfs
    )
endif()

set(app_sources
    "main.c"
    "audio_backend.c"
    "pcmd3180/pcmd3180.c"
    "usb_driver/usb_audio.c"
    "usb_driver/usb_descriptors.c"
    "usb_driver/usb_hid_keyboard.c"
)

if(CONFIG_WS2812_LED_RING_ENABLE)
    list(APPEND app_sources
        "ws2812/ws2812.c"
        "ws2812/led_ring_effects.c"
        "ws2812/led_ring.c"
    )
endif()

idf_component_register(
    SRCS ${app_sources}
    INCLUDE_DIRS
        "."
        "pcmd3180"
        "usb_driver"
        "ws2812"
    PRIV_REQUIRES ${priv_requires}
    WHOLE_ARCHIVE
)

# The managed TinyUSB component must see this component's tusb_config.h while
# TinyUSB itself is being compiled.
idf_build_get_property(build_components BUILD_COMPONENTS)
if(tinyusb IN_LIST build_components)
    set(tinyusb_component tinyusb)
else()
    set(tinyusb_component espressif__tinyusb)
endif()
idf_component_get_property(tinyusb_lib ${tinyusb_component} COMPONENT_LIB)
target_include_directories(${tinyusb_lib} PUBLIC "${COMPONENT_DIR}/usb_driver")
