Fix save config when no audio is playing

This commit is contained in:
George Norton 2023-09-17 22:52:32 +01:00
parent b341d947d7
commit 9902f1815b
3 changed files with 9 additions and 0 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;