Topics | |
| Enumerated Types | |
| Enumerated types for DMIC driver. | |
| Data Structures | |
| Data structures for DMIC driver. | |
| General Functions | |
| General functions for DMIC driver. | |
Maximum number of DMIC channels supported by this API.
The DMIC block is a high-performance digital microphone interface subsystem designed to capture and process audio signals from integrated microphone elements. Each DMIC instance can be configured to support various sample rates, decimation ratios, and gain settings for flexible audio acquisition across different application scenarios.
The driver exposes a unified configuration interface while supporting both polling-based and interrupt-driven audio capture. Internally the driver supports FIFO and DMA data paths depending on hardware capability.
Applications can retrieve audio samples using either:
This allows the same driver to be used for simple applications as well as high-throughput real-time audio processing pipelines.
Features:
Blocking (Polling) Mode
Non-Blocking (Interrupt / Callback) Mode
Typical initialization sequence:
After starting capture, applications may use either blocking or non-blocking data retrieval models.
In blocking mode the application periodically calls dmic_read to retrieve captured audio data. The function waits until a buffer becomes available or the timeout expires.
Typical flow:
This model is recommended for:
In non-blocking mode the driver uses interrupts to notify the application when audio data becomes available. The application registers a callback using dmic_register_callback.
When a DMA period or FIFO threshold is reached the driver invokes the callback with offset and size information describing the available data.
Typical flow:
This model is recommended for:
Starts and stops audio capture from the microphone.
Audio data is transferred using either:
In DMA mode, the application provides a DMA-capable circular ring buffer through dmic_dma_config_t.buffer. The driver programs DMA to write directly into this buffer and maintains read/write period tracking. Data becomes available periodically based on the configured transfer size or FIFO threshold.
Applications retrieve data using:
This architecture allows continuous audio capture while avoiding data loss when the application processes buffers promptly.
The interrupt API supports enabling and monitoring interrupt sources such as:
These interrupts are primarily used internally by the driver for streaming and buffer management but may also be enabled by advanced applications.
When operating in DMA mode, the DMIC driver uses a circular buffer model to continuously capture audio data from the microphone without requiring the application to reconfigure the hardware after each transfer.
The DMA buffer is divided into fixed-size segments called periods. The size of the circular buffer and the transfer period are configured through the DMIC data-path API. The total buffer size must be an integer multiple of the period size. The required relationship is: buffer_bytes % period_bytes == 0. period_bytes should be greater than or equal to frame_bytes. The required relationship is: period_bytes % frame_bytes == 0. For PCM layouts, frame_bytes should match active_channel_count * 4 bytes.
Example buffer layout:
The total buffer size is defined by buffer_bytes, while each transfer segment is defined by period_bytes.
The DMA engine continuously writes microphone samples into the circular buffer. When one period of data is captured, a DMA interrupt occurs and the driver marks the period as available for the application.
Current implementation note:
DMA buffer alignment and maximum supported buffer size are backend/platform dependent. Cache coherency and cache maintenance requirements are outside the scope of this API and must be handled by platform integration. DMA-capable memory alignment may be required by the platform DMA engine. DMA buffer memory is application-owned and must remain valid until dmic_stop completes. DMA mode operates as a zero-copy transfer model; no copy is performed between the DMA ring buffer and application memory.
The dmic_read API retrieves audio samples from the internal circular buffer.
In DMA mode, dmic_read unblocks once per completed period, not when the entire buffer becomes full. This ensures predictable latency and continuous streaming behavior.
For example:
In this configuration the dmic_read call becomes ready approximately every 10 ms when a new period of audio data is available.
This behavior allows applications to process audio data in predictable intervals while maintaining low latency. In DMA mode, each successful dmic_read returns at most one completed DMA period.
Sample container rule:
Internally the driver maintains read and write indices within the circular buffer:
Each DMA interrupt advances the write pointer by period_bytes. The dmic_read function advances the read pointer after returning the captured audio samples to the application. When write_idx reaches the end of the ring buffer, it wraps to the start. The same wrap behavior applies to read_idx after data consumption.
If the application does not read data quickly enough and the write pointer overtakes the read pointer, unread DMA periods may be overwritten, an overflow condition is raised, and the driver reports DMIC_EVENT_OVERFLOW / DMIC_ERROR_OVERFLOW. Capture is backend-dependent and may continue after overflow notification.
Some hardware configurations support a FIFO-based data path instead of DMA. In this mode, audio samples are pushed into an internal hardware FIFO before being read by the CPU.
The FIFO generates interrupts based on configured threshold levels:
The FIFO threshold unit is hardware FIFO words (0-511), not PCM frames. One FIFO word may not equal one interleaved audio frame. FIFO word width may vary by hardware packing/format configuration. The FIFO threshold controls when the application should retrieve samples from the FIFO. FIFO mode copies FIFO register data into the application-provided output buffer.
Example FIFO layout:
When the FIFO level reaches the configured threshold, the hardware raises an interrupt and the driver signals that audio data is ready.
Example configuration where the FIFO threshold is set to 64 FIFO words (typically 64 samples for mono 16-bit capture):
In this configuration the FIFO generates an interrupt whenever 64 samples are accumulated in the hardware buffer (word/sample mapping is hardware-format dependent).
In blocking mode the application periodically calls dmic_read to retrieve samples from the FIFO.
The dmic_read call blocks until the FIFO threshold condition occurs or sufficient data becomes available.
In interrupt-driven operation the application registers a callback and processes audio data whenever the FIFO threshold interrupt occurs.
dmic_read_nonblocking returns immediately. If data is available, buf is populated with currently available data metadata/content; otherwise it returns DMIC_OK with available_bytes set to 0 if no data is currently available. In callback mode, transfer-ready notification is typically DMIC_EVENT_READ_COMPLETE. Some backends may additionally report raw FIFO level events (for example DMIC_EVENT_ALMOST_FULL). Raw FIFO events such as DMIC_EVENT_ALMOST_FULL and DMIC_EVENT_FULL are only reported if enabled through dmic_enable_interrupts. In DMA mode, transfer-ready callback notification is reported using DMIC_EVENT_READ_COMPLETE.
FIFO threshold configuration determines the latency and interrupt frequency.
Example:
Lower thresholds reduce latency but increase interrupt load. Higher thresholds reduce CPU interrupts but increase buffering latency.
Applications should choose FIFO thresholds based on real-time processing requirements and CPU availability.
The DMIC driver supports both blocking and non-blocking data retrieval models.
Blocking Mode
The application calls dmic_read and waits until the requested amount of audio data becomes available or the timeout expires. Timeout semantics:
Typical flow:
Non-Blocking Mode
In non-blocking mode the application registers a callback using dmic_register_callback. The driver invokes the callback when DMA periods or FIFO thresholds are reached.
Typical flow:
This model is recommended for continuous streaming pipelines and real-time audio processing where low latency and deterministic scheduling are required.
For a given DMIC instance, avoid mixing blocking and callback-driven streaming paths concurrently unless backend behavior explicitly supports it. Recommended policy: use one data-retrieval mode per instance at a time.
Thread-safety: unless otherwise documented by the platform integration, concurrent dmic_read/dmic_read_nonblocking calls on the same instance from multiple threads are not guaranteed to be thread-safe.
Callback execution context is backend-dependent and may be ISR context or a deferred worker context; callback handlers should be written accordingly.
/******************************************************************************* Enumerations