CubeMon-Vue-Demo-STM32F407VGT6U
ai.h File Reference

analog inputs library for multi-channel DMA running in interrupt mode, averaging and custom linearization functions More...

Go to the source code of this file.

Typedefs

typedef enum anaInputs anaInputs
 

Enumerations

enum  anaInputs { AI_NONE , AI_1 , AI_2 , AI_NONE }
 

Functions

retStatus analog_input_init (anaInputs an_input_name, int32_t sample_from, liner_fce linearization_function)
 Analog input initialization function. More...
 
retStatus analog_input_get (uint16_t analog_input, uint16_t data, int32_t *value)
 Standardized getter function for digital input library. More...
 
void analog_input_handle (void)
 Handler for analog inputs. More...
 
__weak HAL_StatusTypeDef analog_input_start (ADC_HandleTypeDef adc)
 Starts the ADC with DMA in interrupt mode using STM32 HAL. More...
 
uint32_t lin_adc_no_scaling_no_corrections (uint32_t adc_value)
 Convert ADC reading to voltage for a simple 0-3.3V input.
 

Variables

uint32_t ADC_data_buffer [(AI_NONE *2)+1]
 

Detailed Description

analog inputs library for multi-channel DMA running in interrupt mode, averaging and custom linearization functions

Author
panvicka
Date
8.1.2022

To use this library define flag LIB_AI in the lib_config.h file and create an enum in init.h file with the outputs you would like to use. You then have to initialize each input with input_init function.

typedef enum anaInputs {
MY_ANALOG_INPUT_1,
MY_ANALOG_INPUT_2,
MY_ANALOG_INPUT_3,
AI_NONE
anaInputs
Definition: ai.h:34
Note
Do not forget to include the AI_NONE at the end of the enum listing.

Typedef Documentation

◆ anaInputs

typedef enum anaInputs anaInputs

If the library is not used (LIB_AI is not defined as symbol) this dummy enum will be created to prevent compilation errors

Enumeration Type Documentation

◆ anaInputs

enum anaInputs

If the library is not used (LIB_AI is not defined as symbol) this dummy enum will be created to prevent compilation errors

Enumerator
AI_1 

AI_1 (PA1)

AI_2 

AI_2 (PA2)

Function Documentation

◆ analog_input_get()

retStatus analog_input_get ( uint16_t  analog_input,
uint16_t  data,
int32_t *  value 
)

Standardized getter function for digital input library.

Parameters
[in]analog_inputanalog input identification, defined by anaInputs
[in]datadata for /p analog_input that can be read out of the module, available data aioData
[out]valuegetter output
Note
/p input and /p data types are changed to uint32_t and uint16_t to keep the standard function prototype
Returns
EOK is the /p value is valid ENODEV if the /p an_input_name is out of range defined by anaInputs or not initialized EINVAL if invalid /p data is read

◆ analog_input_handle()

void analog_input_handle ( void  )

Handler for analog inputs.

Note
call inside HAL_ADC_ConvCpltCallback() (from the HAL library)

◆ analog_input_init()

retStatus analog_input_init ( anaInputs  an_input_name,
int32_t  sample_from,
liner_fce  linearization_function 
)

Analog input initialization function.

Parameters
[in]an_input_nameanalog input identification, defined by anaInputs
[in]sample_fromhow many samples should be averaged (0-0x7fff)
[in]linearization_functionin case there is an voltage divider or any other input that needs to be converted
Note
if a simple 0-3.3V input without non-linearities is expected, you can use lin_adc_no_scaling_no_corrections()
Returns
EOK is the initialization completed OK ENODEV if the /p an_input_name is out of range defined by anaInputs EFAULT null pointer passed to /p linearization_function

◆ analog_input_start()

__weak HAL_StatusTypeDef analog_input_start ( ADC_HandleTypeDef  adc)

Starts the ADC with DMA in interrupt mode using STM32 HAL.

Parameters
[in]adcactive ADC
Returns
HAL status