-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
797 lines (733 loc) · 27.5 KB
/
Copy pathCMakeLists.txt
File metadata and controls
797 lines (733 loc) · 27.5 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
####
# USBSID-Pico is a RPi Pico/PicoW (RP2040) & Pico2/Pico2W (RP2350) based board
# for interfacing one or two MOS SID chips and/or hardware SID emulators over
# (WEB)USB with your computer, phone or ASID supporting player
#
# CMakeLists.txt
# This file is part of USBSID-Pico (https://github.com/LouDnl/USBSID-Pico)
# File author: LouD
#
# Copyright (c) 2024-2026 LouD
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
####
### Cmake minimum version
cmake_minimum_required(VERSION 3.17)
### Cmake compiler standard versions
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
### CMake stuff for ZED
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
### Project magic sprinkles
set(PROJECT_NAME usbsidpico)
set(PROJECT_MANUFACTURER "LouD")
set(PRODUCT_STRING "USBSID-Pico")
string(TIMESTAMP MAGIC_SMOKE "%Y%m%d") # Auto generate dated version
set(FWVERSION "0.8.0")
set(PROJECT_VERSION "${FWVERSION}-${MAGIC_SMOKE}") # Generate compile version
### Want a cookie?
# NOTICE: ENABLING THESE DEBUGGING DEFINITIONS WILL HAVE SIGNIFICANT IMPACT AND WILL DELAY PLAYING!
# NOTICE: UART AND USBCDC ARE MUTUALLY EXCLUSIVE!
if(NOT DEFINED $ENV{DISABLE_DEBUGGING}) # MATCHES
set(BUILD_DEBUGGING DEBUG) # Set loglevel from CMake build steps (STATUS,DEBUG,TRACE) override with --log-level
set(USBSID_DEBUGGING 1) # Enable debugging ~ mandatory enable for all other logging types
set(UART_DEBUGGING 1) # Enable debugging over uart pins ~ USBCDC must be 0!
set(USBCDC_DEBUGGING 0) # Enable debugging over cdc port 2 ~ UART must be 0!
set(FILENAME_LOGGING 0) # Enable logging of source filename
set(BOOT_LOGGING 0) # Enable bootlog in usbsid.c
set(DEFAULT_DEBUGGING 1) # Enable debugging in usbsid.c
set(CONFIG_DEBUGGING 1) # Enable debugging in config.c
set(USBIO_DEBUGGING 0) # Enable debugging in usbsid.c
set(GPIOBUS_DEBUGGING 0) # Enable debugging in gpio.c
set(MIDI_DEBUGGING 0) # Enable debugging in midi.c
set(MIDIVOICE_DEBUGGING 0) # Enable debugging in midi.c ~ usMVCE/usMDAT fire on every message
set(ASID_DEBUGGING 1) # Enable debugging in acid.c and asid_buffer.c
set(MEMORY_LOGGING 0) # Enable memory map of SID 1 voices printing
set(SIDWRITES_DEBUGGING 0) # Enable logging of SID writes one core 2
set(EMULATOR_DEBUGGING 1) # Enable debugging in emulator
set(ENABLE_PROFILING 0) # Experimental!
endif()
### Enable / Disable build with USBSID-Player for tune playback and/or Cynthcart
set(ONBOARD_SIDPLAYER 0 CACHE STRING "ONBOARD_SIDPLAYER")
### Run Cynthcart through the player's own MC68B50 ACIA. Requires ONBOARD_SIDPLAYER=1.
### REVERT NOTE: this used to be an alternative to ONBOARD_EMULATOR, a standalone
### emudore-based emulator (repo/lib/emulator + lib/emudore-embedded), which is
### gone now that Cynthcart runs through the player instead - see git history
### for that option and its compilation block if it's ever needed again.
set(ONBOARD_CYNTHCART 0 CACHE STRING "ONBOARD_CYNTHCART")
### Enable/ Disable build with PIO Uart on unused pins 26/27
set(USE_PIO_UART 0)
### Enable/ Disable build with Bluetooth on rp2350_w
set(ENABLE_BLUETOOTH 0 CACHE STRING "ENABLE_BLUETOOTH")
### Enable/ Disable build with CDC telemetry port (pico2 with sidplayer only!)
set(ENABLE_TELEMETRY 0 CACHE STRING "ENABLE_TELEMETRY")
### Information on the use of CDC callback
## This is turned on/off by changing USE_CDC_CALLBACK in globals.h
### Information on the use of Vendor buffer
## This is turned on/off by setting both vendor buffer size
## defines in tusb_config.h
# CFG_TUD_VENDOR_TX_BUFSIZE
# CFG_TUD_VENDOR_RX_BUFSIZE
#######################################
#### You no touchy after this line ####
#######################################
### Build notes
# Do not use the below setting, this _will_ break compilation on both
# rp2040 and rp2350
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -std=c++11")
# rp2040 will bug out complaining about assembly calls not being available
# rp2350 will bug out on PICO_USE_SW_SPIN_LOCK not being available
### Build steps log level
set(CMAKE_MESSAGE_LOG_LEVEL ${BUILD_DEBUGGING})
message(DEBUG "LOG_LEVEL is ${CMAKE_MESSAGE_LOG_LEVEL}")
message(DEBUG "Starting compilation of ${PRODUCT_STRING} firmware version ${PROJECT_VERSION}")
### ONBOARD_CYNTHCART runs inside the player, so it needs one
if(ONBOARD_CYNTHCART EQUAL 1 AND NOT ONBOARD_SIDPLAYER EQUAL 1)
message(FATAL_ERROR "ONBOARD_CYNTHCART requires ONBOARD_SIDPLAYER=1 (it runs inside the player).")
endif()
if(ONBOARD_SIDPLAYER EQUAL 1)
message(STATUS "Firmware is built with ONBOARD_SIDPLAYER")
endif()
if(ONBOARD_CYNTHCART EQUAL 1)
message(STATUS "Firmware is built with ONBOARD_CYNTHCART")
endif()
### Optimization and debugging
# remember that enabling debugging and disabling optimizations
# will weird out tune playing and reading from and writing to
# SKPico will stop functioning
# *3 is required for onboard siplayer but could cause desync
# with DMA read_address and chain_to()
set(DEBUG_SYMBOLS 0) # 0 default, 1 debug symbols & debug build enabled
set(DEBUGGING 0) # 0 default, 1~3 equals -g1~3
set(OPTIMIZATIONS 3) # 3 default, 3 ~ -O1 for debugging
set(WARNINGS_ONLY 0) # 0 default, 0 error on warnings
set(TUSB_DEBUG 0) # 0 default, 0~3 non verbose to very verbose
set(ANALYSE_STACKUSAGE 0) # 0 default, 1 enabled, 0 disabled
### Target board pico, pico_w, pico2
if(DEFINED PICO_BOARD)
message(STATUS "PICO_BOARD is defined as ${PICO_BOARD}")
else()
message(WARNING "PICO_BOARD not defined, defaulting to 'pico'")
set(PICO_BOARD pico)
endif()
### Target platform rp2040, rp2350 (rp2350-arm-s)
if(DEFINED PICO_PLATFORM)
message(STATUS "PICO_PLATFORM is defined as ${PICO_PLATFORM}")
else()
if(DEFINED PICO_BOARD)
if(PICO_BOARD STREQUAL "pico2")
set(PICO_PLATFORM rp2350-arm-s)
message(STATUS "PICO_PLATFORM not defined, board is ${PICO_BOARD} setting PICO_PLATFORM to ${PICO_PLATFORM}")
endif()
else()
message(WARNING "PICO_PLATFORM not defined, defaulting to 'rp2040'")
set(PICO_PLATFORM rp2040)
endif()
endif()
### Header validation check
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/src/globals.h)
file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/src/globals.h VALIDATION_FILE)
set(VALIDATION_SUCCESS False)
set(VALIDATION_LINE "#define PROJECT_VERSION")
while(VALIDATION_FILE)
list(POP_FRONT VALIDATION_FILE LINE)
if (LINE MATCHES ${VALIDATION_LINE})
string(REGEX MATCH "^#define PROJECT_VERSION" VALIDATED ${LINE})
if(${VALIDATED} MATCHES ${VALIDATION_LINE})
set(REDUCTION_SUCCESS True)
message(DEBUG "VALIDATED header line '${VALIDATION_LINE}'")
set(USBSID_MANUFACTURER "${PROJECT_MANUFACTURER} (v${PROJECT_VERSION})")
add_compile_definitions(USBSID_MANUFACTURER="${USBSID_MANUFACTURER}")
### CMake shenanigens
set(PJVER ${PROJECT_VERSION})
add_compile_definitions(PROJECT_VERSION="${PJVER}")
break()
else()
message(SEND_ERROR "ERROR header validation line is present but incorrect")
set(REDUCTION_SUCCESS False)
return()
endif()
endif()
endwhile()
if(NOT REDUCTION_SUCCESS)
message(SEND_ERROR "ERROR header validation fallback line not present")
return()
endif()
else()
message(SEND_ERROR "ERROR globals.h missing")
return()
endif()
# ### Compilers to use
if(${PICO_PLATFORM} MATCHES rp2040)
set(PICO_COMPILER pico_arm_cortex_m0plus_gcc)
elseif(${PICO_PLATFORM} MATCHES rp2350)
set(PICO_COMPILER pico_arm_cortex_m33_gcc)
else()
set(PICO_COMPILER pico_arm_gcc) # required for mem_ops on rp2040
endif()
### Target environment path
set(CMAKE_FIND_ROOT_PATH $ENV{PICO_ENV_PATH})
set(TINYUSB_PATH ${PICO_SDK_PATH}/lib/tinyusb)
### Optimizations
set(PICO_DEFAULT_FLOAT_IMPL pico_float_default)
set(PICO_DEFAULT_DOUBLE_IMPL pico_double_default)
### Build with debug symbols
if(DEBUG_SYMBOLS EQUAL 1)
set(CMAKE_BUILD_TYPE Debug) # for debugging
set(PICO_DEOPTIMIZED_DEBUG 1)
if(TUSB_DEBUG EQUAL 0)
set(CFG_TUSB_DEBUG 1)
# add_compile_definitions(CFG_TUSB_DEBUG=1)
else()
set(CFG_TUSB_DEBUG TUSB_DEBUG)
endif()
else()
set(CMAKE_BUILD_TYPE Release)
set(PICO_DEOPTIMIZED_DEBUG 0)
### TinyUSB debug logging
if(TUSB_DEBUG GREATER 0)
message(DEBUG "TinyUSB debugging set to ${TUSB_DEBUG}")
set(CFG_TUSB_DEBUG ${TUSB_DEBUG})
# add_compile_definitions(CFG_TUSB_DEBUG=${TUSB_DEBUG})
else()
set(CFG_TUSB_DEBUG 0)
endif()
endif()
message(STATUS "Firmware build type is ${CMAKE_BUILD_TYPE}")
### Define compile time debugging
if(DEBUGGING EQUAL 0)
set(D_OPT -DNDEBUG)
elseif(DEBUGGING EQUAL 1)
set(D_OPT -g1)
elseif(DEBUGGING EQUAL 2)
set(D_OPT -g2)
elseif(DEBUGGING EQUAL 3)
set(D_OPT -g3)
endif()
### Define compile time optimizations
if(OPTIMIZATIONS EQUAL 0)
set(O_OPT -O0)
elseif(OPTIMIZATIONS EQUAL 1)
set(O_OPT -Og)
elseif(OPTIMIZATIONS EQUAL 2)
set(O_OPT -Ofast)
elseif(OPTIMIZATIONS EQUAL 3)
set(O_OPT -O3)
endif()
if(WARNINGS_ONLY EQUAL 1)
set(W_OPT
-Wall
-Wextra
-Wunused
)
else()
set(W_OPT
-Werror
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
-Wno-unused-function # extra check to verify no unused lingering code is present
-Wno-maybe-uninitialized
-Wno-unused
-Wno-misleading-indentation
-Wno-implicit-fallthrough
)
endif()
### Compiler flags and options
set(COMPILE_OPTS PRIVATE
${D_OPT}
${W_OPT}
${O_OPT}
-save-temps=obj
-fverbose-asm
-Wl,--wrap=ceil
-Wl,--wrap=memcpy
-Wl,--wrap=memset
-Wl,--wrap=__aeabi_memcpy
-Wl,--wrap=__aeabi_memset
-Wl,--wrap=__aeabi_memcmp
-Wl,--wrap=__aeabi_memcpy4
-Wl,--wrap=__aeabi_memset4
-Wl,--wrap=__aeabi_memcpy8
-Wl,--wrap=__aeabi_memset8
-Wl,--wrap=printf
-Wl,--wrap=vprintf
-Wl,--wrap=puts
)
if(ANALYSE_STACKUSAGE EQUAL 1)
set(COMPILE_OPTS
${COMPILE_OPTS}
-fstack-usage
-fcallgraph-info
-DANALYSE_STACKUSAGE=1)
endif()
### Target product & output filename
if(${PICO_BOARD} STREQUAL "pico")
set(PROJECT_PRODUCT ${PRODUCT_STRING})
set(PROJECT_FILENAME ${PROJECT_NAME})
elseif(${PICO_BOARD} STREQUAL "pico_w")
set(PROJECT_PRODUCT "${PRODUCT_STRING}_W")
set(PROJECT_FILENAME "${PROJECT_NAME}_w")
elseif(${PICO_BOARD} STREQUAL "pico2")
set(PROJECT_PRODUCT "${PRODUCT_STRING}2")
set(PROJECT_FILENAME "${PROJECT_NAME}2")
elseif(${PICO_BOARD} STREQUAL "pico2_w")
set(PROJECT_PRODUCT "${PRODUCT_STRING}2_W")
set(PROJECT_FILENAME "${PROJECT_NAME}2_w")
endif()
### Executable names
list(APPEND FILENAMES
${PROJECT_FILENAME}-v1.0
${PROJECT_FILENAME}-v1.3
${PROJECT_FILENAME}-v1.5
)
list(APPEND PICOTYPES
"LED"
"LED"
"LED"
)
list(APPEND PCBVERSIONS
"1.0"
"1.3"
"1.5"
)
if(${PICO_BOARD} STREQUAL "pico" OR ${PICO_BOARD} STREQUAL "pico2")
list(APPEND FILENAMES
${PROJECT_FILENAME}-v1.0-rgb
${PROJECT_FILENAME}-v1.3-rgb
${PROJECT_FILENAME}-v1.5-rgb
)
list(APPEND PICOTYPES
"RGB"
"RGB"
"RGB"
)
list(APPEND PCBVERSIONS
# "0.1" ## Alpha builds only
# "0.2" ## Unreliable
"1.0"
# "1.1" ## Never built
# "1.2" ## Incorrect gpio pins placing
"1.3"
# "1.4" ## Power delivery issue
"1.5"
)
endif()
### Target override for Pro version
if(${PICO_BOARD} STREQUAL "weact_studio_rp2350b_core")
set(PROJECT_PRODUCT "${PRODUCT_STRING}Pro_rp2350b")
set(PROJECT_FILENAME "${PROJECT_NAME}pro_rp2350b")
set(FILENAMES)
set(PICOTYPES)
set(PCBVERSIONS)
list(APPEND FILENAMES ${PROJECT_FILENAME}-v1.0)
list(APPEND PICOTYPES "PRO")
list(APPEND PCBVERSIONS "1.0")
endif()
### Source files to compile
set(SOURCEFILES
${CMAKE_CURRENT_LIST_DIR}/src/usbsid.c
${CMAKE_CURRENT_LIST_DIR}/src/usbsid_constants.c
${CMAKE_CURRENT_LIST_DIR}/src/config.c
${CMAKE_CURRENT_LIST_DIR}/src/config_bus.c
${CMAKE_CURRENT_LIST_DIR}/src/config_socket.c
${CMAKE_CURRENT_LIST_DIR}/src/config_logging.c
${CMAKE_CURRENT_LIST_DIR}/src/gpio.c
${CMAKE_CURRENT_LIST_DIR}/src/pio.c
${CMAKE_CURRENT_LIST_DIR}/src/dma.c
${CMAKE_CURRENT_LIST_DIR}/src/vu.c
${CMAKE_CURRENT_LIST_DIR}/src/bus.c
${CMAKE_CURRENT_LIST_DIR}/src/midi.c
${CMAKE_CURRENT_LIST_DIR}/src/midi_handler.c
${CMAKE_CURRENT_LIST_DIR}/src/midi_queue.c
${CMAKE_CURRENT_LIST_DIR}/src/midi_engine.c
${CMAKE_CURRENT_LIST_DIR}/src/midi_voice.c
${CMAKE_CURRENT_LIST_DIR}/src/midi_config.c
${CMAKE_CURRENT_LIST_DIR}/src/midi_patch.c
${CMAKE_CURRENT_LIST_DIR}/src/midi_arp_table.c
${CMAKE_CURRENT_LIST_DIR}/src/midi_fmopl.c
${CMAKE_CURRENT_LIST_DIR}/src/asid.c
${CMAKE_CURRENT_LIST_DIR}/src/asid_buffer.c
${CMAKE_CURRENT_LIST_DIR}/src/sysex.c
${CMAKE_CURRENT_LIST_DIR}/src/sid.c
${CMAKE_CURRENT_LIST_DIR}/src/sid_cloneconfig.c
${CMAKE_CURRENT_LIST_DIR}/src/sid_detection.c
${CMAKE_CURRENT_LIST_DIR}/src/sid_tests.c
${CMAKE_CURRENT_LIST_DIR}/src/mcu.c
${CMAKE_CURRENT_LIST_DIR}/src/usb_descriptors.c
)
### Header directories to include
set(TARGET_INCLUDE_DIRS PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/src
${TINYUSB_PATH}/hw
${TINYUSB_PATH}/src
)
### Embedded player stuffs
if(ONBOARD_SIDPLAYER EQUAL 1)
## Empty by default, deliberately. Giving this a default value makes it never
## empty, which silently kills the lib/usbsid-player branch below, and that
## is the branch CI actually wants: it checks the player out to exactly that
## path, so the build should work without EMUDIR being passed at all.
set(EMUDIR "" CACHE STRING "Path to the USBSID-Player checkout")
# NOTICE: SIDPLAYER REQUIRES FULL OPTIMIZATIONS!!
# NOTE TO SELF: -O3 is already set in COMPILE_OPTS and applied via target_compile_options()
# NOTE TO SELF: Do NOT use set(CMAKE_CXX_FLAGS ...) here as it strips Pico SDK architecture flags!
## Set sidplayer list directory
## USBSID-Player lives in player-repo, next to this one in the workspace.
## EMUDIR wins, then lib/usbsid-player if it has been checked out there, then
## the sibling checkout.
if(NOT EMUDIR STREQUAL "")
## A relative EMUDIR is ambiguous, and it fails in a way that reads like a
## different fault. `if(EXISTS)` resolves a relative path against the
## working directory while `include()` resolves it against the including
## file's directory, so `cmake -S master -DEMUDIR=master/lib/usbsid-player`
## passes the existence check below and then fails the include with
## "could not find requested file", having looked in master/master/lib.
## Resolve it here and carry an absolute path from this point on.
if(IS_ABSOLUTE "${EMUDIR}")
set(USPLAYER_LIST_DIR "${EMUDIR}")
else()
set(USPLAYER_LIST_DIR "")
foreach(BASE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/.." "${CMAKE_BINARY_DIR}")
get_filename_component(EMUDIR_TRY "${BASE}/${EMUDIR}" ABSOLUTE)
if(EXISTS "${EMUDIR_TRY}/cmake/usbsid-player.cmake")
set(USPLAYER_LIST_DIR "${EMUDIR_TRY}")
message(STATUS "EMUDIR '${EMUDIR}' is relative, resolved to ${USPLAYER_LIST_DIR}")
break()
endif()
endforeach()
## Nothing matched. Keep the most likely reading so the error below names
## a real path instead of an empty one.
if(USPLAYER_LIST_DIR STREQUAL "")
get_filename_component(USPLAYER_LIST_DIR "${CMAKE_SOURCE_DIR}/${EMUDIR}" ABSOLUTE)
endif()
endif()
elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/lib/usbsid-player/cmake/usbsid-player.cmake")
set(USPLAYER_LIST_DIR "${CMAKE_CURRENT_LIST_DIR}/lib/usbsid-player")
else()
get_filename_component(USPLAYER_LIST_DIR
"${CMAKE_CURRENT_LIST_DIR}/../player-repo" ABSOLUTE)
endif()
message(STATUS "USPLAYER_LIST_DIR is set to ${USPLAYER_LIST_DIR}")
if(NOT EXISTS "${USPLAYER_LIST_DIR}/cmake/usbsid-player.cmake")
message(FATAL_ERROR
"ONBOARD_SIDPLAYER is on but no USBSID-Player at ${USPLAYER_LIST_DIR}.\n"
" EMUDIR was '${EMUDIR}'\n"
" Pass an absolute -DEMUDIR=/path/to/usbsid-player, or check the player "
"out as lib/usbsid-player, or put it beside this repo as ../player-repo.")
endif()
### Adjust filenames for user interpretation
foreach(FILENAME ${FILENAMES})
list(APPEND FILENAMES_tmp "${FILENAME}_sp")
endforeach()
set(FILENAMES ${FILENAMES_tmp})
### The player brings its own file list, include paths and psiddrv target.
### See player-repo/docs/EMBEDDED.md for what it exports and what the
### firmware is expected to call at runtime.
###
### Two things the old player needed and this one does not:
### PICO_CXX_ENABLE_EXCEPTIONS it is built -fno-exceptions -fno-rtti and
### never throws, so the unwind tables would be
### flash spent on nothing
### RCUTILS_NO_64_ATOMIC nothing in it uses atomics
include(${USPLAYER_LIST_DIR}/cmake/usbsid-player.cmake)
set(COMPILE_OPTS ${COMPILE_OPTS} -DEMBEDDED=1)
add_compile_definitions(ONBOARD_SIDPLAYER=1)
add_compile_definitions(${USPLAYER_DEFINITIONS})
### Where it's at
set(SOURCEFILES
${SOURCEFILES}
${USPLAYER_SOURCES}
)
### What it wants
set(TARGET_INCLUDE_DIRS
${TARGET_INCLUDE_DIRS}
${USPLAYER_INCLUDE_DIRS}
)
### Cynthcart through the player's MC68B50 ACIA (see cmake/usbsid-player.cmake)
if(ONBOARD_CYNTHCART EQUAL 1)
add_compile_definitions(ONBOARD_CYNTHCART=1)
set(SOURCEFILES ${SOURCEFILES} ${USPLAYER_CYNTHCART_SOURCES})
set(TARGET_INCLUDE_DIRS ${TARGET_INCLUDE_DIRS} ${USPLAYER_CYNTHCART_INCLUDE_DIRS})
foreach(FILENAME ${FILENAMES})
list(APPEND FILENAMES_cc "${FILENAME}_cc")
endforeach()
set(FILENAMES ${FILENAMES_cc})
endif()
endif()
### PIO Uart compilation additions
if(USE_PIO_UART EQUAL 1)
add_compile_definitions(USE_PIO_UART=1)
set(SOURCEFILES
${SOURCEFILES}
${CMAKE_CURRENT_LIST_DIR}/src/uart.c
)
endif()
### Libraries to link
set(TARGET_LL
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_pio
hardware_pwm
hardware_resets
hardware_structs
hardware_sync
hardware_timer
hardware_uart
# hardware_interp
pico_atomic # memcmp
pico_cxx_options
pico_flash
pico_mem_ops
pico_mem_ops_compiler
pico_malloc
pico_multicore
pico_rand
pico_stdlib
pico_unique_id
pico_usb_reset_interface
pico_async_context_threadsafe_background
tinyusb_device
tinyusb_board
)
### Bluetooth control for _w boards
if(ENABLE_BLUETOOTH EQUAL 1)
if(${PICO_BOARD} STREQUAL "pico2_w")
set(SOURCEFILES
${SOURCEFILES}
${CMAKE_CURRENT_LIST_DIR}/src/bluetooth.c
)
set(TARGET_LL
${TARGET_LL}
pico_cyw43_arch_none # Select 'none', 'background', or 'rtos' architecture
pico_btstack_classic # Main stack for Classic SPP Bluetooth
pico_btstack_cyw43 # Ties BTstack to the onboard CYW chip
)
set(BT_TARGET_PIO 2) # Use rp2350 pio2
add_compile_definitions(USE_BLUETOOTH=1)
endif()
endif()
if(ENABLE_PROFILING EQUAL 1)
add_compile_definitions(ENABLE_PROFILING=1)
# set(COMPILE_OPTS
# ${COMPILE_OPTS}
# -pg
# -mgeneral-regs-only
# )
# set(TARGET_LL
# ${TARGET_LL}
# pico_stdio_semihosting
# )
# set(TARGET_INCLUDE_DIRS
# ${TARGET_INCLUDE_DIRS}
# ${CMAKE_CURRENT_LIST_DIR}/lib/McuLib/config
# ${CMAKE_CURRENT_LIST_DIR}/lib/McuLib/src
# ${CMAKE_CURRENT_LIST_DIR}/lib/CrashCourseC/Content/lib
# )
# add_link_options(-pg --specs=rdimon.specs)
# pico_enable_stdio_semihosting(${CMAKE_PROJECT_NAME} ENABLED)
endif()
if(ENABLE_TELEMETRY EQUAL 1)
if(${PICO_BOARD} STREQUAL "pico2" OR ${PICO_BOARD} STREQUAL "pico2_w")
add_compile_definitions(USE_TELEMETRY=1)
endif()
endif()
### Pio files
set(PIO_BUS ${CMAKE_CURRENT_LIST_DIR}/src/pio/bus_control.pio)
set(PIO_CLOCK ${CMAKE_CURRENT_LIST_DIR}/src/pio/clock.pio)
set(PIO_VU ${CMAKE_CURRENT_LIST_DIR}/src/pio/vu.pio)
set(PIO_RGB ${CMAKE_CURRENT_LIST_DIR}/src/pio/vu_rgb.pio)
set(PIO_COUNTER ${CMAKE_CURRENT_LIST_DIR}/src/pio/cycle_counter.pio)
if(USE_PIO_UART EQUAL 1)
set(PIO_UART ${CMAKE_CURRENT_LIST_DIR}/src/pio/uart_rx.pio)
endif()
### Pico sdk path
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
#include($ENV{PICO_EXTRAS_PATH}/external/pico_extras_import.cmake) # i2s audio
### Project type
project(${PROJECT_NAME} C CXX ASM)
### init sdk
pico_sdk_init()
# Explicitely force pioasm to complete before any firmware targets on clean builds
if(TARGET pioasmBuild)
set(PIOASM_DEPENDENCY pioasmBuild)
endif()
### Include
include_directories(".")
### Double check debugging types
if(UART_DEBUGGING EQUAL 1 AND USBCDC_DEBUGGING EQUAL 1)
message(SEND_ERROR "ERROR cannot have both UART_DEBUGGING and USBCDC_DEBUGGING enabled!")
return()
endif()
### Logging definitions
if(USBSID_DEBUGGING EQUAL 1)
if(UART_DEBUGGING EQUAL 1)
add_compile_definitions(USBSID_UART=1)
endif()
if(USBCDC_DEBUGGING EQUAL 1)
add_compile_definitions(USB_PRINTF=1)
endif()
if(DEFAULT_DEBUGGING EQUAL 1)
add_compile_definitions(USBSID_DEBUG=1)
endif()
if(FILENAME_LOGGING EQUAL 1)
add_compile_definitions(LOG_FILENAME=1)
endif()
if(BOOT_LOGGING EQUAL 1)
add_compile_definitions(USBSID_BOOTLOG=1)
endif()
if(CONFIG_DEBUGGING EQUAL 1)
add_compile_definitions(CONFIG_DEBUG=1)
endif()
if(MEMORY_LOGGING EQUAL 1)
add_compile_definitions(MEM_DEBUG=1)
endif()
if(SIDWRITES_DEBUGGING EQUAL 1)
add_compile_definitions(WRITE_DEBUG=1)
endif()
if(USBIO_DEBUGGING EQUAL 1)
add_compile_definitions(USBIO_DEBUG=1)
endif()
if(MIDI_DEBUGGING EQUAL 1)
add_compile_definitions(MIDI_DEBUG=1)
endif()
if(MIDIVOICE_DEBUGGING EQUAL 1)
add_compile_definitions(MIDIVOICE_DEBUG=1)
endif()
if(ASID_DEBUGGING EQUAL 1)
add_compile_definitions(ASID_DEBUG=1)
endif()
if(GPIOBUS_DEBUGGING EQUAL 1)
add_compile_definitions(USBSIDGPIO_DEBUG=1)
endif()
if(EMULATOR_DEBUGGING EQUAL 1)
add_compile_definitions(EMUDEBUG=1)
endif()
endif()
### It escapes every damn time!
add_compile_definitions(MAGIC_SMOKE=${MAGIC_SMOKE})
### Captain I canna change the options anymore!
message(TRACE "C Compiler root: " ${CMAKE_FIND_ROOT_PATH})
message(TRACE "CXX Compiler root: " ${CMAKE_FIND_ROOT_PATH})
message(TRACE "C Compile time flags:")
message(TRACE "${CMAKE_C_FLAGS}")
message(TRACE "CXX Compile time flags:")
message(TRACE "${CMAKE_CXX_FLAGS}")
message(TRACE "Compile time options:")
message(TRACE "${COMPILE_OPTS}")
message(TRACE "Compile time source files:")
message(TRACE "${SOURCEFILES}")
message(TRACE "Compile time include dirs:")
message(TRACE "${TARGET_INCLUDE_DIRS}")
### Compile targets
# FW_VERSION_INT/PCB_VERSION_INT below get emitted as bare (unquoted) numeric
# -D defines, so the C compiler parses them as C integer literals - any
# literal starting with "0" is octal there, and octal digits only run 0-7.
# "0.8.0" collapses to "080", which broke the very first time a MAJOR
# version of 0 met a MINOR/PATCH digit of 8 or 9 (every version before this
# happened to concatenate to all-0-7 digits, so this never came up). Strip
# leading zeros so the literal can never be mistaken for octal, regardless
# of platform version - "080" -> "80" (still stays a valid, comparable
# integer for the PCB_VERSION_INT >= NN checks throughout src/).
string(REPLACE "." "" FWVER_INT "${FWVERSION}")
string(REGEX REPLACE "^0+" "" FWVER_INT "${FWVER_INT}")
if(FWVER_INT STREQUAL "")
set(FWVER_INT "0")
endif()
foreach(FILENAME PICOTYPE PCBVERSION IN ZIP_LISTS FILENAMES PICOTYPES PCBVERSIONS)
# set filename
set(BUILD ${FILENAME})
set(BUILD_VERSION "")
string(CONCAT BUILD_VERSION ${PROJECT_PRODUCT} " v" ${PCBVERSION})
message(DEBUG "Building ${FILENAME} with PICOTYPE=${PICOTYPE} and MAGIC_SMOKE=${MAGIC_SMOKE}")
message(DEBUG "Set USB manufacturer: ${USBSID_MANUFACTURER}")
message(DEBUG "Set USB product: ${BUILD_VERSION}")
# executable
add_executable(${BUILD} ${SOURCEFILES})
# BUILD TYPES
# Same octal-literal trap as FWVER_INT above - not hit yet (1.0/1.3/1.5
# never start with "0"), but stripped for the same reason so it can't
# silently reappear if a PCB version ever does.
string(REPLACE "." "" PCBVER_INT "${PCBVERSION}")
string(REGEX REPLACE "^0+" "" PCBVER_INT "${PCBVER_INT}")
if(PCBVER_INT STREQUAL "")
set(PCBVER_INT "0")
endif()
if(PICOTYPE STREQUAL "RGB")
target_compile_definitions(${BUILD} PRIVATE USBSID USBSID_PRODUCT="${BUILD_VERSION}" USE_RGB=1 PCB_VERSION="${PCBVERSION}" PCB_VERSION_INT=${PCBVER_INT} FW_VERSION_INT=${FWVER_INT})
else()
target_compile_definitions(${BUILD} PRIVATE USBSID USBSID_PRODUCT="${BUILD_VERSION}" PCB_VERSION="${PCBVERSION}" PCB_VERSION_INT=${PCBVER_INT} FW_VERSION_INT=${FWVER_INT})
endif()
# pio addition
pico_generate_pio_header(${BUILD} ${PIO_BUS})
pico_generate_pio_header(${BUILD} ${PIO_CLOCK})
pico_generate_pio_header(${BUILD} ${PIO_VU})
if(USE_PIO_UART EQUAL 1)
pico_generate_pio_header(${BUILD} ${PIO_UART})
endif()
pico_generate_pio_header(${BUILD} ${PIO_COUNTER})
if(PICOTYPE STREQUAL "RGB")
pico_generate_pio_header(${BUILD} ${PIO_RGB})
endif()
# rsiddrv dependency for sidplayer
if(ONBOARD_SIDPLAYER EQUAL 1)
add_dependencies(${BUILD} RSIDDriver)
endif()
# force pioasm to build first on clean builds
if(DEFINED PIOASM_DEPENDENCY)
add_dependencies(${BUILD} ${PIOASM_DEPENDENCY})
endif()
# source files to compile
target_sources(${BUILD} PUBLIC ${SOURCEFILES})
target_compile_options(${BUILD} ${COMPILE_OPTS})
target_link_options(${BUILD} PRIVATE -Xlinker --print-memory-usage)
# memory map linkers
if(${PICO_PLATFORM} MATCHES rp2350)
if(${PICO_BOARD} STREQUAL "weact_studio_rp2350b_core")
message(TRACE "Memmap linker, platform ${PICO_PLATFORM} MATCHES rp2350b")
target_compile_definitions(${BUILD} PRIVATE USBSID PICO_EMBED_XIP_SETUP=1)
set_target_properties(${BUILD} PROPERTIES PICO_TARGET_LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/src/usbsidpico-rp2350b.ld)
else()
message(TRACE "Memmap linker, platform ${PICO_PLATFORM} MATCHES rp2350")
target_compile_definitions(${BUILD} PRIVATE USBSID PICO_EMBED_XIP_SETUP=1)
set_target_properties(${BUILD} PROPERTIES PICO_TARGET_LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/src/usbsidpico-rp2350.ld)
endif()
else()
message(TRACE "Memmap linker, platform ${PICO_PLATFORM} EQUALS rp2040")
set_target_properties(${BUILD} PROPERTIES PICO_TARGET_LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/src/usbsidpico-rp2040.ld)
endif()
# tell the linker what libraries to link
target_link_libraries(${BUILD} ${TARGET_LL})
if ((ENABLE_BLUETOOTH EQUAL 1) AND (${PICO_BOARD} STREQUAL "pico2_w"))
# Redirect the CYW43 wireless driver to use the third PIO block (PIO2)
target_compile_definitions(${BUILD} PRIVATE
CYW43_SPI_PIO_PREFERRED_PIO=${BT_TARGET_PIO}
)
elseif(PICO_CYW43_SUPPORTED AND NOT (ENABLE_BLUETOOTH EQUAL 1))
target_link_libraries(${BUILD} pico_cyw43_arch_none)
endif()
# target usbsid types
target_include_directories(${BUILD} ${TARGET_INCLUDE_DIRS})
pico_set_program_name(${BUILD} "USBSID-Pico")
pico_set_program_version(${BUILD} "${PROJECT_VERSION}")
# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(${BUILD})
# enable uart output, disable usb output
pico_enable_stdio_uart(${BUILD} 1) # essentialy the same as LL pico_stdio_uart
pico_enable_stdio_usb(${BUILD} 0)
if(${PICO_BOARD} STREQUAL "pico2_w")
pico_add_extra_outputs(${BUILD})
endif()
endforeach()