Skip to content

Commit ab8e594

Browse files
authored
Merge pull request #91 from LouDnl/dev
Dev v0.7.1
2 parents 4bb0458 + 0d32f60 commit ab8e594

7 files changed

Lines changed: 180 additions & 98 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ set(PROJECT_NAME usbsidpico)
3737
set(PROJECT_MANUFACTURER "LouD")
3838
set(PRODUCT_STRING "USBSID-Pico")
3939
string(TIMESTAMP MAGIC_SMOKE "%Y%m%d") # Auto generate dated version
40-
set(PROJECT_VERSION "0.7.0-${MAGIC_SMOKE}") # Generate compile version
40+
set(PROJECT_VERSION "0.7.1-${MAGIC_SMOKE}") # Generate compile version
4141

4242
### Want a cookie?
4343
# NOTICE: ENABLING THESE DEBUGGING DEFINITIONS WILL HAVE SIGNIFICANT IMPACT AND WILL DELAY PLAYING!

examples/config-tool/cfg_usbsid.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ void print_help(void)
15741574
printf(" -sau, --set-audio N : Set and save the mono/stereo audio switch (PCB v1.3+ only!)\n");
15751575
printf(" 0: %s, 1:%s\n", mono_stereo[0], mono_stereo[1]);
15761576
printf(" -lau N, --lock-audio N : Lock and the audio switch in it's current state until reboot: True (1) False (0)\n");
1577-
printf(" -sad N, --sock-autodetect N : Disable/enable and save the automatic socket change detection on boot (PCB v1.5+ only!)\n");
1577+
printf(" -sad N, --sock-autodetect N : Disable/enable and save the automatic socket change detection on boot (PCB v1.5+ only!)\n");
15781578
printf(" 0: %s, 1:%s\n", enabled[0], enabled[1]);
15791579
printf("--[PRESETS]-------------------------------------------------------------------------------------------------------------\n");
15801580
printf(" -single, --single-sid : Socket 1 enabled @ single SID, Socket 2 disabled\n");
@@ -1927,6 +1927,9 @@ void config_usbsidpico(int argc, char **argv)
19271927
memset(read_data, 0, count_of(read_data));
19281928
len = read_chars(read_data, size);
19291929
printf("[R %u] %02X\n", len, read_data[0]);
1930+
if (size > 1) {
1931+
print_cfg_buffer(read_data, size);
1932+
}
19301933
}
19311934
break;
19321935
}

src/config.c

Lines changed: 41 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ void handle_config_buffer(uint8_t * buffer, uint32_t size)
116116
/* TODO: Add something along the line
117117
like this: sidfile = (uint8_t*)calloc(1, 0x10000); */
118118
switch (buffer[1]) {
119-
case FULL_CONFIG:
120-
case SOCKET_CONFIG:
121-
case MIDI_CONFIG:
122-
case MIDI_CCVALUES:
119+
case FULL_CONFIG: break;
120+
case SOCKET_CONFIG: break;
121+
case MIDI_CONFIG: break;
122+
case MIDI_CCVALUES: break;
123123
default:
124124
break;
125125
}
@@ -471,7 +471,7 @@ void handle_config_request(uint8_t * buffer, uint32_t size)
471471
memset(write_buffer_p, 0, 64);
472472
write_buffer_p[0] = (uint8_t)config_unacknowledged();
473473
#else
474-
usCFG("READ_CONFIGACK\n");
474+
usCFG("READ_CONFIGACK Not supported\n");
475475
memset(write_buffer_p, 0, 64);
476476
#endif
477477
write_back_data(1);
@@ -698,7 +698,7 @@ void handle_config_request(uint8_t * buffer, uint32_t size)
698698
apply_config(false); /* Not at boot */
699699
}
700700
break;
701-
case WRITE_CONFIG: /* TODO: FINISH */
701+
case WRITE_CONFIG: /* Incoming write from Host */ /* TODO: FINISH */
702702
/* Max size of incoming buffer = 61 */
703703
usCFG("WRITE_CONFIG\n");
704704
handle_config_buffer(buffer, size);
@@ -814,11 +814,21 @@ void handle_config_request(uint8_t * buffer, uint32_t size)
814814
}
815815
} else {
816816
usCFG("Audio switch is %s, requested change to %d (%s)\n",
817-
monostereo_str((int)usbsid_config.stereo_en), buffer[1], monostereo_str(buffer[1]));
817+
monostereo_str((int)usbsid_config.stereo_en),
818+
buffer[1], monostereo_str(buffer[1]));
818819
return;
819820
}
820821
break;
821-
case GET_AUDIO: /* TODO: Finish */
822+
case GET_AUDIO: /* Returns the audio switch state */
823+
#if PCB_VERSION_INT >= 13
824+
usCFG("GET_AUDIO: %d\n", (int)usbsid_config.stereo_en);
825+
memset(write_buffer_p, 0, 64);
826+
write_buffer_p[0] = (uint8_t)usbsid_config.stereo_en;
827+
#else
828+
usCFG("GET_AUDIO Not supported\n");
829+
memset(write_buffer_p, 0, 64);
830+
#endif
831+
write_back_data(1);
822832
break;
823833
case LOCK_AUDIO:
824834
usCFG("LOCK_AUDIO\n");
@@ -868,14 +878,7 @@ void handle_config_request(uint8_t * buffer, uint32_t size)
868878
memset(write_buffer_p, 0 ,64); /* Empty the write buffer pointer */
869879
read_config(&usbsid_config); /* Read the config into the config buffer */
870880
memcpy(write_buffer_p, config_array, 64); /* Copy the first 64 bytes from the buffer into the write buffer */
871-
switch (rtype) {
872-
case 'C':
873-
cdc_write(cdc_itf, 64);
874-
break;
875-
case 'W':
876-
webserial_write(wusb_itf, 64);
877-
break;
878-
}
881+
write_back_data(64);
879882
} else if (buffer[1] == 1) { /* Only if 1, else just skip! */
880883
if (buffer[2] < 4) {
881884
usCFG("DETECT_SIDS @ $%02x\n", buffer[3]);
@@ -903,14 +906,7 @@ void handle_config_request(uint8_t * buffer, uint32_t size)
903906
memset(write_buffer_p, 0 ,64); /* Empty the write buffer pointer */
904907
read_config(&usbsid_config); /* Read the config into the config buffer */
905908
memcpy(write_buffer_p, config_array, 64); /* Copy the first 64 bytes from the buffer into the write buffer */
906-
switch (rtype) {
907-
case 'C':
908-
cdc_write(cdc_itf, 64);
909-
break;
910-
case 'W':
911-
webserial_write(wusb_itf, 64);
912-
break;
913-
}
909+
write_back_data(64);
914910
break;
915911
case AUTO_DETECT:
916912
usCFG("AUTO_DETECT\n");
@@ -930,14 +926,7 @@ void handle_config_request(uint8_t * buffer, uint32_t size)
930926
memset(write_buffer_p, 0 ,64); /* Empty the write buffer pointer */
931927
read_config(&usbsid_config); /* Read the config into the config buffer */
932928
memcpy(write_buffer_p, config_array, 64); /* Copy the first 64 bytes from the buffer into the write buffer */
933-
switch (rtype) {
934-
case 'C':
935-
cdc_write(cdc_itf, 64);
936-
break;
937-
case 'W':
938-
webserial_write(wusb_itf, 64);
939-
break;
940-
}
929+
write_back_data(64);
941930
}
942931
break;
943932
case TEST_ALLSIDS:
@@ -984,14 +973,7 @@ void handle_config_request(uint8_t * buffer, uint32_t size)
984973
read_firmware_version();
985974
memset(write_buffer_p, 0, MAX_BUFFER_SIZE);
986975
memcpy(write_buffer_p, p_version_array, MAX_BUFFER_SIZE);
987-
switch (rtype) {
988-
case 'C':
989-
cdc_write(cdc_itf, MAX_BUFFER_SIZE);
990-
break;
991-
case 'W':
992-
webserial_write(wusb_itf, MAX_BUFFER_SIZE);
993-
break;
994-
}
976+
write_back_data(MAX_BUFFER_SIZE);
995977
break;
996978
case US_PCB_VERSION:
997979
usCFG("READ_PCB_VERSION\n");
@@ -1000,14 +982,7 @@ void handle_config_request(uint8_t * buffer, uint32_t size)
1000982
read_pcb_version();
1001983
memset(write_buffer_p, 0, MAX_BUFFER_SIZE);
1002984
memcpy(write_buffer_p, p_version_array, MAX_BUFFER_SIZE);
1003-
switch (rtype) {
1004-
case 'C':
1005-
cdc_write(cdc_itf, MAX_BUFFER_SIZE);
1006-
break;
1007-
case 'W':
1008-
webserial_write(wusb_itf, MAX_BUFFER_SIZE);
1009-
break;
1010-
}
985+
write_back_data(MAX_BUFFER_SIZE);
1011986
} else { /* Small write single byte */
1012987
memset(write_buffer_p, 0, 64);
1013988
/* int pcbver = (strcmp(pcb_version, "1.3") == 0 ? 13 : 10); */
@@ -1138,7 +1113,7 @@ void handle_config_request(uint8_t * buffer, uint32_t size)
11381113
// set_sidemu_sidtype(buffer[2], buffer[3]);
11391114
extern uint8_t get_pin_states(void);
11401115
uint8_t pinstates = get_pin_states();
1141-
printf("PINSTATES: 0b%04b\n",pinstates);
1116+
usNFO("PINSTATES: 0b%04b\n",pinstates);
11421117
}
11431118
break;
11441119
case TEST_FN2:
@@ -1149,10 +1124,23 @@ void handle_config_request(uint8_t * buffer, uint32_t size)
11491124
}
11501125
usNFO("\n");
11511126
break;
1152-
case FPGASID: break; /* Reserved for config implementation */
1153-
case SKPICO: break; /* Reserved for config implementation */
1154-
case ARMSID: break; /* Reserved for config implementation */
1155-
case PDSID:
1127+
case READ_CLONECHIP: /* Read configuration / data from clone Chips */
1128+
usCFG("READ_CLONECHIP: $%02x @ $%02x\n", buffer[1], buffer[2]);
1129+
if ((buffer[1]&0x0f) > CHIP_COUNT) break;
1130+
memset(write_buffer_p, 0, MAX_BUFFER_SIZE);
1131+
if (!read_chip_configuration(buffer[2], buffer[1], write_buffer_p)) {
1132+
usNFO("READ ERROR!\n");
1133+
}
1134+
usNFO("WRITE BACK:\n");
1135+
for (int i = 0; i < MAX_BUFFER_SIZE; i++) usNFO("%02x ", write_buffer_p[i]);
1136+
usNFO("\n");
1137+
usNFO("SENDING\n");
1138+
write_back_data(MAX_BUFFER_SIZE);
1139+
break;
1140+
case WRITE_CLONECHIP: /* Write configuration / data to clone Chips */
1141+
write_chip_configuration(buffer[2]);
1142+
break;
1143+
case PDSID: /* TODO: Deprecate and remove */
11561144
if (buffer[1] == 0) {
11571145
usCFG("Toggle PDSID type\n");
11581146
reset_switch_pdsid_type();

src/config.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,9 @@ enum
357357
TEST_FN2 = 0x9A, /* TODO: Remove before v1 release */
358358

359359
/* Hardware SID clone configuration related */
360-
FPGASID = 0xA0, /* Config initiator byte for FPGASID */
361-
SKPICO = 0xA1, /* Config initiator byte for SIDKICK-pico */
362-
ARMSID = 0xA2, /* Config initiator byte for ARMSID */
360+
READ_CLONECHIP = 0xA0, /* Chip config read initiator byte */
361+
WRITE_CLONECHIP = 0xB0, /* Chip config write initiator byte */
362+
/* legacy commands */
363363
PDSID = 0xA3, /* Holds the reset line for 5 seconds to change SID type on a PDSID */
364364

365365
#if defined(ONBOARD_EMULATOR) || defined(ONBOARD_SIDPLAYER)
@@ -393,9 +393,30 @@ enum {
393393
SOCKET_CONFIG = READ_SOCKETCFG, /* 0x37 */
394394
MIDI_CONFIG = 0x60,
395395
MIDI_CCVALUES = 0x70,
396+
VERIFICATION_BYTE = 0x7F,
396397
END_BYTE = 0x8F,
397398
TERMINATION_BYTE = 0xFF,
398-
VERIFICATION_BYTE = 0x7F,
399+
};
400+
401+
/* Clone chip config read/write initiator bytes */
402+
enum {
403+
READ_SKPICO = (READ_CLONECHIP|CHIP_SKPICO), /* a2 */
404+
READ_ARMSID = (READ_CLONECHIP|CHIP_ARMSID), /* a3 */
405+
READ_ARM2SID = (READ_CLONECHIP|CHIP_ARM2SID), /* a4 */
406+
READ_FPGASID = (READ_CLONECHIP|CHIP_FPGASID), /* a5 */
407+
READ_REDIPSID = (READ_CLONECHIP|CHIP_REDIPSID), /* a6 */
408+
READ_PDSID = (READ_CLONECHIP|CHIP_PDSID), /* a7 */
409+
READ_BACKSID = (READ_CLONECHIP|CHIP_BACKSID), /* a8 */
410+
READ_SIDEMU = (READ_CLONECHIP|CHIP_SIDEMU), /* a9 */
411+
//
412+
WRITE_SKPICO = (WRITE_CLONECHIP|CHIP_SKPICO), /* b2 */
413+
WRITE_ARMSID = (WRITE_CLONECHIP|CHIP_ARMSID), /* b3 */
414+
WRITE_ARM2SID = (WRITE_CLONECHIP|CHIP_ARM2SID), /* b4 */
415+
WRITE_FPGASID = (WRITE_CLONECHIP|CHIP_FPGASID), /* b5 */
416+
WRITE_REDIPSID = (WRITE_CLONECHIP|CHIP_REDIPSID), /* b6 */
417+
WRITE_PDSID = (WRITE_CLONECHIP|CHIP_PDSID), /* b7 */
418+
WRITE_BACKSID = (WRITE_CLONECHIP|CHIP_BACKSID), /* b8 */
419+
WRITE_SIDEMU = (WRITE_CLONECHIP|CHIP_SIDEMU), /* b9 */
399420
};
400421

401422
/* SET_CONFIG values */

src/logging.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,15 @@ do { \
4949
for (int i = 0; i < count; i ++) tud_cdc_n_write_char(1, _tempbuf[i]); \
5050
tud_cdc_n_write_flush(1); \
5151
tud_task_ext(0, true); \
52+
stdio_flush(); \
5253
} while(0)
5354
#define _US_DBG(...) cdc_printf(__VA_ARGS__)
5455
#else
55-
#define _US_DBG(...) printf(__VA_ARGS__)
56+
#define _US_DBG(...) \
57+
do { \
58+
printf(__VA_ARGS__); \
59+
stdio_flush(); \
60+
} while (0)
5661
#endif
5762

5863

@@ -81,11 +86,7 @@ do { \
8186
#endif
8287

8388
#ifdef USBSID_BOOTLOG
84-
#define usBOOT(fmt, ...) \
85-
do { \
86-
__DBG("[BOOT] " fmt __VA_OPT__(,) __VA_ARGS__); \
87-
stdio_flush(); \
88-
} while(0)
89+
#define usBOOT(fmt, ...) __DBG("[BOOT] " fmt __VA_OPT__(,) __VA_ARGS__)
8990
#else
9091
#define usBOOT(...) ((void)0)
9192
#endif

0 commit comments

Comments
 (0)