Subversion Repositories DashDisplay

Rev

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

Rev Author Line No. Line
56 mjames 1
/**
2
  ******************************************************************************
3
  * @file    stm32l1xx_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.
10
  * All rights reserved.</center></h2>
11
  *
12
  * This software component is licensed by ST under BSD 3-Clause license,
13
  * the "License"; You may not use this file except in compliance with the
14
  * License. You may obtain a copy of the License at:
15
  *                        opensource.org/licenses/BSD-3-Clause
16
  *
17
  ******************************************************************************
18
  */
19
#if defined(USE_FULL_LL_DRIVER)
20
 
21
/* Includes ------------------------------------------------------------------*/
22
#include "stm32l1xx_ll_adc.h"
23
#include "stm32l1xx_ll_bus.h"
24
 
25
#ifdef  USE_FULL_ASSERT
26
  #include "stm32_assert.h"
27
#else
28
  #define assert_param(expr) ((void)0U)
29
#endif
30
 
31
/** @addtogroup STM32L1xx_LL_Driver
32
  * @{
33
  */
34
 
35
#if defined (ADC1)
36
 
37
/** @addtogroup ADC_LL ADC
38
  * @{
39
  */
40
 
41
/* Private types -------------------------------------------------------------*/
42
/* Private variables ---------------------------------------------------------*/
43
/* Private constants ---------------------------------------------------------*/
44
/* Private macros ------------------------------------------------------------*/
45
 
46
/** @addtogroup ADC_LL_Private_Macros
47
  * @{
48
  */
49
 
50
/* Check of parameters for configuration of ADC hierarchical scope:           */
51
/* common to several ADC instances.                                           */
52
#define IS_LL_ADC_COMMON_CLOCK(__CLOCK__)                                      \
53
  (   ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV1)                                 \
54
   || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV2)                                 \
55
   || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV4)                                 \
56
  )
57
 
58
/* Check of parameters for configuration of ADC hierarchical scope:           */
59
/* ADC instance.                                                              */
60
#define IS_LL_ADC_RESOLUTION(__RESOLUTION__)                                   \
61
  (   ((__RESOLUTION__) == LL_ADC_RESOLUTION_12B)                              \
62
   || ((__RESOLUTION__) == LL_ADC_RESOLUTION_10B)                              \
63
   || ((__RESOLUTION__) == LL_ADC_RESOLUTION_8B)                               \
64
   || ((__RESOLUTION__) == LL_ADC_RESOLUTION_6B)                               \
65
  )
66
 
67
#define IS_LL_ADC_DATA_ALIGN(__DATA_ALIGN__)                                   \
68
  (   ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_RIGHT)                            \
69
   || ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_LEFT)                             \
70
  )
71
 
72
#define IS_LL_ADC_LOW_POWER_AUTOWAIT(__LOW_POWER__)                            \
73
  (   ((__LOW_POWER__) == LL_ADC_LP_AUTOWAIT_NONE)                             \
74
   || ((__LOW_POWER__) == LL_ADC_LP_AUTOWAIT)                                  \
75
   || ((__LOW_POWER__) == LL_ADC_LP_AUTOWAIT_7_APBCLOCKCYCLES)                 \
76
   || ((__LOW_POWER__) == LL_ADC_LP_AUTOWAIT_15_APBCLOCKCYCLES)                \
77
   || ((__LOW_POWER__) == LL_ADC_LP_AUTOWAIT_31_APBCLOCKCYCLES)                \
78
   || ((__LOW_POWER__) == LL_ADC_LP_AUTOWAIT_63_APBCLOCKCYCLES)                \
79
   || ((__LOW_POWER__) == LL_ADC_LP_AUTOWAIT_127_APBCLOCKCYCLES)               \
80
   || ((__LOW_POWER__) == LL_ADC_LP_AUTOWAIT_255_APBCLOCKCYCLES)               \
81
  )
82
 
83
#define IS_LL_ADC_LOW_POWER_AUTOPOWEROFF(__LOW_POWER__)                        \
84
  (   ((__LOW_POWER__) == LL_ADC_LP_AUTOPOWEROFF_NONE)                         \
85
   || ((__LOW_POWER__) == LL_ADC_LP_AUTOPOWEROFF_IDLE_PHASE)                   \
86
   || ((__LOW_POWER__) == LL_ADC_LP_AUTOPOWEROFF_AUTOWAIT_PHASE)               \
87
   || ((__LOW_POWER__) == LL_ADC_LP_AUTOPOWEROFF_IDLE_AUTOWAIT_PHASES)         \
88
  )
89
 
90
#define IS_LL_ADC_SCAN_SELECTION(__SCAN_SELECTION__)                           \
91
  (   ((__SCAN_SELECTION__) == LL_ADC_SEQ_SCAN_DISABLE)                        \
92
   || ((__SCAN_SELECTION__) == LL_ADC_SEQ_SCAN_ENABLE)                         \
93
  )
94
 
95
#define IS_LL_ADC_SEQ_SCAN_MODE(__SEQ_SCAN_MODE__)                             \
96
  (   ((__SCAN_MODE__) == LL_ADC_SEQ_SCAN_DISABLE)                             \
97
   || ((__SCAN_MODE__) == LL_ADC_SEQ_SCAN_ENABLE)                              \
98
  )
99
 
100
#define IS_LL_ADC_CHANNELS_BANK(__CHANNELS_BANK__)                             \
101
  (   ((__CHANNELS_BANK__) == LL_ADC_CHANNELS_BANK_A)                          \
102
   || ((__CHANNELS_BANK__) == LL_ADC_CHANNELS_BANK_B)                          \
103
  )
104
 
105
/* Check of parameters for configuration of ADC hierarchical scope:           */
106
/* ADC group regular                                                          */
107
#define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__)                         \
108
  (   ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE)                      \
109
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_TRGO)                 \
110
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH3)                  \
111
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO)                 \
112
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2)                  \
113
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_CH1)                  \
114
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_CH3)                  \
115
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_TRGO)                 \
116
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4)                  \
117
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM6_TRGO)                 \
118
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM9_CH2)                  \
119
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM9_TRGO)                 \
120
   || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11)               \
121
  )
122
 
123
#define IS_LL_ADC_REG_CONTINUOUS_MODE(__REG_CONTINUOUS_MODE__)                 \
124
  (   ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_SINGLE)                    \
125
   || ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_CONTINUOUS)                \
126
  )
127
 
128
#define IS_LL_ADC_REG_DMA_TRANSFER(__REG_DMA_TRANSFER__)                       \
129
  (   ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_NONE)                 \
130
   || ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_LIMITED)              \
131
   || ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_UNLIMITED)            \
132
  )
133
 
134
#define IS_LL_ADC_REG_FLAG_EOC_SELECTION(__REG_FLAG_EOC_SELECTION__)           \
135
  (   ((__REG_FLAG_EOC_SELECTION__) == LL_ADC_REG_FLAG_EOC_SEQUENCE_CONV)      \
136
   || ((__REG_FLAG_EOC_SELECTION__) == LL_ADC_REG_FLAG_EOC_UNITARY_CONV)       \
137
  )
138
 
139
#define IS_LL_ADC_REG_SEQ_SCAN_LENGTH(__REG_SEQ_SCAN_LENGTH__)                 \
140
  (   ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_DISABLE)               \
141
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS)         \
142
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS)         \
143
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS)         \
144
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS)         \
145
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS)         \
146
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS)         \
147
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS)         \
148
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS)         \
149
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS)        \
150
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS)        \
151
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS)        \
152
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS)        \
153
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS)        \
154
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS)        \
155
   || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS)        \
156
  )
157
 
158
#define IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(__REG_SEQ_DISCONT_MODE__)          \
159
  (   ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_DISABLE)           \
160
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_1RANK)             \
161
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_2RANKS)            \
162
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_3RANKS)            \
163
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_4RANKS)            \
164
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_5RANKS)            \
165
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_6RANKS)            \
166
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_7RANKS)            \
167
   || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_8RANKS)            \
168
  )
169
 
170
/* Check of parameters for configuration of ADC hierarchical scope:           */
171
/* ADC group injected                                                         */
172
#define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__)                         \
173
  (   ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE)                      \
174
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM9_CH1)                  \
175
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM9_TRGO)                 \
176
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO)                 \
177
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1)                  \
178
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4)                  \
179
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO)                 \
180
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_CH1)                  \
181
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_CH2)                  \
182
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_CH3)                  \
183
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM10_CH1)                 \
184
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM7_TRGO)                 \
185
   || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15)               \
186
  )
187
 
188
#define IS_LL_ADC_INJ_TRIG_EXT_EDGE(__INJ_TRIG_EXT_EDGE__)                     \
189
  (   ((__INJ_TRIG_EXT_EDGE__) == LL_ADC_INJ_TRIG_EXT_RISING)                  \
190
   || ((__INJ_TRIG_EXT_EDGE__) == LL_ADC_INJ_TRIG_EXT_FALLING)                 \
191
   || ((__INJ_TRIG_EXT_EDGE__) == LL_ADC_INJ_TRIG_EXT_RISINGFALLING)           \
192
  )
193
 
194
#define IS_LL_ADC_INJ_TRIG_AUTO(__INJ_TRIG_AUTO__)                             \
195
  (   ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_INDEPENDENT)                     \
196
   || ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_FROM_GRP_REGULAR)                \
197
  )
198
 
199
#define IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(__INJ_SEQ_SCAN_LENGTH__)                 \
200
  (   ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_DISABLE)               \
201
   || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS)         \
202
   || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS)         \
203
   || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS)         \
204
  )
205
 
206
#define IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(__INJ_SEQ_DISCONT_MODE__)          \
207
  (   ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_DISABLE)           \
208
   || ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_1RANK)             \
209
  )
210
 
211
/**
212
  * @}
213
  */
214
 
215
 
216
/* Private function prototypes -----------------------------------------------*/
217
 
218
/* Exported functions --------------------------------------------------------*/
219
/** @addtogroup ADC_LL_Exported_Functions
220
  * @{
221
  */
222
 
223
/** @addtogroup ADC_LL_EF_Init
224
  * @{
225
  */
226
 
227
/**
228
  * @brief  De-initialize registers of all ADC instances belonging to
229
  *         the same ADC common instance to their default reset values.
230
  * @param  ADCxy_COMMON ADC common instance
231
  *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
232
  * @retval An ErrorStatus enumeration value:
233
  *          - SUCCESS: ADC common registers are de-initialized
234
  *          - ERROR: not applicable
235
  */
236
ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON)
237
{
238
  /* Check the parameters */
239
  assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
240
 
241
  /* Force reset of ADC clock (core clock) */
242
  LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_ADC1);
243
 
244
  /* Release reset of ADC clock (core clock) */
245
  LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_ADC1);
246
 
247
  return SUCCESS;
248
}
249
 
250
/**
251
  * @brief  Initialize some features of ADC common parameters
252
  *         (all ADC instances belonging to the same ADC common instance)
253
  *         and multimode (for devices with several ADC instances available).
254
  * @note   The setting of ADC common parameters is conditioned to
255
  *         ADC instances state:
256
  *         All ADC instances belonging to the same ADC common instance
257
  *         must be disabled.
258
  * @param  ADCxy_COMMON ADC common instance
259
  *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
260
  * @param  ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure
261
  * @retval An ErrorStatus enumeration value:
262
  *          - SUCCESS: ADC common registers are initialized
263
  *          - ERROR: ADC common registers are not initialized
264
  */
265
ErrorStatus LL_ADC_CommonInit(ADC_Common_TypeDef *ADCxy_COMMON, LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct)
266
{
267
  ErrorStatus status = SUCCESS;
268
 
269
  /* Check the parameters */
270
  assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
271
  assert_param(IS_LL_ADC_COMMON_CLOCK(ADC_CommonInitStruct->CommonClock));
272
 
273
  /* Note: Hardware constraint (refer to description of functions             */
274
  /*       "LL_ADC_SetCommonXXX()":                                           */
275
  /*       On this STM32 serie, setting of these features is conditioned to   */
276
  /*       ADC state:                                                         */
277
  /*       All ADC instances of the ADC common group must be disabled.        */
278
  if(__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(ADCxy_COMMON) == 0U)
279
  {
280
    /* Configuration of ADC hierarchical scope:                               */
281
    /*  - common to several ADC                                               */
282
    /*    (all ADC instances belonging to the same ADC common instance)       */
283
    /*    - Set ADC clock (conversion clock)                                  */
284
    LL_ADC_SetCommonClock(ADCxy_COMMON, ADC_CommonInitStruct->CommonClock);
285
  }
286
  else
287
  {
288
    /* Initialization error: One or several ADC instances belonging to        */
289
    /* the same ADC common instance are not disabled.                         */
290
    status = ERROR;
291
  }
292
 
293
  return status;
294
}
295
 
296
/**
297
  * @brief  Set each @ref LL_ADC_CommonInitTypeDef field to default value.
298
  * @param  ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure
299
  *                              whose fields will be set to default values.
300
  * @retval None
301
  */
302
void LL_ADC_CommonStructInit(LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct)
303
{
304
  /* Set ADC_CommonInitStruct fields to default values */
305
  /* Set fields of ADC common */
306
  /* (all ADC instances belonging to the same ADC common instance) */
307
  ADC_CommonInitStruct->CommonClock = LL_ADC_CLOCK_ASYNC_DIV2;
308
 
309
}
310
 
311
/**
312
  * @brief  De-initialize registers of the selected ADC instance
313
  *         to their default reset values.
314
  * @note   To reset all ADC instances quickly (perform a hard reset),
315
  *         use function @ref LL_ADC_CommonDeInit().
316
  * @param  ADCx ADC instance
317
  * @retval An ErrorStatus enumeration value:
318
  *          - SUCCESS: ADC registers are de-initialized
319
  *          - ERROR: ADC registers are not de-initialized
320
  */
321
ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx)
322
{
323
  ErrorStatus status = SUCCESS;
324
 
325
  /* Check the parameters */
326
  assert_param(IS_ADC_ALL_INSTANCE(ADCx));
327
 
328
  /* Disable ADC instance if not already disabled.                            */
329
  if(LL_ADC_IsEnabled(ADCx) == 1U)
330
  {
331
    /* Set ADC group regular trigger source to SW start to ensure to not      */
332
    /* have an external trigger event occurring during the conversion stop    */
333
    /* ADC disable process.                                                   */
334
    LL_ADC_REG_SetTriggerSource(ADCx, LL_ADC_REG_TRIG_SOFTWARE);
335
 
336
    /* Set ADC group injected trigger source to SW start to ensure to not     */
337
    /* have an external trigger event occurring during the conversion stop    */
338
    /* ADC disable process.                                                   */
339
    LL_ADC_INJ_SetTriggerSource(ADCx, LL_ADC_INJ_TRIG_SOFTWARE);
340
 
341
    /* Disable the ADC instance */
342
    LL_ADC_Disable(ADCx);
343
  }
344
 
345
  /* Check whether ADC state is compliant with expected state */
346
  /* (hardware requirements of bits state to reset registers below) */
347
  if(READ_BIT(ADCx->CR2, ADC_CR2_ADON) == 0U)
348
  {
349
    /* ========== Reset ADC registers ========== */
350
    /* Reset register SR */
351
    CLEAR_BIT(ADCx->SR,
352
              (  LL_ADC_FLAG_STRT
353
               | LL_ADC_FLAG_JSTRT
354
               | LL_ADC_FLAG_EOCS
355
               | LL_ADC_FLAG_OVR
356
               | LL_ADC_FLAG_JEOS
357
               | LL_ADC_FLAG_AWD1 )
358
             );
359
 
360
    /* Reset register CR1 */
361
    CLEAR_BIT(ADCx->CR1,
362
              (  ADC_CR1_OVRIE   | ADC_CR1_RES     | ADC_CR1_AWDEN
363
               | ADC_CR1_JAWDEN  | ADC_CR1_PDI     | ADC_CR1_PDD
364
               | ADC_CR1_DISCNUM | ADC_CR1_JDISCEN | ADC_CR1_DISCEN
365
               | ADC_CR1_JAUTO   | ADC_CR1_AWDSGL  | ADC_CR1_SCAN
366
               | ADC_CR1_JEOCIE  | ADC_CR1_AWDIE   | ADC_CR1_EOCIE
367
               | ADC_CR1_AWDCH                                     )
368
             );
369
 
370
    /* Reset register CR2 */
371
    #if defined(ADC_CR2_CFG)
372
    CLEAR_BIT(ADCx->CR2,
373
              (  ADC_CR2_SWSTART  | ADC_CR2_EXTEN  | ADC_CR2_EXTSEL
374
               | ADC_CR2_JSWSTART | ADC_CR2_JEXTEN | ADC_CR2_JEXTSEL
375
               | ADC_CR2_ALIGN    | ADC_CR2_EOCS
376
               | ADC_CR2_DDS      | ADC_CR2_DMA    | ADC_CR2_DELS
377
               | ADC_CR2_CFG      | ADC_CR2_CONT   | ADC_CR2_ADON   )
378
             );
379
    #else
380
    CLEAR_BIT(ADCx->CR2,
381
              (  ADC_CR2_SWSTART  | ADC_CR2_EXTEN  | ADC_CR2_EXTSEL
382
               | ADC_CR2_JSWSTART | ADC_CR2_JEXTEN | ADC_CR2_JEXTSEL
383
               | ADC_CR2_ALIGN    | ADC_CR2_EOCS
384
               | ADC_CR2_DDS      | ADC_CR2_DMA    | ADC_CR2_DELS
385
               | ADC_CR2_CONT     | ADC_CR2_ADON                    )
386
             );
387
    #endif /* ADC_CR2_CFG */
388
 
389
    /* Reset register SMPR1 */
390
    /* Note: On STM32L1, ADC channels 27, 28, 29, 30, 31 are not available    */
391
    /*       on all devices: only on STM32L1 Cat.4 and Cat.5.                 */
392
    #if defined(ADC_SMPR0_SMP31)
393
    CLEAR_BIT(ADCx->SMPR1,
394
              (  ADC_SMPR1_SMP29 | ADC_SMPR1_SMP28 | ADC_SMPR1_SMP27
395
               | ADC_SMPR1_SMP26 | ADC_SMPR1_SMP25 | ADC_SMPR1_SMP24
396
               | ADC_SMPR1_SMP23 | ADC_SMPR1_SMP22 | ADC_SMPR1_SMP21
397
               | ADC_SMPR1_SMP20                                    )
398
             );
399
    #else
400
    CLEAR_BIT(ADCx->SMPR1,
401
              (  ADC_SMPR1_SMP26 | ADC_SMPR1_SMP25 | ADC_SMPR1_SMP24
402
               | ADC_SMPR1_SMP23 | ADC_SMPR1_SMP22 | ADC_SMPR1_SMP21
403
               | ADC_SMPR1_SMP20                                    )
404
             );
405
    #endif /* ADC_SMPR0_SMP31 */
406
 
407
    /* Reset register SMPR2 */
408
    CLEAR_BIT(ADCx->SMPR2,
409
              (  ADC_SMPR2_SMP19 | ADC_SMPR2_SMP18 | ADC_SMPR2_SMP17
410
               | ADC_SMPR2_SMP16 | ADC_SMPR2_SMP15 | ADC_SMPR2_SMP14
411
               | ADC_SMPR2_SMP13 | ADC_SMPR2_SMP12 | ADC_SMPR2_SMP11
412
               | ADC_SMPR2_SMP10                                    )
413
             );
414
 
415
    /* Reset register SMPR3 */
416
    CLEAR_BIT(ADCx->SMPR3,
417
              (  ADC_SMPR3_SMP9 | ADC_SMPR3_SMP8 | ADC_SMPR3_SMP7
418
               | ADC_SMPR3_SMP6 | ADC_SMPR3_SMP5 | ADC_SMPR3_SMP4
419
               | ADC_SMPR3_SMP3 | ADC_SMPR3_SMP2 | ADC_SMPR3_SMP1
420
               | ADC_SMPR3_SMP0                                  )
421
             );
422
 
423
    #if defined(ADC_SMPR0_SMP31)
424
    /* Reset register SMPR0 */
425
    CLEAR_BIT(ADCx->SMPR0, (ADC_SMPR0_SMP31 | ADC_SMPR0_SMP30));
426
    #endif /* ADC_SMPR0_SMP31 */
427
 
428
    /* Reset register JOFR1 */
429
    CLEAR_BIT(ADCx->JOFR1, ADC_JOFR1_JOFFSET1);
430
    /* Reset register JOFR2 */
431
    CLEAR_BIT(ADCx->JOFR2, ADC_JOFR2_JOFFSET2);
432
    /* Reset register JOFR3 */
433
    CLEAR_BIT(ADCx->JOFR3, ADC_JOFR3_JOFFSET3);
434
    /* Reset register JOFR4 */
435
    CLEAR_BIT(ADCx->JOFR4, ADC_JOFR4_JOFFSET4);
436
 
437
    /* Reset register HTR */
438
    SET_BIT(ADCx->HTR, ADC_HTR_HT);
439
    /* Reset register LTR */
440
    CLEAR_BIT(ADCx->LTR, ADC_LTR_LT);
441
 
442
    /* Reset register SQR1 */
443
    CLEAR_BIT(ADCx->SQR1,
444
              (  ADC_SQR1_L
445
    #if defined(ADC_SQR1_SQ28)
446
               | ADC_SQR1_SQ28 | ADC_SQR1_SQ27
447
    #endif
448
               | ADC_SQR1_SQ26 | ADC_SQR1_SQ25)
449
             );
450
 
451
    /* Reset register SQR2 */
452
    CLEAR_BIT(ADCx->SQR2,
453
              (  ADC_SQR2_SQ24 | ADC_SQR2_SQ23 | ADC_SQR2_SQ22
454
               | ADC_SQR2_SQ21 | ADC_SQR2_SQ20 | ADC_SQR2_SQ19)
455
             );
456
 
457
    /* Reset register SQR3 */
458
    CLEAR_BIT(ADCx->SQR3,
459
              (  ADC_SQR3_SQ18 | ADC_SQR3_SQ17 | ADC_SQR3_SQ16
460
               | ADC_SQR3_SQ15 | ADC_SQR3_SQ14 | ADC_SQR3_SQ13)
461
             );
462
 
463
    /* Reset register SQR4 */
464
    CLEAR_BIT(ADCx->SQR4,
465
              (  ADC_SQR4_SQ12 | ADC_SQR4_SQ11 | ADC_SQR4_SQ10
466
               | ADC_SQR4_SQ9  | ADC_SQR4_SQ8  | ADC_SQR4_SQ7 )
467
             );
468
 
469
    /* Reset register SQR5 */
470
    CLEAR_BIT(ADCx->SQR5,
471
              (  ADC_SQR5_SQ6 | ADC_SQR5_SQ5 | ADC_SQR5_SQ4
472
               | ADC_SQR5_SQ3 | ADC_SQR5_SQ2 | ADC_SQR5_SQ1 )
473
             );
474
 
475
 
476
    /* Reset register JSQR */
477
    CLEAR_BIT(ADCx->JSQR,
478
              (  ADC_JSQR_JL
479
               | ADC_JSQR_JSQ4 | ADC_JSQR_JSQ3
480
               | ADC_JSQR_JSQ2 | ADC_JSQR_JSQ1  )
481
             );
482
 
483
    /* Reset register DR */
484
    /* bits in access mode read only, no direct reset applicable */
485
 
486
    /* Reset registers JDR1, JDR2, JDR3, JDR4 */
487
    /* bits in access mode read only, no direct reset applicable */
488
 
489
    /* Reset register CCR */
490
    CLEAR_BIT(ADC->CCR, ADC_CCR_TSVREFE | ADC_CCR_ADCPRE);
491
  }
492
 
493
  return status;
494
}
495
 
496
/**
497
  * @brief  Initialize some features of ADC instance.
498
  * @note   These parameters have an impact on ADC scope: ADC instance.
499
  *         Affects both group regular and group injected (availability
500
  *         of ADC group injected depends on STM32 families).
501
  *         Refer to corresponding unitary functions into
502
  *         @ref ADC_LL_EF_Configuration_ADC_Instance .
503
  * @note   The setting of these parameters by function @ref LL_ADC_Init()
504
  *         is conditioned to ADC state:
505
  *         ADC instance must be disabled.
506
  *         This condition is applied to all ADC features, for efficiency
507
  *         and compatibility over all STM32 families. However, the different
508
  *         features can be set under different ADC state conditions
509
  *         (setting possible with ADC enabled without conversion on going,
510
  *         ADC enabled with conversion on going, ...)
511
  *         Each feature can be updated afterwards with a unitary function
512
  *         and potentially with ADC in a different state than disabled,
513
  *         refer to description of each function for setting
514
  *         conditioned to ADC state.
515
  * @note   After using this function, some other features must be configured
516
  *         using LL unitary functions.
517
  *         The minimum configuration remaining to be done is:
518
  *          - Set ADC group regular or group injected sequencer:
519
  *            map channel on the selected sequencer rank.
520
  *            Refer to function @ref LL_ADC_REG_SetSequencerRanks().
521
  *          - Set ADC channel sampling time
522
  *            Refer to function LL_ADC_SetChannelSamplingTime();
523
  * @param  ADCx ADC instance
524
  * @param  ADC_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
525
  * @retval An ErrorStatus enumeration value:
526
  *          - SUCCESS: ADC registers are initialized
527
  *          - ERROR: ADC registers are not initialized
528
  */
529
ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct)
530
{
531
  ErrorStatus status = SUCCESS;
532
 
533
  /* Check the parameters */
534
  assert_param(IS_ADC_ALL_INSTANCE(ADCx));
535
 
536
  assert_param(IS_LL_ADC_RESOLUTION(ADC_InitStruct->Resolution));
537
  assert_param(IS_LL_ADC_DATA_ALIGN(ADC_InitStruct->DataAlignment));
538
  /* Note: On STM32L1, low power feature is set by concatenating              */
539
  /*       values of @ref ADC_LL_EC_LP_MODE_AUTOWAIT                          */
540
  /*       and @ref ADC_LL_EC_LP_MODE_AUTOPOWEROFF.                           */
541
  /*       Check of the parameter is done for each of group of values,        */
542
  /*       by excluding the other group of values.                            */
543
  assert_param(IS_LL_ADC_LOW_POWER_AUTOWAIT(ADC_InitStruct->LowPowerMode & ~(ADC_CR1_PDI | ADC_CR1_PDD)));
544
  assert_param(IS_LL_ADC_LOW_POWER_AUTOPOWEROFF(ADC_InitStruct->LowPowerMode & ~(ADC_CR2_DELS)));
545
  assert_param(IS_LL_ADC_SCAN_SELECTION(ADC_InitStruct->SequencersScanMode));
546
 
547
  /* Note: Hardware constraint (refer to description of this function):       */
548
  /*       ADC instance must be disabled.                                     */
549
  if(LL_ADC_IsEnabled(ADCx) == 0U)
550
  {
551
    /* Configuration of ADC hierarchical scope:                               */
552
    /*  - ADC instance                                                        */
553
    /*    - Set ADC data resolution                                           */
554
    /*    - Set ADC conversion data alignment                                 */
555
    /*    - Set ADC low power mode                                            */
556
    MODIFY_REG(ADCx->CR1,
557
                 ADC_CR1_RES
558
               | ADC_CR1_PDI
559
               | ADC_CR1_PDD
560
               | ADC_CR1_SCAN
561
              ,
562
                 ADC_InitStruct->Resolution
563
               | (ADC_InitStruct->LowPowerMode & (ADC_CR1_PDI | ADC_CR1_PDD))
564
               | ADC_InitStruct->SequencersScanMode
565
              );
566
 
567
    MODIFY_REG(ADCx->CR2,
568
                 ADC_CR2_ALIGN
569
               | ADC_CR2_DELS
570
              ,
571
                 ADC_InitStruct->DataAlignment
572
               | (ADC_InitStruct->LowPowerMode & ADC_CR2_DELS)
573
              );
574
 
575
  }
576
  else
577
  {
578
    /* Initialization error: ADC instance is not disabled. */
579
    status = ERROR;
580
  }
581
  return status;
582
}
583
 
584
/**
585
  * @brief  Set each @ref LL_ADC_InitTypeDef field to default value.
586
  * @param  ADC_InitStruct Pointer to a @ref LL_ADC_InitTypeDef structure
587
  *                        whose fields will be set to default values.
588
  * @retval None
589
  */
590
void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct)
591
{
592
  /* Set ADC_InitStruct fields to default values */
593
  /* Set fields of ADC instance */
594
  ADC_InitStruct->Resolution    = LL_ADC_RESOLUTION_12B;
595
  ADC_InitStruct->DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
596
  ADC_InitStruct->LowPowerMode  = (LL_ADC_LP_AUTOWAIT_NONE | LL_ADC_LP_AUTOPOWEROFF_NONE);
597
 
598
  /* Enable scan mode to have a generic behavior with ADC of other            */
599
  /* STM32 families, without this setting available:                          */
600
  /* ADC group regular sequencer and ADC group injected sequencer depend      */
601
  /* only of their own configuration.                                         */
602
  ADC_InitStruct->SequencersScanMode      = LL_ADC_SEQ_SCAN_ENABLE;
603
 
604
}
605
 
606
/**
607
  * @brief  Initialize some features of ADC group regular.
608
  * @note   These parameters have an impact on ADC scope: ADC group regular.
609
  *         Refer to corresponding unitary functions into
610
  *         @ref ADC_LL_EF_Configuration_ADC_Group_Regular
611
  *         (functions with prefix "REG").
612
  * @note   The setting of these parameters by function @ref LL_ADC_Init()
613
  *         is conditioned to ADC state:
614
  *         ADC instance must be disabled.
615
  *         This condition is applied to all ADC features, for efficiency
616
  *         and compatibility over all STM32 families. However, the different
617
  *         features can be set under different ADC state conditions
618
  *         (setting possible with ADC enabled without conversion on going,
619
  *         ADC enabled with conversion on going, ...)
620
  *         Each feature can be updated afterwards with a unitary function
621
  *         and potentially with ADC in a different state than disabled,
622
  *         refer to description of each function for setting
623
  *         conditioned to ADC state.
624
  * @note   After using this function, other features must be configured
625
  *         using LL unitary functions.
626
  *         The minimum configuration remaining to be done is:
627
  *          - Set ADC group regular or group injected sequencer:
628
  *            map channel on the selected sequencer rank.
629
  *            Refer to function @ref LL_ADC_REG_SetSequencerRanks().
630
  *          - Set ADC channel sampling time
631
  *            Refer to function LL_ADC_SetChannelSamplingTime();
632
  * @param  ADCx ADC instance
633
  * @param  ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
634
  * @retval An ErrorStatus enumeration value:
635
  *          - SUCCESS: ADC registers are initialized
636
  *          - ERROR: ADC registers are not initialized
637
  */
638
ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
639
{
640
  ErrorStatus status = SUCCESS;
641
 
642
  /* Check the parameters */
643
  assert_param(IS_ADC_ALL_INSTANCE(ADCx));
644
  assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADC_REG_InitStruct->TriggerSource));
645
  assert_param(IS_LL_ADC_REG_SEQ_SCAN_LENGTH(ADC_REG_InitStruct->SequencerLength));
646
  if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
647
  {
648
    assert_param(IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(ADC_REG_InitStruct->SequencerDiscont));
649
  }
650
  assert_param(IS_LL_ADC_REG_CONTINUOUS_MODE(ADC_REG_InitStruct->ContinuousMode));
651
  assert_param(IS_LL_ADC_REG_DMA_TRANSFER(ADC_REG_InitStruct->DMATransfer));
61 mjames 652
 
653
  /* ADC group regular continuous mode and discontinuous mode                 */
654
  /* can not be enabled simultenaeously                                       */
655
  assert_param((ADC_REG_InitStruct->ContinuousMode == LL_ADC_REG_CONV_SINGLE)
656
               || (ADC_REG_InitStruct->SequencerDiscont == LL_ADC_REG_SEQ_DISCONT_DISABLE));
657
 
56 mjames 658
  /* Note: Hardware constraint (refer to description of this function):       */
659
  /*       ADC instance must be disabled.                                     */
660
  if(LL_ADC_IsEnabled(ADCx) == 0U)
661
  {
662
    /* Configuration of ADC hierarchical scope:                               */
663
    /*  - ADC group regular                                                   */
664
    /*    - Set ADC group regular trigger source                              */
665
    /*    - Set ADC group regular sequencer length                            */
666
    /*    - Set ADC group regular sequencer discontinuous mode                */
667
    /*    - Set ADC group regular continuous mode                             */
668
    /*    - Set ADC group regular conversion data transfer: no transfer or    */
669
    /*      transfer by DMA, and DMA requests mode                            */
670
    /* Note: On this STM32 serie, ADC trigger edge is set when starting       */
671
    /*       ADC conversion.                                                  */
672
    /*       Refer to function @ref LL_ADC_REG_StartConversionExtTrig().      */
673
    if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
674
    {
675
      MODIFY_REG(ADCx->CR1,
676
                   ADC_CR1_DISCEN
677
                 | ADC_CR1_DISCNUM
678
                ,
679
                   ADC_REG_InitStruct->SequencerLength
680
                 | ADC_REG_InitStruct->SequencerDiscont
681
                );
682
    }
683
    else
684
    {
685
      MODIFY_REG(ADCx->CR1,
686
                   ADC_CR1_DISCEN
687
                 | ADC_CR1_DISCNUM
688
                ,
689
                   ADC_REG_InitStruct->SequencerLength
690
                 | LL_ADC_REG_SEQ_DISCONT_DISABLE
691
                );
692
    }
693
 
694
    MODIFY_REG(ADCx->CR2,
695
                 ADC_CR2_EXTSEL
696
               | ADC_CR2_EXTEN
697
               | ADC_CR2_CONT
698
               | ADC_CR2_DMA
699
               | ADC_CR2_DDS
700
              ,
701
                (ADC_REG_InitStruct->TriggerSource & ADC_CR2_EXTSEL)
702
               | ADC_REG_InitStruct->ContinuousMode
703
               | ADC_REG_InitStruct->DMATransfer
704
              );
705
 
706
    /* Set ADC group regular sequencer length and scan direction */
707
    /* Note: Hardware constraint (refer to description of this function):     */
708
    /* Note: If ADC instance feature scan mode is disabled                    */
709
    /*       (refer to  ADC instance initialization structure                 */
710
    /*       parameter @ref SequencersScanMode                                */
711
    /*       or function @ref LL_ADC_SetSequencersScanMode() ),               */
712
    /*       this parameter is discarded.                                     */
713
    LL_ADC_REG_SetSequencerLength(ADCx, ADC_REG_InitStruct->SequencerLength);
714
  }
715
  else
716
  {
717
    /* Initialization error: ADC instance is not disabled. */
718
    status = ERROR;
719
  }
720
  return status;
721
}
722
 
723
/**
724
  * @brief  Set each @ref LL_ADC_REG_InitTypeDef field to default value.
725
  * @param  ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
726
  *                            whose fields will be set to default values.
727
  * @retval None
728
  */
729
void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
730
{
731
  /* Set ADC_REG_InitStruct fields to default values */
732
  /* Set fields of ADC group regular */
733
  /* Note: On this STM32 serie, ADC trigger edge is set when starting         */
734
  /*       ADC conversion.                                                    */
735
  /*       Refer to function @ref LL_ADC_REG_StartConversionExtTrig().        */
736
  ADC_REG_InitStruct->TriggerSource    = LL_ADC_REG_TRIG_SOFTWARE;
737
  ADC_REG_InitStruct->SequencerLength  = LL_ADC_REG_SEQ_SCAN_DISABLE;
738
  ADC_REG_InitStruct->SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE;
739
  ADC_REG_InitStruct->ContinuousMode   = LL_ADC_REG_CONV_SINGLE;
740
  ADC_REG_InitStruct->DMATransfer      = LL_ADC_REG_DMA_TRANSFER_NONE;
741
}
742
 
743
/**
744
  * @brief  Initialize some features of ADC group injected.
745
  * @note   These parameters have an impact on ADC scope: ADC group injected.
746
  *         Refer to corresponding unitary functions into
747
  *         @ref ADC_LL_EF_Configuration_ADC_Group_Regular
748
  *         (functions with prefix "INJ").
749
  * @note   The setting of these parameters by function @ref LL_ADC_Init()
750
  *         is conditioned to ADC state:
751
  *         ADC instance must be disabled.
752
  *         This condition is applied to all ADC features, for efficiency
753
  *         and compatibility over all STM32 families. However, the different
754
  *         features can be set under different ADC state conditions
755
  *         (setting possible with ADC enabled without conversion on going,
756
  *         ADC enabled with conversion on going, ...)
757
  *         Each feature can be updated afterwards with a unitary function
758
  *         and potentially with ADC in a different state than disabled,
759
  *         refer to description of each function for setting
760
  *         conditioned to ADC state.
761
  * @note   After using this function, other features must be configured
762
  *         using LL unitary functions.
763
  *         The minimum configuration remaining to be done is:
764
  *          - Set ADC group injected sequencer:
765
  *            map channel on the selected sequencer rank.
766
  *            Refer to function @ref LL_ADC_INJ_SetSequencerRanks().
767
  *          - Set ADC channel sampling time
768
  *            Refer to function LL_ADC_SetChannelSamplingTime();
769
  * @param  ADCx ADC instance
770
  * @param  ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
771
  * @retval An ErrorStatus enumeration value:
772
  *          - SUCCESS: ADC registers are initialized
773
  *          - ERROR: ADC registers are not initialized
774
  */
775
ErrorStatus LL_ADC_INJ_Init(ADC_TypeDef *ADCx, LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
776
{
777
  ErrorStatus status = SUCCESS;
778
 
779
  /* Check the parameters */
780
  assert_param(IS_ADC_ALL_INSTANCE(ADCx));
781
  assert_param(IS_LL_ADC_INJ_TRIG_SOURCE(ADC_INJ_InitStruct->TriggerSource));
782
  assert_param(IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(ADC_INJ_InitStruct->SequencerLength));
783
  if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_INJ_SEQ_SCAN_DISABLE)
784
  {
785
    assert_param(IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(ADC_INJ_InitStruct->SequencerDiscont));
786
  }
787
  assert_param(IS_LL_ADC_INJ_TRIG_AUTO(ADC_INJ_InitStruct->TrigAuto));
788
 
789
  /* Note: Hardware constraint (refer to description of this function):       */
790
  /*       ADC instance must be disabled.                                     */
791
  if(LL_ADC_IsEnabled(ADCx) == 0U)
792
  {
793
    /* Configuration of ADC hierarchical scope:                               */
794
    /*  - ADC group injected                                                  */
795
    /*    - Set ADC group injected trigger source                             */
796
    /*    - Set ADC group injected sequencer length                           */
797
    /*    - Set ADC group injected sequencer discontinuous mode               */
798
    /*    - Set ADC group injected conversion trigger: independent or         */
799
    /*      from ADC group regular                                            */
800
    /* Note: On this STM32 serie, ADC trigger edge is set when starting       */
801
    /*       ADC conversion.                                                  */
802
    /*       Refer to function @ref LL_ADC_INJ_StartConversionExtTrig().      */
803
    if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
804
    {
805
      MODIFY_REG(ADCx->CR1,
806
                   ADC_CR1_JDISCEN
807
                 | ADC_CR1_JAUTO
808
                ,
809
                   ADC_INJ_InitStruct->SequencerDiscont
810
                 | ADC_INJ_InitStruct->TrigAuto
811
                );
812
    }
813
    else
814
    {
815
      MODIFY_REG(ADCx->CR1,
816
                   ADC_CR1_JDISCEN
817
                 | ADC_CR1_JAUTO
818
                ,
819
                   LL_ADC_REG_SEQ_DISCONT_DISABLE
820
                 | ADC_INJ_InitStruct->TrigAuto
821
                );
822
    }
823
 
824
    MODIFY_REG(ADCx->CR2,
825
                 ADC_CR2_JEXTSEL
826
               | ADC_CR2_JEXTEN
827
              ,
828
                (ADC_INJ_InitStruct->TriggerSource & ADC_CR2_JEXTSEL)
829
              );
830
 
831
    /* Note: Hardware constraint (refer to description of this function):     */
832
    /* Note: If ADC instance feature scan mode is disabled                    */
833
    /*       (refer to  ADC instance initialization structure                 */
834
    /*       parameter @ref SequencersScanMode                                */
835
    /*       or function @ref LL_ADC_SetSequencersScanMode() ),               */
836
    /*       this parameter is discarded.                                     */
837
    LL_ADC_INJ_SetSequencerLength(ADCx, ADC_INJ_InitStruct->SequencerLength);
838
  }
839
  else
840
  {
841
    /* Initialization error: ADC instance is not disabled. */
842
    status = ERROR;
843
  }
844
  return status;
845
}
846
 
847
/**
848
  * @brief  Set each @ref LL_ADC_INJ_InitTypeDef field to default value.
849
  * @param  ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
850
  *                            whose fields will be set to default values.
851
  * @retval None
852
  */
853
void LL_ADC_INJ_StructInit(LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
854
{
855
  /* Set ADC_INJ_InitStruct fields to default values */
856
  /* Set fields of ADC group injected */
857
  ADC_INJ_InitStruct->TriggerSource    = LL_ADC_INJ_TRIG_SOFTWARE;
858
  ADC_INJ_InitStruct->SequencerLength  = LL_ADC_INJ_SEQ_SCAN_DISABLE;
859
  ADC_INJ_InitStruct->SequencerDiscont = LL_ADC_INJ_SEQ_DISCONT_DISABLE;
860
  ADC_INJ_InitStruct->TrigAuto         = LL_ADC_INJ_TRIG_INDEPENDENT;
861
}
862
 
863
/**
864
  * @}
865
  */
866
 
867
/**
868
  * @}
869
  */
870
 
871
/**
872
  * @}
873
  */
874
 
875
#endif /* ADC1 */
876
 
877
/**
878
  * @}
879
  */
880
 
881
#endif /* USE_FULL_LL_DRIVER */
882
 
883
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/