PER Firmware
Loading...
Searching...
No Matches
adc_priv.c File Reference

Register-level implementation of the STM32G4 ADC PHAL. More...

Include dependency graph for adc_priv.c:

Functions

static ADC_Common_TypeDef * adc_common_registers (const ADC_TypeDef *instance)
 Return the common register bank containing an ADC instance.
 
static void adc_enable_clock (const ADC_TypeDef *instance)
 Enable and synchronize the peripheral clock for an ADC instance.
 
static void adc_configure_clock (const ADC_TypeDef *instance)
 Select the synchronous HCLK/4 ADC clock if it is not already configured.
 
static bool adc_wait_for_register (const volatile uint32_t *reg, uint32_t mask, bool expected_set)
 Wait for masked register bits to reach the requested state.
 
static void adc_regulator_delay (void)
 Wait at least the ADC regulator startup interval.
 
static void adc_set_sequence_slot (ADC_TypeDef *instance, uint8_t rank, uint8_t channel)
 Program one channel into a regular conversion sequence rank.
 
static void adc_set_sample_time (ADC_TypeDef *instance, uint8_t channel)
 Set one channel to the driver's fixed maximum sampling time.
 
static void adc_configure_sequence (ADC_TypeDef *instance, const PHAL_ADC_ChannelConfig_t *channels, size_t channel_count)
 Program the configured channel order and sampling times.
 
static void adc_configure_conversion (ADC_TypeDef *instance)
 Apply the driver's fixed resolution, trigger, and DMA conversion settings.
 
static bool adc_calibrate (ADC_TypeDef *instance)
 Run single-ended ADC calibration and wait for completion.
 
bool ADC_PRIV_instance_is_supported (const ADC_TypeDef *instance)
 Return whether an ADC instance is supported by this driver.
 
bool ADC_PRIV_configure (ADC_TypeDef *instance, const PHAL_ADC_ChannelConfig_t *channels, size_t channel_count)
 Configure and calibrate a disabled ADC instance.
 
bool ADC_PRIV_enable (ADC_TypeDef *instance)
 Enable an ADC instance and wait for it to become ready.
 
bool ADC_PRIV_disable (ADC_TypeDef *instance)
 Stop and disable an ADC instance.
 
bool ADC_PRIV_is_ready (const ADC_TypeDef *instance)
 Return whether an ADC instance is enabled and ready.
 
void ADC_PRIV_prepare_transfer (ADC_TypeDef *instance, bool continuous)
 Clear transfer flags and select single or continuous DMA requests.
 
void ADC_PRIV_start_conversion (ADC_TypeDef *instance)
 Start the configured regular conversion sequence.
 
bool ADC_PRIV_stop_conversion (ADC_TypeDef *instance)
 Stop an active regular conversion sequence.
 

Variables

static constexpr uint32_t ADC_PRIV_HSI_CLOCK_RATE_HZ = 16'000'000U
 HSI16 rate, used only as a fallback when SystemCoreClock is unset.
 
static constexpr uint32_t ADC_PRIV_WAIT_ITERATIONS = 100'000U
 
static constexpr uint32_t ADC_PRIV_SAMPLE_TIME_MAX = 7U
 

Detailed Description

Register-level implementation of the STM32G4 ADC PHAL.

All direct ADC register manipulation lives here so the public layer only coordinates the ADC with its DMA channel. Covers clocking, calibration, sequence and sampling-time programming, and bounded busy-wait start/stop helpers.

Author
Ronak Jain (jain7.nosp@m.17@p.nosp@m.urdue.nosp@m..edu)

Function Documentation

◆ adc_calibrate()

static bool adc_calibrate ( ADC_TypeDef * instance)
static

Run single-ended ADC calibration and wait for completion.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ adc_common_registers()

static ADC_Common_TypeDef * adc_common_registers ( const ADC_TypeDef * instance)
static

Return the common register bank containing an ADC instance.

Here is the caller graph for this function:

◆ adc_configure_clock()

static void adc_configure_clock ( const ADC_TypeDef * instance)
static

Select the synchronous HCLK/4 ADC clock if it is not already configured.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ adc_configure_conversion()

static void adc_configure_conversion ( ADC_TypeDef * instance)
static

Apply the driver's fixed resolution, trigger, and DMA conversion settings.

Here is the caller graph for this function:

◆ adc_configure_sequence()

static void adc_configure_sequence ( ADC_TypeDef * instance,
const PHAL_ADC_ChannelConfig_t * channels,
size_t channel_count )
static

Program the configured channel order and sampling times.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ adc_enable_clock()

static void adc_enable_clock ( const ADC_TypeDef * instance)
static

Enable and synchronize the peripheral clock for an ADC instance.

Here is the caller graph for this function:

◆ ADC_PRIV_configure()

bool ADC_PRIV_configure ( ADC_TypeDef * instance,
const PHAL_ADC_ChannelConfig_t * channels,
size_t channel_count )

Configure and calibrate a disabled ADC instance.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADC_PRIV_disable()

bool ADC_PRIV_disable ( ADC_TypeDef * instance)

Stop and disable an ADC instance.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADC_PRIV_enable()

bool ADC_PRIV_enable ( ADC_TypeDef * instance)

Enable an ADC instance and wait for it to become ready.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADC_PRIV_instance_is_supported()

bool ADC_PRIV_instance_is_supported ( const ADC_TypeDef * instance)

Return whether an ADC instance is supported by this driver.

Here is the caller graph for this function:

◆ ADC_PRIV_is_ready()

bool ADC_PRIV_is_ready ( const ADC_TypeDef * instance)

Return whether an ADC instance is enabled and ready.

◆ ADC_PRIV_prepare_transfer()

void ADC_PRIV_prepare_transfer ( ADC_TypeDef * instance,
bool continuous )

Clear transfer flags and select single or continuous DMA requests.

Here is the caller graph for this function:

◆ ADC_PRIV_start_conversion()

void ADC_PRIV_start_conversion ( ADC_TypeDef * instance)

Start the configured regular conversion sequence.

Here is the caller graph for this function:

◆ ADC_PRIV_stop_conversion()

bool ADC_PRIV_stop_conversion ( ADC_TypeDef * instance)

Stop an active regular conversion sequence.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ adc_regulator_delay()

static void adc_regulator_delay ( void )
static

Wait at least the ADC regulator startup interval.

Here is the caller graph for this function:

◆ adc_set_sample_time()

static void adc_set_sample_time ( ADC_TypeDef * instance,
uint8_t channel )
static

Set one channel to the driver's fixed maximum sampling time.

Here is the caller graph for this function:

◆ adc_set_sequence_slot()

static void adc_set_sequence_slot ( ADC_TypeDef * instance,
uint8_t rank,
uint8_t channel )
static

Program one channel into a regular conversion sequence rank.

Here is the caller graph for this function:

◆ adc_wait_for_register()

static bool adc_wait_for_register ( const volatile uint32_t * reg,
uint32_t mask,
bool expected_set )
static

Wait for masked register bits to reach the requested state.

Here is the caller graph for this function:

Variable Documentation

◆ ADC_PRIV_HSI_CLOCK_RATE_HZ

uint32_t ADC_PRIV_HSI_CLOCK_RATE_HZ = 16'000'000U
staticconstexpr

HSI16 rate, used only as a fallback when SystemCoreClock is unset.

◆ ADC_PRIV_SAMPLE_TIME_MAX

uint32_t ADC_PRIV_SAMPLE_TIME_MAX = 7U
staticconstexpr

◆ ADC_PRIV_WAIT_ITERATIONS

uint32_t ADC_PRIV_WAIT_ITERATIONS = 100'000U
staticconstexpr