Skip to content

Commit 79f3138

Browse files
TomasBarakNXPkartben
authored andcommitted
samples: drivers: i2s: Format i2s_codec sample main.c
- format code according to the coding rules Signed-off-by: Tomas Barak <tomas.barak@nxp.com>
1 parent 3b74862 commit 79f3138

File tree

1 file changed

+17
-21
lines changed
  • samples/drivers/i2s/i2s_codec/src

1 file changed

+17
-21
lines changed

samples/drivers/i2s/i2s_codec/src/main.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
#include "sine.h"
1616
#endif
1717

18-
#define I2S_CODEC_TX DT_ALIAS(i2s_codec_tx)
18+
#define I2S_CODEC_TX DT_ALIAS(i2s_codec_tx)
1919

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)
2323
#if CONFIG_USE_DMIC
24-
#define NUMBER_OF_CHANNELS CONFIG_DMIC_CHANNELS
24+
#define NUMBER_OF_CHANNELS CONFIG_DMIC_CHANNELS
2525
#else
2626
#define NUMBER_OF_CHANNELS (2U)
2727
#endif
2828
/* 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)
3232

3333
#define BLOCK_SIZE (BYTES_PER_SAMPLE * SAMPLES_PER_BLOCK)
3434
#define BLOCK_COUNT (INITIAL_BLOCKS + 32)
@@ -47,8 +47,7 @@ static bool configure_tx_streams(const struct device *i2s_dev, struct i2s_config
4747
return true;
4848
}
4949

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)
5251
{
5352
int ret;
5453

@@ -70,12 +69,12 @@ int main(void)
7069
const struct device *const codec_dev = DEVICE_DT_GET(DT_NODELABEL(audio_codec));
7170
struct i2s_config config;
7271
struct audio_codec_cfg audio_cfg;
73-
int ret;
72+
int ret = 0;
7473

7574
#if CONFIG_USE_DMIC
7675
struct pcm_stream_cfg stream = {
7776
.pcm_width = SAMPLE_BIT_WIDTH,
78-
.mem_slab = &mem_slab,
77+
.mem_slab = &mem_slab,
7978
};
8079
struct dmic_cfg cfg = {
8180
.io = {
@@ -108,15 +107,14 @@ int main(void)
108107
return 0;
109108
}
110109

111-
112110
if (!device_is_ready(codec_dev)) {
113111
printk("%s is not ready", codec_dev->name);
114112
return 0;
115113
}
116114
audio_cfg.dai_route = AUDIO_ROUTE_PLAYBACK;
117115
audio_cfg.dai_type = AUDIO_DAI_TYPE_I2S;
118116
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;
120118
audio_cfg.dai_cfg.i2s.format = I2S_FMT_DATA_FORMAT_I2S;
121119
audio_cfg.dai_cfg.i2s.options = I2S_OPT_FRAME_CLK_MASTER;
122120
audio_cfg.dai_cfg.i2s.frame_clk_freq = SAMPLE_FREQUENCY;
@@ -127,14 +125,13 @@ int main(void)
127125

128126
#if CONFIG_USE_DMIC
129127
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);
133130
cfg.streams[0].pcm_rate = SAMPLE_FREQUENCY;
134131
cfg.streams[0].block_size = BLOCK_SIZE;
135132

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);
138135

139136
ret = dmic_configure(dmic_dev, &cfg);
140137
if (ret < 0) {
@@ -198,8 +195,7 @@ int main(void)
198195
started = true;
199196
}
200197
}
201-
if (!trigger_command(i2s_dev_codec,
202-
I2S_TRIGGER_DROP)) {
198+
if (!trigger_command(i2s_dev_codec, I2S_TRIGGER_DROP)) {
203199
printk("Send I2S trigger DRAIN failed: %d", ret);
204200
return 0;
205201
}

0 commit comments

Comments
 (0)