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

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

#include <main.h>
#include <lib/ai.h>
#include <lib/uti/utility.h>
#include <lib/uti/swo.h>

Data Structures

struct  analogInput
 

Typedefs

typedef struct analogInput analogInput
 

Functions

retStatus analog_input_get (uint16_t analog_input, uint16_t data, int32_t *value)
 Standardized getter function for digital input library. More...
 
retStatus analog_input_init (anaInputs an_input_name, int32_t sample_from, liner_fce linearization_function)
 Analog input initialization function. 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

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