15
15
#include "sine.h"
16
16
#endif
17
17
18
- #define I2S_CODEC_TX DT_ALIAS(i2s_codec_tx)
18
+ #define I2S_CODEC_TX DT_ALIAS(i2s_codec_tx)
19
19
20
- #define SAMPLE_FREQUENCY CONFIG_SAMPLE_FREQ
21
- #define SAMPLE_BIT_WIDTH (16U)
22
- #define BYTES_PER_SAMPLE sizeof(int16_t)
20
+ #define SAMPLE_FREQUENCY CONFIG_SAMPLE_FREQ
21
+ #define SAMPLE_BIT_WIDTH (16U)
22
+ #define BYTES_PER_SAMPLE sizeof(int16_t)
23
23
#if CONFIG_USE_DMIC
24
- #define NUMBER_OF_CHANNELS CONFIG_DMIC_CHANNELS
24
+ #define NUMBER_OF_CHANNELS CONFIG_DMIC_CHANNELS
25
25
#else
26
26
#define NUMBER_OF_CHANNELS (2U)
27
27
#endif
28
28
/* Such block length provides an echo with the delay of 100 ms. */
29
- #define SAMPLES_PER_BLOCK ((SAMPLE_FREQUENCY / 10) * NUMBER_OF_CHANNELS)
30
- #define INITIAL_BLOCKS CONFIG_I2S_INIT_BUFFERS
31
- #define TIMEOUT (2000U)
29
+ #define SAMPLES_PER_BLOCK ((SAMPLE_FREQUENCY / 10) * NUMBER_OF_CHANNELS)
30
+ #define INITIAL_BLOCKS CONFIG_I2S_INIT_BUFFERS
31
+ #define TIMEOUT (2000U)
32
32
33
33
#define BLOCK_SIZE (BYTES_PER_SAMPLE * SAMPLES_PER_BLOCK)
34
34
#define BLOCK_COUNT (INITIAL_BLOCKS + 32)
@@ -47,8 +47,7 @@ static bool configure_tx_streams(const struct device *i2s_dev, struct i2s_config
47
47
return true;
48
48
}
49
49
50
- static bool trigger_command (const struct device * i2s_dev_codec ,
51
- enum i2s_trigger_cmd cmd )
50
+ static bool trigger_command (const struct device * i2s_dev_codec , enum i2s_trigger_cmd cmd )
52
51
{
53
52
int ret ;
54
53
@@ -70,12 +69,12 @@ int main(void)
70
69
const struct device * const codec_dev = DEVICE_DT_GET (DT_NODELABEL (audio_codec ));
71
70
struct i2s_config config ;
72
71
struct audio_codec_cfg audio_cfg ;
73
- int ret ;
72
+ int ret = 0 ;
74
73
75
74
#if CONFIG_USE_DMIC
76
75
struct pcm_stream_cfg stream = {
77
76
.pcm_width = SAMPLE_BIT_WIDTH ,
78
- .mem_slab = & mem_slab ,
77
+ .mem_slab = & mem_slab ,
79
78
};
80
79
struct dmic_cfg cfg = {
81
80
.io = {
@@ -108,15 +107,14 @@ int main(void)
108
107
return 0 ;
109
108
}
110
109
111
-
112
110
if (!device_is_ready (codec_dev )) {
113
111
printk ("%s is not ready" , codec_dev -> name );
114
112
return 0 ;
115
113
}
116
114
audio_cfg .dai_route = AUDIO_ROUTE_PLAYBACK ;
117
115
audio_cfg .dai_type = AUDIO_DAI_TYPE_I2S ;
118
116
audio_cfg .dai_cfg .i2s .word_size = SAMPLE_BIT_WIDTH ;
119
- audio_cfg .dai_cfg .i2s .channels = 2 ;
117
+ audio_cfg .dai_cfg .i2s .channels = 2 ;
120
118
audio_cfg .dai_cfg .i2s .format = I2S_FMT_DATA_FORMAT_I2S ;
121
119
audio_cfg .dai_cfg .i2s .options = I2S_OPT_FRAME_CLK_MASTER ;
122
120
audio_cfg .dai_cfg .i2s .frame_clk_freq = SAMPLE_FREQUENCY ;
@@ -127,14 +125,13 @@ int main(void)
127
125
128
126
#if CONFIG_USE_DMIC
129
127
cfg .channel .req_num_chan = 2 ;
130
- cfg .channel .req_chan_map_lo =
131
- dmic_build_channel_map (0 , 0 , PDM_CHAN_LEFT ) |
132
- dmic_build_channel_map (1 , 0 , PDM_CHAN_RIGHT );
128
+ cfg .channel .req_chan_map_lo = dmic_build_channel_map (0 , 0 , PDM_CHAN_LEFT ) |
129
+ dmic_build_channel_map (1 , 0 , PDM_CHAN_RIGHT );
133
130
cfg .streams [0 ].pcm_rate = SAMPLE_FREQUENCY ;
134
131
cfg .streams [0 ].block_size = BLOCK_SIZE ;
135
132
136
- printk ("PCM output rate: %u, channels: %u\n" ,
137
- cfg . streams [ 0 ]. pcm_rate , cfg .channel .req_num_chan );
133
+ printk ("PCM output rate: %u, channels: %u\n" , cfg . streams [ 0 ]. pcm_rate ,
134
+ cfg .channel .req_num_chan );
138
135
139
136
ret = dmic_configure (dmic_dev , & cfg );
140
137
if (ret < 0 ) {
@@ -198,8 +195,7 @@ int main(void)
198
195
started = true;
199
196
}
200
197
}
201
- if (!trigger_command (i2s_dev_codec ,
202
- I2S_TRIGGER_DROP )) {
198
+ if (!trigger_command (i2s_dev_codec , I2S_TRIGGER_DROP )) {
203
199
printk ("Send I2S trigger DRAIN failed: %d" , ret );
204
200
return 0 ;
205
201
}
0 commit comments