Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
dmic.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018, Intel Corporation
3 *
4 * Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
5 * Sathish Kuttan <sathish.k.kuttan@intel.com>
6 *
7 * SPDX-License-Identifier: Apache-2.0
8 */
9
17#ifndef ZEPHYR_INCLUDE_AUDIO_DMIC_H_
18#define ZEPHYR_INCLUDE_AUDIO_DMIC_H_
19
20
35#include <kernel.h>
36#include <device.h>
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
46 DMIC_STATE_UNINIT, /* Uninitialized */
47 DMIC_STATE_INITIALIZED, /* Initialized */
48 DMIC_STATE_CONFIGURED, /* Configured */
49 DMIC_STATE_ACTIVE, /* Active */
50 DMIC_STATE_PAUSED, /* Paused */
51};
52
57 DMIC_TRIGGER_STOP, /* stop stream */
58 DMIC_TRIGGER_START, /* start stream */
59 DMIC_TRIGGER_PAUSE, /* pause the stream */
60 DMIC_TRIGGER_RELEASE, /* release paused stream */
61 DMIC_TRIGGER_RESET, /* reset */
62};
63
67enum pdm_lr {
70};
71
75struct pdm_io_cfg {
76 /* parameters global to all PDM controllers */
77
78 /* minimum clock frequency supported by the mic */
80 /* maximum clock frequency supported by the mic */
82 /* minimum duty cycle in % supported by the mic */
84 /* maximum duty cycle in % supported by the mic */
86
87 /* parameters unique to each PDM controller */
88
89 /* Bit mask to optionally invert PDM clock */
91 /* Bit mask to optionally invert mic data */
93 /* Collection of clock skew values for each PDM port */
95};
96
101 /*
102 * if either rate or width is set to 0 for a stream,
103 * the stream would be disabled
104 */
105
106 /* PCM sample rate of stream */
108 /* PCM sample width of stream */
110 /* PCM sample block size per transfer */
112 /* SLAB for DMIC driver to allocate buffers for stream */
113 struct k_mem_slab *mem_slab;
114};
115
120 /*
121 * mapping of PDM controller and mic channel to logical channel
122 * since each controller can have 2 audio channels (stereo),
123 * there can be total of 8x2=16 channels.
124 * The actual number of channels shall be described in
125 * pcm_stream_cfg.num_chan.
126 * if 2 streams are enabled, the channel order will be the same for
127 * both streams
128 * Each channel is described as a 4 bit number, the least significant
129 * bit indicates LEFT/RIGHT selection of the PDM controller.
130 * The most significant 3 bits indicate the PDM controller number.
131 * bits 0-3 are for channel 0, bit 0 indicates LEFT or RIGHT
132 * bits 4-7 are for channel 1, bit 4 indicates LEFT or RIGHT
133 * and so on.
134 * CONSTRAINT: The LEFT and RIGHT channels of EACH PDM controller needs
135 * to be adjacent to each other.
136 */
137 /* Requested channel map */
138 uint32_t req_chan_map_lo; /* Channels 0 to 7 */
139 uint32_t req_chan_map_hi; /* Channels 8 to 15 */
140 /* Actual channel map that the driver could configure */
141 uint32_t act_chan_map_lo; /* Channels 0 to 7 */
142 uint32_t act_chan_map_hi; /* Channels 8 to 15 */
143 /* requested number of channels */
145 /* Actual number of channels that the driver could configure */
147 /* requested number of streams for each channel */
149 /* Actual number of streams that the driver could configure */
151};
152
156struct dmic_cfg {
158 /*
159 * Array of pcm_stream_cfg for application to provide
160 * configuration for each stream
161 */
164};
165
169struct _dmic_ops {
170 int (*configure)(const struct device *dev, struct dmic_cfg *config);
171 int (*trigger)(const struct device *dev, enum dmic_trigger cmd);
172 int (*read)(const struct device *dev, uint8_t stream, void **buffer,
173 size_t *size, int32_t timeout);
174};
175
189 enum pdm_lr lr)
190{
191 return ((((pdm & BIT_MASK(3)) << 1) | lr) <<
192 ((channel & BIT_MASK(3)) * 4U));
193}
194
209static inline void dmic_parse_channel_map(uint32_t channel_map_lo,
210 uint32_t channel_map_hi, uint8_t channel, uint8_t *pdm, enum pdm_lr *lr)
211{
212 uint32_t channel_map;
213
214 channel_map = (channel < 8) ? channel_map_lo : channel_map_hi;
215 channel_map >>= ((channel & BIT_MASK(3)) * 4U);
216
217 *pdm = (channel >> 1) & BIT_MASK(3);
218 *lr = (enum pdm_lr) (channel & BIT(0));
219}
220
233{
234 return ((skew & BIT_MASK(4)) << ((pdm & BIT_MASK(3)) * 4U));
235}
236
248static inline int dmic_configure(const struct device *dev,
249 struct dmic_cfg *cfg)
250{
251 const struct _dmic_ops *api =
252 (const struct _dmic_ops *)dev->api;
253
254 return api->configure(dev, cfg);
255}
256
267static inline int dmic_trigger(const struct device *dev,
268 enum dmic_trigger cmd)
269{
270 const struct _dmic_ops *api =
271 (const struct _dmic_ops *)dev->api;
272
273 return api->trigger(dev, cmd);
274}
275
291static inline int dmic_read(const struct device *dev, uint8_t stream,
292 void **buffer,
293 size_t *size, int32_t timeout)
294{
295 const struct _dmic_ops *api =
296 (const struct _dmic_ops *)dev->api;
297
298 return api->read(dev, stream, buffer, size, timeout);
299}
300
301#ifdef __cplusplus
302}
303#endif
304
309#endif /* ZEPHYR_INCLUDE_AUDIO_DMIC_H_ */
ZTEST_BMEM int timeout
Definition: main.c:31
#define BIT_MASK(n)
Definition: adc.h:14
static int dmic_configure(const struct device *dev, struct dmic_cfg *cfg)
Definition: dmic.h:248
dmic_trigger
Definition: dmic.h:56
static uint32_t dmic_build_channel_map(uint8_t channel, uint8_t pdm, enum pdm_lr lr)
Definition: dmic.h:188
static int dmic_read(const struct device *dev, uint8_t stream, void **buffer, size_t *size, int32_t timeout)
Definition: dmic.h:291
pdm_lr
Definition: dmic.h:67
static void dmic_parse_channel_map(uint32_t channel_map_lo, uint32_t channel_map_hi, uint8_t channel, uint8_t *pdm, enum pdm_lr *lr)
Definition: dmic.h:209
dmic_state
Definition: dmic.h:45
static uint32_t dmic_build_clk_skew_map(uint8_t pdm, uint8_t skew)
Definition: dmic.h:232
@ DMIC_TRIGGER_START
Definition: dmic.h:58
@ DMIC_TRIGGER_PAUSE
Definition: dmic.h:59
@ DMIC_TRIGGER_RELEASE
Definition: dmic.h:60
@ DMIC_TRIGGER_RESET
Definition: dmic.h:61
@ DMIC_TRIGGER_STOP
Definition: dmic.h:57
@ PDM_CHAN_RIGHT
Definition: dmic.h:69
@ PDM_CHAN_LEFT
Definition: dmic.h:68
@ DMIC_STATE_PAUSED
Definition: dmic.h:50
@ DMIC_STATE_UNINIT
Definition: dmic.h:46
@ DMIC_STATE_CONFIGURED
Definition: dmic.h:48
@ DMIC_STATE_INITIALIZED
Definition: dmic.h:47
@ DMIC_STATE_ACTIVE
Definition: dmic.h:49
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition: ft8xx_reference_api.h:153
static ZTEST_BMEM char buffer[8]
Test mailbox enhance capabilities.
Definition: test_mbox_api.c:566
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition: util_macro.h:44
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__INT32_TYPE__ int32_t
Definition: stdint.h:44
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
const void * api
Definition: device.h:373
Definition: dmic.h:156
struct pcm_stream_cfg * streams
Definition: dmic.h:162
struct pdm_chan_cfg channel
Definition: dmic.h:163
struct pdm_io_cfg io
Definition: dmic.h:157
Definition: dmic.h:100
uint16_t block_size
Definition: dmic.h:111
uint8_t pcm_width
Definition: dmic.h:109
struct k_mem_slab * mem_slab
Definition: dmic.h:113
uint32_t pcm_rate
Definition: dmic.h:107
Definition: dmic.h:119
uint32_t req_chan_map_lo
Definition: dmic.h:138
uint32_t req_chan_map_hi
Definition: dmic.h:139
uint8_t act_num_chan
Definition: dmic.h:146
uint32_t act_chan_map_lo
Definition: dmic.h:141
uint8_t act_num_streams
Definition: dmic.h:150
uint32_t act_chan_map_hi
Definition: dmic.h:142
uint8_t req_num_chan
Definition: dmic.h:144
uint8_t req_num_streams
Definition: dmic.h:148
Definition: dmic.h:75
uint8_t min_pdm_clk_dc
Definition: dmic.h:83
uint8_t pdm_clk_pol
Definition: dmic.h:90
uint32_t max_pdm_clk_freq
Definition: dmic.h:81
uint32_t pdm_clk_skew
Definition: dmic.h:94
uint8_t max_pdm_clk_dc
Definition: dmic.h:85
uint8_t pdm_data_pol
Definition: dmic.h:92
uint32_t min_pdm_clk_freq
Definition: dmic.h:79