Subversion Repositories EngineBay2

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 28
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32l1xx_hal_adc_ex.c
3
  * @file    stm32l1xx_hal_adc_ex.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @version V1.2.0
-
 
6
  * @date    01-July-2016
-
 
7
  * @brief   This file provides firmware functions to manage the following
5
  * @brief   This file provides firmware functions to manage the following
8
  *          functionalities of the Analog to Digital Convertor (ADC)
6
  *          functionalities of the Analog to Digital Convertor (ADC)
9
  *          peripheral:
7
  *          peripheral:
10
  *           + Operation functions
8
  *           + Operation functions
11
  *             ++ Start, stop, get result of conversions of injected
9
  *             ++ Start, stop, get result of conversions of injected
12
  *                group, using 2 possible modes: polling, interruption.
10
  *                group, using 2 possible modes: polling, interruption.
13
  *             ++ Calibration (ADC automatic self-calibration)
-
 
14
  *           + Control functions
11
  *           + Control functions
15
  *             ++ Channels configuration on injected group
12
  *             ++ Channels configuration on injected group
16
  *          Other functions (generic functions) are available in file
13
  *          Other functions (generic functions) are available in file
17
  *          "stm32l1xx_hal_adc.c".
14
  *          "stm32l1xx_hal_adc.c".
18
  *
15
  *
Line 23... Line 20...
23
  [..]
20
  [..]
24
  @endverbatim
21
  @endverbatim
25
  ******************************************************************************
22
  ******************************************************************************
26
  * @attention
23
  * @attention
27
  *
24
  *
28
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
25
  * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
-
 
26
  * All rights reserved.</center></h2>
29
  *
27
  *
30
  * Redistribution and use in source and binary forms, with or without modification,
28
  * This software component is licensed by ST under BSD 3-Clause license,
31
  * are permitted provided that the following conditions are met:
29
  * the "License"; You may not use this file except in compliance with the
32
  *   1. Redistributions of source code must retain the above copyright notice,
-
 
33
  *      this list of conditions and the following disclaimer.
-
 
34
  *   2. Redistributions in binary form must reproduce the above copyright notice,
-
 
35
  *      this list of conditions and the following disclaimer in the documentation
-
 
36
  *      and/or other materials provided with the distribution.
30
  * License. You may obtain a copy of the License at:
37
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-
 
38
  *      may be used to endorse or promote products derived from this software
31
  *                        opensource.org/licenses/BSD-3-Clause
39
  *      without specific prior written permission.
-
 
40
  *
-
 
41
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-
 
42
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-
 
43
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-
 
44
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-
 
45
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-
 
46
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-
 
47
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-
 
48
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-
 
49
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-
 
50
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
51
  *
32
  *
52
  ******************************************************************************
33
  ******************************************************************************
53
  */
34
  */
54
 
35
 
55
/* Includes ------------------------------------------------------------------*/
36
/* Includes ------------------------------------------------------------------*/
Line 73... Line 54...
73
  */
54
  */
74
 
55
 
75
  /* ADC conversion cycles (unit: ADC clock cycles)                           */
56
  /* ADC conversion cycles (unit: ADC clock cycles)                           */
76
  /* (selected sampling time + conversion time of 12 ADC clock cycles, with   */
57
  /* (selected sampling time + conversion time of 12 ADC clock cycles, with   */
77
  /* resolution 12 bits)                                                      */
58
  /* resolution 12 bits)                                                      */
78
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_4CYCLE5   ((uint32_t) 16)
59
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_4CYCLE5   ( 16U)
79
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_9CYCLES   ((uint32_t) 21)
60
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_9CYCLES   ( 21U)
80
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_16CYCLES  ((uint32_t) 28)
61
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_16CYCLES  ( 28U)
81
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_24CYCLES  ((uint32_t) 36)
62
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_24CYCLES  ( 36U)
82
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_48CYCLES  ((uint32_t) 60)
63
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_48CYCLES  ( 60U)
83
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_96CYCLES  ((uint32_t)108)
64
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_96CYCLES  (108U)
84
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_192CYCLES ((uint32_t)204)
65
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_192CYCLES (204U)
85
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_384CYCLES ((uint32_t)396)
66
  #define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_384CYCLES (396U)
86
 
67
 
87
  /* Delay for temperature sensor stabilization time.                         */
68
  /* Delay for temperature sensor stabilization time.                         */
88
  /* Maximum delay is 10us (refer to device datasheet, parameter tSTART).     */
69
  /* Maximum delay is 10us (refer to device datasheet, parameter tSTART).     */
89
  /* Unit: us                                                                 */
70
  /* Unit: us                                                                 */
90
  #define ADC_TEMPSENSOR_DELAY_US         ((uint32_t) 10)
71
  #define ADC_TEMPSENSOR_DELAY_US         (10U)
91
 
72
 
92
/**
73
/**
93
  * @}
74
  * @}
94
  */
75
  */
95
 
76
 
Line 122... Line 103...
122
  */
103
  */
123
 
104
 
124
/**
105
/**
125
  * @brief  Enables ADC, starts conversion of injected group.
106
  * @brief  Enables ADC, starts conversion of injected group.
126
  *         Interruptions enabled in this function: None.
107
  *         Interruptions enabled in this function: None.
127
  * @param  hadc: ADC handle
108
  * @param  hadc ADC handle
128
  * @retval HAL status
109
  * @retval HAL status
129
  */
110
  */
130
HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
111
HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
131
{
112
{
132
  HAL_StatusTypeDef tmp_hal_status = HAL_OK;
113
  HAL_StatusTypeDef tmp_hal_status = HAL_OK;
Line 194... Line 175...
194
  *         regular group, function HAL_ADC_Stop must be used to stop both
175
  *         regular group, function HAL_ADC_Stop must be used to stop both
195
  *         injected and regular groups, and disable the ADC.
176
  *         injected and regular groups, and disable the ADC.
196
  * @note   If injected group mode auto-injection is enabled,
177
  * @note   If injected group mode auto-injection is enabled,
197
  *         function HAL_ADC_Stop must be used.
178
  *         function HAL_ADC_Stop must be used.
198
  * @note   In case of auto-injection mode, HAL_ADC_Stop must be used.
179
  * @note   In case of auto-injection mode, HAL_ADC_Stop must be used.
199
  * @param  hadc: ADC handle
180
  * @param  hadc ADC handle
200
  * @retval None
181
  * @retval None
201
  */
182
  */
202
HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc)
183
HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc)
203
{
184
{
204
  HAL_StatusTypeDef tmp_hal_status = HAL_OK;
185
  HAL_StatusTypeDef tmp_hal_status = HAL_OK;
Line 246... Line 227...
246
  return tmp_hal_status;
227
  return tmp_hal_status;
247
}
228
}
248
 
229
 
249
/**
230
/**
250
  * @brief  Wait for injected group conversion to be completed.
231
  * @brief  Wait for injected group conversion to be completed.
251
  * @param  hadc: ADC handle
232
  * @param  hadc ADC handle
252
  * @param  Timeout: Timeout value in millisecond.
233
  * @param  Timeout Timeout value in millisecond.
253
  * @retval HAL status
234
  * @retval HAL status
254
  */
235
  */
255
HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
236
HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
256
{
237
{
257
  uint32_t tickstart;
238
  uint32_t tickstart;
Line 382... Line 363...
382
 
363
 
383
/**
364
/**
384
  * @brief  Enables ADC, starts conversion of injected group with interruption.
365
  * @brief  Enables ADC, starts conversion of injected group with interruption.
385
  *          - JEOC (end of conversion of injected group)
366
  *          - JEOC (end of conversion of injected group)
386
  *         Each of these interruptions has its dedicated callback function.
367
  *         Each of these interruptions has its dedicated callback function.
387
  * @param  hadc: ADC handle
368
  * @param  hadc ADC handle
388
  * @retval HAL status.
369
  * @retval HAL status.
389
  */
370
  */
390
HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
371
HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
391
{
372
{
392
  HAL_StatusTypeDef tmp_hal_status = HAL_OK;
373
  HAL_StatusTypeDef tmp_hal_status = HAL_OK;
Line 457... Line 438...
457
  * @note   If ADC must be disabled and if conversion is on going on
438
  * @note   If ADC must be disabled and if conversion is on going on
458
  *         regular group, function HAL_ADC_Stop must be used to stop both
439
  *         regular group, function HAL_ADC_Stop must be used to stop both
459
  *         injected and regular groups, and disable the ADC.
440
  *         injected and regular groups, and disable the ADC.
460
  * @note   If injected group mode auto-injection is enabled,
441
  * @note   If injected group mode auto-injection is enabled,
461
  *         function HAL_ADC_Stop must be used.
442
  *         function HAL_ADC_Stop must be used.
462
  * @param  hadc: ADC handle
443
  * @param  hadc ADC handle
463
  * @retval None
444
  * @retval None
464
  */
445
  */
465
HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
446
HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
466
{
447
{
467
  HAL_StatusTypeDef tmp_hal_status = HAL_OK;
448
  HAL_StatusTypeDef tmp_hal_status = HAL_OK;
Line 529... Line 510...
529
  *         (feature low power auto-wait, not available on all STM32 families).
510
  *         (feature low power auto-wait, not available on all STM32 families).
530
  *         To clear this flag, either use function:
511
  *         To clear this flag, either use function:
531
  *         in programming model IT: @ref HAL_ADC_IRQHandler(), in programming
512
  *         in programming model IT: @ref HAL_ADC_IRQHandler(), in programming
532
  *         model polling: @ref HAL_ADCEx_InjectedPollForConversion()
513
  *         model polling: @ref HAL_ADCEx_InjectedPollForConversion()
533
  *         or @ref __HAL_ADC_CLEAR_FLAG(&hadc, ADC_FLAG_JEOS).
514
  *         or @ref __HAL_ADC_CLEAR_FLAG(&hadc, ADC_FLAG_JEOS).
534
  * @param  hadc: ADC handle
515
  * @param  hadc ADC handle
535
  * @param  InjectedRank: the converted ADC injected rank.
516
  * @param  InjectedRank the converted ADC injected rank.
536
  *          This parameter can be one of the following values:
517
  *          This parameter can be one of the following values:
537
  *            @arg ADC_INJECTED_RANK_1: Injected Channel1 selected
518
  *            @arg ADC_INJECTED_RANK_1: Injected Channel1 selected
538
  *            @arg ADC_INJECTED_RANK_2: Injected Channel2 selected
519
  *            @arg ADC_INJECTED_RANK_2: Injected Channel2 selected
539
  *            @arg ADC_INJECTED_RANK_3: Injected Channel3 selected
520
  *            @arg ADC_INJECTED_RANK_3: Injected Channel3 selected
540
  *            @arg ADC_INJECTED_RANK_4: Injected Channel4 selected
521
  *            @arg ADC_INJECTED_RANK_4: Injected Channel4 selected
Line 570... Line 551...
570
  return tmp_jdr;
551
  return tmp_jdr;
571
}
552
}
572
 
553
 
573
/**
554
/**
574
  * @brief  Injected conversion complete callback in non blocking mode
555
  * @brief  Injected conversion complete callback in non blocking mode
575
  * @param  hadc: ADC handle
556
  * @param  hadc ADC handle
576
  * @retval None
557
  * @retval None
577
  */
558
  */
578
__weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc)
559
__weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc)
579
{
560
{
580
  /* Prevent unused argument(s) compilation warning */
561
  /* Prevent unused argument(s) compilation warning */
Line 610... Line 591...
610
  *         This function initializes injected group, following calls to this
591
  *         This function initializes injected group, following calls to this
611
  *         function can be used to reconfigure some parameters of structure
592
  *         function can be used to reconfigure some parameters of structure
612
  *         "ADC_InjectionConfTypeDef" on the fly, without reseting the ADC.
593
  *         "ADC_InjectionConfTypeDef" on the fly, without reseting the ADC.
613
  *         The setting of these parameters is conditioned to ADC state:
594
  *         The setting of these parameters is conditioned to ADC state:
614
  *         this function must be called when ADC is not under conversion.
595
  *         this function must be called when ADC is not under conversion.
615
  * @param  hadc: ADC handle
596
  * @param  hadc ADC handle
616
  * @param  sConfigInjected: Structure of ADC injected group and ADC channel for
597
  * @param  sConfigInjected Structure of ADC injected group and ADC channel for
617
  *         injected group.
598
  *         injected group.
618
  * @retval None
599
  * @retval None
619
  */
600
  */
620
HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_InjectionConfTypeDef* sConfigInjected)
601
HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_InjectionConfTypeDef* sConfigInjected)
621
{  
602
{