ADC interface for measuring external analog signals. More...
Data Structures | |
struct | ADC_Config |
ADC configuration structure. More... | |
struct | ADC_t |
Struct definition for ADC interface. Provides the API handle for consumers to interact with an ADC peripheral instance. More... | |
Functions | |
ADC_t | ADC_init (ADC_TypeDef *adc_regs, ADC_Config *config) |
bool | ADC_startConversion (ADC_t *adc, ADC_ConversionType type) |
Starts a regular ADC conversion. | |
uint16_t | ADC_readData (ADC_t *adc) |
Reads the data from the last ADC regular conversion. | |
bool | ADC_updateConfig (ADC_t *adc, ADC_Config *config) |
Update ADC peripheral configuration. | |
ADC interface for measuring external analog signals.
struct ADC_Config |
ADC configuration structure.
Holds all configurable parameters for the ADC peripheral. This structure is used to initialize or update the ADC settings.
Data Fields | ||
---|---|---|
ADC_Resolution | RES | Resolution of the ADC (CR1.RES). |
bool | AWDEN | Analog Watchdog Enable on regular channels (CR1.AWDEN). |
bool | JAWDEN | Analog Watchdog Enable on injected channels (CR1.JAWDEN). |
bool | EOCIE | Interrupt Enable for End Of regular Conversion (CR1.EOCIE). |
bool | AWDIE | Interrupt Enable for Analog Watchdog (CR1.AWDIE). |
bool | JEOCIE | Interrupt Enable for End Of Injected Conversion (CR1.JEOCIE). |
bool | AWDSGL | Analog Watchdog on single channel (true) or all (false) (CR1.AWDSGL). |
bool | SCAN | Scan mode enable for regular channels (CR1.SCAN). |
ADC_Channel | AWDCH | Analog Watchdog Channel Select (if AWDSGL is true) (CR1.AWDCH). |
ADC_Align | ALIGN | Data alignment (CR2.ALIGN). |
ADC_EocSelect | EOCS | End Of Conversion Selection (CR2.EOCS). |
bool | DMA | Direct Memory Access mode enable for regular channels (CR2.DMA). |
bool | CONT | Continuous conversion mode for regular channels (CR2.CONT). |
ADC_SampleTime | SMP[19] | Sampling time for each channel (0-18) (SMPR1, SMPR2). |
uint16_t | HTR | Analog watchdog higher threshold (HTR). Value should be 12-bit. |
uint16_t | LTR | Analog watchdog lower threshold (LTR). Value should be 12-bit. |
ADC_SequenceLength | L | Regular channel sequence length (1 to 16 conversions) (SQR1.L). |
ADC_Channel | SQ[16] | Regular channel sequence definition (SQ1 to SQ16) (SQR1, SQR2, SQR3). |
ADC_SequenceLength | JL | Injected channel sequence length (1 to 4 conversions) (JSQR.JL). |
ADC_Channel | JSQ[4] | Injected channel sequence definition (JSQ1 to JSQ4) (JSQR). |
bool | TSVREFE | Temperature sensor and VREFINT enable (ADC_CCR.TSVREFE). |
bool | VBATE | VBAT channel enable (ADC_CCR.VBATE). |
ADC_Prescale | ADCPRE | ADC prescaler for ADCCLK (ADC_CCR.ADCPRE). |
struct ADC_t |
Struct definition for ADC interface. Provides the API handle for consumers to interact with an ADC peripheral instance.
Data Fields | ||
---|---|---|
ADC_TypeDef * | interface | Pointer to the STM32 ADC peripheral register map (e.g., ADC1). |
ADC_Config | config | Current configuration of the ADC peripheral. |
bool(*)(struct _ADC *adc, ADC_Config *config) | updateConfig |
Function pointer to update the ADC configuration.
|
bool(*)(struct _ADC *adc, ADC_ConversionType type) | startConversion |
Function pointer to start an ADC conversion (regular or injected).
|
uint16_t(*)(struct _ADC *adc) | readData |
Function pointer to read the ADC regular conversion result.
|
enum ADC_Channel |
ADC input channels enumeration.
Defines the available analog input channels for the ADC.
enum ADC_Resolution |
enum ADC_Align |
enum ADC_EocSelect |
enum ADC_SampleTime |
ADC channel sample time enumeration.
Defines the duration for which the input voltage is sampled by the ADC. Expressed in number of ADCCLK cycles. Longer sample times can improve accuracy for high impedance sources.
enum ADC_SequenceLength |
ADC regular channel sequence length enumeration.
Defines the number of conversions in the regular channel group sequence. The value (e.g., ADC_L1 for 1 conversion) directly corresponds to the SQR1.L field value. ADC_L1
means 1 conversion, ADC_L16
means 16 conversions.
enum ADC_Prescale |
ADC prescaler selection enumeration.
Defines the division factor for the ADC clock (ADCCLK) derived from PCLK2.
enum ADC_ConversionType |
ADC_t ADC_init | ( | ADC_TypeDef * | interface, |
ADC_Config * | config ) |
bool ADC_startConversion | ( | ADC_t * | adc, |
ADC_ConversionType | type ) |
Starts a regular ADC conversion.
Sets the SWSTART (or JWSTART) bit in ADC_CR2 register to begin a conversion for the regular group. For continuous mode, this starts the sequence. For single mode, it starts one conversion.
adc | Pointer to the ADC_t handle. |
uint16_t ADC_readData | ( | ADC_t * | adc | ) |
bool ADC_updateConfig | ( | ADC_t * | adc, |
ADC_Config * | config ) |