Day40 - Acquisition Mode & Control Plane Refactor¶
๐ฏ Goal¶
Refactor the control plane of the IIO ADC driver by introducing a mode-based acquisition model, replacing the previous implicit behavior driven by parameter combinations.
๐ง Problem Statement (Before Day40)¶
The driver previously relied on:
- sampling_frequency
- fifo_enable
- internal config bits
to determine behavior.
Issues:
- No clear concept of "mode"
- DRDY / FIFO / idle behavior mixed together
- sampling_frequency = 0 used as implicit "disable"
- Hard to extend (e.g. one-shot)
๐ง Design Overview¶
Introduce acquisition modes as the primary control abstraction.
Supported Modes¶
| Mode | Description |
|---|---|
| idle | Sensor disabled, no sampling |
| continuous | Periodic sampling + DRDY IRQ |
| fifo | Periodic sampling + FIFO + watermark IRQ |
| one-shot | Reserved (not implemented yet) |
๐งฉ Control Plane Design¶
Single Source of Truth¶
Other parameters become configuration inputs, not behavior drivers.
Parameter Roles¶
| Parameter | Role |
|---|---|
| sampling_frequency | staged configuration |
| fifo_watermark | staged FIFO parameter |
| fifo_enable | compatibility wrapper |
๐ Staged Parameter Model¶
Sampling Frequency¶
- Stored in data->sample_rate_hz
- Behavior:
FIFO Watermark¶
- Stored in data->fifo_watermark
- Behavior:
Rollback Mechanism¶
If hardware apply fails:
Ensures driver never enters inconsistent state.
โ๏ธ apply_mode() Design¶
myadc_apply_mode() is the core of Day40.
Responsibilities:
- Map logical mode โ hardware config
- Apply staged parameters
- Ensure deterministic state
Example Mapping¶
IDLE
ENABLE = 0
IRQ = 0
CONTINUOUS
ENABLE = 1
DRDY = 1
FIFO = 0
IRQ = 1
FIFO
ENABLE = 1
DRDY = 0
FIFO = 1
IRQ = 1
Key Rule¶
- Do NOT depend on previous config state
- Always generate final state from mode
๐ Data Path Refactor¶
Before¶
After¶
Trigger Handler¶
๐ Compatibility Layer¶
fifo_enable¶
Still exposed for compatibility:
But:
๐ซ Removed Behavior¶
- sampling_frequency = 0 as "disable"
- implicit mode via parameter combinations
๐งช Validation Rules¶
When buffer is enabled¶
All control changes are rejected:
๐ Summary¶
Day40 establishes a clean architecture:
- Mode-driven control plane
- Staged parameter model
- Deterministic hardware configuration
- Clear separation of behavior vs configuration
๐ Next Step (Day41)¶
- one-shot acquisition
- IRQ policy separation
- STM32 register redesign