diff --git a/firmware/code/configuration_manager.c b/firmware/code/configuration_manager.c index d112044..aceeb63 100644 --- a/firmware/code/configuration_manager.c +++ b/firmware/code/configuration_manager.c @@ -433,6 +433,12 @@ bool process_cmd(tlv_header* cmd) { case SAVE_CONFIGURATION: { if (cmd->length == 4) { saveState = SaveRequested; + if (audio_state.interface == 0) { + // The OS will configure the alternate "zero" interface when the device is not in use + // in this sate we can write to flash now. Otherwise, defer the save until we get the next + // usb packet. + save_config(); + } result->type = OK; result->length = 4; return true; diff --git a/firmware/code/run.c b/firmware/code/run.c index ebbb455..8d2ebe5 100644 --- a/firmware/code/run.c +++ b/firmware/code/run.c @@ -52,6 +52,7 @@ static uint8_t *userbuf; audio_state_config audio_state = { .freq = 48000, .de_emphasis_frequency = 0x1, // 48khz + .interface = 0 }; preprocessing_config preprocessing = { @@ -769,6 +770,7 @@ static const struct usb_transfer_type _audio_cmd_transfer_type = { static bool as_set_alternate(struct usb_interface *interface, uint alt) { assert(interface == &as_op_interface); + audio_state.interface = alt; switch (alt) { case 0: power_down_dac(); return true; case 1: power_up_dac(); return true; diff --git a/firmware/code/run.h b/firmware/code/run.h index ff339e9..5bec27a 100644 --- a/firmware/code/run.h +++ b/firmware/code/run.h @@ -76,6 +76,7 @@ typedef struct _audio_state_config { int16_t _target_pcm3060_registers; }; int16_t pcm3060_registers; + int8_t interface; } audio_state_config; extern audio_state_config audio_state;