2024-07-29 04:24:28 +08:00
|
|
|
cmake_minimum_required(VERSION 3.6)
|
|
|
|
|
2024-11-26 04:06:20 +08:00
|
|
|
## Version Configuration
|
2024-07-29 04:24:28 +08:00
|
|
|
set(VERSION_MAJOR 00)
|
2024-12-05 03:00:13 +08:00
|
|
|
set(VERSION_MINOR 162)
|
2023-12-25 06:22:05 +08:00
|
|
|
|
2024-11-26 04:06:20 +08:00
|
|
|
## Release Type Selection
|
|
|
|
option(DH_DEBUG "Build a debug version" OFF)
|
|
|
|
|
|
|
|
## Hardware Configuration
|
|
|
|
set(DP_PIN_DEFAULT 14 CACHE STRING "Default USB D+ Pin Number")
|
|
|
|
set(PIO_USE_TINYUSB 1 CACHE STRING "Make TinyUSB Manage the PIO USB Port")
|
|
|
|
set(PICO_BOARD "pico")
|
|
|
|
|
|
|
|
## Pico SDK Configuration
|
2023-12-25 06:22:05 +08:00
|
|
|
set(PICO_SDK_FETCH_FROM_GIT off)
|
2024-03-25 02:02:37 +08:00
|
|
|
set(PICO_SDK_PATH ${CMAKE_CURRENT_LIST_DIR}/pico-sdk)
|
2024-11-26 04:06:20 +08:00
|
|
|
set(SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
|
2023-12-25 06:22:05 +08:00
|
|
|
include(pico_sdk_import.cmake)
|
2024-01-03 17:48:34 +08:00
|
|
|
|
2024-11-26 04:06:20 +08:00
|
|
|
## Project Setup
|
2023-12-25 06:22:05 +08:00
|
|
|
project(deskhop_project C CXX ASM)
|
|
|
|
set(CMAKE_C_STANDARD 11)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2024-11-26 04:06:20 +08:00
|
|
|
set(PICO_COPY_TO_RAM 1)
|
2024-01-28 05:38:46 +08:00
|
|
|
|
2024-11-26 04:06:20 +08:00
|
|
|
## Compiler Flags
|
|
|
|
set(CMAKE_C_FLAGS "-Ofast -Wall -mcpu=cortex-m0plus -mtune=cortex-m0plus -fstack-usage")
|
|
|
|
|
|
|
|
## Initialize Pico SDK
|
2023-12-25 06:22:05 +08:00
|
|
|
pico_sdk_init()
|
|
|
|
|
2024-11-26 04:06:20 +08:00
|
|
|
## PIO USB Library Setup
|
2023-12-25 06:22:05 +08:00
|
|
|
set(PICO_PIO_USB_DIR ${CMAKE_CURRENT_LIST_DIR}/Pico-PIO-USB)
|
|
|
|
|
|
|
|
add_library(Pico-PIO-USB STATIC
|
2024-11-26 04:06:20 +08:00
|
|
|
${PICO_PIO_USB_DIR}/src/pio_usb.c
|
|
|
|
${PICO_PIO_USB_DIR}/src/pio_usb_host.c
|
|
|
|
${PICO_PIO_USB_DIR}/src/usb_crc.c
|
2023-12-25 06:22:05 +08:00
|
|
|
)
|
|
|
|
pico_generate_pio_header(Pico-PIO-USB ${PICO_PIO_USB_DIR}/src/usb_tx.pio)
|
|
|
|
pico_generate_pio_header(Pico-PIO-USB ${PICO_PIO_USB_DIR}/src/usb_rx.pio)
|
|
|
|
|
|
|
|
target_link_libraries(Pico-PIO-USB PRIVATE
|
|
|
|
pico_stdlib
|
|
|
|
pico_multicore
|
|
|
|
hardware_pio
|
|
|
|
hardware_dma
|
|
|
|
)
|
|
|
|
target_include_directories(Pico-PIO-USB PRIVATE ${PICO_PIO_USB_DIR})
|
|
|
|
|
2024-11-26 04:06:20 +08:00
|
|
|
## Source Files
|
2023-12-25 06:22:05 +08:00
|
|
|
set(COMMON_SOURCES
|
2024-11-26 04:06:20 +08:00
|
|
|
${SRC_DIR}/usb_descriptors.c
|
|
|
|
${SRC_DIR}/defaults.c
|
|
|
|
${SRC_DIR}/constants.c
|
|
|
|
${SRC_DIR}/protocol.c
|
|
|
|
${SRC_DIR}/hid_parser.c
|
|
|
|
${SRC_DIR}/hid_report.c
|
|
|
|
${SRC_DIR}/utils.c
|
|
|
|
${SRC_DIR}/handlers.c
|
|
|
|
${SRC_DIR}/setup.c
|
|
|
|
${SRC_DIR}/keyboard.c
|
|
|
|
${SRC_DIR}/mouse.c
|
|
|
|
${SRC_DIR}/tasks.c
|
|
|
|
${SRC_DIR}/led.c
|
|
|
|
${SRC_DIR}/uart.c
|
|
|
|
${SRC_DIR}/usb.c
|
|
|
|
${SRC_DIR}/main.c
|
|
|
|
${SRC_DIR}/ramdisk.c
|
|
|
|
${PICO_TINYUSB_PATH}/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c
|
|
|
|
${PICO_TINYUSB_PATH}/src/portable/raspberrypi/pio_usb/hcd_pio_usb.c
|
2023-12-25 06:22:05 +08:00
|
|
|
)
|
|
|
|
|
2024-11-26 04:06:20 +08:00
|
|
|
## Include Directories
|
2023-12-25 06:22:05 +08:00
|
|
|
set(COMMON_INCLUDES
|
2024-11-26 04:06:20 +08:00
|
|
|
${SRC_DIR}/include
|
|
|
|
${PICO_PIO_USB_DIR}/src
|
2023-12-25 06:22:05 +08:00
|
|
|
)
|
|
|
|
|
2024-11-26 04:06:20 +08:00
|
|
|
## Library Dependencies
|
2023-12-25 06:22:05 +08:00
|
|
|
set(COMMON_LINK_LIBRARIES
|
|
|
|
pico_stdlib
|
2024-01-17 01:38:24 +08:00
|
|
|
hardware_flash
|
2023-12-25 06:22:05 +08:00
|
|
|
hardware_uart
|
|
|
|
hardware_gpio
|
2024-01-03 17:48:34 +08:00
|
|
|
hardware_pio
|
2024-07-29 04:24:28 +08:00
|
|
|
hardware_dma
|
2023-12-25 06:22:05 +08:00
|
|
|
|
|
|
|
tinyusb_device
|
2024-01-03 17:48:34 +08:00
|
|
|
tinyusb_host
|
2023-12-25 06:22:05 +08:00
|
|
|
pico_multicore
|
|
|
|
Pico-PIO-USB
|
|
|
|
)
|
2024-07-29 04:24:28 +08:00
|
|
|
set(binary deskhop)
|
2023-12-25 06:22:05 +08:00
|
|
|
|
2024-11-26 04:06:20 +08:00
|
|
|
## Disk Image Configuration
|
|
|
|
# This assembles disk.S, then updates the elf section in post-build
|
|
|
|
# With the disk FAT image binary in /disk/disk.img
|
|
|
|
|
2024-07-29 04:24:28 +08:00
|
|
|
set(DISK_ASM "${CMAKE_CURRENT_LIST_DIR}/disk/disk.S")
|
|
|
|
set(DISK_BIN "${CMAKE_CURRENT_LIST_DIR}/disk/disk.img")
|
|
|
|
set_property(SOURCE ${DISK_ASM} APPEND PROPERTY COMPILE_OPTIONS "-x" "assembler-with-cpp")
|
2024-03-25 02:02:37 +08:00
|
|
|
|
2024-07-29 04:24:28 +08:00
|
|
|
add_executable(${binary} ${DISK_ASM})
|
2023-12-25 06:22:05 +08:00
|
|
|
|
2024-07-29 04:24:28 +08:00
|
|
|
target_sources(${binary} PUBLIC ${COMMON_SOURCES})
|
|
|
|
target_compile_definitions(${binary}
|
|
|
|
PRIVATE
|
2024-11-26 04:06:20 +08:00
|
|
|
PIO_USB_USE_TINYUSB=${PIO_USE_TINYUSB}
|
|
|
|
PIO_USB_DP_PIN_DEFAULT=${DP_PIN_DEFAULT}
|
2024-07-29 04:24:28 +08:00
|
|
|
__disk_file_path__="${DISK_BIN}"
|
|
|
|
)
|
2024-11-26 04:06:20 +08:00
|
|
|
|
|
|
|
## Support building a debug version
|
|
|
|
if (DH_DEBUG)
|
|
|
|
add_definitions(-DDH_DEBUG)
|
|
|
|
endif()
|
2024-07-29 04:24:28 +08:00
|
|
|
|
|
|
|
target_include_directories(${binary} PUBLIC ${COMMON_INCLUDES})
|
|
|
|
target_link_libraries(${binary} PUBLIC ${COMMON_LINK_LIBRARIES})
|
|
|
|
|
2024-11-26 04:06:20 +08:00
|
|
|
## Configure Pico Library
|
2024-07-29 04:24:28 +08:00
|
|
|
pico_enable_stdio_usb(${binary} 0)
|
|
|
|
pico_enable_stdio_uart(${binary} 0)
|
2024-11-26 04:06:20 +08:00
|
|
|
pico_set_linker_script(${binary} ${CMAKE_SOURCE_DIR}/memory_map.ld)
|
2024-07-29 04:24:28 +08:00
|
|
|
|
2024-11-26 04:06:20 +08:00
|
|
|
## Build other file formats as well
|
2024-07-29 04:24:28 +08:00
|
|
|
pico_add_extra_outputs(${binary})
|
|
|
|
|
2024-11-26 04:06:20 +08:00
|
|
|
## Post-Build Commands
|
2024-07-29 04:24:28 +08:00
|
|
|
add_custom_command(
|
|
|
|
TARGET ${binary} POST_BUILD
|
|
|
|
COMMAND python3 ${CMAKE_SOURCE_DIR}/tools/crc32.py ${binary}.bin ${binary}.crc ${VERSION_MAJOR}${VERSION_MINOR}
|
|
|
|
COMMAND ${CMAKE_OBJCOPY} --update-section .section_metadata=${binary}.crc ${binary}.elf
|
|
|
|
COMMAND ${CMAKE_OBJCOPY} -O binary ${binary}.elf ${binary}.bin
|
|
|
|
COMMAND ${CMAKE_BINARY_DIR}/elf2uf2/elf2uf2 ${binary}.elf ${binary}.uf2
|
|
|
|
COMMENT "Update CRC32 section to match the actual binary"
|
|
|
|
)
|
2024-01-12 00:57:29 +08:00
|
|
|
|
2024-11-26 04:06:20 +08:00
|
|
|
## Linker Options
|
2024-07-29 04:24:28 +08:00
|
|
|
target_link_options(${binary} PRIVATE
|
|
|
|
-Xlinker
|
|
|
|
--print-memory-usage
|
|
|
|
)
|
2024-01-17 01:38:24 +08:00
|
|
|
|