-
Notifications
You must be signed in to change notification settings - Fork 201
/
Copy pathCMakeLists.txt
146 lines (121 loc) · 3.88 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
cmake_minimum_required(VERSION 3.6)
## Version Configuration
set(VERSION_MAJOR 00)
set(VERSION_MINOR 162)
## 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
set(PICO_SDK_FETCH_FROM_GIT off)
set(PICO_SDK_PATH ${CMAKE_CURRENT_LIST_DIR}/pico-sdk)
set(SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
include(${PICO_SDK_PATH}/pico_sdk_import.cmake)
## Project Setup
project(deskhop_project C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(PICO_COPY_TO_RAM 1)
## Compiler Flags
set(CMAKE_C_FLAGS "-Ofast -Wall -mcpu=cortex-m0plus -mtune=cortex-m0plus -fstack-usage")
## Initialize Pico SDK
pico_sdk_init()
## PIO USB Library Setup
set(PICO_PIO_USB_DIR ${CMAKE_CURRENT_LIST_DIR}/Pico-PIO-USB)
add_library(Pico-PIO-USB STATIC
${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
)
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})
## Source Files
set(COMMON_SOURCES
${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
)
## Include Directories
set(COMMON_INCLUDES
${SRC_DIR}/include
${PICO_PIO_USB_DIR}/src
)
## Library Dependencies
set(COMMON_LINK_LIBRARIES
pico_stdlib
hardware_flash
hardware_uart
hardware_gpio
hardware_pio
hardware_dma
tinyusb_device
tinyusb_host
pico_multicore
Pico-PIO-USB
)
set(binary deskhop)
## 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
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")
add_executable(${binary} ${DISK_ASM})
target_sources(${binary} PUBLIC ${COMMON_SOURCES})
target_compile_definitions(${binary}
PRIVATE
PIO_USB_USE_TINYUSB=${PIO_USE_TINYUSB}
PIO_USB_DP_PIN_DEFAULT=${DP_PIN_DEFAULT}
__disk_file_path__="${DISK_BIN}"
)
## Support building a debug version
if (DH_DEBUG)
add_definitions(-DDH_DEBUG)
endif()
target_include_directories(${binary} PUBLIC ${COMMON_INCLUDES})
target_link_libraries(${binary} PUBLIC ${COMMON_LINK_LIBRARIES})
## Configure Pico Library
pico_enable_stdio_usb(${binary} 0)
pico_enable_stdio_uart(${binary} 0)
pico_set_linker_script(${binary} ${CMAKE_SOURCE_DIR}/misc/memory_map.ld)
## Build other file formats as well
pico_add_extra_outputs(${binary})
## Post-Build Commands
add_custom_command(
TARGET ${binary} POST_BUILD
COMMAND python3 ${CMAKE_SOURCE_DIR}/misc/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"
)
## Linker Options
target_link_options(${binary} PRIVATE
-Xlinker
--print-memory-usage
)