-
Notifications
You must be signed in to change notification settings - Fork 0
/
ADC_ex.h
executable file
·139 lines (109 loc) · 3.7 KB
/
ADC_ex.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*!\file ADC_ex.h
** \author SMFSW
** \copyright MIT (c) 2017-2024, SMFSW
** \brief Simple extension for ADCs
** \details ADC_ex is meant to automate ADC conversions using DMA.
** - DMA must be configured for ADC peripherals:
** - Peripheral to Memory
** - Circular Mode
** - Increment Memory
** - Data width Word for both peripheral and memory
** - ADC configuration:
** - Scan conversion mode across channels enabled
** - Continuous conversion is optional (if disabled, user has to start conversions manually when needed)
** - DMA continuous request when available
** - Interrupt generated at end of conversion
** \note Define USE_ADC_EX symbol at project level to use ADC_ex functionalities
** \note Configuration done calling ADC_cfg.h file
**/
/****************************************************************/
#ifndef __ADC_EX_H
#define __ADC_EX_H
#ifdef __cplusplus
extern "C" {
#endif
#include "sarmfsw.h"
#if defined(HAL_ADC_MODULE_ENABLED) && defined(USE_ADC_EX)
#include "ADC_cfg.h"
/****************************************************************/
#if !defined(TEMP_CALC_VTEMP)
#if defined(TEMP_CALC_V25) || defined(TEMP_CALC_V30) //!< Alias for legacy code using TEMP_CALC_V25 or TEMP_CALC_V30
#define TEMP_CALC_VTEMP
#endif
#endif
#if !defined(Def_VTemp)
#if defined(Def_V25)
#define Def_VTemp Def_V25 //!< Alias for legacy code using Def_V25 (not accurate following families, leading to name change)
#endif
#if defined(Def_V30)
#define Def_VTemp Def_V30 //!< Alias for legacy code using Def_V30 (not accurate following families, leading to name change)
#endif
#endif
#if !defined(Def_VAlim)
#define Def_VAlim VDD_VALUE //!< Def_VAlim needs to be defined (in mV) if special power supply voltage used (eg. U5 variable power supply range)
#endif
#if !defined(ADC_RESOLUTION)
#define ADC_RESOLUTION 12 //!< ADC resolution in bits (defaults to 12 if not set)
#endif
#define DefRangeADC (LSHIFT(1U, ADC_RESOLUTION) - 1) //!< ADC digital range
#define Def_ADCStep(mv) ((mv) / (float) (DefRangeADC * 1000)) //!< Step value (in mV) following given \b v
/*!\enum eADCidx
** \brief ADC peripheral instance indexes
**/
typedef enum eADCidx {
#if defined(ADC1)
ADC_1 = 0, //!< ADC1 index
#endif
#if defined(ADC2)
ADC_2, //!< ADC2 index
#endif
#if defined(ADC3)
ADC_3, //!< ADC3 index
#endif
ADC_MAX //!< Adc MAX index
} eADCidx;
//typedef enum eAnalogInput {
// #if defined(ADC_USE_VREF)
// Adc_Vref, //!< Adc VRef (converted value in V)
// #endif
// #if defined(ADC_USE_TEMP)
// Adc_Temp, //!< Adc Temperature (converted value in °C)
// #endif
// #if defined(ADC_USE_VBAT)
// Adc_Vbat, //!< Adc VBat (converted value in V)
// #endif
// Adc_MAX //!< Adc MAX
//} eAnalogInput;
/*!\struct ADC_Cfg
** \brief ADC channel declaration config structure
**/
typedef struct ADC_Cfg {
const eADCidx adc; //!< ADC instance index
const uint8_t chan; //!< Channel index
float (* const conv) (const float); //!< Pointer to conversion function
} ADC_Cfg;
/*!\brief Get ADC channel raw value
** \param[in] input - Input index
** \return Channel raw value
**/
uint16_t ADC_GetRawVal(const eAnalogInput input);
/*!\brief Get ADC channel converted value
** \param[in] input - Input index
** \return Channel converted value
**/
float ADC_GetConvertedVal(const eAnalogInput input);
/*!\brief Start ADC conversions
** \return FctERR - Error code
**/
FctERR ADC_Start(void);
/*!\brief Stop ADC conversions
** \return FctERR - Error code
**/
FctERR ADC_Stop(void);
/****************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* defined(HAL_ADC_MODULE_ENABLED) */
#endif /* __ADC_EX_H */
/****************************************************************/