my fork

Dependents:   Nucleo_blueNRG

Fork of mbed by mbed official

Committer:
filartrix
Date:
Wed Apr 08 14:12:53 2015 +0000
Revision:
97:4298809c7c9e
Parent:
90:cb3d968589d8
First reale BlueNRG module for nucleo 401 board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 90:cb3d968589d8 1 /**
Kojto 90:cb3d968589d8 2 ******************************************************************************
Kojto 90:cb3d968589d8 3 * @file stm32l1xx_hal_adc_ex.h
Kojto 90:cb3d968589d8 4 * @author MCD Application Team
Kojto 90:cb3d968589d8 5 * @version V1.0.0
Kojto 90:cb3d968589d8 6 * @date 5-September-2014
Kojto 90:cb3d968589d8 7 * @brief Header file of ADC HAL Extension module.
Kojto 90:cb3d968589d8 8 ******************************************************************************
Kojto 90:cb3d968589d8 9 * @attention
Kojto 90:cb3d968589d8 10 *
Kojto 90:cb3d968589d8 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
Kojto 90:cb3d968589d8 12 *
Kojto 90:cb3d968589d8 13 * Redistribution and use in source and binary forms, with or without modification,
Kojto 90:cb3d968589d8 14 * are permitted provided that the following conditions are met:
Kojto 90:cb3d968589d8 15 * 1. Redistributions of source code must retain the above copyright notice,
Kojto 90:cb3d968589d8 16 * this list of conditions and the following disclaimer.
Kojto 90:cb3d968589d8 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
Kojto 90:cb3d968589d8 18 * this list of conditions and the following disclaimer in the documentation
Kojto 90:cb3d968589d8 19 * and/or other materials provided with the distribution.
Kojto 90:cb3d968589d8 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Kojto 90:cb3d968589d8 21 * may be used to endorse or promote products derived from this software
Kojto 90:cb3d968589d8 22 * without specific prior written permission.
Kojto 90:cb3d968589d8 23 *
Kojto 90:cb3d968589d8 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Kojto 90:cb3d968589d8 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Kojto 90:cb3d968589d8 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Kojto 90:cb3d968589d8 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Kojto 90:cb3d968589d8 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Kojto 90:cb3d968589d8 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Kojto 90:cb3d968589d8 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Kojto 90:cb3d968589d8 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Kojto 90:cb3d968589d8 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Kojto 90:cb3d968589d8 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 90:cb3d968589d8 34 *
Kojto 90:cb3d968589d8 35 ******************************************************************************
Kojto 90:cb3d968589d8 36 */
Kojto 90:cb3d968589d8 37
Kojto 90:cb3d968589d8 38 /* Define to prevent recursive inclusion -------------------------------------*/
Kojto 90:cb3d968589d8 39 #ifndef __STM32L1xx_HAL_ADC_EX_H
Kojto 90:cb3d968589d8 40 #define __STM32L1xx_HAL_ADC_EX_H
Kojto 90:cb3d968589d8 41
Kojto 90:cb3d968589d8 42 #ifdef __cplusplus
Kojto 90:cb3d968589d8 43 extern "C" {
Kojto 90:cb3d968589d8 44 #endif
Kojto 90:cb3d968589d8 45
Kojto 90:cb3d968589d8 46 /* Includes ------------------------------------------------------------------*/
Kojto 90:cb3d968589d8 47 #include "stm32l1xx_hal_def.h"
Kojto 90:cb3d968589d8 48
Kojto 90:cb3d968589d8 49 /** @addtogroup STM32L1xx_HAL_Driver
Kojto 90:cb3d968589d8 50 * @{
Kojto 90:cb3d968589d8 51 */
Kojto 90:cb3d968589d8 52
Kojto 90:cb3d968589d8 53 /** @addtogroup ADCEx
Kojto 90:cb3d968589d8 54 * @{
Kojto 90:cb3d968589d8 55 */
Kojto 90:cb3d968589d8 56
Kojto 90:cb3d968589d8 57 /* Exported types ------------------------------------------------------------*/
Kojto 90:cb3d968589d8 58 /** @defgroup ADCEx_Exported_Types ADCEx Exported Types
Kojto 90:cb3d968589d8 59 * @{
Kojto 90:cb3d968589d8 60 */
Kojto 90:cb3d968589d8 61
Kojto 90:cb3d968589d8 62 /**
Kojto 90:cb3d968589d8 63 * @brief ADC Configuration injected Channel structure definition
Kojto 90:cb3d968589d8 64 * @note Parameters of this structure are shared within 2 scopes:
Kojto 90:cb3d968589d8 65 * - Scope channel: InjectedChannel, InjectedRank, InjectedSamplingTime, InjectedOffset
Kojto 90:cb3d968589d8 66 * - Scope injected group (affects all channels of injected group): InjectedNbrOfConversion, InjectedDiscontinuousConvMode,
Kojto 90:cb3d968589d8 67 * AutoInjectedConv, ExternalTrigInjecConvEdge, ExternalTrigInjecConv.
Kojto 90:cb3d968589d8 68 * @note The setting of these parameters with function HAL_ADCEx_InjectedConfigChannel() is conditioned to ADC state.
Kojto 90:cb3d968589d8 69 * ADC state can be either:
Kojto 90:cb3d968589d8 70 * - For all parameters: ADC disabled
Kojto 90:cb3d968589d8 71 * - For all except parameters 'InjectedDiscontinuousConvMode' and 'AutoInjectedConv': ADC enabled without conversion on going on injected group.
Kojto 90:cb3d968589d8 72 * - For parameters 'ExternalTrigInjecConv' and 'ExternalTrigInjecConvEdge': ADC enabled, even with conversion on going on injected group.
Kojto 90:cb3d968589d8 73 */
Kojto 90:cb3d968589d8 74 typedef struct
Kojto 90:cb3d968589d8 75 {
Kojto 90:cb3d968589d8 76 uint32_t InjectedChannel; /*!< Selection of ADC channel to configure
Kojto 90:cb3d968589d8 77 This parameter can be a value of @ref ADC_channels
Kojto 90:cb3d968589d8 78 Note: Depending on devices, some channels may not be available on package pins. Refer to device datasheet for channels availability. */
Kojto 90:cb3d968589d8 79 uint32_t InjectedRank; /*!< Rank in the injected group sequencer
Kojto 90:cb3d968589d8 80 This parameter must be a value of @ref ADCEx_injected_rank
Kojto 90:cb3d968589d8 81 Note: In case of need to disable a channel or change order of conversion sequencer, rank containing a previous channel setting can be overwritten by the new channel setting (or parameter number of conversions can be adjusted) */
Kojto 90:cb3d968589d8 82 uint32_t InjectedSamplingTime; /*!< Sampling time value to be set for the selected channel.
Kojto 90:cb3d968589d8 83 Unit: ADC clock cycles
Kojto 90:cb3d968589d8 84 Conversion time is the addition of sampling time and processing time (12 ADC clock cycles at ADC resolution 12 bits, 11 cycles at 10 bits, 9 cycles at 8 bits, 7 cycles at 6 bits).
Kojto 90:cb3d968589d8 85 This parameter can be a value of @ref ADC_sampling_times
Kojto 90:cb3d968589d8 86 Caution: This parameter updates the parameter property of the channel, that can be used into regular and/or injected groups.
Kojto 90:cb3d968589d8 87 If this same channel has been previously configured in the other group (regular/injected), it will be updated to last setting.
Kojto 90:cb3d968589d8 88 Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor),
Kojto 90:cb3d968589d8 89 sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting)
Kojto 90:cb3d968589d8 90 Refer to device datasheet for timings values, parameters TS_vrefint, TS_temp (values rough order: 4us min). */
Kojto 90:cb3d968589d8 91 uint32_t InjectedOffset; /*!< Defines the offset to be subtracted from the raw converted data (for channels set on injected group only).
Kojto 90:cb3d968589d8 92 Offset value must be a positive number.
Kojto 90:cb3d968589d8 93 Depending of ADC resolution selected (12, 10, 8 or 6 bits),
Kojto 90:cb3d968589d8 94 this parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively. */
Kojto 90:cb3d968589d8 95 uint32_t InjectedNbrOfConversion; /*!< Specifies the number of ranks that will be converted within the injected group sequencer.
Kojto 90:cb3d968589d8 96 To use the injected group sequencer and convert several ranks, parameter 'ScanConvMode' must be enabled.
Kojto 90:cb3d968589d8 97 This parameter must be a number between Min_Data = 1 and Max_Data = 4.
Kojto 90:cb3d968589d8 98 Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
Kojto 90:cb3d968589d8 99 configure a channel on injected group can impact the configuration of other channels previously set. */
Kojto 90:cb3d968589d8 100 uint32_t InjectedDiscontinuousConvMode; /*!< Specifies whether the conversions sequence of injected group is performed in Complete-sequence/Discontinuous-sequence (main sequence subdivided in successive parts).
Kojto 90:cb3d968589d8 101 Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded.
Kojto 90:cb3d968589d8 102 Discontinuous mode can be enabled only if continuous mode is disabled. If continuous mode is enabled, this parameter setting is discarded.
Kojto 90:cb3d968589d8 103 This parameter can be set to ENABLE or DISABLE.
Kojto 90:cb3d968589d8 104 Note: For injected group, number of discontinuous ranks increment is fixed to one-by-one.
Kojto 90:cb3d968589d8 105 Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
Kojto 90:cb3d968589d8 106 configure a channel on injected group can impact the configuration of other channels previously set. */
Kojto 90:cb3d968589d8 107 uint32_t AutoInjectedConv; /*!< Enables or disables the selected ADC automatic injected group conversion after regular one
Kojto 90:cb3d968589d8 108 This parameter can be set to ENABLE or DISABLE.
Kojto 90:cb3d968589d8 109 Note: To use Automatic injected conversion, discontinuous mode must be disabled ('DiscontinuousConvMode' and 'InjectedDiscontinuousConvMode' set to DISABLE)
Kojto 90:cb3d968589d8 110 Note: To use Automatic injected conversion, injected group external triggers must be disabled ('ExternalTrigInjecConv' set to ADC_SOFTWARE_START)
Kojto 90:cb3d968589d8 111 Note: In case of DMA used with regular group: if DMA configured in normal mode (single shot) JAUTO will be stopped upon DMA transfer complete.
Kojto 90:cb3d968589d8 112 To maintain JAUTO always enabled, DMA must be configured in circular mode.
Kojto 90:cb3d968589d8 113 Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
Kojto 90:cb3d968589d8 114 configure a channel on injected group can impact the configuration of other channels previously set. */
Kojto 90:cb3d968589d8 115 uint32_t ExternalTrigInjecConv; /*!< Selects the external event used to trigger the conversion start of injected group.
Kojto 90:cb3d968589d8 116 If set to ADC_INJECTED_SOFTWARE_START, external triggers are disabled.
Kojto 90:cb3d968589d8 117 If set to external trigger source, triggering is on event rising edge.
Kojto 90:cb3d968589d8 118 This parameter can be a value of @ref ADCEx_External_trigger_source_Injected
Kojto 90:cb3d968589d8 119 Note: This parameter must be modified when ADC is disabled (before ADC start conversion or after ADC stop conversion).
Kojto 90:cb3d968589d8 120 If ADC is enabled, this parameter setting is bypassed without error reporting (as it can be the expected behaviour in case of another parameter update on the fly)
Kojto 90:cb3d968589d8 121 Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
Kojto 90:cb3d968589d8 122 configure a channel on injected group can impact the configuration of other channels previously set. */
Kojto 90:cb3d968589d8 123 uint32_t ExternalTrigInjecConvEdge; /*!< Selects the external trigger edge of injected group.
Kojto 90:cb3d968589d8 124 This parameter can be a value of @ref ADCEx_External_trigger_edge_Injected.
Kojto 90:cb3d968589d8 125 If trigger is set to ADC_INJECTED_SOFTWARE_START, this parameter is discarded.
Kojto 90:cb3d968589d8 126 Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
Kojto 90:cb3d968589d8 127 configure a channel on injected group can impact the configuration of other channels previously set. */
Kojto 90:cb3d968589d8 128 }ADC_InjectionConfTypeDef;
Kojto 90:cb3d968589d8 129 /**
Kojto 90:cb3d968589d8 130 * @}
Kojto 90:cb3d968589d8 131 */
Kojto 90:cb3d968589d8 132
Kojto 90:cb3d968589d8 133
Kojto 90:cb3d968589d8 134 /* Exported constants --------------------------------------------------------*/
Kojto 90:cb3d968589d8 135
Kojto 90:cb3d968589d8 136 /** @defgroup ADCEx_Exported_Constants ADCEx Exported Constants
Kojto 90:cb3d968589d8 137 * @{
Kojto 90:cb3d968589d8 138 */
Kojto 90:cb3d968589d8 139
Kojto 90:cb3d968589d8 140 /** @defgroup ADCEx_injected_rank ADCEx injected rank
Kojto 90:cb3d968589d8 141 * @{
Kojto 90:cb3d968589d8 142 */
Kojto 90:cb3d968589d8 143 #define ADC_INJECTED_RANK_1 ((uint32_t)0x00000001)
Kojto 90:cb3d968589d8 144 #define ADC_INJECTED_RANK_2 ((uint32_t)0x00000002)
Kojto 90:cb3d968589d8 145 #define ADC_INJECTED_RANK_3 ((uint32_t)0x00000003)
Kojto 90:cb3d968589d8 146 #define ADC_INJECTED_RANK_4 ((uint32_t)0x00000004)
Kojto 90:cb3d968589d8 147
Kojto 90:cb3d968589d8 148 #define IS_ADC_INJECTED_RANK(CHANNEL) (((CHANNEL) == ADC_INJECTED_RANK_1) || \
Kojto 90:cb3d968589d8 149 ((CHANNEL) == ADC_INJECTED_RANK_2) || \
Kojto 90:cb3d968589d8 150 ((CHANNEL) == ADC_INJECTED_RANK_3) || \
Kojto 90:cb3d968589d8 151 ((CHANNEL) == ADC_INJECTED_RANK_4) )
Kojto 90:cb3d968589d8 152 /**
Kojto 90:cb3d968589d8 153 * @}
Kojto 90:cb3d968589d8 154 */
Kojto 90:cb3d968589d8 155
Kojto 90:cb3d968589d8 156 /** @defgroup ADCEx_External_trigger_edge_Injected ADCEx External trigger edge Injected
Kojto 90:cb3d968589d8 157 * @{
Kojto 90:cb3d968589d8 158 */
Kojto 90:cb3d968589d8 159 #define ADC_EXTERNALTRIGINJECCONV_EDGE_NONE ((uint32_t)0x00000000)
Kojto 90:cb3d968589d8 160 #define ADC_EXTERNALTRIGINJECCONV_EDGE_RISING ((uint32_t)ADC_CR2_JEXTEN_0)
Kojto 90:cb3d968589d8 161 #define ADC_EXTERNALTRIGINJECCONV_EDGE_FALLING ((uint32_t)ADC_CR2_JEXTEN_1)
Kojto 90:cb3d968589d8 162 #define ADC_EXTERNALTRIGINJECCONV_EDGE_RISINGFALLING ((uint32_t)ADC_CR2_JEXTEN)
Kojto 90:cb3d968589d8 163
Kojto 90:cb3d968589d8 164 #define IS_ADC_EXTTRIGINJEC_EDGE(EDGE) (((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_NONE) || \
Kojto 90:cb3d968589d8 165 ((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_RISING) || \
Kojto 90:cb3d968589d8 166 ((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_FALLING) || \
Kojto 90:cb3d968589d8 167 ((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_RISINGFALLING) )
Kojto 90:cb3d968589d8 168 /**
Kojto 90:cb3d968589d8 169 * @}
Kojto 90:cb3d968589d8 170 */
Kojto 90:cb3d968589d8 171
Kojto 90:cb3d968589d8 172 /** @defgroup ADCEx_External_trigger_source_Injected ADCEx External trigger source Injected
Kojto 90:cb3d968589d8 173 * @{
Kojto 90:cb3d968589d8 174 */
Kojto 90:cb3d968589d8 175 /* External triggers for injected groups of ADC1 */
Kojto 90:cb3d968589d8 176 #define ADC_EXTERNALTRIGINJECCONV_T2_CC1 ADC_EXTERNALTRIGINJEC_T2_CC1
Kojto 90:cb3d968589d8 177 #define ADC_EXTERNALTRIGINJECCONV_T2_TRGO ADC_EXTERNALTRIGINJEC_T2_TRGO
Kojto 90:cb3d968589d8 178 #define ADC_EXTERNALTRIGINJECCONV_T3_CC4 ADC_EXTERNALTRIGINJEC_T3_CC4
Kojto 90:cb3d968589d8 179 #define ADC_EXTERNALTRIGINJECCONV_T4_TRGO ADC_EXTERNALTRIGINJEC_T4_TRGO
Kojto 90:cb3d968589d8 180 #define ADC_EXTERNALTRIGINJECCONV_T4_CC1 ADC_EXTERNALTRIGINJEC_T4_CC1
Kojto 90:cb3d968589d8 181 #define ADC_EXTERNALTRIGINJECCONV_T4_CC2 ADC_EXTERNALTRIGINJEC_T4_CC2
Kojto 90:cb3d968589d8 182 #define ADC_EXTERNALTRIGINJECCONV_T4_CC3 ADC_EXTERNALTRIGINJEC_T4_CC3
Kojto 90:cb3d968589d8 183 #define ADC_EXTERNALTRIGINJECCONV_T7_TRGO ADC_EXTERNALTRIGINJEC_T7_TRGO
Kojto 90:cb3d968589d8 184 #define ADC_EXTERNALTRIGINJECCONV_T9_CC1 ADC_EXTERNALTRIGINJEC_T9_CC1
Kojto 90:cb3d968589d8 185 #define ADC_EXTERNALTRIGINJECCONV_T9_TRGO ADC_EXTERNALTRIGINJEC_T9_TRGO
Kojto 90:cb3d968589d8 186 #define ADC_EXTERNALTRIGINJECCONV_T10_CC1 ADC_EXTERNALTRIGINJEC_T10_CC1
Kojto 90:cb3d968589d8 187 #define ADC_EXTERNALTRIGINJECCONV_EXT_IT15 ADC_EXTERNALTRIGINJEC_EXT_IT15
Kojto 90:cb3d968589d8 188
Kojto 90:cb3d968589d8 189 #define ADC_INJECTED_SOFTWARE_START ((uint32_t)0x00000010)
Kojto 90:cb3d968589d8 190
Kojto 90:cb3d968589d8 191 #define IS_ADC_EXTTRIGINJEC(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_CC1) || \
Kojto 90:cb3d968589d8 192 ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_TRGO) || \
Kojto 90:cb3d968589d8 193 ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T3_CC4) || \
Kojto 90:cb3d968589d8 194 ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_TRGO) || \
Kojto 90:cb3d968589d8 195 ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_CC1) || \
Kojto 90:cb3d968589d8 196 ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_CC2) || \
Kojto 90:cb3d968589d8 197 ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_CC3) || \
Kojto 90:cb3d968589d8 198 ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T7_TRGO) || \
Kojto 90:cb3d968589d8 199 ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T9_CC1) || \
Kojto 90:cb3d968589d8 200 ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T9_TRGO) || \
Kojto 90:cb3d968589d8 201 ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T10_CC1) || \
Kojto 90:cb3d968589d8 202 ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_EXT_IT15) || \
Kojto 90:cb3d968589d8 203 ((REGTRIG) == ADC_SOFTWARE_START) )
Kojto 90:cb3d968589d8 204 /**
Kojto 90:cb3d968589d8 205 * @}
Kojto 90:cb3d968589d8 206 */
Kojto 90:cb3d968589d8 207
Kojto 90:cb3d968589d8 208 /** @defgroup ADCEx_Internal_HAL_driver_Ext_trig_src_Injected ADCEx Internal HAL driver Ext trig src Injected
Kojto 90:cb3d968589d8 209 * @{
Kojto 90:cb3d968589d8 210 */
Kojto 90:cb3d968589d8 211
Kojto 90:cb3d968589d8 212 /* List of external triggers of injected group for ADC1: */
Kojto 90:cb3d968589d8 213 /* (used internally by HAL driver. To not use into HAL structure parameters) */
Kojto 90:cb3d968589d8 214 #define ADC_EXTERNALTRIGINJEC_T9_CC1 ((uint32_t) 0x00000000)
Kojto 90:cb3d968589d8 215 #define ADC_EXTERNALTRIGINJEC_T9_TRGO ((uint32_t)( ADC_CR2_JEXTSEL_0))
Kojto 90:cb3d968589d8 216 #define ADC_EXTERNALTRIGINJEC_T2_TRGO ((uint32_t)( ADC_CR2_JEXTSEL_1 ))
Kojto 90:cb3d968589d8 217 #define ADC_EXTERNALTRIGINJEC_T2_CC1 ((uint32_t)( ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0))
Kojto 90:cb3d968589d8 218 #define ADC_EXTERNALTRIGINJEC_T3_CC4 ((uint32_t)( ADC_CR2_JEXTSEL_2 ))
Kojto 90:cb3d968589d8 219 #define ADC_EXTERNALTRIGINJEC_T4_TRGO ((uint32_t)( ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_0))
Kojto 90:cb3d968589d8 220 #define ADC_EXTERNALTRIGINJEC_T4_CC1 ((uint32_t)( ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1 ))
Kojto 90:cb3d968589d8 221 #define ADC_EXTERNALTRIGINJEC_T4_CC2 ((uint32_t)( ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0))
Kojto 90:cb3d968589d8 222 #define ADC_EXTERNALTRIGINJEC_T4_CC3 ((uint32_t)(ADC_CR2_JEXTSEL_3 ))
Kojto 90:cb3d968589d8 223 #define ADC_EXTERNALTRIGINJEC_T10_CC1 ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_0))
Kojto 90:cb3d968589d8 224 #define ADC_EXTERNALTRIGINJEC_T7_TRGO ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_1 ))
Kojto 90:cb3d968589d8 225 #define ADC_EXTERNALTRIGINJEC_EXT_IT15 ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0))
Kojto 90:cb3d968589d8 226
Kojto 90:cb3d968589d8 227 /**
Kojto 90:cb3d968589d8 228 * @}
Kojto 90:cb3d968589d8 229 */
Kojto 90:cb3d968589d8 230
Kojto 90:cb3d968589d8 231
Kojto 90:cb3d968589d8 232 /** @defgroup ADCEx_injected_nb_conv_verification ADCEx injected nb conv verification
Kojto 90:cb3d968589d8 233 * @{
Kojto 90:cb3d968589d8 234 */
Kojto 90:cb3d968589d8 235 #define IS_ADC_INJECTED_NB_CONV(LENGTH) (((LENGTH) >= ((uint32_t)1)) && ((LENGTH) <= ((uint32_t)4)))
Kojto 90:cb3d968589d8 236 /**
Kojto 90:cb3d968589d8 237 * @}
Kojto 90:cb3d968589d8 238 */
Kojto 90:cb3d968589d8 239
Kojto 90:cb3d968589d8 240 /**
Kojto 90:cb3d968589d8 241 * @}
Kojto 90:cb3d968589d8 242 */
Kojto 90:cb3d968589d8 243
Kojto 90:cb3d968589d8 244
Kojto 90:cb3d968589d8 245 /* Exported macro ------------------------------------------------------------*/
Kojto 90:cb3d968589d8 246
Kojto 90:cb3d968589d8 247 /** @defgroup ADCEx_Exported_Macros ADCEx Exported Macros
Kojto 90:cb3d968589d8 248 * @{
Kojto 90:cb3d968589d8 249 */
Kojto 90:cb3d968589d8 250 /* Macro for internal HAL driver usage, and possibly can be used into code of */
Kojto 90:cb3d968589d8 251 /* final user. */
Kojto 90:cb3d968589d8 252
Kojto 90:cb3d968589d8 253 /**
Kojto 90:cb3d968589d8 254 * @brief Selection of channels bank.
Kojto 90:cb3d968589d8 255 * Note: Banks availability depends on devices categories.
Kojto 90:cb3d968589d8 256 * This macro is intended to change bank selection quickly on the fly,
Kojto 90:cb3d968589d8 257 * without going through ADC init structure update and execution of function
Kojto 90:cb3d968589d8 258 * 'HAL_ADC_Init()'.
Kojto 90:cb3d968589d8 259 * @param __HANDLE__: ADC handle
Kojto 90:cb3d968589d8 260 * @param __BANK__: Bank selection. This parameter can be a value of @ref ADC_ChannelsBank.
Kojto 90:cb3d968589d8 261 * @retval None
Kojto 90:cb3d968589d8 262 */
Kojto 90:cb3d968589d8 263 #define __HAL_ADC_CHANNELS_BANK(__HANDLE__, __BANK__) \
Kojto 90:cb3d968589d8 264 MODIFY_REG((__HANDLE__)->Instance->CR2, ADC_CR2_CFG, (__BANK__))
Kojto 90:cb3d968589d8 265
Kojto 90:cb3d968589d8 266 #if defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
Kojto 90:cb3d968589d8 267 /**
Kojto 90:cb3d968589d8 268 * @brief Configures the ADC channels speed.
Kojto 90:cb3d968589d8 269 * Limited to channels 3, 8, 13 and to devices category Cat.3, Cat.4, Cat.5.
Kojto 90:cb3d968589d8 270 * - For ADC_CHANNEL_3: Used as ADC direct channel (fast channel) if OPAMP1 is
Kojto 90:cb3d968589d8 271 * in power down mode.
Kojto 90:cb3d968589d8 272 * - For ADC_CHANNEL_8: Used as ADC direct channel (fast channel) if OPAMP2 is
Kojto 90:cb3d968589d8 273 * in power down mode.
Kojto 90:cb3d968589d8 274 * - For ADC_CHANNEL_13: Used as ADC re-routed channel if OPAMP3 is in
Kojto 90:cb3d968589d8 275 * power down mode. Otherwise, channel 13 is connected to OPAMP3 output and
Kojto 90:cb3d968589d8 276 * routed through switches COMP1_SW1 and VCOMP to ADC switch matrix.
Kojto 90:cb3d968589d8 277 * (Note: OPAMP3 is available on STM32L1 Cat.4 only).
Kojto 90:cb3d968589d8 278 * @param __CHANNEL__: ADC channel
Kojto 90:cb3d968589d8 279 * This parameter can be one of the following values:
Kojto 90:cb3d968589d8 280 * @arg ADC_CHANNEL_3: Channel 3 is selected.
Kojto 90:cb3d968589d8 281 * @arg ADC_CHANNEL_8: Channel 8 is selected.
Kojto 90:cb3d968589d8 282 * @arg ADC_CHANNEL_13: Channel 13 is selected.
Kojto 90:cb3d968589d8 283 * @retval None
Kojto 90:cb3d968589d8 284 */
Kojto 90:cb3d968589d8 285 #define __HAL_ADC_CHANNEL_SPEED_FAST(__CHANNEL__) \
Kojto 90:cb3d968589d8 286 ( ( ((__CHANNEL__) == ADC_CHANNEL_3) \
Kojto 90:cb3d968589d8 287 )? \
Kojto 90:cb3d968589d8 288 (SET_BIT(COMP->CSR, COMP_CSR_FCH3)) \
Kojto 90:cb3d968589d8 289 : \
Kojto 90:cb3d968589d8 290 ( ( ((__CHANNEL__) == ADC_CHANNEL_8) \
Kojto 90:cb3d968589d8 291 )? \
Kojto 90:cb3d968589d8 292 (SET_BIT(COMP->CSR, COMP_CSR_FCH8)) \
Kojto 90:cb3d968589d8 293 : \
Kojto 90:cb3d968589d8 294 ( ( ((__CHANNEL__) == ADC_CHANNEL_13) \
Kojto 90:cb3d968589d8 295 )? \
Kojto 90:cb3d968589d8 296 (SET_BIT(COMP->CSR, COMP_CSR_RCH13)) \
Kojto 90:cb3d968589d8 297 : \
Kojto 90:cb3d968589d8 298 (SET_BIT(COMP->CSR, 0x00000000)) \
Kojto 90:cb3d968589d8 299 ) \
Kojto 90:cb3d968589d8 300 ) \
Kojto 90:cb3d968589d8 301 )
Kojto 90:cb3d968589d8 302
Kojto 90:cb3d968589d8 303 #define __HAL_ADC_CHANNEL_SPEED_SLOW(__CHANNEL__) \
Kojto 90:cb3d968589d8 304 ( ( ((__CHANNEL__) == ADC_CHANNEL_3) \
Kojto 90:cb3d968589d8 305 )? \
Kojto 90:cb3d968589d8 306 (CLEAR_BIT(COMP->CSR, COMP_CSR_FCH3)) \
Kojto 90:cb3d968589d8 307 : \
Kojto 90:cb3d968589d8 308 ( ( ((__CHANNEL__) == ADC_CHANNEL_8) \
Kojto 90:cb3d968589d8 309 )? \
Kojto 90:cb3d968589d8 310 (CLEAR_BIT(COMP->CSR, COMP_CSR_FCH8)) \
Kojto 90:cb3d968589d8 311 : \
Kojto 90:cb3d968589d8 312 ( ( ((__CHANNEL__) == ADC_CHANNEL_13) \
Kojto 90:cb3d968589d8 313 )? \
Kojto 90:cb3d968589d8 314 (CLEAR_BIT(COMP->CSR, COMP_CSR_RCH13)) \
Kojto 90:cb3d968589d8 315 : \
Kojto 90:cb3d968589d8 316 (SET_BIT(COMP->CSR, 0x00000000)) \
Kojto 90:cb3d968589d8 317 ) \
Kojto 90:cb3d968589d8 318 ) \
Kojto 90:cb3d968589d8 319 )
Kojto 90:cb3d968589d8 320 #endif /* STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
Kojto 90:cb3d968589d8 321
Kojto 90:cb3d968589d8 322 /**
Kojto 90:cb3d968589d8 323 * @}
Kojto 90:cb3d968589d8 324 */
Kojto 90:cb3d968589d8 325
Kojto 90:cb3d968589d8 326 /* Private macro ------------------------------------------------------------*/
Kojto 90:cb3d968589d8 327
Kojto 90:cb3d968589d8 328 /** @defgroup ADCEx_Private_Macro ADCEx Private Macro
Kojto 90:cb3d968589d8 329 * @{
Kojto 90:cb3d968589d8 330 */
Kojto 90:cb3d968589d8 331 /* Macro reserved for internal HAL driver usage, not intended to be used in */
Kojto 90:cb3d968589d8 332 /* code of final user. */
Kojto 90:cb3d968589d8 333
Kojto 90:cb3d968589d8 334 /**
Kojto 90:cb3d968589d8 335 * @brief Set ADC number of ranks into regular channel sequence length.
Kojto 90:cb3d968589d8 336 * @param _NbrOfConversion_: Regular channel sequence length
Kojto 90:cb3d968589d8 337 * @retval None
Kojto 90:cb3d968589d8 338 */
Kojto 90:cb3d968589d8 339 #define __ADC_SQR1_L(_NbrOfConversion_) (((_NbrOfConversion_) - (uint8_t)1) << POSITION_VAL(ADC_SQR1_L))
Kojto 90:cb3d968589d8 340
Kojto 90:cb3d968589d8 341 /**
Kojto 90:cb3d968589d8 342 * @brief Set ADC ranks available in register SQR1.
Kojto 90:cb3d968589d8 343 * Register SQR1 bits availability depends on device category.
Kojto 90:cb3d968589d8 344 * @param _NbrOfConversion_: Regular channel sequence length
Kojto 90:cb3d968589d8 345 * @retval None
Kojto 90:cb3d968589d8 346 */
Kojto 90:cb3d968589d8 347 #if defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
Kojto 90:cb3d968589d8 348 #define __ADC_SQR1_SQXX ADC_SQR1_SQ28 | ADC_SQR1_SQ27 | ADC_SQR1_SQ26 | ADC_SQR1_SQ25
Kojto 90:cb3d968589d8 349 #else
Kojto 90:cb3d968589d8 350 #define __ADC_SQR1_SQXX ADC_SQR1_SQ27 | ADC_SQR1_SQ26 | ADC_SQR1_SQ25
Kojto 90:cb3d968589d8 351 #endif /* STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
Kojto 90:cb3d968589d8 352
Kojto 90:cb3d968589d8 353 /**
Kojto 90:cb3d968589d8 354 * @brief Set the ADC's sample time for channel numbers between 30 and 31.
Kojto 90:cb3d968589d8 355 * Register SMPR0 availability depends on device category. If register is not
Kojto 90:cb3d968589d8 356 * available on the current device, this macro does nothing.
Kojto 90:cb3d968589d8 357 * @retval None
Kojto 90:cb3d968589d8 358 * @param _SAMPLETIME_: Sample time parameter.
Kojto 90:cb3d968589d8 359 * @param _CHANNELNB_: Channel number.
Kojto 90:cb3d968589d8 360 * @retval None
Kojto 90:cb3d968589d8 361 */
Kojto 90:cb3d968589d8 362 #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
Kojto 90:cb3d968589d8 363 #define __ADC_SMPR0(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3 * ((_CHANNELNB_) - 30)))
Kojto 90:cb3d968589d8 364 #else
Kojto 90:cb3d968589d8 365 #define __ADC_SMPR0(_SAMPLETIME_, _CHANNELNB_) ((uint32_t)0x00000000)
Kojto 90:cb3d968589d8 366 #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
Kojto 90:cb3d968589d8 367
Kojto 90:cb3d968589d8 368 #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
Kojto 90:cb3d968589d8 369 /**
Kojto 90:cb3d968589d8 370 * @brief Set the ADC's sample time for channel numbers between 20 and 29.
Kojto 90:cb3d968589d8 371 * @param _SAMPLETIME_: Sample time parameter.
Kojto 90:cb3d968589d8 372 * @param _CHANNELNB_: Channel number.
Kojto 90:cb3d968589d8 373 * @retval None
Kojto 90:cb3d968589d8 374 */
Kojto 90:cb3d968589d8 375 #define __ADC_SMPR1(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3 * ((_CHANNELNB_) - 20)))
Kojto 90:cb3d968589d8 376 #else
Kojto 90:cb3d968589d8 377 /**
Kojto 90:cb3d968589d8 378 * @brief Set the ADC's sample time for channel numbers between 20 and 26.
Kojto 90:cb3d968589d8 379 * @param _SAMPLETIME_: Sample time parameter.
Kojto 90:cb3d968589d8 380 * @param _CHANNELNB_: Channel number.
Kojto 90:cb3d968589d8 381 * @retval None
Kojto 90:cb3d968589d8 382 */
Kojto 90:cb3d968589d8 383 #define __ADC_SMPR1(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3 * ((_CHANNELNB_) - 20)))
Kojto 90:cb3d968589d8 384 #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
Kojto 90:cb3d968589d8 385
Kojto 90:cb3d968589d8 386 /**
Kojto 90:cb3d968589d8 387 * @brief Defines the highest channel available in register SMPR1. Channels
Kojto 90:cb3d968589d8 388 * availability depends on device category:
Kojto 90:cb3d968589d8 389 * Highest channel in register SMPR1 is channel 26 for devices Cat.1, Cat.2, Cat.3
Kojto 90:cb3d968589d8 390 * Highest channel in register SMPR1 is channel 29 for devices Cat.4, Cat.5
Kojto 90:cb3d968589d8 391 * @param None
Kojto 90:cb3d968589d8 392 * @retval None
Kojto 90:cb3d968589d8 393 */
Kojto 90:cb3d968589d8 394 #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
Kojto 90:cb3d968589d8 395 #define ADC_SMPR1_CHANNEL_MAX ADC_CHANNEL_29
Kojto 90:cb3d968589d8 396 #else
Kojto 90:cb3d968589d8 397 #define ADC_SMPR1_CHANNEL_MAX ADC_CHANNEL_26
Kojto 90:cb3d968589d8 398 #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
Kojto 90:cb3d968589d8 399
Kojto 90:cb3d968589d8 400 /**
Kojto 90:cb3d968589d8 401 * @brief Set the ADC's sample time for channel numbers between 10 and 18.
Kojto 90:cb3d968589d8 402 * @param _SAMPLETIME_: Sample time parameter.
Kojto 90:cb3d968589d8 403 * @param _CHANNELNB_: Channel number.
Kojto 90:cb3d968589d8 404 * @retval None
Kojto 90:cb3d968589d8 405 */
Kojto 90:cb3d968589d8 406 #define __ADC_SMPR2(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3 * ((_CHANNELNB_) - 10)))
Kojto 90:cb3d968589d8 407
Kojto 90:cb3d968589d8 408 /**
Kojto 90:cb3d968589d8 409 * @brief Set the ADC's sample time for channel numbers between 0 and 9.
Kojto 90:cb3d968589d8 410 * @param _SAMPLETIME_: Sample time parameter.
Kojto 90:cb3d968589d8 411 * @param _CHANNELNB_: Channel number.
Kojto 90:cb3d968589d8 412 * @retval None
Kojto 90:cb3d968589d8 413 */
Kojto 90:cb3d968589d8 414 #define __ADC_SMPR3(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3 * (_CHANNELNB_)))
Kojto 90:cb3d968589d8 415
Kojto 90:cb3d968589d8 416 /**
Kojto 90:cb3d968589d8 417 * @brief Set the selected regular channel rank for rank between 1 and 6.
Kojto 90:cb3d968589d8 418 * @param _CHANNELNB_: Channel number.
Kojto 90:cb3d968589d8 419 * @param _RANKNB_: Rank number.
Kojto 90:cb3d968589d8 420 * @retval None
Kojto 90:cb3d968589d8 421 */
Kojto 90:cb3d968589d8 422 #define __ADC_SQR5_RK(_CHANNELNB_, _RANKNB_) ((_CHANNELNB_) << (5 * ((_RANKNB_) - 1)))
Kojto 90:cb3d968589d8 423
Kojto 90:cb3d968589d8 424 /**
Kojto 90:cb3d968589d8 425 * @brief Set the selected regular channel rank for rank between 7 and 12.
Kojto 90:cb3d968589d8 426 * @param _CHANNELNB_: Channel number.
Kojto 90:cb3d968589d8 427 * @param _RANKNB_: Rank number.
Kojto 90:cb3d968589d8 428 * @retval None
Kojto 90:cb3d968589d8 429 */
Kojto 90:cb3d968589d8 430 #define __ADC_SQR4_RK(_CHANNELNB_, _RANKNB_) ((_CHANNELNB_) << (5 * ((_RANKNB_) - 7)))
Kojto 90:cb3d968589d8 431
Kojto 90:cb3d968589d8 432 /**
Kojto 90:cb3d968589d8 433 * @brief Set the selected regular channel rank for rank between 13 and 18.
Kojto 90:cb3d968589d8 434 * @param _CHANNELNB_: Channel number.
Kojto 90:cb3d968589d8 435 * @param _RANKNB_: Rank number.
Kojto 90:cb3d968589d8 436 * @retval None
Kojto 90:cb3d968589d8 437 */
Kojto 90:cb3d968589d8 438 #define __ADC_SQR3_RK(_CHANNELNB_, _RANKNB_) ((_CHANNELNB_) << (5 * ((_RANKNB_) - 13)))
Kojto 90:cb3d968589d8 439
Kojto 90:cb3d968589d8 440 /**
Kojto 90:cb3d968589d8 441 * @brief Set the selected regular channel rank for rank between 19 and 24.
Kojto 90:cb3d968589d8 442 * @param _CHANNELNB_: Channel number.
Kojto 90:cb3d968589d8 443 * @param _RANKNB_: Rank number.
Kojto 90:cb3d968589d8 444 * @retval None
Kojto 90:cb3d968589d8 445 */
Kojto 90:cb3d968589d8 446 #define __ADC_SQR2_RK(_CHANNELNB_, _RANKNB_) ((_CHANNELNB_) << (5 * ((_RANKNB_) - 19)))
Kojto 90:cb3d968589d8 447
Kojto 90:cb3d968589d8 448 /**
Kojto 90:cb3d968589d8 449 * @brief Set the selected regular channel rank for rank between 25 and 28.
Kojto 90:cb3d968589d8 450 * @param _CHANNELNB_: Channel number.
Kojto 90:cb3d968589d8 451 * @param _RANKNB_: Rank number.
Kojto 90:cb3d968589d8 452 * @retval None
Kojto 90:cb3d968589d8 453 */
Kojto 90:cb3d968589d8 454 #define __ADC_SQR1_RK(_CHANNELNB_, _RANKNB_) ((_CHANNELNB_) << (5 * ((_RANKNB_) - 25)))
Kojto 90:cb3d968589d8 455
Kojto 90:cb3d968589d8 456 /**
Kojto 90:cb3d968589d8 457 * @brief Set the injected sequence length.
Kojto 90:cb3d968589d8 458 * @param _JSQR_JL_: Sequence length.
Kojto 90:cb3d968589d8 459 * @retval None
Kojto 90:cb3d968589d8 460 */
Kojto 90:cb3d968589d8 461 #define __ADC_JSQR_JL(_JSQR_JL_) (((_JSQR_JL_) -1) << 20)
Kojto 90:cb3d968589d8 462
Kojto 90:cb3d968589d8 463 /**
Kojto 90:cb3d968589d8 464 * @brief Set the selected injected Channel rank (channels sequence starting from 4-JL)
Kojto 90:cb3d968589d8 465 * @param _CHANNELNB_: Channel number.
Kojto 90:cb3d968589d8 466 * @param _RANKNB_: Rank number.
Kojto 90:cb3d968589d8 467 * @param _JSQR_JL_: Sequence length.
Kojto 90:cb3d968589d8 468 * @retval None
Kojto 90:cb3d968589d8 469 */
Kojto 90:cb3d968589d8 470 #define __ADC_JSQR_RK(_CHANNELNB_, _RANKNB_, _JSQR_JL_) \
Kojto 90:cb3d968589d8 471 ((_CHANNELNB_) << (5 * ((4 - ((_JSQR_JL_) - (_RANKNB_))) - 1)))
Kojto 90:cb3d968589d8 472
Kojto 90:cb3d968589d8 473
Kojto 90:cb3d968589d8 474 /**
Kojto 90:cb3d968589d8 475 * @brief Enable the ADC DMA continuous request.
Kojto 90:cb3d968589d8 476 * @param _DMACONTREQ_MODE_: DMA continuous request mode.
Kojto 90:cb3d968589d8 477 * @retval None
Kojto 90:cb3d968589d8 478 */
Kojto 90:cb3d968589d8 479 #define __ADC_CR2_DMACONTREQ(_DMACONTREQ_MODE_) ((_DMACONTREQ_MODE_) << POSITION_VAL(ADC_CR2_DDS))
Kojto 90:cb3d968589d8 480
Kojto 90:cb3d968589d8 481 /**
Kojto 90:cb3d968589d8 482 * @brief Enable ADC continuous conversion mode.
Kojto 90:cb3d968589d8 483 * @param _CONTINUOUS_MODE_: Continuous mode.
Kojto 90:cb3d968589d8 484 * @retval None
Kojto 90:cb3d968589d8 485 */
Kojto 90:cb3d968589d8 486 #define __ADC_CR2_CONTINUOUS(_CONTINUOUS_MODE_) ((_CONTINUOUS_MODE_) << POSITION_VAL(ADC_CR2_CONT))
Kojto 90:cb3d968589d8 487
Kojto 90:cb3d968589d8 488 /**
Kojto 90:cb3d968589d8 489 * @brief Define mask of configuration bits of ADC and regular group in
Kojto 90:cb3d968589d8 490 * register CR2 (bits of ADC enable, conversion start and injected group are
Kojto 90:cb3d968589d8 491 * excluded of this mask).
Kojto 90:cb3d968589d8 492 * @retval None
Kojto 90:cb3d968589d8 493 */
Kojto 90:cb3d968589d8 494 #if defined (STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined (STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined (STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
Kojto 90:cb3d968589d8 495 #define __ADC_CR2_MASK_ADCINIT() \
Kojto 90:cb3d968589d8 496 (ADC_CR2_EXTEN | ADC_CR2_EXTSEL | ADC_CR2_ALIGN | ADC_CR2_EOCS | ADC_CR2_DDS | ADC_CR2_DELS | ADC_CR2_CFG | ADC_CR2_CONT)
Kojto 90:cb3d968589d8 497 #else
Kojto 90:cb3d968589d8 498 #define __ADC_CR2_MASK_ADCINIT() \
Kojto 90:cb3d968589d8 499 (ADC_CR2_EXTEN | ADC_CR2_EXTSEL | ADC_CR2_ALIGN | ADC_CR2_EOCS | ADC_CR2_DDS | ADC_CR2_DELS | ADC_CR2_CONT)
Kojto 90:cb3d968589d8 500 #endif
Kojto 90:cb3d968589d8 501
Kojto 90:cb3d968589d8 502 /**
Kojto 90:cb3d968589d8 503 * @brief Configures the number of discontinuous conversions for the regular group channels.
Kojto 90:cb3d968589d8 504 * @param _NBR_DISCONTINUOUS_CONV_: Number of discontinuous conversions.
Kojto 90:cb3d968589d8 505 * @retval None
Kojto 90:cb3d968589d8 506 */
Kojto 90:cb3d968589d8 507 #define __ADC_CR1_DISCONTINUOUS_NUM(_NBR_DISCONTINUOUS_CONV_) (((_NBR_DISCONTINUOUS_CONV_) - 1) << POSITION_VAL(ADC_CR1_DISCNUM))
Kojto 90:cb3d968589d8 508
Kojto 90:cb3d968589d8 509 /**
Kojto 90:cb3d968589d8 510 * @brief Enable ADC scan mode to convert multiple ranks with sequencer.
Kojto 90:cb3d968589d8 511 * @param _SCAN_MODE_: Scan conversion mode.
Kojto 90:cb3d968589d8 512 * @retval None
Kojto 90:cb3d968589d8 513 */
Kojto 90:cb3d968589d8 514 #define __ADC_CR1_SCAN(_SCAN_MODE_) \
Kojto 90:cb3d968589d8 515 ( ( (_SCAN_MODE_) == (ADC_SCAN_ENABLE) \
Kojto 90:cb3d968589d8 516 )? (ADC_CR1_SCAN) : (0x00000000) \
Kojto 90:cb3d968589d8 517 )
Kojto 90:cb3d968589d8 518
Kojto 90:cb3d968589d8 519 /**
Kojto 90:cb3d968589d8 520 * @brief Get the maximum ADC conversion cycles on all channels.
Kojto 90:cb3d968589d8 521 * Returns the selected sampling time + conversion time (12.5 ADC clock cycles)
Kojto 90:cb3d968589d8 522 * Approximation of sampling time within 2 ranges, returns the higher value:
Kojto 90:cb3d968589d8 523 * below 24 cycles {4 cycles; 9 cycles; 16 cycles; 24 cycles}
Kojto 90:cb3d968589d8 524 * between 48 cycles and 384 cycles {48 cycles; 96 cycles; 192 cycles; 384 cycles}
Kojto 90:cb3d968589d8 525 * Unit: ADC clock cycles
Kojto 90:cb3d968589d8 526 * @param __HANDLE__: ADC handle
Kojto 90:cb3d968589d8 527 * @retval ADC conversion cycles on all channels
Kojto 90:cb3d968589d8 528 */
Kojto 90:cb3d968589d8 529 #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
Kojto 90:cb3d968589d8 530 #define __ADC_CONVCYCLES_MAX_RANGE(__HANDLE__) \
Kojto 90:cb3d968589d8 531 (( (((__HANDLE__)->Instance->SMPR3 & ADC_SAMPLETIME_ALLCHANNELS_SMPR3BIT2) == RESET) && \
Kojto 90:cb3d968589d8 532 (((__HANDLE__)->Instance->SMPR2 & ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT2) == RESET) && \
Kojto 90:cb3d968589d8 533 (((__HANDLE__)->Instance->SMPR1 & ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT2) == RESET) && \
Kojto 90:cb3d968589d8 534 (((__HANDLE__)->Instance->SMPR0 & ADC_SAMPLETIME_ALLCHANNELS_SMPR0BIT2) == RESET) ) ? \
Kojto 90:cb3d968589d8 535 \
Kojto 90:cb3d968589d8 536 ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_24CYCLES : ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_384CYCLES \
Kojto 90:cb3d968589d8 537 )
Kojto 90:cb3d968589d8 538 #else
Kojto 90:cb3d968589d8 539 #define __ADC_CONVCYCLES_MAX_RANGE(__HANDLE__) \
Kojto 90:cb3d968589d8 540 (( (((__HANDLE__)->Instance->SMPR3 & ADC_SAMPLETIME_ALLCHANNELS_SMPR3BIT2) == RESET) && \
Kojto 90:cb3d968589d8 541 (((__HANDLE__)->Instance->SMPR2 & ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT2) == RESET) && \
Kojto 90:cb3d968589d8 542 (((__HANDLE__)->Instance->SMPR1 & ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT2) == RESET) ) ? \
Kojto 90:cb3d968589d8 543 \
Kojto 90:cb3d968589d8 544 ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_24CYCLES : ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_384CYCLES \
Kojto 90:cb3d968589d8 545 )
Kojto 90:cb3d968589d8 546 #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
Kojto 90:cb3d968589d8 547
Kojto 90:cb3d968589d8 548 /**
Kojto 90:cb3d968589d8 549 * @brief Get the ADC clock prescaler from ADC common control register
Kojto 90:cb3d968589d8 550 * and convert it to its decimal number setting (refer to reference manual)
Kojto 90:cb3d968589d8 551 * @retval None
Kojto 90:cb3d968589d8 552 */
Kojto 90:cb3d968589d8 553 #define __ADC_GET_CLOCK_PRESCALER_DECIMAL(__HANDLE__) \
Kojto 90:cb3d968589d8 554 ((0x01) << ((ADC->CCR & ADC_CCR_ADCPRE) >> POSITION_VAL(ADC_CCR_ADCPRE)))
Kojto 90:cb3d968589d8 555
Kojto 90:cb3d968589d8 556 /**
Kojto 90:cb3d968589d8 557 * @brief Clear register SMPR0.
Kojto 90:cb3d968589d8 558 * Register SMPR0 availability depends on device category. If register is not
Kojto 90:cb3d968589d8 559 * available on the current device, this macro performs no action.
Kojto 90:cb3d968589d8 560 * @param __HANDLE__: ADC handle
Kojto 90:cb3d968589d8 561 * @retval None
Kojto 90:cb3d968589d8 562 */
Kojto 90:cb3d968589d8 563 #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
Kojto 90:cb3d968589d8 564 #define __ADC_SMPR0_CLEAR(__HANDLE__) \
Kojto 90:cb3d968589d8 565 (CLEAR_BIT((__HANDLE__)->Instance->SMPR0, (ADC_SMPR0_SMP31 | ADC_SMPR0_SMP30)))
Kojto 90:cb3d968589d8 566 #else
Kojto 90:cb3d968589d8 567 #define __ADC_SMPR0_CLEAR(__HANDLE__) __NOP()
Kojto 90:cb3d968589d8 568 #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
Kojto 90:cb3d968589d8 569
Kojto 90:cb3d968589d8 570 /**
Kojto 90:cb3d968589d8 571 * @brief Clear register CR2.
Kojto 90:cb3d968589d8 572 * @param __HANDLE__: ADC handle
Kojto 90:cb3d968589d8 573 * @retval None
Kojto 90:cb3d968589d8 574 */
Kojto 90:cb3d968589d8 575 #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
Kojto 90:cb3d968589d8 576 #define __ADC_CR2_CLEAR(__HANDLE__) \
Kojto 90:cb3d968589d8 577 (CLEAR_BIT((__HANDLE__)->Instance->CR2, (ADC_CR2_SWSTART | ADC_CR2_EXTEN | ADC_CR2_EXTSEL | \
Kojto 90:cb3d968589d8 578 ADC_CR2_JSWSTART | ADC_CR2_JEXTEN | ADC_CR2_JEXTSEL | \
Kojto 90:cb3d968589d8 579 ADC_CR2_ALIGN | ADC_CR2_EOCS | ADC_CR2_DDS | \
Kojto 90:cb3d968589d8 580 ADC_CR2_DMA | ADC_CR2_DELS | ADC_CR2_CFG | \
Kojto 90:cb3d968589d8 581 ADC_CR2_CONT | ADC_CR2_ADON )) \
Kojto 90:cb3d968589d8 582 )
Kojto 90:cb3d968589d8 583 #else
Kojto 90:cb3d968589d8 584 #define __ADC_CR2_CLEAR(__HANDLE__) \
Kojto 90:cb3d968589d8 585 (CLEAR_BIT((__HANDLE__)->Instance->CR2, (ADC_CR2_SWSTART | ADC_CR2_EXTEN | ADC_CR2_EXTSEL | \
Kojto 90:cb3d968589d8 586 ADC_CR2_JSWSTART | ADC_CR2_JEXTEN | ADC_CR2_JEXTSEL | \
Kojto 90:cb3d968589d8 587 ADC_CR2_ALIGN | ADC_CR2_EOCS | ADC_CR2_DDS | \
Kojto 90:cb3d968589d8 588 ADC_CR2_DMA | ADC_CR2_DELS | \
Kojto 90:cb3d968589d8 589 ADC_CR2_CONT | ADC_CR2_ADON )) \
Kojto 90:cb3d968589d8 590 )
Kojto 90:cb3d968589d8 591 #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
Kojto 90:cb3d968589d8 592
Kojto 90:cb3d968589d8 593 /**
Kojto 90:cb3d968589d8 594 * @brief Set the sampling time of selected channel on register SMPR0
Kojto 90:cb3d968589d8 595 * Register SMPR0 availability depends on device category. If register is not
Kojto 90:cb3d968589d8 596 * available on the current device, this macro performs no action.
Kojto 90:cb3d968589d8 597 * @param __HANDLE__: ADC handle
Kojto 90:cb3d968589d8 598 * @param _SAMPLETIME_: Sample time parameter.
Kojto 90:cb3d968589d8 599 * @param __CHANNEL__: Channel number.
Kojto 90:cb3d968589d8 600 * @retval None
Kojto 90:cb3d968589d8 601 */
Kojto 90:cb3d968589d8 602 #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
Kojto 90:cb3d968589d8 603 #define __ADC_SMPR0_CHANNEL_SET(__HANDLE__, _SAMPLETIME_, __CHANNEL__) \
Kojto 90:cb3d968589d8 604 MODIFY_REG((__HANDLE__)->Instance->SMPR0, \
Kojto 90:cb3d968589d8 605 __ADC_SMPR0(ADC_SMPR0_SMP30, (__CHANNEL__)), \
Kojto 90:cb3d968589d8 606 __ADC_SMPR0((_SAMPLETIME_), (__CHANNEL__)) )
Kojto 90:cb3d968589d8 607 #else
Kojto 90:cb3d968589d8 608 #define __ADC_SMPR0_CHANNEL_SET(__HANDLE__, _SAMPLETIME_, __CHANNEL__) __NOP()
Kojto 90:cb3d968589d8 609 #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
Kojto 90:cb3d968589d8 610
Kojto 90:cb3d968589d8 611
Kojto 90:cb3d968589d8 612 /**
Kojto 90:cb3d968589d8 613 * @brief Enable the ADC peripheral
Kojto 90:cb3d968589d8 614 * @param __HANDLE__: ADC handle
Kojto 90:cb3d968589d8 615 * @retval None
Kojto 90:cb3d968589d8 616 */
Kojto 90:cb3d968589d8 617 #define __ADC_ENABLE(__HANDLE__) \
Kojto 90:cb3d968589d8 618 (__HANDLE__)->Instance->CR2 |= ADC_CR2_ADON
Kojto 90:cb3d968589d8 619
Kojto 90:cb3d968589d8 620 /**
Kojto 90:cb3d968589d8 621 * @brief Disable the ADC peripheral
Kojto 90:cb3d968589d8 622 * @param __HANDLE__: ADC handle
Kojto 90:cb3d968589d8 623 * @retval None
Kojto 90:cb3d968589d8 624 */
Kojto 90:cb3d968589d8 625 #define __ADC_DISABLE(__HANDLE__) \
Kojto 90:cb3d968589d8 626 (__HANDLE__)->Instance->CR2 &= ~ADC_CR2_ADON
Kojto 90:cb3d968589d8 627
Kojto 90:cb3d968589d8 628 /**
Kojto 90:cb3d968589d8 629 * @}
Kojto 90:cb3d968589d8 630 */
Kojto 90:cb3d968589d8 631
Kojto 90:cb3d968589d8 632
Kojto 90:cb3d968589d8 633 /* Exported functions --------------------------------------------------------*/
Kojto 90:cb3d968589d8 634 /** @addtogroup ADCEx_Exported_Functions
Kojto 90:cb3d968589d8 635 * @{
Kojto 90:cb3d968589d8 636 */
Kojto 90:cb3d968589d8 637
Kojto 90:cb3d968589d8 638 /* IO operation functions *****************************************************/
Kojto 90:cb3d968589d8 639 /** @addtogroup ADCEx_Exported_Functions_Group1
Kojto 90:cb3d968589d8 640 * @{
Kojto 90:cb3d968589d8 641 */
Kojto 90:cb3d968589d8 642
Kojto 90:cb3d968589d8 643 /* Blocking mode: Polling */
Kojto 90:cb3d968589d8 644 HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc);
Kojto 90:cb3d968589d8 645 HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc);
Kojto 90:cb3d968589d8 646 HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
Kojto 90:cb3d968589d8 647
Kojto 90:cb3d968589d8 648 /* Non-blocking mode: Interruption */
Kojto 90:cb3d968589d8 649 HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc);
Kojto 90:cb3d968589d8 650 HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc);
Kojto 90:cb3d968589d8 651
Kojto 90:cb3d968589d8 652 /* ADC retrieve conversion value intended to be used with polling or interruption */
Kojto 90:cb3d968589d8 653 uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank);
Kojto 90:cb3d968589d8 654
Kojto 90:cb3d968589d8 655 /* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption) */
Kojto 90:cb3d968589d8 656 void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc);
Kojto 90:cb3d968589d8 657 /**
Kojto 90:cb3d968589d8 658 * @}
Kojto 90:cb3d968589d8 659 */
Kojto 90:cb3d968589d8 660
Kojto 90:cb3d968589d8 661
Kojto 90:cb3d968589d8 662 /* Peripheral Control functions ***********************************************/
Kojto 90:cb3d968589d8 663 /** @addtogroup ADCEx_Exported_Functions_Group2
Kojto 90:cb3d968589d8 664 * @{
Kojto 90:cb3d968589d8 665 */
Kojto 90:cb3d968589d8 666
Kojto 90:cb3d968589d8 667 HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc,ADC_InjectionConfTypeDef* sConfigInjected);
Kojto 90:cb3d968589d8 668 /**
Kojto 90:cb3d968589d8 669 * @}
Kojto 90:cb3d968589d8 670 */
Kojto 90:cb3d968589d8 671
Kojto 90:cb3d968589d8 672
Kojto 90:cb3d968589d8 673 /**
Kojto 90:cb3d968589d8 674 * @}
Kojto 90:cb3d968589d8 675 */
Kojto 90:cb3d968589d8 676
Kojto 90:cb3d968589d8 677
Kojto 90:cb3d968589d8 678 /**
Kojto 90:cb3d968589d8 679 * @}
Kojto 90:cb3d968589d8 680 */
Kojto 90:cb3d968589d8 681
Kojto 90:cb3d968589d8 682 /**
Kojto 90:cb3d968589d8 683 * @}
Kojto 90:cb3d968589d8 684 */
Kojto 90:cb3d968589d8 685
Kojto 90:cb3d968589d8 686 #ifdef __cplusplus
Kojto 90:cb3d968589d8 687 }
Kojto 90:cb3d968589d8 688 #endif
Kojto 90:cb3d968589d8 689
Kojto 90:cb3d968589d8 690 #endif /* __STM32L1xx_HAL_ADC_EX_H */
Kojto 90:cb3d968589d8 691
Kojto 90:cb3d968589d8 692
Kojto 90:cb3d968589d8 693 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/