cmake_minimum_required(VERSION 3.13)

include(pico_sdk_import.cmake)

project(host_cdc_msc_hid C CXX ASM)
set(CMAKE_C_STNDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(PICO_EXAMPLES_PATH ${PROJECT_SOURCE_DIR})

pico_sdk_init()


add_executable(host_cdc_msc_hid)

pico_generate_pio_header(host_cdc_msc_hid ${CMAKE_CURRENT_LIST_DIR}/lib/sd_driver/SDIO/rp2040_sdio.pio)

# Example source
target_sources(host_cdc_msc_hid PUBLIC
        hid_app.c
        main.c
        msc_app.c
        cdc_app.c
        diskio_USB.c
        diskio_SDIO.c
        com_usb.c
        log.c
        messagerie.c
        lib/FatFs/source/ff.c
        lib/FatFs/source/ffsystem.c
        lib/FatFs/source/diskio.c
        lib/sd_driver/my_debug.c
        lib/sd_driver/dma_interrupts.c
        lib/sd_driver/sd_card.c
        lib/sd_driver/crc.c
        lib/sd_driver/crash.c
        lib/sd_driver/f_util.c
        lib/sd_driver/my_rtc.c
        lib/sd_driver/sd_timeouts.c
        lib/sd_driver/SDIO/rp2040_sdio.c
        lib/sd_driver/SDIO/sd_card_sdio.c
        lib/sd_driver/SPI/my_spi.c
        lib/sd_driver/SPI/sd_card_spi.c
        lib/sd_driver/SPI/sd_spi.c
        ws2812.c
        )

# generate the header file into the source tree as it is included in the RP2040 datasheet
pico_generate_pio_header(host_cdc_msc_hid ${CMAKE_CURRENT_LIST_DIR}/ws2812.pio)


# Make sure TinyUSB can find tusb_config.h
target_include_directories(host_cdc_msc_hid PUBLIC
        ${CMAKE_CURRENT_LIST_DIR}/
        ${CMAKE_CURRENT_LIST_DIR}/lib/FatFs/source/
        ${CMAKE_CURRENT_LIST_DIR}/lib/sd_driver/)

if(PICO_RISCV)
    set(HWDEP_LIBS hardware_watchdog)
else()
    set(HWDEP_LIBS cmsis_core)
endif()

# In addition to pico_stdlib required for common PicoSDK functionality, add dependency on tinyusb_host
# for TinyUSB device support and tinyusb_board for the additional board support library used by the example
target_link_libraries( host_cdc_msc_hid PUBLIC
        pico_stdlib 
        tinyusb_host 
        tinyusb_board
        hardware_dma
        hardware_pio
        hardware_spi
        hardware_sync
        pico_aon_timer
        pico_stdlib
        pico_multicore
        ${HWDEP_LIBS}
        )


pico_add_extra_outputs(host_cdc_msc_hid)


add_custom_target(Flash
    DEPENDS host_cdc_msc_hid
    COMMAND sudo picotool load -f ${PROJECT_BINARY_DIR}/host_cdc_msc_hid.uf2
)

add_definitions(-DPICO_STDIO_ENABLE_CRLF_SUPPORT=0)
