Skip to content

Commit d94a3e9

Browse files
committed
bt_ota: stop audio player task when doing ota
1 parent 775259d commit d94a3e9

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

main/inc/core/os.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef enum user_event_group_bits {
3030

3131
AUDIO_PLAYER_RUN_BIT = BIT11,
3232
AUDIO_PLAYER_IDLE_BIT = BIT12,
33+
AUDIO_PLAYER_EXIT_BIT = BIT13,
3334
} user_event_group_bits_t;
3435

3536
extern EventGroupHandle_t user_event_group;

main/inc/user/audio_player.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extern const char snd3_mp3_ptr[] asm("_binary_snd3_mp3_start");
2424
extern const char snd3_mp3_end[] asm("_binary_snd3_mp3_end");
2525

2626
extern void audio_player_play_file(uint8_t idx);
27+
extern void audio_player_set_mode(uint8_t idx);
2728

2829
extern void audio_player_init(void);
2930

main/src/user/audio_player.c

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ static const char *mp3_file_ptr[][2] = {
4444
#endif
4545
};
4646

47-
static uint8_t mp3_file_index = 0;
47+
static uint8_t aplay_mode = 1;
48+
static uint8_t mp3_file_index = 0;
4849
static uint8_t playback_pending = 0;
4950

5051
static void audio_player_task(void *pvParameters)
@@ -63,12 +64,26 @@ static void audio_player_task(void *pvParameters)
6364
while (1) {
6465
xEventGroupWaitBits(
6566
user_event_group,
66-
AUDIO_PLAYER_RUN_BIT,
67+
AUDIO_PLAYER_RUN_BIT | AUDIO_PLAYER_EXIT_BIT,
6768
pdFALSE,
6869
pdFALSE,
6970
portMAX_DELAY
7071
);
7172

73+
EventBits_t uxBits = xEventGroupGetBits(user_event_group);
74+
if (uxBits & AUDIO_PLAYER_EXIT_BIT) {
75+
xEventGroupSetBits(user_event_group, AUDIO_PLAYER_IDLE_BIT);
76+
xEventGroupClearBits(user_event_group, AUDIO_PLAYER_RUN_BIT);
77+
78+
free(synth);
79+
free(frame);
80+
free(stream);
81+
82+
ESP_LOGI(TAG, "exited.");
83+
84+
vTaskDelete(NULL);
85+
}
86+
7287
// Initialize mp3 parts
7388
mad_stream_init(stream);
7489
mad_frame_init(frame);
@@ -108,7 +123,8 @@ static void audio_player_task(void *pvParameters)
108123
free(stream);
109124

110125
ESP_LOGE(TAG, "unrecoverable error");
111-
esp_restart();
126+
127+
vTaskDelete(NULL);
112128
}
113129

114130
void audio_player_play_file(uint8_t idx)
@@ -123,6 +139,9 @@ void audio_player_play_file(uint8_t idx)
123139
}
124140
mp3_file_index = idx;
125141
EventBits_t uxBits = xEventGroupGetBits(user_event_group);
142+
if (uxBits & AUDIO_PLAYER_EXIT_BIT) {
143+
return;
144+
}
126145
if (uxBits & AUDIO_PLAYER_RUN_BIT) {
127146
// Previous playback is still not complete
128147
playback_pending = 1;
@@ -133,6 +152,21 @@ void audio_player_play_file(uint8_t idx)
133152
#endif
134153
}
135154

155+
void audio_player_set_mode(uint8_t idx)
156+
{
157+
#ifdef CONFIG_ENABLE_AUDIO_PROMPT
158+
aplay_mode = idx;
159+
ESP_LOGI(TAG, "mode: %u", aplay_mode);
160+
161+
if (aplay_mode) {
162+
xEventGroupClearBits(user_event_group, AUDIO_PLAYER_EXIT_BIT);
163+
audio_player_init();
164+
} else {
165+
xEventGroupSetBits(user_event_group, AUDIO_PLAYER_EXIT_BIT);
166+
}
167+
#endif
168+
}
169+
136170
void audio_player_init(void)
137171
{
138172
EventBits_t uxBits = xEventGroupGetBits(user_event_group);

main/src/user/bt_spp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "user/ble_app.h"
3131
#include "user/ble_gatts.h"
3232
#include "user/audio_input.h"
33+
#include "user/audio_player.h"
3334

3435
#define BT_SPP_TAG "bt_spp"
3536
#define BT_OTA_TAG "bt_ota"
@@ -104,6 +105,7 @@ void bt_app_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
104105
image_length = 0;
105106

106107
i2s_output_init();
108+
audio_player_set_mode(1);
107109
#ifndef CONFIG_AUDIO_INPUT_NONE
108110
audio_input_set_mode(ain_prev_mode);
109111
#endif
@@ -208,6 +210,7 @@ void bt_app_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
208210
audio_input_set_mode(0);
209211
#endif
210212
#ifdef CONFIG_ENABLE_AUDIO_PROMPT
213+
audio_player_set_mode(0);
211214
xEventGroupWaitBits(
212215
user_event_group,
213216
AUDIO_PLAYER_IDLE_BIT,
@@ -282,6 +285,7 @@ void bt_app_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
282285
esp_spp_write(param->write.handle, strlen(rsp_str[2]), (uint8_t *)rsp_str[2]);
283286

284287
i2s_output_init();
288+
audio_player_set_mode(1);
285289
#ifndef CONFIG_AUDIO_INPUT_NONE
286290
audio_input_set_mode(ain_prev_mode);
287291
#endif

sdkconfig.defaults

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ CONFIG_BT_GATTS_ENABLE=y
2727
CONFIG_BT_GATTC_ENABLE=n
2828
CONFIG_BT_BLE_SMP_ENABLE=n
2929
CONFIG_BT_STACK_NO_LOG=y
30+
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=y
3031

3132
#
3233
# Compiler options

0 commit comments

Comments
 (0)