Skip to content

Commit

Permalink
Persistent audio mute support revisions (portapack-mayhem#1169)
Browse files Browse the repository at this point in the history
* Don't disable DAC when other audio output is using it
* Persistent audio mute revisions
* Moved persistent audio mute code to audio.cpp
* Make "Disable AK speaker amp" take effect immediately
  • Loading branch information
NotherNgineer authored Jun 19, 2023
1 parent f83027d commit fa06df1
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 38 deletions.
1 change: 1 addition & 0 deletions firmware/application/apps/ui_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ SetAudioView::SetAudioView(NavigationView& nav) {
button_save.on_select = [&nav, this](Button&) {
persistent_memory::set_tone_mix(field_tone_mix.value());
persistent_memory::set_config_speaker_disable(checkbox_speaker_disable.value());
audio::output::update_audio_mute();
nav.pop();
};

Expand Down
18 changes: 9 additions & 9 deletions firmware/application/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,6 @@ void unmute() {
}
}

void speaker_disable() {
cfg_speaker_disable = true;
audio_codec->speaker_disable();
}

void speaker_enable() {
cfg_speaker_disable = false;
}

// The following functions are used by the navigation-bar Speaker Mute only,
// and override all other audio mute/unmute requests from apps
void speaker_mute() {
Expand All @@ -191,6 +182,15 @@ void speaker_unmute() {
}
}

void update_audio_mute() {
cfg_speaker_disable = portapack::persistent_memory::config_speaker_disable();

if (portapack::persistent_memory::config_audio_mute())
speaker_mute();
else
speaker_unmute();
}

} /* namespace output */

namespace input {
Expand Down
1 change: 1 addition & 0 deletions firmware/application/audio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void speaker_disable();
void speaker_enable();
void speaker_mute();
void speaker_unmute();
void update_audio_mute();

} /* namespace output */

Expand Down
14 changes: 0 additions & 14 deletions firmware/application/portapack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,6 @@ bool get_antenna_bias() {
return antenna_bias;
}

void set_audio_mute(const bool v) {
if (v)
audio::output::speaker_mute();
else
audio::output::speaker_unmute();
}

void set_speaker_disable(const bool v) {
if (v)
audio::output::speaker_disable();
else
audio::output::speaker_enable();
}

static constexpr uint32_t systick_count(const uint32_t clock_source_f) {
return clock_source_f / CH_FREQUENCY;
}
Expand Down
3 changes: 0 additions & 3 deletions firmware/application/portapack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ extern ClockManager clock_manager;
extern ReceiverModel receiver_model;
extern TransmitterModel transmitter_model;

void set_audio_mute(const bool v);
void set_speaker_disable(const bool v);

extern uint32_t bl_tick_counter;
extern bool antenna_bias;

Expand Down
14 changes: 4 additions & 10 deletions firmware/application/ui_navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ SystemStatusView::SystemStatusView(
button_clock_status.on_select = [this](ImageButton&) {
this->on_clk();
};

audio::output::update_audio_mute();
}

void SystemStatusView::refresh() {
Expand All @@ -213,9 +215,6 @@ void SystemStatusView::refresh() {
}
}

portapack::set_speaker_disable(portapack::persistent_memory::config_speaker_disable());
portapack::set_audio_mute(portapack::persistent_memory::config_audio_mute());

if (portapack::persistent_memory::config_audio_mute()) {
button_speaker.set_foreground(Color::light_grey());
button_speaker.set_bitmap(&bitmap_icon_speaker_mute);
Expand Down Expand Up @@ -287,13 +286,8 @@ void SystemStatusView::on_converter() {
}

void SystemStatusView::on_speaker() {
if (portapack::persistent_memory::config_audio_mute()) {
portapack::set_audio_mute(false);
portapack::persistent_memory::set_config_audio_mute(false);
} else {
portapack::set_audio_mute(true);
portapack::persistent_memory::set_config_audio_mute(true);
}
portapack::persistent_memory::set_config_audio_mute(!portapack::persistent_memory::config_audio_mute());
audio::output::update_audio_mute();
refresh();
}

Expand Down
12 changes: 10 additions & 2 deletions firmware/common/ak4951.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ void AK4951::headphone_enable() {

void AK4951::headphone_disable() {
set_headphone_power(false);
set_dac_power(false);

// Don't power off DAC unless Speaker is disabled also
if (map.r.power_management_2.PMSL == 0) {
set_dac_power(false);
}
}

void AK4951::speaker_enable() {
Expand Down Expand Up @@ -210,7 +214,11 @@ void AK4951::speaker_disable() {
update(Register::SignalSelect1);

// Power down DAC, Programmable Filter and speaker: PMDAC=PMPFIL=PMSL bits= “1”→“0”
set_dac_power(false);
// Exception: Don't power off DAC unless Headphones are disabled too
if (map.r.power_management_2.PMHPL == 0) {
set_dac_power(false);
}

// map.r.power_management_1.PMPFIL = 0;
// update(Register::PowerManagement1);
set_speaker_power(false);
Expand Down

0 comments on commit fa06df1

Please sign in to comment.