Skip to content

Commit cb8eeea

Browse files
samples: bluetooth: le_audio: auracast: fix push-to-talk
Fixes PDM configuration when push-to-talk feature is enabled. This also makes feature configurable. Signed-off-by: Honkala Petri <petri.honkala@alifsemi.com>
1 parent 5940470 commit cb8eeea

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

samples/bluetooth/le_audio/auracast/auracast_source/auracast_source.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ LOG_MODULE_REGISTER(auracast_source, CONFIG_AURACAST_SOURCE_LOG_LEVEL);
2828

2929
#define MIC_NODE DT_ALIAS(pdm_mic)
3030

31-
#define MIC_ENABLED (DT_NODE_EXISTS(MIC_NODE) && DT_NODE_EXISTS(DT_ALIAS(sw0)))
31+
#define MIC_ENABLED \
32+
(IS_ENABLED(CONFIG_AUDIO_DMIC) && DT_NODE_EXISTS(MIC_NODE) && DT_NODE_EXISTS(DT_ALIAS(sw0)))
3233

3334
#define PRESENTATION_DELAY_US (CONFIG_LE_AUDIO_PRESENTATION_DELAY_MS * 1000)
3435
#define SUBGROUP_ID 0
@@ -545,6 +546,11 @@ static int configure_led(void)
545546
/* Initialisation to perform pre-main */
546547
static int auracast_source_init(void)
547548
{
549+
if (!device_is_ready(DEVICE_DT_GET(MIC_NODE))) {
550+
LOG_ERR("mic device is not ready");
551+
return -1;
552+
}
553+
548554
if (configure_button()) {
549555
return -1;
550556
}

samples/bluetooth/le_audio/auracast/src/audio_datapath.c

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@
2424
#define INT_RAMFUNC
2525
#endif
2626

27-
#define I2S_SINK_DEV DEVICE_DT_GET(CODEC_I2S_NODE)
28-
29-
#if DT_NODE_EXISTS(I2S_MIC_NODE)
30-
#define I2S_SOURCE_DEV DEVICE_DT_GET(I2S_MIC_NODE)
31-
#else
32-
#define I2S_SOURCE_DEV I2S_SINK_DEV
33-
#endif
27+
#define CODEC_I2S_DEV DEVICE_DT_GET(CODEC_I2S_NODE)
3428

3529
BUILD_ASSERT(!DT_PROP(CODEC_I2S_NODE, mono_mode), "I2S must be configured in stereo mode");
3630

@@ -55,18 +49,12 @@ static int unicast_audio_path_init(void)
5549
return -1;
5650
}
5751

58-
ret = device_is_ready(I2S_SINK_DEV);
52+
ret = device_is_ready(CODEC_I2S_DEV);
5953
if (!ret) {
6054
LOG_ERR("I2S is not ready");
6155
return -1;
6256
}
6357

64-
ret = device_is_ready(I2S_SOURCE_DEV);
65-
if (!ret) {
66-
LOG_ERR("I2S mic is not ready");
67-
return -1;
68-
}
69-
7058
/* Stop codec output if started during init */
7159
audio_codec_stop_output(DEVICE_DT_GET(CODEC_CFG_NODE));
7260

@@ -144,7 +132,7 @@ int audio_datapath_create_source(struct audio_datapath_config const *const cfg)
144132
}
145133

146134
struct audio_encoder_params const enc_params = {
147-
.i2s_dev = I2S_SOURCE_DEV,
135+
.i2s_dev = CODEC_I2S_DEV,
148136
.frame_duration_us = cfg->frame_duration_is_10ms ? 10000 : 7500,
149137
.sampling_rate_hz = cfg->sampling_rate_hz,
150138
.audio_buffer_len_us = cfg->pres_delay_us,
@@ -171,14 +159,12 @@ int audio_datapath_create_source(struct audio_datapath_config const *const cfg)
171159
#endif
172160

173161
if (cfg->mic_dev) {
174-
#if DT_NODE_EXISTS(I2S_MIC_NODE)
175-
int ret = mic_configure(cfg->mic_dev, I2S_SOURCE_DEV, env.encoder);
162+
int ret = mic_configure(cfg->mic_dev, CODEC_I2S_DEV, env.encoder);
176163

177164
if (ret != 0) {
178165
LOG_ERR("Failed to configure mic input, err %d", ret);
179166
return ret;
180167
}
181-
#endif
182168
}
183169

184170
LOG_DBG("Source audio datapath created");
@@ -241,7 +227,7 @@ int audio_datapath_create_sink(struct audio_datapath_config const *const cfg)
241227
}
242228

243229
struct audio_decoder_params const dec_params = {
244-
.i2s_dev = I2S_SINK_DEV,
230+
.i2s_dev = CODEC_I2S_DEV,
245231
.frame_duration_us = cfg->frame_duration_is_10ms ? 10000 : 7500,
246232
.sampling_rate_hz = cfg->sampling_rate_hz,
247233
.pres_delay_us = cfg->pres_delay_us,

samples/bluetooth/le_audio/auracast/src/audio_datapath.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#define CODEC_CFG_NODE DT_ALIAS(audio_codec)
1616
#define CODEC_I2S_NODE DT_ALIAS(i2s_bus)
17-
#define I2S_MIC_NODE DT_ALIAS(i2s_mic)
1817
/* #define MCLK_GEN_NODE DT_ALIAS(mclk_gen) */
1918

2019
struct audio_datapath_config {

samples/bluetooth/le_audio/auracast/src/mic_source.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
#define MIC_SOURCE_H
1212

1313
#include "bluetooth/le_audio/audio_encoder.h"
14+
#include <zephyr/toolchain.h>
1415

16+
#if CONFIG_AUDIO_DMIC
1517
/**
1618
* @brief Configure microphone source
1719
*
@@ -23,7 +25,7 @@
2325
* @retval Negative error code on failure
2426
*/
2527
int mic_configure(const struct device *mic_dev, const struct device *i2s_dev,
26-
struct audio_encoder *audio_encoder);
28+
struct audio_encoder *audio_encoder);
2729

2830
/**
2931
* @brief Start the microphone source stream
@@ -42,4 +44,25 @@ void mic_stop(void);
4244
*/
4345
void mic_control(bool const start);
4446

47+
#else
48+
static inline int mic_configure(const struct device *mic_dev, const struct device *i2s_dev,
49+
struct audio_encoder *audio_encoder)
50+
{
51+
return 0;
52+
}
53+
54+
static inline void mic_start(void)
55+
{
56+
}
57+
58+
static inline void mic_stop(void)
59+
{
60+
}
61+
62+
static inline void mic_control(bool const start)
63+
{
64+
ARG_UNUSED(start);
65+
}
66+
#endif
67+
4568
#endif /* MIC_SOURCE_H */

0 commit comments

Comments
 (0)