Skip to content

Commit d18b73f

Browse files
committed
rg_audio i2s: Initialize the amp control pin during driver init, instead of each time in set_mute (#226)
1 parent fbe84ff commit d18b73f

File tree

1 file changed

+15
-7
lines changed
  • components/retro-go/drivers/audio

1 file changed

+15
-7
lines changed

components/retro-go/drivers/audio/i2s.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
#include <driver/dac.h>
1616
#endif
1717

18+
#ifdef RG_GPIO_SND_AMP_ENABLE_INVERT
19+
#define MUTE_ENABLE 1
20+
#define MUTE_DISABLE 0
21+
#else
22+
#define MUTE_ENABLE 0
23+
#define MUTE_DISABLE 1
24+
#endif
25+
1826
static struct {
1927
const char *last_error;
2028
int device;
@@ -80,6 +88,11 @@ static bool driver_init(int device, int sample_rate)
8088
state.last_error = "This device does not support external DAC mode!";
8189
#endif
8290
}
91+
#ifdef RG_GPIO_SND_AMP_ENABLE
92+
gpio_reset_pin(RG_GPIO_SND_AMP_ENABLE);
93+
gpio_set_level(RG_GPIO_SND_AMP_ENABLE, MUTE_ENABLE);
94+
gpio_set_direction(RG_GPIO_SND_AMP_ENABLE, GPIO_MODE_OUTPUT);
95+
#endif
8396
return state.last_error == NULL;
8497
}
8598

@@ -179,13 +192,8 @@ static bool driver_submit(const rg_audio_frame_t *frames, size_t count)
179192
static bool driver_set_mute(bool mute)
180193
{
181194
i2s_zero_dma_buffer(I2S_NUM_0);
182-
#if defined(RG_GPIO_SND_AMP_ENABLE)
183-
gpio_set_direction(RG_GPIO_SND_AMP_ENABLE, GPIO_MODE_OUTPUT);
184-
#ifdef RG_GPIO_SND_AMP_ENABLE_INVERT
185-
gpio_set_level(RG_GPIO_SND_AMP_ENABLE, mute ? 1 : 0);
186-
#else
187-
gpio_set_level(RG_GPIO_SND_AMP_ENABLE, mute ? 0 : 1);
188-
#endif
195+
#ifdef RG_GPIO_SND_AMP_ENABLE
196+
gpio_set_level(RG_GPIO_SND_AMP_ENABLE, mute ? MUTE_ENABLE : MUTE_DISABLE);
189197
#endif
190198
state.muted = mute;
191199
return true;

0 commit comments

Comments
 (0)