|
PER Firmware
|
G4 ADC public API. DMA-only, DMA-first conversions. More...
#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include "stm32g474xx.h"#include "common/phal_G4/dma/dma.h"Go to the source code of this file.
Classes | |
| struct | PHAL_ADC_ChannelConfig_t |
| One entry in the conversion sequence. More... | |
| struct | PHAL_ADC_Config_t |
| Static configuration for one ADC instance. More... | |
| struct | PHAL_ADC_Handle_t |
| Runtime handle for one ADC instance. More... | |
Functions | |
| bool | PHAL_ADC_init (PHAL_ADC_Handle_t *handle, const PHAL_ADC_Config_t *config) |
| Configure an ADC instance and its DMA channel. | |
| bool | PHAL_ADC_readDMA (PHAL_ADC_Handle_t *handle, uint16_t *buffer, uint16_t length) |
Start an asynchronous circular-DMA conversion into buffer | |
| bool | PHAL_ADC_readBlocking (PHAL_ADC_Handle_t *handle, uint16_t *buffer, uint16_t length, uint32_t timeout) |
| Synchronous one-buffer conversion using the DMA engine. | |
| bool | PHAL_ADC_stop (PHAL_ADC_Handle_t *handle) |
| Abort any transfer in flight and leave the ADC idle. | |
| bool | PHAL_ADC_busy (const PHAL_ADC_Handle_t *handle) |
| Check whether a transfer is currently in flight. | |
| void | PHAL_ADC_conversionCompleteCallback (PHAL_ADC_Handle_t *handle) |
| Weak callback fired once per completed DMA buffer. | |
Variables | |
| static constexpr uint8_t | PHAL_ADC_MAX_CHANNEL_COUNT = 16U |
| Maximum number of channels one ADC conversion sequence can hold. | |
| static constexpr uint8_t | PHAL_ADC_MAX_CHANNEL_NUMBER = 18U |
| Highest ADC channel number (IN18 on the G474) | |
G4 ADC public API. DMA-only, DMA-first conversions.
| bool PHAL_ADC_busy | ( | const PHAL_ADC_Handle_t * | handle | ) |
Check whether a transfer is currently in flight.
| handle | initialized handle |
|
extern |
Weak callback fired once per completed DMA buffer.
Called from the DMA interrupt context after each asynchronous circular-DMA buffer completes, and from the caller's context at the end of a successful PHAL_ADC_readBlocking(). On a DMA error, handle->transfer_error is true. Keep it short; the default implementation does nothing.
| handle | the handle whose transfer just completed |
| bool PHAL_ADC_init | ( | PHAL_ADC_Handle_t * | handle, |
| const PHAL_ADC_Config_t * | config ) |
Configure an ADC instance and its DMA channel.
What this does, in order:
The DMA channel is fixed per instance (ADC1 -> DMA1 ch1, ADC2 -> DMA2 ch1, ADC3 -> DMA2 ch2, ADC4 -> DMA2 ch3). Only one handle may claim each ADC instance; handles remain claimed for the lifetime of the application.
| handle | zero-initialized handle to populate |
| config | static configuration to use; must stay valid for the lifetime of the handle |
| bool PHAL_ADC_readBlocking | ( | PHAL_ADC_Handle_t * | handle, |
| uint16_t * | buffer, | ||
| uint16_t | length, | ||
| uint32_t | timeout ) |
Synchronous one-buffer conversion using the DMA engine.
Starts the circular acquisition, blocks until one buffer has completed, then stops the acquisition. A successful transfer fires PHAL_ADC_conversionCompleteCallback() before returning.
Note: timeout is a count of busy-wait iterations, not a wall-clock time. At 16 MHz one iteration is a handful of CPU cycles; the ADC itself takes roughly (640.5 + 12.5) / fADC seconds per sample (about 163 us at 4 MHz fADC).
| handle | initialized handle |
| buffer | destination for the samples |
| length | number of 16-bit samples to collect |
| timeout | busy-wait iteration budget (0 = return immediately) |
| bool PHAL_ADC_readDMA | ( | PHAL_ADC_Handle_t * | handle, |
| uint16_t * | buffer, | ||
| uint16_t | length ) |
Start an asynchronous circular-DMA conversion into buffer
The ADC continuously refreshes buffer and remains active until PHAL_ADC_stop() is called. PHAL_ADC_conversionCompleteCallback() fires (from the DMA interrupt context) after each buffer wrap.
If length is not a multiple of the sequence length, the final burst is a partial sequence (still one sample per conversion).
Fails without starting anything if a transfer is already in flight, the handle was never initialized, buffer is null or not halfword-aligned, or length is zero.
| handle | initialized handle |
| buffer | destination, must stay valid until PHAL_ADC_stop() is called |
| length | number of 16-bit samples to collect (1 - 65535) |
| bool PHAL_ADC_stop | ( | PHAL_ADC_Handle_t * | handle | ) |
Abort any transfer in flight and leave the ADC idle.
Safe to call at any time, even with no transfer running (it is then a no-op). Does not fire the completion callback.
| handle | initialized handle |
|
staticconstexpr |
Maximum number of channels one ADC conversion sequence can hold.
|
staticconstexpr |
Highest ADC channel number (IN18 on the G474)