Subversion Repositories LedShow

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/**
2
  ******************************************************************************
3
  * @file    stm32f1xx_ll_adc.c
4
  * @author  MCD Application Team
5
  * @brief   ADC LL module driver
6
  ******************************************************************************
7
  * @attention
8
  *
9
  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
10
  *
11
  * Redistribution and use in source and binary forms, with or without modification,
12
  * are permitted provided that the following conditions are met:
13
  *   1. Redistributions of source code must retain the above copyright notice,
14
  *      this list of conditions and the following disclaimer.
15
  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
  *      this list of conditions and the following disclaimer in the documentation
17
  *      and/or other materials provided with the distribution.
18
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
  *      may be used to endorse or promote products derived from this software
20
  *      without specific prior written permission.
21
  *
22
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
  *
33
  ******************************************************************************
34
  */
35
#if defined(USE_FULL_LL_DRIVER)
36
 
37
/* Includes ------------------------------------------------------------------*/
38
#include "stm32f1xx_ll_adc.h"
39
#include "stm32f1xx_ll_bus.h"
40
 
41
#ifdef  USE_FULL_ASSERT
42
  #include "stm32_assert.h"
43
#else
44
  #define assert_param(expr) ((void)0U)
45
#endif
46
 
47
/** @addtogroup STM32F1xx_LL_Driver
48
  * @{
49
  */
50
 
51
#if defined (ADC1) || defined (ADC2) || defined (ADC3)
52
 
53
/** @addtogroup ADC_LL ADC
54
  * @{
55
  */
56
 
57
/* Private types -------------------------------------------------------------*/
58
/* Private variables ---------------------------------------------------------*/
59
/* Private constants ---------------------------------------------------------*/
60
/* Private macros ------------------------------------------------------------*/
61
 
62
/** @addtogroup ADC_LL_Private_Macros
63
  * @{
64
  */
65
 
66
/* Check of parameters for configuration of ADC hierarchical scope:           */
67
/* common to several ADC instances.                                           */
68
/* Check of parameters for configuration of ADC hierarchical scope:           */
69
/* ADC instance.                                                              */
70
#define IS_LL_ADC_DATA_ALIGN(__DATA_ALIGN__)                                   \
71
  (   ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_RIGHT)                            \
72
   || ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_LEFT)                             \
73
  )
74
 
75
#define IS_LL_ADC_SCAN_SELECTION(__SCAN_SELECTION__)                           \
76
  (   ((__SCAN_SELECTION__) == LL_ADC_SEQ_SCAN_DISABLE)                        \
77
   || ((__SCAN_SELECTION__) == LL_ADC_SEQ_SCAN_ENABLE)                         \
78
  )
79
 
80
#define IS_LL_ADC_SEQ_SCAN_MODE(__SEQ_SCAN_MODE__)                             \
81
  (   ((__SCAN_MODE__) == LL_ADC_SEQ_SCAN_DISABLE)                             \
82
   || ((__SCAN_MODE__) == LL_ADC_SEQ_SCAN_ENABLE)                              \
83
  )
84
 
85
/* Check of parameters for configuration of ADC hierarchical scope:           */
86
/* ADC group regular                                                          */
87
#if defined(ADC3)
88
#define IS_LL_ADC_REG_TRIG_SOURCE(__ADC_INSTANCE__, __REG_TRIG_SOURCE__)       \
89
  ((((__ADC_INSTANCE__) == ADC1) || ((__ADC_INSTANCE__) == ADC2))              \
90
    ? (   ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE)                  \
91
       || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3)              \
92
       || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1)              \
93
       || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2)              \
94
       || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2)              \
95
       || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO)             \
96
       || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4)              \
97
       || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11)           \
98
       || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO)             \
99
      )                                                                        \
100
      :                                                                        \
101
      (   ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE)                  \
102
       || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3)              \
103
       || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_CH1)              \
104
       || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH3)              \
105
       || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_CH1)              \
106
       || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO_ADC3)        \
107
       || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM5_CH1)              \
108
       || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM5_CH3)              \
109
      )                                                                        \
110
  )
111
#else
112
#if defined (STM32F101xE) || defined (STM32F105xC) || defined (STM32F107xC)
113
#define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__)                         \
114
  (   ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE)                      \
115
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3)                  \
116
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1)                  \
117
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2)                  \
118
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2)                  \
119
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO)                 \
120
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4)                  \
121
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11)               \
122
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO)                 \
123
  )
124
#else
125
#define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__)                         \
126
  (   ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE)                      \
127
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3)                  \
128
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1)                  \
129
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2)                  \
130
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2)                  \
131
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO)                 \
132
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4)                  \
133
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11)               \
134
  )
135
#endif
136
#endif
137
#define IS_LL_ADC_REG_CONTINUOUS_MODE(__REG_CONTINUOUS_MODE__)                 \
138
  (   ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_SINGLE)                    \
139
   || ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_CONTINUOUS)                \
140
  )
141
 
142
#define IS_LL_ADC_REG_DMA_TRANSFER(__REG_DMA_TRANSFER__)                       \
143
  (   ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_NONE)                 \
144
   || ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_UNLIMITED)            \
145
  )
146
 
147
#define IS_LL_ADC_REG_SEQ_SCAN_LENGTH(__REG_SEQ_SCAN_LENGTH__)                 \
148
  (   ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_DISABLE)               \
149
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS)         \
150
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS)         \
151
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS)         \
152
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS)         \
153
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS)         \
154
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS)         \
155
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS)         \
156
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS)         \
157
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS)        \
158
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS)        \
159
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS)        \
160
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS)        \
161
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS)        \
162
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS)        \
163
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS)        \
164
  )
165
 
166
#define IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(__REG_SEQ_DISCONT_MODE__)          \
167
  (   ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_DISABLE)           \
168
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_1RANK)             \
169
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_2RANKS)            \
170
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_3RANKS)            \
171
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_4RANKS)            \
172
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_5RANKS)            \
173
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_6RANKS)            \
174
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_7RANKS)            \
175
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_8RANKS)            \
176
  )
177
 
178
/* Check of parameters for configuration of ADC hierarchical scope:           */
179
/* ADC group injected                                                         */
180
#if defined(ADC3)
181
#define IS_LL_ADC_INJ_TRIG_SOURCE(__ADC_INSTANCE__, __INJ_TRIG_SOURCE__)       \
182
  ((((__ADC_INSTANCE__) == ADC1) || ((__ADC_INSTANCE__) == ADC2))              \
183
    ? (   ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE)                  \
184
       || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO)             \
185
       || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4)              \
186
       || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO)             \
187
       || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1)              \
188
       || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4)              \
189
       || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO)             \
190
       || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15)           \
191
       || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4)              \
192
      )                                                                        \
193
      :                                                                        \
194
      (   ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE)                  \
195
       || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO)             \
196
       || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4)              \
197
       || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_CH3)              \
198
       || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH2)              \
199
       || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4_ADC3)         \
200
       || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM5_TRGO)             \
201
       || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM5_CH4)              \
202
      )                                                                        \
203
  )
204
#else
205
#if defined (STM32F101xE) || defined (STM32F105xC) || defined (STM32F107xC)
206
#define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__)                         \
207
  (   ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE)                      \
208
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO)                 \
209
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4)                  \
210
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO)                 \
211
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1)                  \
212
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4)                  \
213
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO)                 \
214
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15)               \
215
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4)                  \
216
  )
217
#else
218
#define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__)                         \
219
  (   ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE)                      \
220
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO)                 \
221
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4)                  \
222
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO)                 \
223
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1)                  \
224
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4)                  \
225
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO)                 \
226
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15)               \
227
  )
228
#endif
229
#endif
230
#define IS_LL_ADC_INJ_TRIG_AUTO(__INJ_TRIG_AUTO__)                             \
231
  (   ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_INDEPENDENT)                     \
232
   || ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_FROM_GRP_REGULAR)                \
233
  )
234
 
235
#define IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(__INJ_SEQ_SCAN_LENGTH__)                 \
236
  (   ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_DISABLE)               \
237
   || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS)         \
238
   || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS)         \
239
   || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS)         \
240
  )
241
 
242
#define IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(__INJ_SEQ_DISCONT_MODE__)          \
243
  (   ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_DISABLE)           \
244
   || ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_1RANK)             \
245
  )
246
 
247
#if defined(ADC_MULTIMODE_SUPPORT)
248
/* Check of parameters for configuration of ADC hierarchical scope:           */
249
/* multimode.                                                                 */
250
#define IS_LL_ADC_MULTI_MODE(__MULTI_MODE__)                                   \
251
  (   ((__MULTI_MODE__) == LL_ADC_MULTI_INDEPENDENT)                           \
252
   || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIMULT)                       \
253
   || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTERL_FAST)                  \
254
   || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTERL_SLOW)                  \
255
   || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_INJ_SIMULT)                       \
256
   || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_INJ_ALTERN)                       \
257
   || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIM_INJ_SIM)                  \
258
   || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIM_INJ_ALT)                  \
259
   || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTFAST_INJ_SIM)              \
260
   || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTSLOW_INJ_SIM)              \
261
  )
262
 
263
#define IS_LL_ADC_MULTI_MASTER_SLAVE(__MULTI_MASTER_SLAVE__)                   \
264
  (   ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_MASTER)                        \
265
   || ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_SLAVE)                         \
266
   || ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_MASTER_SLAVE)                  \
267
  )
268
 
269
#endif /* ADC_MULTIMODE_SUPPORT */
270
/**
271
  * @}
272
  */
273
 
274
 
275
/* Private function prototypes -----------------------------------------------*/
276
 
277
/* Exported functions --------------------------------------------------------*/
278
/** @addtogroup ADC_LL_Exported_Functions
279
  * @{
280
  */
281
 
282
/** @addtogroup ADC_LL_EF_Init
283
  * @{
284
  */
285
 
286
/**
287
  * @brief  De-initialize registers of all ADC instances belonging to
288
  *         the same ADC common instance to their default reset values.
289
  * @param  ADCxy_COMMON ADC common instance
290
  *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
291
  * @retval An ErrorStatus enumeration value:
292
  *          - SUCCESS: ADC common registers are de-initialized
293
  *          - ERROR: not applicable
294
  */
295
ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON)
296
{
297
  /* Check the parameters */
298
  assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
299
 
300
  /* Force reset of ADC clock (core clock) */
301
  LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_ADC1);
302
 
303
  /* Release reset of ADC clock (core clock) */
304
  LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_ADC1);
305
 
306
  return SUCCESS;
307
}
308
 
309
/**
310
  * @brief  Initialize some features of ADC common parameters
311
  *         (all ADC instances belonging to the same ADC common instance)
312
  *         and multimode (for devices with several ADC instances available).
313
  * @note   The setting of ADC common parameters is conditioned to
314
  *         ADC instances state:
315
  *         All ADC instances belonging to the same ADC common instance
316
  *         must be disabled.
317
  * @param  ADCxy_COMMON ADC common instance
318
  *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
319
  * @param  ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure
320
  * @retval An ErrorStatus enumeration value:
321
  *          - SUCCESS: ADC common registers are initialized
322
  *          - ERROR: ADC common registers are not initialized
323
  */
324
ErrorStatus LL_ADC_CommonInit(ADC_Common_TypeDef *ADCxy_COMMON, LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct)
325
{
326
  ErrorStatus status = SUCCESS;
327
 
328
  /* Check the parameters */
329
  assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
330
#if defined(ADC_MULTIMODE_SUPPORT)
331
  assert_param(IS_LL_ADC_MULTI_MODE(ADC_CommonInitStruct->Multimode));
332
#endif /* ADC_MULTIMODE_SUPPORT */
333
 
334
  /* Note: Hardware constraint (refer to description of functions             */
335
  /*       "LL_ADC_SetCommonXXX()" and "LL_ADC_SetMultiXXX()"):               */
336
  /*       On this STM32 serie, setting of these features is conditioned to   */
337
  /*       ADC state:                                                         */
338
  /*       All ADC instances of the ADC common group must be disabled.        */
339
  if(__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(ADCxy_COMMON) == 0U)
340
  {
341
    /* Configuration of ADC hierarchical scope:                               */
342
    /*  - common to several ADC                                               */
343
    /*    (all ADC instances belonging to the same ADC common instance)       */
344
    /*  - multimode (if several ADC instances available on the                */
345
    /*    selected device)                                                    */
346
    /*    - Set ADC multimode configuration                                   */
347
    /*    - Set ADC multimode DMA transfer                                    */
348
    /*    - Set ADC multimode: delay between 2 sampling phases                */
349
#if defined(ADC_MULTIMODE_SUPPORT)
350
    if(ADC_CommonInitStruct->Multimode != LL_ADC_MULTI_INDEPENDENT)
351
    {
352
      MODIFY_REG(ADCxy_COMMON->CR1,
353
                 ADC_CR1_DUALMOD,
354
                 ADC_CommonInitStruct->Multimode
355
                );
356
    }
357
    else
358
    {
359
      MODIFY_REG(ADCxy_COMMON->CR1,
360
                 ADC_CR1_DUALMOD,
361
                 LL_ADC_MULTI_INDEPENDENT
362
                );
363
    }
364
#endif
365
  }
366
  else
367
  {
368
    /* Initialization error: One or several ADC instances belonging to        */
369
    /* the same ADC common instance are not disabled.                         */
370
    status = ERROR;
371
  }
372
 
373
  return status;
374
}
375
 
376
/**
377
  * @brief  Set each @ref LL_ADC_CommonInitTypeDef field to default value.
378
  * @param  ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure
379
  *                              whose fields will be set to default values.
380
  * @retval None
381
  */
382
void LL_ADC_CommonStructInit(LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct)
383
{
384
  /* Set ADC_CommonInitStruct fields to default values */
385
  /* Set fields of ADC common */
386
  /* (all ADC instances belonging to the same ADC common instance) */
387
 
388
#if defined(ADC_MULTIMODE_SUPPORT)
389
  /* Set fields of ADC multimode */
390
  ADC_CommonInitStruct->Multimode             = LL_ADC_MULTI_INDEPENDENT;
391
#endif /* ADC_MULTIMODE_SUPPORT */
392
}
393
 
394
/**
395
  * @brief  De-initialize registers of the selected ADC instance
396
  *         to their default reset values.
397
  * @note   To reset all ADC instances quickly (perform a hard reset),
398
  *         use function @ref LL_ADC_CommonDeInit().
399
  * @param  ADCx ADC instance
400
  * @retval An ErrorStatus enumeration value:
401
  *          - SUCCESS: ADC registers are de-initialized
402
  *          - ERROR: ADC registers are not de-initialized
403
  */
404
ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx)
405
{
406
  ErrorStatus status = SUCCESS;
407
 
408
  /* Check the parameters */
409
  assert_param(IS_ADC_ALL_INSTANCE(ADCx));
410
 
411
  /* Disable ADC instance if not already disabled.                            */
412
  if(LL_ADC_IsEnabled(ADCx) == 1U)
413
  {
414
    /* Set ADC group regular trigger source to SW start to ensure to not      */
415
    /* have an external trigger event occurring during the conversion stop    */
416
    /* ADC disable process.                                                   */
417
    LL_ADC_REG_SetTriggerSource(ADCx, LL_ADC_REG_TRIG_SOFTWARE);
418
 
419
    /* Set ADC group injected trigger source to SW start to ensure to not     */
420
    /* have an external trigger event occurring during the conversion stop    */
421
    /* ADC disable process.                                                   */
422
    LL_ADC_INJ_SetTriggerSource(ADCx, LL_ADC_INJ_TRIG_SOFTWARE);
423
 
424
    /* Disable the ADC instance */
425
    LL_ADC_Disable(ADCx);
426
  }
427
 
428
  /* Check whether ADC state is compliant with expected state */
429
  /* (hardware requirements of bits state to reset registers below) */
430
  if(READ_BIT(ADCx->CR2, ADC_CR2_ADON) == 0U)
431
  {
432
    /* ========== Reset ADC registers ========== */
433
    /* Reset register SR */
434
    CLEAR_BIT(ADCx->SR,
435
              (  LL_ADC_FLAG_STRT
436
               | LL_ADC_FLAG_JSTRT
437
               | LL_ADC_FLAG_EOS
438
               | LL_ADC_FLAG_JEOS
439
               | LL_ADC_FLAG_AWD1 )
440
             );
441
 
442
    /* Reset register CR1 */
443
  #if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
444
 
445
    CLEAR_BIT(ADCx->CR1,
446
              (  ADC_CR1_AWDEN   | ADC_CR1_JAWDEN  | ADC_CR1_DUALMOD
447
               | ADC_CR1_DISCNUM | ADC_CR1_JDISCEN | ADC_CR1_DISCEN
448
               | ADC_CR1_JAUTO   | ADC_CR1_AWDSGL  | ADC_CR1_SCAN
449
               | ADC_CR1_JEOCIE  | ADC_CR1_AWDIE   | ADC_CR1_EOCIE
450
               | ADC_CR1_AWDCH                                     )
451
             );
452
  #else 
453
 
454
    CLEAR_BIT(ADCx->CR1,
455
              (  ADC_CR1_AWDEN   | ADC_CR1_JAWDEN  | ADC_CR1_DISCNUM
456
               | ADC_CR1_JDISCEN | ADC_CR1_DISCEN  | ADC_CR1_JAUTO
457
               | ADC_CR1_AWDSGL  | ADC_CR1_SCAN    | ADC_CR1_JEOCIE  
458
               | ADC_CR1_AWDIE   | ADC_CR1_EOCIE   | ADC_CR1_AWDCH )
459
             );
460
  #endif
461
 
462
    /* Reset register CR2 */
463
    CLEAR_BIT(ADCx->CR2,
464
              (  ADC_CR2_TSVREFE
465
               | ADC_CR2_SWSTART  | ADC_CR2_EXTTRIG  | ADC_CR2_EXTSEL
466
               | ADC_CR2_JSWSTART | ADC_CR2_JEXTTRIG | ADC_CR2_JEXTSEL
467
               | ADC_CR2_ALIGN    | ADC_CR2_DMA
468
               | ADC_CR2_RSTCAL   | ADC_CR2_CAL
469
               | ADC_CR2_CONT     | ADC_CR2_ADON                      )
470
             );
471
 
472
    /* Reset register SMPR1 */
473
    CLEAR_BIT(ADCx->SMPR1,
474
              (  ADC_SMPR1_SMP17 | ADC_SMPR1_SMP16
475
               | ADC_SMPR1_SMP15 | ADC_SMPR1_SMP14 | ADC_SMPR1_SMP13
476
               | ADC_SMPR1_SMP12 | ADC_SMPR1_SMP11 | ADC_SMPR1_SMP10)
477
             );
478
 
479
    /* Reset register SMPR2 */
480
    CLEAR_BIT(ADCx->SMPR2,
481
              (  ADC_SMPR2_SMP9
482
               | ADC_SMPR2_SMP8 | ADC_SMPR2_SMP7 | ADC_SMPR2_SMP6
483
               | ADC_SMPR2_SMP5 | ADC_SMPR2_SMP4 | ADC_SMPR2_SMP3
484
               | ADC_SMPR2_SMP2 | ADC_SMPR2_SMP1 | ADC_SMPR2_SMP0)
485
             );
486
 
487
    /* Reset register JOFR1 */
488
    CLEAR_BIT(ADCx->JOFR1, ADC_JOFR1_JOFFSET1);
489
    /* Reset register JOFR2 */
490
    CLEAR_BIT(ADCx->JOFR2, ADC_JOFR2_JOFFSET2);
491
    /* Reset register JOFR3 */
492
    CLEAR_BIT(ADCx->JOFR3, ADC_JOFR3_JOFFSET3);
493
    /* Reset register JOFR4 */
494
    CLEAR_BIT(ADCx->JOFR4, ADC_JOFR4_JOFFSET4);
495
 
496
    /* Reset register HTR */
497
    SET_BIT(ADCx->HTR, ADC_HTR_HT);
498
    /* Reset register LTR */
499
    CLEAR_BIT(ADCx->LTR, ADC_LTR_LT);
500
 
501
    /* Reset register SQR1 */
502
    CLEAR_BIT(ADCx->SQR1,
503
              (  ADC_SQR1_L
504
               | ADC_SQR1_SQ16
505
               | ADC_SQR1_SQ15 | ADC_SQR1_SQ14 | ADC_SQR1_SQ13)
506
             );
507
 
508
    /* Reset register SQR2 */
509
    CLEAR_BIT(ADCx->SQR2,
510
              (  ADC_SQR2_SQ12 | ADC_SQR2_SQ11 | ADC_SQR2_SQ10
511
               | ADC_SQR2_SQ9 | ADC_SQR2_SQ8 | ADC_SQR2_SQ7)
512
             );
513
 
514
 
515
    /* Reset register JSQR */
516
    CLEAR_BIT(ADCx->JSQR,
517
              (  ADC_JSQR_JL
518
               | ADC_JSQR_JSQ4 | ADC_JSQR_JSQ3
519
               | ADC_JSQR_JSQ2 | ADC_JSQR_JSQ1  )
520
             );
521
 
522
    /* Reset register DR */
523
    /* bits in access mode read only, no direct reset applicable */
524
 
525
    /* Reset registers JDR1, JDR2, JDR3, JDR4 */
526
    /* bits in access mode read only, no direct reset applicable */
527
 
528
  }
529
 
530
  return status;
531
}
532
 
533
/**
534
  * @brief  Initialize some features of ADC instance.
535
  * @note   These parameters have an impact on ADC scope: ADC instance.
536
  *         Affects both group regular and group injected (availability
537
  *         of ADC group injected depends on STM32 families).
538
  *         Refer to corresponding unitary functions into
539
  *         @ref ADC_LL_EF_Configuration_ADC_Instance .
540
  * @note   The setting of these parameters by function @ref LL_ADC_Init()
541
  *         is conditioned to ADC state:
542
  *         ADC instance must be disabled.
543
  *         This condition is applied to all ADC features, for efficiency
544
  *         and compatibility over all STM32 families. However, the different
545
  *         features can be set under different ADC state conditions
546
  *         (setting possible with ADC enabled without conversion on going,
547
  *         ADC enabled with conversion on going, ...)
548
  *         Each feature can be updated afterwards with a unitary function
549
  *         and potentially with ADC in a different state than disabled,
550
  *         refer to description of each function for setting
551
  *         conditioned to ADC state.
552
  * @note   After using this function, some other features must be configured
553
  *         using LL unitary functions.
554
  *         The minimum configuration remaining to be done is:
555
  *          - Set ADC group regular or group injected sequencer:
556
  *            map channel on the selected sequencer rank.
557
  *            Refer to function @ref LL_ADC_REG_SetSequencerRanks().
558
  *          - Set ADC channel sampling time
559
  *            Refer to function LL_ADC_SetChannelSamplingTime();
560
  * @param  ADCx ADC instance
561
  * @param  ADC_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
562
  * @retval An ErrorStatus enumeration value:
563
  *          - SUCCESS: ADC registers are initialized
564
  *          - ERROR: ADC registers are not initialized
565
  */
566
ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct)
567
{
568
  ErrorStatus status = SUCCESS;
569
 
570
  /* Check the parameters */
571
  assert_param(IS_ADC_ALL_INSTANCE(ADCx));
572
 
573
  assert_param(IS_LL_ADC_DATA_ALIGN(ADC_InitStruct->DataAlignment));
574
  assert_param(IS_LL_ADC_SCAN_SELECTION(ADC_InitStruct->SequencersScanMode));
575
 
576
  /* Note: Hardware constraint (refer to description of this function):       */
577
  /*       ADC instance must be disabled.                                     */
578
  if(LL_ADC_IsEnabled(ADCx) == 0U)
579
  {
580
    /* Configuration of ADC hierarchical scope:                               */
581
    /*  - ADC instance                                                        */
582
    /*    - Set ADC conversion data alignment                                 */
583
    MODIFY_REG(ADCx->CR1,
584
                 ADC_CR1_SCAN
585
              ,
586
                 ADC_InitStruct->SequencersScanMode
587
              );
588
 
589
    MODIFY_REG(ADCx->CR2,
590
                 ADC_CR2_ALIGN
591
              ,
592
                 ADC_InitStruct->DataAlignment
593
              );
594
 
595
  }
596
  else
597
  {
598
    /* Initialization error: ADC instance is not disabled. */
599
    status = ERROR;
600
  }
601
  return status;
602
}
603
 
604
/**
605
  * @brief  Set each @ref LL_ADC_InitTypeDef field to default value.
606
  * @param  ADC_InitStruct Pointer to a @ref LL_ADC_InitTypeDef structure
607
  *                        whose fields will be set to default values.
608
  * @retval None
609
  */
610
void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct)
611
{
612
  /* Set ADC_InitStruct fields to default values */
613
  /* Set fields of ADC instance */
614
  ADC_InitStruct->DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
615
 
616
  /* Enable scan mode to have a generic behavior with ADC of other            */
617
  /* STM32 families, without this setting available:                          */
618
  /* ADC group regular sequencer and ADC group injected sequencer depend      */
619
  /* only of their own configuration.                                         */
620
  ADC_InitStruct->SequencersScanMode      = LL_ADC_SEQ_SCAN_ENABLE;
621
 
622
}
623
 
624
/**
625
  * @brief  Initialize some features of ADC group regular.
626
  * @note   These parameters have an impact on ADC scope: ADC group regular.
627
  *         Refer to corresponding unitary functions into
628
  *         @ref ADC_LL_EF_Configuration_ADC_Group_Regular
629
  *         (functions with prefix "REG").
630
  * @note   The setting of these parameters by function @ref LL_ADC_Init()
631
  *         is conditioned to ADC state:
632
  *         ADC instance must be disabled.
633
  *         This condition is applied to all ADC features, for efficiency
634
  *         and compatibility over all STM32 families. However, the different
635
  *         features can be set under different ADC state conditions
636
  *         (setting possible with ADC enabled without conversion on going,
637
  *         ADC enabled with conversion on going, ...)
638
  *         Each feature can be updated afterwards with a unitary function
639
  *         and potentially with ADC in a different state than disabled,
640
  *         refer to description of each function for setting
641
  *         conditioned to ADC state.
642
  * @note   After using this function, other features must be configured
643
  *         using LL unitary functions.
644
  *         The minimum configuration remaining to be done is:
645
  *          - Set ADC group regular or group injected sequencer:
646
  *            map channel on the selected sequencer rank.
647
  *            Refer to function @ref LL_ADC_REG_SetSequencerRanks().
648
  *          - Set ADC channel sampling time
649
  *            Refer to function LL_ADC_SetChannelSamplingTime();
650
  * @param  ADCx ADC instance
651
  * @param  ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
652
  * @retval An ErrorStatus enumeration value:
653
  *          - SUCCESS: ADC registers are initialized
654
  *          - ERROR: ADC registers are not initialized
655
  */
656
ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
657
{
658
  ErrorStatus status = SUCCESS;
659
 
660
  /* Check the parameters */
661
  assert_param(IS_ADC_ALL_INSTANCE(ADCx));
662
#if defined(ADC3)
663
  assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADCx, ADC_REG_InitStruct->TriggerSource));
664
#else
665
  assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADC_REG_InitStruct->TriggerSource));
666
#endif
667
  assert_param(IS_LL_ADC_REG_SEQ_SCAN_LENGTH(ADC_REG_InitStruct->SequencerLength));
668
  if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
669
  {
670
    assert_param(IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(ADC_REG_InitStruct->SequencerDiscont));
671
  }
672
  assert_param(IS_LL_ADC_REG_CONTINUOUS_MODE(ADC_REG_InitStruct->ContinuousMode));
673
  assert_param(IS_LL_ADC_REG_DMA_TRANSFER(ADC_REG_InitStruct->DMATransfer));
674
 
675
  /* Note: Hardware constraint (refer to description of this function):       */
676
  /*       ADC instance must be disabled.                                     */
677
  if(LL_ADC_IsEnabled(ADCx) == 0U)
678
  {
679
    /* Configuration of ADC hierarchical scope:                               */
680
    /*  - ADC group regular                                                   */
681
    /*    - Set ADC group regular trigger source                              */
682
    /*    - Set ADC group regular sequencer length                            */
683
    /*    - Set ADC group regular sequencer discontinuous mode                */
684
    /*    - Set ADC group regular continuous mode                             */
685
    /*    - Set ADC group regular conversion data transfer: no transfer or    */
686
    /*      transfer by DMA, and DMA requests mode                            */
687
    /* Note: On this STM32 serie, ADC trigger edge is set when starting       */
688
    /*       ADC conversion.                                                  */
689
    /*       Refer to function @ref LL_ADC_REG_StartConversionExtTrig().      */
690
    if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
691
    {
692
      MODIFY_REG(ADCx->CR1,
693
                   ADC_CR1_DISCEN
694
                 | ADC_CR1_DISCNUM
695
                ,
696
                   ADC_REG_InitStruct->SequencerLength
697
                 | ADC_REG_InitStruct->SequencerDiscont
698
                );
699
    }
700
    else
701
    {
702
      MODIFY_REG(ADCx->CR1,
703
                   ADC_CR1_DISCEN
704
                 | ADC_CR1_DISCNUM
705
                ,
706
                   ADC_REG_InitStruct->SequencerLength
707
                 | LL_ADC_REG_SEQ_DISCONT_DISABLE
708
                );
709
    }
710
 
711
    MODIFY_REG(ADCx->CR2,
712
                 ADC_CR2_EXTSEL
713
               | ADC_CR2_CONT
714
               | ADC_CR2_DMA
715
              ,
716
                 ADC_REG_InitStruct->TriggerSource
717
               | ADC_REG_InitStruct->ContinuousMode
718
               | ADC_REG_InitStruct->DMATransfer
719
              );
720
 
721
    /* Set ADC group regular sequencer length and scan direction */
722
    /* Note: Hardware constraint (refer to description of this function):     */
723
    /* Note: If ADC instance feature scan mode is disabled                    */
724
    /*       (refer to  ADC instance initialization structure                 */
725
    /*       parameter @ref SequencersScanMode                                */
726
    /*       or function @ref LL_ADC_SetSequencersScanMode() ),               */
727
    /*       this parameter is discarded.                                     */
728
    LL_ADC_REG_SetSequencerLength(ADCx, ADC_REG_InitStruct->SequencerLength);
729
  }
730
  else
731
  {
732
    /* Initialization error: ADC instance is not disabled. */
733
    status = ERROR;
734
  }
735
  return status;
736
}
737
 
738
/**
739
  * @brief  Set each @ref LL_ADC_REG_InitTypeDef field to default value.
740
  * @param  ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
741
  *                            whose fields will be set to default values.
742
  * @retval None
743
  */
744
void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
745
{
746
  /* Set ADC_REG_InitStruct fields to default values */
747
  /* Set fields of ADC group regular */
748
  /* Note: On this STM32 serie, ADC trigger edge is set when starting         */
749
  /*       ADC conversion.                                                    */
750
  /*       Refer to function @ref LL_ADC_REG_StartConversionExtTrig().        */
751
  ADC_REG_InitStruct->TriggerSource    = LL_ADC_REG_TRIG_SOFTWARE;
752
  ADC_REG_InitStruct->SequencerLength  = LL_ADC_REG_SEQ_SCAN_DISABLE;
753
  ADC_REG_InitStruct->SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE;
754
  ADC_REG_InitStruct->ContinuousMode   = LL_ADC_REG_CONV_SINGLE;
755
  ADC_REG_InitStruct->DMATransfer      = LL_ADC_REG_DMA_TRANSFER_NONE;
756
}
757
 
758
/**
759
  * @brief  Initialize some features of ADC group injected.
760
  * @note   These parameters have an impact on ADC scope: ADC group injected.
761
  *         Refer to corresponding unitary functions into
762
  *         @ref ADC_LL_EF_Configuration_ADC_Group_Regular
763
  *         (functions with prefix "INJ").
764
  * @note   The setting of these parameters by function @ref LL_ADC_Init()
765
  *         is conditioned to ADC state:
766
  *         ADC instance must be disabled.
767
  *         This condition is applied to all ADC features, for efficiency
768
  *         and compatibility over all STM32 families. However, the different
769
  *         features can be set under different ADC state conditions
770
  *         (setting possible with ADC enabled without conversion on going,
771
  *         ADC enabled with conversion on going, ...)
772
  *         Each feature can be updated afterwards with a unitary function
773
  *         and potentially with ADC in a different state than disabled,
774
  *         refer to description of each function for setting
775
  *         conditioned to ADC state.
776
  * @note   After using this function, other features must be configured
777
  *         using LL unitary functions.
778
  *         The minimum configuration remaining to be done is:
779
  *          - Set ADC group injected sequencer:
780
  *            map channel on the selected sequencer rank.
781
  *            Refer to function @ref LL_ADC_INJ_SetSequencerRanks().
782
  *          - Set ADC channel sampling time
783
  *            Refer to function LL_ADC_SetChannelSamplingTime();
784
  * @param  ADCx ADC instance
785
  * @param  ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
786
  * @retval An ErrorStatus enumeration value:
787
  *          - SUCCESS: ADC registers are initialized
788
  *          - ERROR: ADC registers are not initialized
789
  */
790
ErrorStatus LL_ADC_INJ_Init(ADC_TypeDef *ADCx, LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
791
{
792
  ErrorStatus status = SUCCESS;
793
 
794
  /* Check the parameters */
795
  assert_param(IS_ADC_ALL_INSTANCE(ADCx));
796
#if defined(ADC3)
797
  assert_param(IS_LL_ADC_INJ_TRIG_SOURCE(ADCx, ADC_INJ_InitStruct->TriggerSource));
798
#else
799
  assert_param(IS_LL_ADC_INJ_TRIG_SOURCE(ADC_INJ_InitStruct->TriggerSource));
800
#endif
801
  assert_param(IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(ADC_INJ_InitStruct->SequencerLength));
802
  if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_INJ_SEQ_SCAN_DISABLE)
803
  {
804
    assert_param(IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(ADC_INJ_InitStruct->SequencerDiscont));
805
  }
806
  assert_param(IS_LL_ADC_INJ_TRIG_AUTO(ADC_INJ_InitStruct->TrigAuto));
807
 
808
  /* Note: Hardware constraint (refer to description of this function):       */
809
  /*       ADC instance must be disabled.                                     */
810
  if(LL_ADC_IsEnabled(ADCx) == 0U)
811
  {
812
    /* Configuration of ADC hierarchical scope:                               */
813
    /*  - ADC group injected                                                  */
814
    /*    - Set ADC group injected trigger source                             */
815
    /*    - Set ADC group injected sequencer length                           */
816
    /*    - Set ADC group injected sequencer discontinuous mode               */
817
    /*    - Set ADC group injected conversion trigger: independent or         */
818
    /*      from ADC group regular                                            */
819
    /* Note: On this STM32 serie, ADC trigger edge is set when starting       */
820
    /*       ADC conversion.                                                  */
821
    /*       Refer to function @ref LL_ADC_INJ_StartConversionExtTrig().      */
822
    if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
823
    {
824
      MODIFY_REG(ADCx->CR1,
825
                   ADC_CR1_JDISCEN
826
                 | ADC_CR1_JAUTO
827
                ,
828
                   ADC_INJ_InitStruct->SequencerDiscont
829
                 | ADC_INJ_InitStruct->TrigAuto
830
                );
831
    }
832
    else
833
    {
834
      MODIFY_REG(ADCx->CR1,
835
                   ADC_CR1_JDISCEN
836
                 | ADC_CR1_JAUTO
837
                ,
838
                   LL_ADC_REG_SEQ_DISCONT_DISABLE
839
                 | ADC_INJ_InitStruct->TrigAuto
840
                );
841
    }
842
 
843
    MODIFY_REG(ADCx->CR2,
844
               ADC_CR2_JEXTSEL
845
              ,
846
               ADC_INJ_InitStruct->TriggerSource
847
              );
848
 
849
    /* Note: Hardware constraint (refer to description of this function):     */
850
    /* Note: If ADC instance feature scan mode is disabled                    */
851
    /*       (refer to  ADC instance initialization structure                 */
852
    /*       parameter @ref SequencersScanMode                                */
853
    /*       or function @ref LL_ADC_SetSequencersScanMode() ),               */
854
    /*       this parameter is discarded.                                     */
855
    LL_ADC_INJ_SetSequencerLength(ADCx, ADC_INJ_InitStruct->SequencerLength);
856
  }
857
  else
858
  {
859
    /* Initialization error: ADC instance is not disabled. */
860
    status = ERROR;
861
  }
862
  return status;
863
}
864
 
865
/**
866
  * @brief  Set each @ref LL_ADC_INJ_InitTypeDef field to default value.
867
  * @param  ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
868
  *                            whose fields will be set to default values.
869
  * @retval None
870
  */
871
void LL_ADC_INJ_StructInit(LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
872
{
873
  /* Set ADC_INJ_InitStruct fields to default values */
874
  /* Set fields of ADC group injected */
875
  ADC_INJ_InitStruct->TriggerSource    = LL_ADC_INJ_TRIG_SOFTWARE;
876
  ADC_INJ_InitStruct->SequencerLength  = LL_ADC_INJ_SEQ_SCAN_DISABLE;
877
  ADC_INJ_InitStruct->SequencerDiscont = LL_ADC_INJ_SEQ_DISCONT_DISABLE;
878
  ADC_INJ_InitStruct->TrigAuto         = LL_ADC_INJ_TRIG_INDEPENDENT;
879
}
880
 
881
/**
882
  * @}
883
  */
884
 
885
/**
886
  * @}
887
  */
888
 
889
/**
890
  * @}
891
  */
892
 
893
#endif /* ADC1 || ADC2 || ADC3 */
894
 
895
/**
896
  * @}
897
  */
898
 
899
#endif /* USE_FULL_LL_DRIVER */
900
 
901
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/