馃 meltybrain avocado
2.7 kB
94 lines
1cmake_minimum_required(VERSION 3.13)
2
3# Export compile_commands.json so clangd resolves SDK headers.
4set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5
6include(pico_sdk_import.cmake)
7
8project(holy_guacamole C CXX ASM)
9
10set(CMAKE_C_STANDARD 11)
11set(CMAKE_CXX_STANDARD 17)
12
13pico_sdk_init()
14
15# Sensor source selection. Override with -DSENSOR_SOURCE=rssi at configure time.
16# Options: imu_ekf (default), rssi, or imu_ekf,rssi (fusion)
17if(NOT DEFINED SENSOR_SOURCE)
18 set(SENSOR_SOURCE imu_ekf)
19endif()
20
21message(STATUS "Sensor source: ${SENSOR_SOURCE}")
22
23# CMake lists are semicolon-separated; convert the comma-separated option.
24string(REPLACE "," ";" SENSOR_LIST "${SENSOR_SOURCE}")
25
26add_executable(holy_guacamole
27 src/main.c
28 src/dshot/dshot.c
29 src/crsf/crsf.c
30 src/math/linalg.c
31 src/estimation/ekf.c
32 src/estimation/edge_pll.c
33 src/estimation/rssi_interp.c
34 src/estimation/autocorr.c
35 src/estimation/rssi_heading.c
36 src/control/drift.c
37 src/control/pid.c
38 src/app/control_loop.c
39 src/led/head_led.c
40 src/safety/watchdog.c
41 src/safety/battery.c
42 src/safety/rc_health.c
43)
44
45# Parse comma-separated sensor sources and link + define each.
46set(_valid_sources imu_ekf rssi)
47foreach(src IN LISTS SENSOR_LIST)
48 string(STRIP "${src}" src)
49 if(src STREQUAL "imu_ekf")
50 target_sources(holy_guacamole PRIVATE
51 src/sensor/sensor_imu_ekf.c
52 src/imu/latch.c
53 src/imu/imu_spi.c
54 src/estimation/imu_geom.c
55 src/estimation/meas_model.c
56 src/estimation/imu_convert.c
57 src/estimation/accel_cal.c
58 )
59 target_compile_definitions(holy_guacamole PRIVATE SENSOR_SOURCE_IMU_EKF)
60 elseif(src STREQUAL "rssi")
61 target_sources(holy_guacamole PRIVATE
62 src/sensor/sensor_rssi.c
63 src/sensor/rssi_uart.c
64 )
65 target_compile_definitions(holy_guacamole PRIVATE SENSOR_SOURCE_RSSI)
66 else()
67 message(FATAL_ERROR "Unknown sensor source '${src}'. Valid: ${_valid_sources}")
68 endif()
69endforeach()
70
71# Generate PIO header from .pio file
72pico_generate_pio_header(holy_guacamole ${CMAKE_CURRENT_SOURCE_DIR}/src/dshot/dshot_bidir_600.pio)
73
74target_include_directories(holy_guacamole PRIVATE
75 ${CMAKE_CURRENT_SOURCE_DIR}/include
76 ${CMAKE_CURRENT_SOURCE_DIR}/src
77)
78
79target_link_libraries(holy_guacamole PRIVATE
80 pico_stdlib
81 pico_multicore
82 hardware_pio
83 hardware_spi
84 hardware_adc
85 hardware_uart
86 hardware_dma
87 hardware_irq
88)
89
90pico_add_extra_outputs(holy_guacamole)
91
92# Console over USB CDC, not UART: UART0 is dedicated to the CRSF receiver.
93pico_enable_stdio_usb(holy_guacamole 1)
94pico_enable_stdio_uart(holy_guacamole 0)