-
Notifications
You must be signed in to change notification settings - Fork 28
/
CMakeLists.txt
137 lines (115 loc) · 4.16 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
# CMakeLists
#
# MIT License
#
# Copyright (c) 2021, 2024 Matt Evans
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#
cmake_minimum_required(VERSION 3.13)
# Options that should be defined when initialising the build
# directory with cmake, e.g. "cmake .. -DOPTION=true":
#
option(USE_SD "Build in SD support" OFF)
set(SD_TX 3 CACHE STRING "SD SPI TX pin")
set(SD_RX 4 CACHE STRING "SD SPI RX pin")
set(SD_SCK 2 CACHE STRING "SD SPI SCK pin")
set(SD_CS 5 CACHE STRING "SD SPI CS pin")
set(SD_MHZ 5 CACHE STRING "SD SPI speed in MHz")
# See below, -DMEMSIZE=<size in KB> will configure umac's memory size,
# overriding defaults.
# initialize the SDK based on PICO_SDK_PATH
# note: this must happen before project()
include(pico_sdk_import.cmake)
project(firmware)
# initialize the Raspberry Pi Pico SDK
pico_sdk_init()
# For TUSB host stuff:
set(FAMILY rp2040)
set(BOARD raspberry_pi_pico)
set(TINYUSB_PATH ${PICO_SDK_PATH}/lib/tinyusb)
# umac subproject (and Musashi sub-subproject)
set(UMAC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/external/umac)
set(UMAC_MUSASHI_PATH ${UMAC_PATH}/external/Musashi)
set(UMAC_INCLUDE_PATHS ${UMAC_PATH}/include ${UMAC_MUSASHI_PATH})
# This isn't very nice, but hey it's Sunday :p
set(UMAC_SOURCES
${UMAC_PATH}/src/disc.c
${UMAC_PATH}/src/main.c
${UMAC_PATH}/src/rom.c
${UMAC_PATH}/src/scc.c
${UMAC_PATH}/src/via.c
${UMAC_MUSASHI_PATH}/m68kcpu.c
${UMAC_MUSASHI_PATH}/m68kdasm.c
${UMAC_MUSASHI_PATH}/m68kops.c
${UMAC_MUSASHI_PATH}/softfloat/softfloat.c
)
set(MEMSIZE 128 CACHE STRING "Memory size, in KB")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -DPICO -DMUSASHI_CNF=\\\"../include/m68kconf.h\\\" -DUMAC_MEMSIZE=${MEMSIZE}")
if (USE_SD)
add_compile_definitions(USE_SD=1)
set(FF_DISABLE_RTC ${PICO_RP2350}) # RP2350 doesn't have RTC, so disable it
add_subdirectory(external/no-OS-FatFS-SD-SPI-RPi-Pico/FatFs_SPI build)
set(EXTRA_SD_SRC src/sd_hw_config.c)
set(EXTRA_SD_LIB FatFs_SPI)
add_compile_definitions(SD_TX=${SD_TX} SD_RX=${SD_RX} SD_SCK=${SD_SCK} SD_CS=${SD_CS} SD_MHZ=${SD_MHZ})
endif()
if (TARGET tinyusb_device)
add_executable(firmware
src/main.c
src/video.c
src/kbd.c
src/hid.c
${EXTRA_SD_SRC}
${UMAC_SOURCES}
)
# The umac sources need to prepare Musashi (some sources are generated):
add_custom_command(OUTPUT ${UMAC_MUSASHI_PATH}/m68kops.c
COMMAND echo "*** Preparing umac source ***"
COMMAND make -C ${UMAC_PATH} prepare
)
add_custom_target(prepare_umac
DEPENDS ${UMAC_MUSASHI_PATH}/m68kops.c
)
add_dependencies(firmware prepare_umac)
target_link_libraries(firmware
pico_stdlib
pico_multicore
tinyusb_host
tinyusb_board
hardware_dma
hardware_pio
hardware_sync
${EXTRA_SD_LIB}
)
target_include_directories(firmware PRIVATE
${CMAKE_CURRENT_LIST_DIR}/include
${TINYUSB_PATH}/hw
${TINYUSB_PATH}/src
${UMAC_INCLUDE_PATHS}
incbin
)
pico_generate_pio_header(firmware ${CMAKE_CURRENT_LIST_DIR}/src/pio_video.pio)
pico_enable_stdio_uart(firmware 1)
# Needed for UF2:
pico_add_extra_outputs(firmware)
elseif(PICO_ON_DEVICE)
message(WARNING "not building firmware because TinyUSB submodule is not initialized in the SDK")
endif()