fast ADC using the DMA. We have 8 channels available 10 PA0-WKUP ADC1_IN0 Channel 0 11 PA1 ADC1_IN1 Channel 1 13 PA3 ADC1_IN3 Channel 2 14 PA4 ADC1_IN4 Channel 3 15 PA5 ADC1_IN5 Channel 4 16 PA6 ADC1_IN6 Channel 5 17 PA7 ADC1_IN7 Channel 6 18 PB0 ADC1_IN8 Channe 7
More...
#include <AnalogReaderDMA.h>
|
| AnalogReaderDMA (int channels) |
| Construct a new stm32 dma adc object w/o timer in ContinuousConvMode. More...
|
|
| AnalogReaderDMA (int channels, TIM_TypeDef *timerNum, int sampleRate, TcallbackADC adcCallback=nullptr, uint32_t bufferSize=0) |
| Construct a new stm32 dma adc object with defined sample rate (using a timer) More...
|
|
| ~AnalogReaderDMA () |
| Destructor.
|
|
bool | begin () |
| Starts the ADC Processing.
|
|
int16_t | avg (int ch) |
| Provides the avg calculated over the initial samples for the indicated channel. Values are only available with normalization active: Call setCenterZero(true) before begin()!
|
|
bool | isActive () |
| Returns true if it has been started
|
|
int | channels () |
| Provides the number of active channels.
|
|
void | end () |
| Stops the ADC processing.
|
|
int16_t | analogRead (int in) |
| Returns the actual ADC value for the indicated channel (0 - 7) or pin PA0 to PB0.
|
|
void | setRateCorrectionFactor (float factor) |
| We can correct the sampling rate if the effective data input does not match.
|
|
float | rateCorrectionFactor () |
| Actually defined correction factor which is applied to the sample rate.
|
|
void | setSamplingTime (uint32_t st) |
| Define the sampling time e.g. ADC_SAMPLETIME_15CYCLES.
|
|
uint32_t | samplingTime () |
| Provides the actually defined sampleing time.
|
|
void | setCenterZero (bool active) |
| Audio data is usually centered at 0 with negative and positive values: activate value normalization by setting active to true!
|
|
bool | isCenterZero () |
| Returns true if the values are normlized around 0.
|
|
|
int | getBufferSize (int bufferSize) |
| determines the "correct" buffer size based on the requested size
|
|
int | getChannelForPin (int pin) |
| Determines the channel for the indicated pin
|
|
void | addHandlers () |
|
void | removeHandlers () |
|
void | MX_ADC1_Init (void) |
| ADC1 Initialization Function.
|
|
void | MX_DMA_Init (void) |
|
void | MX_GPIO_Init (void) |
| GPIO Initialization Function.
|
|
void | HAL_ADC_ConvCpltCallback (ADC_HandleTypeDef *hadc) |
| DMA Callback.
|
|
void | HAL_ADC_ConvHalfCpltCallback (ADC_HandleTypeDef *hadc) |
| DMA Callback.
|
|
void | HAL_ADC_MspInit (ADC_HandleTypeDef *hadc) |
| ADC MSP Initialization This function configures the hardware resources used in this example. More...
|
|
void | HAL_ADC_MspDeInit (ADC_HandleTypeDef *hadc) |
| ADC MSP De-Initialization This function freeze the hardware resources used in this example.
|
|
void | DMA2_Stream0_IRQHandler (void) |
|
void | STM32_LOG (ErrorLevelSTM32 level, const char *fmt,...) |
|
void | Error_Handler (void) |
|
|
HardwareTimer * | p_timer =nullptr |
|
TIM_TypeDef * | timer_num |
|
float | correction_factor = 1.0 |
|
bool | is_active = false |
|
bool | is_center_zero = false |
|
bool | is_center_zero_in_progress |
|
bool | is_continuous_conv_mode |
|
int | channel_cnt =0 |
|
int | sample_rate =0 |
|
int | lastFrameStartIdx =0 |
|
uint32_t | sampling_time = ADC_SAMPLETIME_28CYCLES |
|
uint8_t * | adc_buffer = nullptr |
|
uint16_t | adc_buffer_size = 0 |
|
volatile int16_t * | adc_result = nullptr |
|
ADC_HandleTypeDef | hadc1 |
|
DMA_HandleTypeDef | hdma_adc1 |
|
TcallbackADC | adc_callback = nullptr |
|
ADCAverageCalculator * | p_avg = nullptr |
|
const std::function< void(ADC_HandleTypeDef *)> | f_HAL_ADC_MspInit =std::bind(&AnalogReaderDMA::HAL_ADC_MspInit, this, std::placeholders::_1) |
|
const std::function< void(ADC_HandleTypeDef *)> | f_HAL_ADC_MspDeInit =std::bind(&AnalogReaderDMA::HAL_ADC_MspDeInit, this, std::placeholders::_1) |
|
const std::function< void(ADC_HandleTypeDef *)> | f_HAL_ADC_ConvCpltCallback =std::bind(&AnalogReaderDMA::HAL_ADC_ConvCpltCallback, this, std::placeholders::_1) |
|
const std::function< void(ADC_HandleTypeDef *)> | f_HAL_ADC_ConvHalfCpltCallback =std::bind(&AnalogReaderDMA::HAL_ADC_ConvHalfCpltCallback, this, std::placeholders::_1) |
|
const std::function< void()> | f_DMA2_Stream0_IRQHandler =std::bind(&AnalogReaderDMA::DMA2_Stream0_IRQHandler, this) |
|
fast ADC using the DMA. We have 8 channels available 10 PA0-WKUP ADC1_IN0 Channel 0 11 PA1 ADC1_IN1 Channel 1 13 PA3 ADC1_IN3 Channel 2 14 PA4 ADC1_IN4 Channel 3 15 PA5 ADC1_IN5 Channel 4 16 PA6 ADC1_IN6 Channel 5 17 PA7 ADC1_IN7 Channel 6 18 PB0 ADC1_IN8 Channe 7
◆ AnalogReaderDMA() [1/2]
AnalogReaderDMA::AnalogReaderDMA |
( |
int |
channels | ) |
|
|
inline |
Construct a new stm32 dma adc object w/o timer in ContinuousConvMode.
- Parameters
-
◆ AnalogReaderDMA() [2/2]
AnalogReaderDMA::AnalogReaderDMA |
( |
int |
channels, |
|
|
TIM_TypeDef * |
timerNum, |
|
|
int |
sampleRate, |
|
|
TcallbackADC |
adcCallback = nullptr , |
|
|
uint32_t |
bufferSize = 0 |
|
) |
| |
|
inline |
Construct a new stm32 dma adc object with defined sample rate (using a timer)
- Parameters
-
timerNum | |
sampleRate | |
bufferSize | |
◆ HAL_ADC_MspInit()
void AnalogReaderDMA::HAL_ADC_MspInit |
( |
ADC_HandleTypeDef * |
hadc | ) |
|
|
inlineprotected |
ADC MSP Initialization This function configures the hardware resources used in this example.
ADC1 GPIO Configuration PA0 ---—> ADC1_IN0 PA1 ---—> ADC1_IN1 PA3 ---—> ADC1_IN3 PA4 ---—> ADC1_IN4 PA5 ---—> ADC1_IN5 PA6 ---—> ADC1_IN6 PA7 ---—> ADC1_IN7 PB0 ---—> ADC1_IN8
◆ MX_DMA_Init()
void AnalogReaderDMA::MX_DMA_Init |
( |
void |
| ) |
|
|
inlineprotected |
Enable DMA controller clock
The documentation for this class was generated from the following file: