Skip to content

Commit 853abe9

Browse files
committed
Change midi->SID control to user defined channel and save settings per channel (like an instrument)
1 parent 3d0539b commit 853abe9

28 files changed

Lines changed: 1214 additions & 323 deletions

CMakeLists.txt

Lines changed: 90 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
### Cmake minimum version
2626
cmake_minimum_required(VERSION 3.17)
2727

28+
### Cmake compiler standard versions
29+
set(CMAKE_C_STANDARD 11)
30+
set(CMAKE_CXX_STANDARD 17)
31+
32+
### CMake stuff for ZED
33+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
34+
2835
### Project magic sprinkles
2936
set(PROJECT_NAME usbsidpico)
3037
set(PROJECT_MANUFACTURER "LouD")
@@ -47,11 +54,12 @@ if(NOT DEFINED $ENV{DISABLE_DEBUGGING}) # MATCHES
4754
set(USBIO_DEBUGGING 0) # Enable debugging in usbsid.c
4855
set(GPIOBUS_DEBUGGING 0) # Enable debugging in gpio.c
4956
set(MIDI_DEBUGGING 0) # Enable debugging in midi.c
50-
set(MIDIVOICE_DEBUGGING 0) # Enable debugging in midi.c
51-
set(ASID_DEBUGGING 0) # Enable debugging in acid.c and asid_buffer.c
57+
set(MIDIVOICE_DEBUGGING 1) # Enable debugging in midi.c
58+
set(ASID_DEBUGGING 1) # Enable debugging in acid.c and asid_buffer.c
5259
set(MEMORY_LOGGING 0) # Enable memory map of SID 1 voices printing
5360
set(SIDWRITES_DEBUGGING 0) # Enable logging of SID writes one core 2
54-
set(EMULATOR_DEBUGGING 0) # Enable debugging in emulator
61+
set(EMULATOR_DEBUGGING 1) # Enable debugging in emulator
62+
set(ENABLE_PROFILING 0) # Experimental!
5563
endif()
5664

5765
### Enable / Disable build with embedded emulator for Midi
@@ -175,10 +183,6 @@ else()
175183
set(PICO_COMPILER pico_arm_gcc) # required for mem_ops on rp2040
176184
endif()
177185

178-
### Cmake compiler standard versions
179-
set(CMAKE_C_STANDARD 11)
180-
set(CMAKE_CXX_STANDARD 17)
181-
182186
### Target environment path
183187
set(CMAKE_FIND_ROOT_PATH $ENV{PICO_ENV_PATH})
184188
set(TINYUSB_PATH ${PICO_SDK_PATH}/lib/tinyusb)
@@ -301,28 +305,55 @@ endif()
301305
list(APPEND FILENAMES
302306
${PROJECT_FILENAME}-v1.0
303307
${PROJECT_FILENAME}-v1.3
308+
${PROJECT_FILENAME}-v1.4
304309
)
305310
list(APPEND PICOTYPES
306311
"LED"
307-
"LED_AUDIOSWITCH"
312+
"LED"
313+
"LED"
314+
# "LED_AUDIOSWITCH"
315+
# "LED_AUTOCONFIG"
308316
)
309317
list(APPEND PCBVERSIONS
310318
"1.0"
311319
"1.3"
320+
"1.4"
312321
)
313322
if(${PICO_BOARD} STREQUAL "pico" OR ${PICO_BOARD} STREQUAL "pico2")
314323
list(APPEND FILENAMES
315324
${PROJECT_FILENAME}-v1.0-rgb
316325
${PROJECT_FILENAME}-v1.3-rgb
326+
${PROJECT_FILENAME}-v1.4-rgb
317327
)
318328
list(APPEND PICOTYPES
319329
"RGB"
320-
"RGB_AUDIOSWITCH"
330+
"RGB"
331+
"RGB"
332+
# "RGB_AUDIOSWITCH"
333+
# "RGB_AUTOCONFIG"
321334
)
322335
list(APPEND PCBVERSIONS
336+
# "0.1" ## Alpha builds only
337+
# "0.2" ## Unreliable
323338
"1.0"
339+
# "1.1" ## Never built
340+
# "1.2" ## Incorrect gpio pins placing
324341
"1.3"
325-
)
342+
# "1.4" ## Power delivery issue
343+
"1.5"
344+
)
345+
endif()
346+
347+
### Target override for Pro version
348+
if(${PICO_BOARD} STREQUAL "weact_studio_rp2350b_core")
349+
set(PROJECT_PRODUCT "${PRODUCT_STRING}Pro_rp2350b")
350+
set(PROJECT_FILENAME "${PROJECT_NAME}pro_rp2350b")
351+
set(FILENAMES)
352+
set(PICOTYPES)
353+
set(PCBVERSIONS)
354+
list(APPEND FILENAMES ${PROJECT_FILENAME}-v1.0)
355+
list(APPEND PICOTYPES "PRO")
356+
list(APPEND PCBVERSIONS "1.0")
326357
endif()
327358

328359
### Source files to compile
@@ -379,6 +410,13 @@ if(ONBOARD_SIDPLAYER EQUAL 1)
379410
endforeach()
380411
set(FILENAMES ${FILENAMES_tmp})
381412

413+
### Attempt at adding a subdirectory, failed miserably
414+
# set(DESKTOP 0 CACHE INTERNAL "")
415+
# set(RADARE2 0 CACHE INTERNAL "")
416+
# set(EMBEDDED 1 CACHE INTERNAL "")
417+
# add_subdirectory(lib/usplayer)
418+
# target_link_libraries(${PROJECT_NAME} PRIVATE usbsid)
419+
382420
### Build psiddrv header
383421
add_custom_command(
384422
# Use absolute paths
@@ -408,6 +446,7 @@ if(ONBOARD_SIDPLAYER EQUAL 1)
408446
${USPLAYER_LIST_DIR}/src/c64/mos6560_6561_vic.cpp
409447
${USPLAYER_LIST_DIR}/src/c64/mos6581_8580_sid.cpp
410448
${USPLAYER_LIST_DIR}/src/c64/mos906114_pla.cpp
449+
# ${USPLAYER_LIST_DIR}/src/c64/timers.cpp
411450
${USPLAYER_LIST_DIR}/src/psid/sidfile.cpp
412451
${USPLAYER_LIST_DIR}/src/psiddrv/psid.cpp
413452
${USPLAYER_LIST_DIR}/src/psiddrv/reloc65.c
@@ -518,6 +557,29 @@ set(TARGET_LL
518557
tinyusb_board
519558
)
520559

560+
561+
if(ENABLE_PROFILING EQUAL 1)
562+
add_compile_definitions(ENABLE_PROFILING=1)
563+
# set(COMPILE_OPTS
564+
# ${COMPILE_OPTS}
565+
# -pg
566+
# -mgeneral-regs-only
567+
# )
568+
# set(TARGET_LL
569+
# ${TARGET_LL}
570+
# pico_stdio_semihosting
571+
# )
572+
# set(TARGET_INCLUDE_DIRS
573+
# ${TARGET_INCLUDE_DIRS}
574+
# ${CMAKE_CURRENT_LIST_DIR}/lib/McuLib/config
575+
# ${CMAKE_CURRENT_LIST_DIR}/lib/McuLib/src
576+
# ${CMAKE_CURRENT_LIST_DIR}/lib/CrashCourseC/Content/lib
577+
# )
578+
# add_link_options(-pg --specs=rdimon.specs)
579+
# pico_enable_stdio_semihosting(${CMAKE_PROJECT_NAME} ENABLED)
580+
endif()
581+
582+
521583
### Pio files
522584
set(PIO_BUS ${CMAKE_CURRENT_LIST_DIR}/src/pio/bus_control.pio)
523585
set(PIO_CLOCK ${CMAKE_CURRENT_LIST_DIR}/src/pio/clock.pio)
@@ -627,17 +689,18 @@ foreach(FILENAME PICOTYPE PCBVERSION IN ZIP_LISTS FILENAMES PICOTYPES PCBVERSION
627689
# executable
628690
add_executable(${BUILD} ${SOURCEFILES})
629691
# BUILD TYPES
692+
string(REPLACE "." "" PCBVER_INT "${PCBVERSION}")
630693
if(PICOTYPE STREQUAL "RGB")
631-
target_compile_definitions(${BUILD} PRIVATE USBSID USBSID_PRODUCT="${BUILD_VERSION}" USE_RGB=1 PCB_VERSION="${PCBVERSION}")
694+
target_compile_definitions(${BUILD} PRIVATE USBSID USBSID_PRODUCT="${BUILD_VERSION}" USE_RGB=1 PCB_VERSION="${PCBVERSION}" PCB_VERSION_INT=${PCBVER_INT})
632695
# add_compile_definitions(USE_RGB=1)
633-
elseif(PICOTYPE STREQUAL "RGB_AUDIOSWITCH")
634-
target_compile_definitions(${BUILD} PRIVATE USBSID USBSID_PRODUCT="${BUILD_VERSION}" USE_RGB=1 HAS_AUDIOSWITCH=1 PCB_VERSION="${PCBVERSION}")
635-
# add_compile_definitions(USE_RGB=1 HAS_AUDIOSWITCH=1)
636-
elseif(PICOTYPE STREQUAL "LED_AUDIOSWITCH")
637-
target_compile_definitions(${BUILD} PRIVATE USBSID USBSID_PRODUCT="${BUILD_VERSION}" HAS_AUDIOSWITCH=1 PCB_VERSION="${PCBVERSION}")
638-
# add_compile_definitions(HAS_AUDIOSWITCH=1)
696+
# elseif(PICOTYPE STREQUAL "RGB_AUDIOSWITCH")
697+
# target_compile_definitions(${BUILD} PRIVATE USBSID USBSID_PRODUCT="${BUILD_VERSION}" USE_RGB=1 PCB_VERSION="${PCBVERSION}")
698+
# # add_compile_definitions(USE_RGB=1 HAS_AUDIOSWITCH=1)
699+
# elseif(PICOTYPE STREQUAL "LED_AUDIOSWITCH")
700+
# target_compile_definitions(${BUILD} PRIVATE USBSID USBSID_PRODUCT="${BUILD_VERSION}" PCB_VERSION="${PCBVERSION}")
701+
# # add_compile_definitions(HAS_AUDIOSWITCH=1)
639702
else()
640-
target_compile_definitions(${BUILD} PRIVATE USBSID USBSID_PRODUCT="${BUILD_VERSION}" PCB_VERSION="${PCBVERSION}")
703+
target_compile_definitions(${BUILD} PRIVATE USBSID USBSID_PRODUCT="${BUILD_VERSION}" PCB_VERSION="${PCBVERSION}" PCB_VERSION_INT=${PCBVER_INT})
641704
endif()
642705
# pio addition
643706
pico_generate_pio_header(${BUILD} ${PIO_BUS})
@@ -664,9 +727,15 @@ foreach(FILENAME PICOTYPE PCBVERSION IN ZIP_LISTS FILENAMES PICOTYPES PCBVERSION
664727
target_link_options(${BUILD} PRIVATE -Xlinker --print-memory-usage)
665728
# memory map linkers
666729
if(${PICO_PLATFORM} MATCHES rp2350)
667-
message(TRACE "Memmap linker, platform ${PICO_PLATFORM} MATCHES rp2350")
668-
target_compile_definitions(${BUILD} PRIVATE USBSID PICO_EMBED_XIP_SETUP=1)
669-
set_target_properties(${BUILD} PROPERTIES PICO_TARGET_LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/src/usbsidpico-rp2350.ld)
730+
if(${PICO_BOARD} STREQUAL "weact_studio_rp2350b_core")
731+
message(TRACE "Memmap linker, platform ${PICO_PLATFORM} MATCHES rp2350b")
732+
target_compile_definitions(${BUILD} PRIVATE USBSID PICO_EMBED_XIP_SETUP=1)
733+
set_target_properties(${BUILD} PROPERTIES PICO_TARGET_LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/src/usbsidpico-rp2350b.ld)
734+
else()
735+
message(TRACE "Memmap linker, platform ${PICO_PLATFORM} MATCHES rp2350")
736+
target_compile_definitions(${BUILD} PRIVATE USBSID PICO_EMBED_XIP_SETUP=1)
737+
set_target_properties(${BUILD} PROPERTIES PICO_TARGET_LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/src/usbsidpico-rp2350.ld)
738+
endif()
670739
else()
671740
message(TRACE "Memmap linker, platform ${PICO_PLATFORM} EQUALS rp2040")
672741
set_target_properties(${BUILD} PROPERTIES PICO_TARGET_LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/src/usbsidpico-rp2040.ld)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
stl-thumb "USBSID-Pico v1.3 top case open with reset and rgb led opening.stl" "USBSID-Pico v1.3 top case open with reset and rgb led opening.png"

examples/config-tool/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
### Cmake minimum version
2929
cmake_minimum_required(VERSION 3.17)
3030

31+
### CMake stuff for ZED
32+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
33+
3134
### Project magic sprinkles
3235
set(PROJECT_NAME cfg_usbsid)
3336
set(EXECUTABLE ${PROJECT_NAME} CACHE STRING "EXECUTABLE")

examples/config-tool/cfg_usbsid

99.1 KB
Binary file not shown.

examples/send_sid/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
### Cmake minimum version
2929
cmake_minimum_required(VERSION 3.17)
3030

31+
### CMake stuff for ZED
32+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
33+
3134
### Project magic sprinkles
3235
set(PROJECT_NAME send_sid)
3336
set(EXECUTABLE ${PROJECT_NAME} CACHE STRING "EXECUTABLE")

examples/send_sid/send_sid

21.7 KB
Binary file not shown.

src/config.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ void handle_config_request(uint8_t * buffer, uint32_t size)
724724
break;
725725
case TOGGLE_AUDIO: /* Toggle the audio state regardless of config setting */
726726
usCFG("TOGGLE_AUDIO\n");
727-
toggle_audio_switch(); /* if HAS_AUDIOSWITCH is not defined, this doesn't do anything */
727+
toggle_audio_switch(); /* if PCB_VERSION_INT >= 13 is not defined, this doesn't do anything */
728728
break;
729729
case SET_AUDIO: /* Set the audio state from buffer setting (saves config if provided) */
730730
usCFG("SET_AUDIO\n");
@@ -1005,6 +1005,39 @@ void handle_config_request(uint8_t * buffer, uint32_t size)
10051005
(test_after - test_before)
10061006
);
10071007
}
1008+
if (buffer[1] == 0x0b) {
1009+
if (detect_socket_change() != CFG_OK) {
1010+
detected_sid_change = true;
1011+
if (detected_sid_change) {
1012+
set_SID5v_state(false);
1013+
set_SIDhv_state(false);
1014+
}
1015+
}
1016+
}
1017+
#if PCB_VERSION_INT == 14
1018+
if (buffer[1] == 0x0c) {
1019+
switch (buffer[2]) {
1020+
case 0:
1021+
set_SID5v_state((bool)buffer[3]);
1022+
break;
1023+
case 1:
1024+
set_SIDhv_state((bool)buffer[3]);
1025+
break;
1026+
case 2:
1027+
set_SID1_highvoltage((bool)buffer[3]);
1028+
break;
1029+
case 3:
1030+
set_SID2_highvoltage((bool)buffer[3]);
1031+
break;
1032+
}
1033+
}
1034+
#endif
1035+
if (buffer[1] == 0x0d) {
1036+
// set_sidemu_sidtype(buffer[2], buffer[3]);
1037+
extern uint8_t get_pin_states(void);
1038+
uint8_t pinstates = get_pin_states();
1039+
printf("PINSTATES: 0b%04b\n",pinstates);
1040+
}
10081041
break;
10091042
case TEST_FN2:
10101043
usNFO("Printing SID memory\n");

src/config_logging.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void print_config_overview(void)
172172
usCFG(" FMOpl available @ SID %d\n",
173173
(int)usbsid_config.FMOpl.sidno);
174174
usCFG("\n");
175-
#if defined(HAS_AUDIOSWITCH)
175+
#if PCB_VERSION_INT >= 13
176176
usCFG(" Audio switch is set to %s\n",
177177
monostereo_str((int)usbsid_config.stereo_en));
178178
usCFG(" Audio switch position = %s\n",

src/config_socket.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,49 @@ ConfigError apply_detection_results(const DetectionResult *det)
210210
return validate_config();
211211
}
212212

213+
/**
214+
* @brief Verifies detection results on socket change activity only
215+
*
216+
* @param det
217+
* @return ConfigError
218+
*/
219+
ConfigError verify_socket_detection_results(const DetectionResult *det)
220+
{
221+
if (!det->success) {
222+
return det->error != CFG_OK ? det->error : CFG_ERR_DETECTION_FAILED;
223+
}
224+
225+
/* Verify Socket 1 results */
226+
bool s1check1 = (usbsid_config.socketOne.chiptype != det->socket[0].chiptype);
227+
bool s1check2 = (usbsid_config.socketOne.dualsid != det->socket[0].supports_dual);
228+
bool s1check3 = (usbsid_config.socketOne.enabled != det->socket[0].present);
229+
/* Verify Socket 2 results */
230+
bool s2check1 = (usbsid_config.socketTwo.chiptype != det->socket[1].chiptype);
231+
bool s2check2 = (usbsid_config.socketTwo.dualsid != det->socket[1].supports_dual);
232+
bool s2check3 = (usbsid_config.socketTwo.enabled != det->socket[1].present);
233+
if ((det->socket[0].chiptype == CHIP_REAL) && s1check1) {
234+
/* Do something because voltage change! */
235+
}
236+
if ((det->socket[1].chiptype == CHIP_REAL) && s2check1) {
237+
/* Do something because voltage change! */
238+
}
239+
240+
241+
// TODO: REMOVE
242+
printf("SocketOne: %d %d\n",
243+
s1check1, s1check2, s1check3);
244+
printf("SocketTwo: %d %d\n",
245+
s2check1, s2check2, s2check3);
246+
247+
/* Anything changed!? */
248+
if (s1check1 || s1check2 || s1check3
249+
|| s2check1 || s2check2 || s2check3 ) {
250+
return CFG_ERR_CHANGE_DETECTED;
251+
}
252+
253+
return CFG_OK;
254+
}
255+
213256
/**
214257
* @brief Validate socket configuration for provided socket
215258
*

src/config_socket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void apply_fmopl_config(void);
4343
void apply_preset_wrapper(SocketPreset preset);
4444
void flip_sockets(void);
4545
ConfigError apply_detection_results(const DetectionResult *det);
46+
ConfigError verify_socket_detection_results(const DetectionResult *det);
4647
Socket default_socket(int id);
4748

4849

0 commit comments

Comments
 (0)