The path from raw sensor output to usable data in an embedded pipeline involves more steps than it looks.
ADC pipeline:
- Configure ADC peripheral (reference voltage, resolution, sampling time, trigger source)
- Set up DMA transfer from ADC data register to circular buffer
- On DMA half-complete interrupt: process first half of buffer
- On DMA complete interrupt: process second half
- Convert raw counts to physical units:
voltage = count * Vref / (2^bits - 1) - Apply calibration offset and gain from factory trim values
Why DMA is essential: A 12-bit ADC at 1 MSPS generates data at 2 MB/s. Handling each sample in an interrupt at 1 MHz interrupt rate is not feasible — interrupt overhead alone would saturate the CPU. DMA moves samples to a ring buffer without CPU involvement; the CPU processes blocks at a fraction of the interrupt rate.
Timestamp alignment: When fusing data from multiple sensors (accelerometer + gyroscope + temperature), the samples must be timestamped. The RP2040's hardware timer has 1μs resolution. Recording the DMA start timestamp and computing per-sample timestamps from the DMA transfer index gives accurate alignment without per-sample interrupts.
In AeroStream: the sensor ingestion stage (ADC + DMA) is implemented as a DMA interrupt handler that pushes raw samples to a heapless::spsc::Queue. The DSP pipeline runs from the queue in a lower-priority task.