cmake_minimum_required(VERSION 3.21)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include(ExternalProject)

ExternalProject_Add(tools
    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools
    BINARY_DIR ${CMAKE_BINARY_DIR}/tools
    CMAKE_ARGS -DCMAKE_C_COMPILER=cc
               -DCMAKE_CXX_COMPILER=c++
    INSTALL_COMMAND ""
)

include($ENV{PICO_SDK_PATH}/pico_sdk_init.cmake)

project(pico-pio-adc)
pico_sdk_init()

add_executable(pico-pio-adc main.c)

add_subdirectory(vendor/pico-stdio-usb-simple)

target_link_libraries(
  pico-pio-adc
  pico_stdio_usb_simple

  pico_divider
  pico_multicore
  pico_stdlib
  pico_util
  hardware_adc
  hardware_pwm
  hardware_divider
  hardware_dma
  hardware_pio
  hardware_timer
  hardware_vreg
)

target_compile_definitions(pico-pio-adc PRIVATE
	PLL_SYS_REFDIV=1
	PLL_SYS_VCO_FREQ_HZ=1584000000
	PLL_SYS_POSTDIV1=6
	PLL_SYS_POSTDIV2=2
	SYS_CLK_HZ=132000000
)

pico_add_extra_outputs(pico-pio-adc)

set_property(TARGET pico-pio-adc PROPERTY C_STANDARD 23)
target_compile_options(pico-pio-adc PRIVATE -Wall -Wextra -Wnull-dereference)
target_compile_definitions(pico-pio-adc PUBLIC PICO_MAX_SHARED_IRQ_HANDLERS=8u)
target_compile_definitions(pico-pio-adc PUBLIC PICO_STDIO_ENABLE_CRLF_SUPPORT=1)
target_compile_definitions(pico-pio-adc PUBLIC PICO_STDIO_DEFAULT_CRLF=1)
target_compile_definitions(pico-pio-adc PUBLIC PICO_STDIO_AUX=1)

target_include_directories(pico-pio-adc PRIVATE include)

#pico_set_binary_type(pico-pio-adc no_flash)
#pico_set_binary_type(pico-pio-adc copy_to_ram)
