mbed(SerialHalfDuplex入り)

Fork of mbed by mbed official

Committer:
bogdanm
Date:
Fri Sep 12 16:41:52 2014 +0100
Revision:
89:552587b429a1
Child:
92:4fc01daae5a5
Release 89 of the mbed library

Main changes:

- low power optimizations for Nordic targets
- code structure changes for Freescale K64F targets
- bug fixes in various backends

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 89:552587b429a1 1 /**
bogdanm 89:552587b429a1 2 ******************************************************************************
bogdanm 89:552587b429a1 3 * @file stm32f4xx_hal_adc.h
bogdanm 89:552587b429a1 4 * @author MCD Application Team
bogdanm 89:552587b429a1 5 * @version V1.1.0RC2
bogdanm 89:552587b429a1 6 * @date 14-May-2014
bogdanm 89:552587b429a1 7 * @brief Header file of ADC HAL extension module.
bogdanm 89:552587b429a1 8 ******************************************************************************
bogdanm 89:552587b429a1 9 * @attention
bogdanm 89:552587b429a1 10 *
bogdanm 89:552587b429a1 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
bogdanm 89:552587b429a1 12 *
bogdanm 89:552587b429a1 13 * Redistribution and use in source and binary forms, with or without modification,
bogdanm 89:552587b429a1 14 * are permitted provided that the following conditions are met:
bogdanm 89:552587b429a1 15 * 1. Redistributions of source code must retain the above copyright notice,
bogdanm 89:552587b429a1 16 * this list of conditions and the following disclaimer.
bogdanm 89:552587b429a1 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
bogdanm 89:552587b429a1 18 * this list of conditions and the following disclaimer in the documentation
bogdanm 89:552587b429a1 19 * and/or other materials provided with the distribution.
bogdanm 89:552587b429a1 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
bogdanm 89:552587b429a1 21 * may be used to endorse or promote products derived from this software
bogdanm 89:552587b429a1 22 * without specific prior written permission.
bogdanm 89:552587b429a1 23 *
bogdanm 89:552587b429a1 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
bogdanm 89:552587b429a1 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
bogdanm 89:552587b429a1 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
bogdanm 89:552587b429a1 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
bogdanm 89:552587b429a1 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
bogdanm 89:552587b429a1 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
bogdanm 89:552587b429a1 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
bogdanm 89:552587b429a1 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
bogdanm 89:552587b429a1 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
bogdanm 89:552587b429a1 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bogdanm 89:552587b429a1 34 *
bogdanm 89:552587b429a1 35 ******************************************************************************
bogdanm 89:552587b429a1 36 */
bogdanm 89:552587b429a1 37
bogdanm 89:552587b429a1 38 /* Define to prevent recursive inclusion -------------------------------------*/
bogdanm 89:552587b429a1 39 #ifndef __STM32F4xx_ADC_H
bogdanm 89:552587b429a1 40 #define __STM32F4xx_ADC_H
bogdanm 89:552587b429a1 41
bogdanm 89:552587b429a1 42 #ifdef __cplusplus
bogdanm 89:552587b429a1 43 extern "C" {
bogdanm 89:552587b429a1 44 #endif
bogdanm 89:552587b429a1 45
bogdanm 89:552587b429a1 46 /* Includes ------------------------------------------------------------------*/
bogdanm 89:552587b429a1 47 #include "stm32f4xx_hal_def.h"
bogdanm 89:552587b429a1 48
bogdanm 89:552587b429a1 49 /** @addtogroup STM32F4xx_HAL_Driver
bogdanm 89:552587b429a1 50 * @{
bogdanm 89:552587b429a1 51 */
bogdanm 89:552587b429a1 52
bogdanm 89:552587b429a1 53 /** @addtogroup ADC
bogdanm 89:552587b429a1 54 * @{
bogdanm 89:552587b429a1 55 */
bogdanm 89:552587b429a1 56
bogdanm 89:552587b429a1 57 /* Exported types ------------------------------------------------------------*/
bogdanm 89:552587b429a1 58
bogdanm 89:552587b429a1 59 /**
bogdanm 89:552587b429a1 60 * @brief HAL State structures definition
bogdanm 89:552587b429a1 61 */
bogdanm 89:552587b429a1 62 typedef enum
bogdanm 89:552587b429a1 63 {
bogdanm 89:552587b429a1 64 HAL_ADC_STATE_RESET = 0x00, /*!< ADC not yet initialized or disabled */
bogdanm 89:552587b429a1 65 HAL_ADC_STATE_READY = 0x01, /*!< ADC peripheral ready for use */
bogdanm 89:552587b429a1 66 HAL_ADC_STATE_BUSY = 0x02, /*!< An internal process is ongoing */
bogdanm 89:552587b429a1 67 HAL_ADC_STATE_BUSY_REG = 0x12, /*!< Regular conversion is ongoing */
bogdanm 89:552587b429a1 68 HAL_ADC_STATE_BUSY_INJ = 0x22, /*!< Injected conversion is ongoing */
bogdanm 89:552587b429a1 69 HAL_ADC_STATE_BUSY_INJ_REG = 0x32, /*!< Injected and regular conversion are ongoing */
bogdanm 89:552587b429a1 70 HAL_ADC_STATE_TIMEOUT = 0x03, /*!< Timeout state */
bogdanm 89:552587b429a1 71 HAL_ADC_STATE_ERROR = 0x04, /*!< ADC state error */
bogdanm 89:552587b429a1 72 HAL_ADC_STATE_EOC = 0x05, /*!< Conversion is completed */
bogdanm 89:552587b429a1 73 HAL_ADC_STATE_EOC_REG = 0x15, /*!< Regular conversion is completed */
bogdanm 89:552587b429a1 74 HAL_ADC_STATE_EOC_INJ = 0x25, /*!< Injected conversion is completed */
bogdanm 89:552587b429a1 75 HAL_ADC_STATE_EOC_INJ_REG = 0x35, /*!< Injected and regular conversion are completed */
bogdanm 89:552587b429a1 76 HAL_ADC_STATE_AWD = 0x06 /*!< ADC state analog watchdog */
bogdanm 89:552587b429a1 77
bogdanm 89:552587b429a1 78 }HAL_ADC_StateTypeDef;
bogdanm 89:552587b429a1 79
bogdanm 89:552587b429a1 80 /**
bogdanm 89:552587b429a1 81 * @brief ADC Init structure definition
bogdanm 89:552587b429a1 82 */
bogdanm 89:552587b429a1 83 typedef struct
bogdanm 89:552587b429a1 84 {
bogdanm 89:552587b429a1 85 uint32_t ClockPrescaler; /*!< Select the frequency of the clock to the ADC. The clock is common for
bogdanm 89:552587b429a1 86 all the ADCs.
bogdanm 89:552587b429a1 87 This parameter can be a value of @ref ADC_ClockPrescaler */
bogdanm 89:552587b429a1 88 uint32_t Resolution; /*!< Configures the ADC resolution dual mode.
bogdanm 89:552587b429a1 89 This parameter can be a value of @ref ADC_Resolution */
bogdanm 89:552587b429a1 90 uint32_t DataAlign; /*!< Specifies whether the ADC data alignment is left or right.
bogdanm 89:552587b429a1 91 This parameter can be a value of @ref ADC_data_align */
bogdanm 89:552587b429a1 92 uint32_t ScanConvMode; /*!< Specifies whether the conversion is performed in Scan (multi channels) or
bogdanm 89:552587b429a1 93 Single (one channel) mode.
bogdanm 89:552587b429a1 94 This parameter can be set to ENABLE or DISABLE */
bogdanm 89:552587b429a1 95 uint32_t EOCSelection; /*!< Specifies whether the EOC flag is set
bogdanm 89:552587b429a1 96 at the end of single channel conversion or at the end of all conversions.
bogdanm 89:552587b429a1 97 This parameter can be a value of @ref ADC_EOCSelection */
bogdanm 89:552587b429a1 98 uint32_t ContinuousConvMode; /*!< Specifies whether the conversion is performed in Continuous or Single mode.
bogdanm 89:552587b429a1 99 This parameter can be set to ENABLE or DISABLE. */
bogdanm 89:552587b429a1 100 uint32_t DMAContinuousRequests; /*!< Specifies whether the DMA requests is performed in Continuous or in Single mode.
bogdanm 89:552587b429a1 101 This parameter can be set to ENABLE or DISABLE. */
bogdanm 89:552587b429a1 102 uint32_t NbrOfConversion; /*!< Specifies the number of ADC conversions that will be done using the sequencer for
bogdanm 89:552587b429a1 103 regular channel group.
bogdanm 89:552587b429a1 104 This parameter must be a number between Min_Data = 1 and Max_Data = 16. */
bogdanm 89:552587b429a1 105 uint32_t DiscontinuousConvMode; /*!< Specifies whether the conversion is performed in Discontinuous or not
bogdanm 89:552587b429a1 106 for regular channels.
bogdanm 89:552587b429a1 107 This parameter can be set to ENABLE or DISABLE. */
bogdanm 89:552587b429a1 108 uint32_t NbrOfDiscConversion; /*!< Specifies the number of ADC discontinuous conversions that will be done
bogdanm 89:552587b429a1 109 using the sequencer for regular channel group.
bogdanm 89:552587b429a1 110 This parameter must be a number between Min_Data = 1 and Max_Data = 8. */
bogdanm 89:552587b429a1 111 uint32_t ExternalTrigConvEdge; /*!< Select the external trigger edge and enable the trigger of a regular group.
bogdanm 89:552587b429a1 112 This parameter can be a value of @ref ADC_External_trigger_edge_Regular */
bogdanm 89:552587b429a1 113 uint32_t ExternalTrigConv; /*!< Select the external event used to trigger the start of conversion of a regular group.
bogdanm 89:552587b429a1 114 This parameter can be a value of @ref ADC_External_trigger_Source_Regular */
bogdanm 89:552587b429a1 115 }ADC_InitTypeDef;
bogdanm 89:552587b429a1 116
bogdanm 89:552587b429a1 117 /**
bogdanm 89:552587b429a1 118 * @brief ADC handle Structure definition
bogdanm 89:552587b429a1 119 */
bogdanm 89:552587b429a1 120 typedef struct
bogdanm 89:552587b429a1 121 {
bogdanm 89:552587b429a1 122 ADC_TypeDef *Instance; /*!< Register base address */
bogdanm 89:552587b429a1 123
bogdanm 89:552587b429a1 124 ADC_InitTypeDef Init; /*!< ADC required parameters */
bogdanm 89:552587b429a1 125
bogdanm 89:552587b429a1 126 __IO uint32_t NbrOfCurrentConversionRank; /*!< ADC number of current conversion rank */
bogdanm 89:552587b429a1 127
bogdanm 89:552587b429a1 128 DMA_HandleTypeDef *DMA_Handle; /*!< Pointer DMA Handler */
bogdanm 89:552587b429a1 129
bogdanm 89:552587b429a1 130 HAL_LockTypeDef Lock; /*!< ADC locking object */
bogdanm 89:552587b429a1 131
bogdanm 89:552587b429a1 132 __IO HAL_ADC_StateTypeDef State; /*!< ADC communication state */
bogdanm 89:552587b429a1 133
bogdanm 89:552587b429a1 134 __IO uint32_t ErrorCode; /*!< ADC Error code */
bogdanm 89:552587b429a1 135 }ADC_HandleTypeDef;
bogdanm 89:552587b429a1 136
bogdanm 89:552587b429a1 137 /**
bogdanm 89:552587b429a1 138 * @brief ADC Configuration regular Channel structure definition
bogdanm 89:552587b429a1 139 */
bogdanm 89:552587b429a1 140 typedef struct
bogdanm 89:552587b429a1 141 {
bogdanm 89:552587b429a1 142 uint32_t Channel; /*!< The ADC channel to configure.
bogdanm 89:552587b429a1 143 This parameter can be a value of @ref ADC_channels */
bogdanm 89:552587b429a1 144 uint32_t Rank; /*!< The rank in the regular group sequencer.
bogdanm 89:552587b429a1 145 This parameter must be a number between Min_Data = 1 and Max_Data = 16 */
bogdanm 89:552587b429a1 146 uint32_t SamplingTime; /*!< The sample time value to be set for the selected channel.
bogdanm 89:552587b429a1 147 This parameter can be a value of @ref ADC_sampling_times */
bogdanm 89:552587b429a1 148 uint32_t Offset; /*!< Reserved for future use, can be set to 0 */
bogdanm 89:552587b429a1 149 }ADC_ChannelConfTypeDef;
bogdanm 89:552587b429a1 150
bogdanm 89:552587b429a1 151 /**
bogdanm 89:552587b429a1 152 * @brief ADC Configuration multi-mode structure definition
bogdanm 89:552587b429a1 153 */
bogdanm 89:552587b429a1 154 typedef struct
bogdanm 89:552587b429a1 155 {
bogdanm 89:552587b429a1 156 uint32_t WatchdogMode; /*!< Configures the ADC analog watchdog mode.
bogdanm 89:552587b429a1 157 This parameter can be a value of @ref ADC_analog_watchdog_selection */
bogdanm 89:552587b429a1 158 uint32_t HighThreshold; /*!< Configures the ADC analog watchdog High threshold value.
bogdanm 89:552587b429a1 159 This parameter must be a 12-bit value. */
bogdanm 89:552587b429a1 160 uint32_t LowThreshold; /*!< Configures the ADC analog watchdog High threshold value.
bogdanm 89:552587b429a1 161 This parameter must be a 12-bit value. */
bogdanm 89:552587b429a1 162 uint32_t Channel; /*!< Configures ADC channel for the analog watchdog.
bogdanm 89:552587b429a1 163 This parameter has an effect only if watchdog mode is configured on single channel
bogdanm 89:552587b429a1 164 This parameter can be a value of @ref ADC_channels */
bogdanm 89:552587b429a1 165 uint32_t ITMode; /*!< Specifies whether the analog watchdog is configured
bogdanm 89:552587b429a1 166 is interrupt mode or in polling mode.
bogdanm 89:552587b429a1 167 This parameter can be set to ENABLE or DISABLE */
bogdanm 89:552587b429a1 168 uint32_t WatchdogNumber; /*!< Reserved for future use, can be set to 0 */
bogdanm 89:552587b429a1 169 }ADC_AnalogWDGConfTypeDef;
bogdanm 89:552587b429a1 170
bogdanm 89:552587b429a1 171 /* Exported constants --------------------------------------------------------*/
bogdanm 89:552587b429a1 172
bogdanm 89:552587b429a1 173 /** @defgroup ADC_Exported_Constants
bogdanm 89:552587b429a1 174 * @{
bogdanm 89:552587b429a1 175 */
bogdanm 89:552587b429a1 176
bogdanm 89:552587b429a1 177
bogdanm 89:552587b429a1 178 /** @defgroup ADC_Error_Code
bogdanm 89:552587b429a1 179 * @{
bogdanm 89:552587b429a1 180 */
bogdanm 89:552587b429a1 181
bogdanm 89:552587b429a1 182 #define HAL_ADC_ERROR_NONE ((uint32_t)0x00) /*!< No error */
bogdanm 89:552587b429a1 183 #define HAL_ADC_ERROR_OVR ((uint32_t)0x01) /*!< OVR error */
bogdanm 89:552587b429a1 184 #define HAL_ADC_ERROR_DMA ((uint32_t)0x02) /*!< DMA transfer error */
bogdanm 89:552587b429a1 185 /**
bogdanm 89:552587b429a1 186 * @}
bogdanm 89:552587b429a1 187 */
bogdanm 89:552587b429a1 188
bogdanm 89:552587b429a1 189
bogdanm 89:552587b429a1 190 /** @defgroup ADC_ClockPrescaler
bogdanm 89:552587b429a1 191 * @{
bogdanm 89:552587b429a1 192 */
bogdanm 89:552587b429a1 193 #define ADC_CLOCKPRESCALER_PCLK_DIV2 ((uint32_t)0x00000000)
bogdanm 89:552587b429a1 194 #define ADC_CLOCKPRESCALER_PCLK_DIV4 ((uint32_t)ADC_CCR_ADCPRE_0)
bogdanm 89:552587b429a1 195 #define ADC_CLOCKPRESCALER_PCLK_DIV6 ((uint32_t)ADC_CCR_ADCPRE_1)
bogdanm 89:552587b429a1 196 #define ADC_CLOCKPRESCALER_PCLK_DIV8 ((uint32_t)ADC_CCR_ADCPRE)
bogdanm 89:552587b429a1 197 #define IS_ADC_CLOCKPRESCALER(ADC_CLOCK) (((ADC_CLOCK) == ADC_CLOCKPRESCALER_PCLK_DIV2) || \
bogdanm 89:552587b429a1 198 ((ADC_CLOCK) == ADC_CLOCKPRESCALER_PCLK_DIV4) || \
bogdanm 89:552587b429a1 199 ((ADC_CLOCK) == ADC_CLOCKPRESCALER_PCLK_DIV6) || \
bogdanm 89:552587b429a1 200 ((ADC_CLOCK) == ADC_CLOCKPRESCALER_PCLK_DIV8))
bogdanm 89:552587b429a1 201 /**
bogdanm 89:552587b429a1 202 * @}
bogdanm 89:552587b429a1 203 */
bogdanm 89:552587b429a1 204
bogdanm 89:552587b429a1 205 /** @defgroup ADC_Resolution
bogdanm 89:552587b429a1 206 * @{
bogdanm 89:552587b429a1 207 */
bogdanm 89:552587b429a1 208 #define ADC_RESOLUTION12b ((uint32_t)0x00000000)
bogdanm 89:552587b429a1 209 #define ADC_RESOLUTION10b ((uint32_t)ADC_CR1_RES_0)
bogdanm 89:552587b429a1 210 #define ADC_RESOLUTION8b ((uint32_t)ADC_CR1_RES_1)
bogdanm 89:552587b429a1 211 #define ADC_RESOLUTION6b ((uint32_t)ADC_CR1_RES)
bogdanm 89:552587b429a1 212
bogdanm 89:552587b429a1 213 #define IS_ADC_RESOLUTION(RESOLUTION) (((RESOLUTION) == ADC_RESOLUTION12b) || \
bogdanm 89:552587b429a1 214 ((RESOLUTION) == ADC_RESOLUTION10b) || \
bogdanm 89:552587b429a1 215 ((RESOLUTION) == ADC_RESOLUTION8b) || \
bogdanm 89:552587b429a1 216 ((RESOLUTION) == ADC_RESOLUTION6b))
bogdanm 89:552587b429a1 217 /**
bogdanm 89:552587b429a1 218 * @}
bogdanm 89:552587b429a1 219 */
bogdanm 89:552587b429a1 220
bogdanm 89:552587b429a1 221 /** @defgroup ADC_External_trigger_edge_Regular
bogdanm 89:552587b429a1 222 * @{
bogdanm 89:552587b429a1 223 */
bogdanm 89:552587b429a1 224 #define ADC_EXTERNALTRIGCONVEDGE_NONE ((uint32_t)0x00000000)
bogdanm 89:552587b429a1 225 #define ADC_EXTERNALTRIGCONVEDGE_RISING ((uint32_t)ADC_CR2_EXTEN_0)
bogdanm 89:552587b429a1 226 #define ADC_EXTERNALTRIGCONVEDGE_FALLING ((uint32_t)ADC_CR2_EXTEN_1)
bogdanm 89:552587b429a1 227 #define ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING ((uint32_t)ADC_CR2_EXTEN)
bogdanm 89:552587b429a1 228
bogdanm 89:552587b429a1 229 #define IS_ADC_EXT_TRIG_EDGE(EDGE) (((EDGE) == ADC_EXTERNALTRIGCONVEDGE_NONE) || \
bogdanm 89:552587b429a1 230 ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISING) || \
bogdanm 89:552587b429a1 231 ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_FALLING) || \
bogdanm 89:552587b429a1 232 ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING))
bogdanm 89:552587b429a1 233 /**
bogdanm 89:552587b429a1 234 * @}
bogdanm 89:552587b429a1 235 */
bogdanm 89:552587b429a1 236
bogdanm 89:552587b429a1 237 /** @defgroup ADC_External_trigger_Source_Regular
bogdanm 89:552587b429a1 238 * @{
bogdanm 89:552587b429a1 239 */
bogdanm 89:552587b429a1 240 #define ADC_EXTERNALTRIGCONV_T1_CC1 ((uint32_t)0x00000000)
bogdanm 89:552587b429a1 241 #define ADC_EXTERNALTRIGCONV_T1_CC2 ((uint32_t)ADC_CR2_EXTSEL_0)
bogdanm 89:552587b429a1 242 #define ADC_EXTERNALTRIGCONV_T1_CC3 ((uint32_t)ADC_CR2_EXTSEL_1)
bogdanm 89:552587b429a1 243 #define ADC_EXTERNALTRIGCONV_T2_CC2 ((uint32_t)(ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
bogdanm 89:552587b429a1 244 #define ADC_EXTERNALTRIGCONV_T2_CC3 ((uint32_t)ADC_CR2_EXTSEL_2)
bogdanm 89:552587b429a1 245 #define ADC_EXTERNALTRIGCONV_T2_CC4 ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_0))
bogdanm 89:552587b429a1 246 #define ADC_EXTERNALTRIGCONV_T2_TRGO ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1))
bogdanm 89:552587b429a1 247 #define ADC_EXTERNALTRIGCONV_T3_CC1 ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
bogdanm 89:552587b429a1 248 #define ADC_EXTERNALTRIGCONV_T3_TRGO ((uint32_t)ADC_CR2_EXTSEL_3)
bogdanm 89:552587b429a1 249 #define ADC_EXTERNALTRIGCONV_T4_CC4 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_0))
bogdanm 89:552587b429a1 250 #define ADC_EXTERNALTRIGCONV_T5_CC1 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_1))
bogdanm 89:552587b429a1 251 #define ADC_EXTERNALTRIGCONV_T5_CC2 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
bogdanm 89:552587b429a1 252 #define ADC_EXTERNALTRIGCONV_T5_CC3 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2))
bogdanm 89:552587b429a1 253 #define ADC_EXTERNALTRIGCONV_T8_CC1 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_0))
bogdanm 89:552587b429a1 254 #define ADC_EXTERNALTRIGCONV_T8_TRGO ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1))
bogdanm 89:552587b429a1 255 #define ADC_EXTERNALTRIGCONV_Ext_IT11 ((uint32_t)ADC_CR2_EXTSEL)
bogdanm 89:552587b429a1 256
bogdanm 89:552587b429a1 257 #define IS_ADC_EXT_TRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC1) || \
bogdanm 89:552587b429a1 258 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC2) || \
bogdanm 89:552587b429a1 259 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC3) || \
bogdanm 89:552587b429a1 260 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC2) || \
bogdanm 89:552587b429a1 261 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC3) || \
bogdanm 89:552587b429a1 262 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC4) || \
bogdanm 89:552587b429a1 263 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_TRGO) || \
bogdanm 89:552587b429a1 264 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_CC1) || \
bogdanm 89:552587b429a1 265 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \
bogdanm 89:552587b429a1 266 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T4_CC4) || \
bogdanm 89:552587b429a1 267 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC1) || \
bogdanm 89:552587b429a1 268 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC2) || \
bogdanm 89:552587b429a1 269 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC3) || \
bogdanm 89:552587b429a1 270 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T8_CC1) || \
bogdanm 89:552587b429a1 271 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T8_TRGO) || \
bogdanm 89:552587b429a1 272 ((REGTRIG) == ADC_EXTERNALTRIGCONV_Ext_IT11))
bogdanm 89:552587b429a1 273 /**
bogdanm 89:552587b429a1 274 * @}
bogdanm 89:552587b429a1 275 */
bogdanm 89:552587b429a1 276
bogdanm 89:552587b429a1 277 /** @defgroup ADC_data_align
bogdanm 89:552587b429a1 278 * @{
bogdanm 89:552587b429a1 279 */
bogdanm 89:552587b429a1 280 #define ADC_DATAALIGN_RIGHT ((uint32_t)0x00000000)
bogdanm 89:552587b429a1 281 #define ADC_DATAALIGN_LEFT ((uint32_t)ADC_CR2_ALIGN)
bogdanm 89:552587b429a1 282
bogdanm 89:552587b429a1 283 #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DATAALIGN_RIGHT) || \
bogdanm 89:552587b429a1 284 ((ALIGN) == ADC_DATAALIGN_LEFT))
bogdanm 89:552587b429a1 285 /**
bogdanm 89:552587b429a1 286 * @}
bogdanm 89:552587b429a1 287 */
bogdanm 89:552587b429a1 288
bogdanm 89:552587b429a1 289 /** @defgroup ADC_channels
bogdanm 89:552587b429a1 290 * @{
bogdanm 89:552587b429a1 291 */
bogdanm 89:552587b429a1 292 #define ADC_CHANNEL_0 ((uint32_t)0x00000000)
bogdanm 89:552587b429a1 293 #define ADC_CHANNEL_1 ((uint32_t)ADC_CR1_AWDCH_0)
bogdanm 89:552587b429a1 294 #define ADC_CHANNEL_2 ((uint32_t)ADC_CR1_AWDCH_1)
bogdanm 89:552587b429a1 295 #define ADC_CHANNEL_3 ((uint32_t)(ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
bogdanm 89:552587b429a1 296 #define ADC_CHANNEL_4 ((uint32_t)ADC_CR1_AWDCH_2)
bogdanm 89:552587b429a1 297 #define ADC_CHANNEL_5 ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_0))
bogdanm 89:552587b429a1 298 #define ADC_CHANNEL_6 ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1))
bogdanm 89:552587b429a1 299 #define ADC_CHANNEL_7 ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
bogdanm 89:552587b429a1 300 #define ADC_CHANNEL_8 ((uint32_t)ADC_CR1_AWDCH_3)
bogdanm 89:552587b429a1 301 #define ADC_CHANNEL_9 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_0))
bogdanm 89:552587b429a1 302 #define ADC_CHANNEL_10 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_1))
bogdanm 89:552587b429a1 303 #define ADC_CHANNEL_11 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
bogdanm 89:552587b429a1 304 #define ADC_CHANNEL_12 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2))
bogdanm 89:552587b429a1 305 #define ADC_CHANNEL_13 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_0))
bogdanm 89:552587b429a1 306 #define ADC_CHANNEL_14 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1))
bogdanm 89:552587b429a1 307 #define ADC_CHANNEL_15 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
bogdanm 89:552587b429a1 308 #define ADC_CHANNEL_16 ((uint32_t)ADC_CR1_AWDCH_4)
bogdanm 89:552587b429a1 309 #define ADC_CHANNEL_17 ((uint32_t)(ADC_CR1_AWDCH_4 | ADC_CR1_AWDCH_0))
bogdanm 89:552587b429a1 310 #define ADC_CHANNEL_18 ((uint32_t)(ADC_CR1_AWDCH_4 | ADC_CR1_AWDCH_1))
bogdanm 89:552587b429a1 311
bogdanm 89:552587b429a1 312 #define ADC_CHANNEL_TEMPSENSOR ((uint32_t)ADC_CHANNEL_16)
bogdanm 89:552587b429a1 313 #define ADC_CHANNEL_VREFINT ((uint32_t)ADC_CHANNEL_17)
bogdanm 89:552587b429a1 314 #define ADC_CHANNEL_VBAT ((uint32_t)ADC_CHANNEL_18)
bogdanm 89:552587b429a1 315
bogdanm 89:552587b429a1 316 #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_CHANNEL_0) || \
bogdanm 89:552587b429a1 317 ((CHANNEL) == ADC_CHANNEL_1) || \
bogdanm 89:552587b429a1 318 ((CHANNEL) == ADC_CHANNEL_2) || \
bogdanm 89:552587b429a1 319 ((CHANNEL) == ADC_CHANNEL_3) || \
bogdanm 89:552587b429a1 320 ((CHANNEL) == ADC_CHANNEL_4) || \
bogdanm 89:552587b429a1 321 ((CHANNEL) == ADC_CHANNEL_5) || \
bogdanm 89:552587b429a1 322 ((CHANNEL) == ADC_CHANNEL_6) || \
bogdanm 89:552587b429a1 323 ((CHANNEL) == ADC_CHANNEL_7) || \
bogdanm 89:552587b429a1 324 ((CHANNEL) == ADC_CHANNEL_8) || \
bogdanm 89:552587b429a1 325 ((CHANNEL) == ADC_CHANNEL_9) || \
bogdanm 89:552587b429a1 326 ((CHANNEL) == ADC_CHANNEL_10) || \
bogdanm 89:552587b429a1 327 ((CHANNEL) == ADC_CHANNEL_11) || \
bogdanm 89:552587b429a1 328 ((CHANNEL) == ADC_CHANNEL_12) || \
bogdanm 89:552587b429a1 329 ((CHANNEL) == ADC_CHANNEL_13) || \
bogdanm 89:552587b429a1 330 ((CHANNEL) == ADC_CHANNEL_14) || \
bogdanm 89:552587b429a1 331 ((CHANNEL) == ADC_CHANNEL_15) || \
bogdanm 89:552587b429a1 332 ((CHANNEL) == ADC_CHANNEL_16) || \
bogdanm 89:552587b429a1 333 ((CHANNEL) == ADC_CHANNEL_17) || \
bogdanm 89:552587b429a1 334 ((CHANNEL) == ADC_CHANNEL_18))
bogdanm 89:552587b429a1 335 /**
bogdanm 89:552587b429a1 336 * @}
bogdanm 89:552587b429a1 337 */
bogdanm 89:552587b429a1 338
bogdanm 89:552587b429a1 339 /** @defgroup ADC_sampling_times
bogdanm 89:552587b429a1 340 * @{
bogdanm 89:552587b429a1 341 */
bogdanm 89:552587b429a1 342 #define ADC_SAMPLETIME_3CYCLES ((uint32_t)0x00000000)
bogdanm 89:552587b429a1 343 #define ADC_SAMPLETIME_15CYCLES ((uint32_t)ADC_SMPR1_SMP10_0)
bogdanm 89:552587b429a1 344 #define ADC_SAMPLETIME_28CYCLES ((uint32_t)ADC_SMPR1_SMP10_1)
bogdanm 89:552587b429a1 345 #define ADC_SAMPLETIME_56CYCLES ((uint32_t)(ADC_SMPR1_SMP10_1 | ADC_SMPR1_SMP10_0))
bogdanm 89:552587b429a1 346 #define ADC_SAMPLETIME_84CYCLES ((uint32_t)ADC_SMPR1_SMP10_2)
bogdanm 89:552587b429a1 347 #define ADC_SAMPLETIME_112CYCLES ((uint32_t)(ADC_SMPR1_SMP10_2 | ADC_SMPR1_SMP10_0))
bogdanm 89:552587b429a1 348 #define ADC_SAMPLETIME_144CYCLES ((uint32_t)(ADC_SMPR1_SMP10_2 | ADC_SMPR1_SMP10_1))
bogdanm 89:552587b429a1 349 #define ADC_SAMPLETIME_480CYCLES ((uint32_t)ADC_SMPR1_SMP10)
bogdanm 89:552587b429a1 350
bogdanm 89:552587b429a1 351 #define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SAMPLETIME_3CYCLES) || \
bogdanm 89:552587b429a1 352 ((TIME) == ADC_SAMPLETIME_15CYCLES) || \
bogdanm 89:552587b429a1 353 ((TIME) == ADC_SAMPLETIME_28CYCLES) || \
bogdanm 89:552587b429a1 354 ((TIME) == ADC_SAMPLETIME_56CYCLES) || \
bogdanm 89:552587b429a1 355 ((TIME) == ADC_SAMPLETIME_84CYCLES) || \
bogdanm 89:552587b429a1 356 ((TIME) == ADC_SAMPLETIME_112CYCLES) || \
bogdanm 89:552587b429a1 357 ((TIME) == ADC_SAMPLETIME_144CYCLES) || \
bogdanm 89:552587b429a1 358 ((TIME) == ADC_SAMPLETIME_480CYCLES))
bogdanm 89:552587b429a1 359 /**
bogdanm 89:552587b429a1 360 * @}
bogdanm 89:552587b429a1 361 */
bogdanm 89:552587b429a1 362
bogdanm 89:552587b429a1 363 /** @defgroup ADC_EOCSelection
bogdanm 89:552587b429a1 364 * @{
bogdanm 89:552587b429a1 365 */
bogdanm 89:552587b429a1 366 #define EOC_SEQ_CONV ((uint32_t)0x00000000)
bogdanm 89:552587b429a1 367 #define EOC_SINGLE_CONV ((uint32_t)0x00000001)
bogdanm 89:552587b429a1 368 #define EOC_SINGLE_SEQ_CONV ((uint32_t)0x00000002) /*!< reserved for future use */
bogdanm 89:552587b429a1 369
bogdanm 89:552587b429a1 370 #define IS_ADC_EOCSelection(EOCSelection) (((EOCSelection) == EOC_SINGLE_CONV) || \
bogdanm 89:552587b429a1 371 ((EOCSelection) == EOC_SEQ_CONV) || \
bogdanm 89:552587b429a1 372 ((EOCSelection) == EOC_SINGLE_SEQ_CONV))
bogdanm 89:552587b429a1 373 /**
bogdanm 89:552587b429a1 374 * @}
bogdanm 89:552587b429a1 375 */
bogdanm 89:552587b429a1 376
bogdanm 89:552587b429a1 377 /** @defgroup ADC_Event_type
bogdanm 89:552587b429a1 378 * @{
bogdanm 89:552587b429a1 379 */
bogdanm 89:552587b429a1 380 #define AWD_EVENT ((uint32_t)ADC_FLAG_AWD)
bogdanm 89:552587b429a1 381 #define OVR_EVENT ((uint32_t)ADC_FLAG_OVR)
bogdanm 89:552587b429a1 382
bogdanm 89:552587b429a1 383 #define IS_ADC_EVENT_TYPE(EVENT) (((EVENT) == AWD_EVENT) || \
bogdanm 89:552587b429a1 384 ((EVENT) == OVR_EVENT))
bogdanm 89:552587b429a1 385 /**
bogdanm 89:552587b429a1 386 * @}
bogdanm 89:552587b429a1 387 */
bogdanm 89:552587b429a1 388
bogdanm 89:552587b429a1 389 /** @defgroup ADC_analog_watchdog_selection
bogdanm 89:552587b429a1 390 * @{
bogdanm 89:552587b429a1 391 */
bogdanm 89:552587b429a1 392 #define ADC_ANALOGWATCHDOG_SINGLE_REG ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_AWDEN))
bogdanm 89:552587b429a1 393 #define ADC_ANALOGWATCHDOG_SINGLE_INJEC ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_JAWDEN))
bogdanm 89:552587b429a1 394 #define ADC_ANALOGWATCHDOG_SINGLE_REGINJEC ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_AWDEN | ADC_CR1_JAWDEN))
bogdanm 89:552587b429a1 395 #define ADC_ANALOGWATCHDOG_ALL_REG ((uint32_t)ADC_CR1_AWDEN)
bogdanm 89:552587b429a1 396 #define ADC_ANALOGWATCHDOG_ALL_INJEC ((uint32_t)ADC_CR1_JAWDEN)
bogdanm 89:552587b429a1 397 #define ADC_ANALOGWATCHDOG_ALL_REGINJEC ((uint32_t)(ADC_CR1_AWDEN | ADC_CR1_JAWDEN))
bogdanm 89:552587b429a1 398 #define ADC_ANALOGWATCHDOG_NONE ((uint32_t)0x00000000)
bogdanm 89:552587b429a1 399
bogdanm 89:552587b429a1 400 #define IS_ADC_ANALOG_WATCHDOG(WATCHDOG) (((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_REG) || \
bogdanm 89:552587b429a1 401 ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_INJEC) || \
bogdanm 89:552587b429a1 402 ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_REGINJEC) || \
bogdanm 89:552587b429a1 403 ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_REG) || \
bogdanm 89:552587b429a1 404 ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_INJEC) || \
bogdanm 89:552587b429a1 405 ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_REGINJEC) || \
bogdanm 89:552587b429a1 406 ((WATCHDOG) == ADC_ANALOGWATCHDOG_NONE))
bogdanm 89:552587b429a1 407 /**
bogdanm 89:552587b429a1 408 * @}
bogdanm 89:552587b429a1 409 */
bogdanm 89:552587b429a1 410
bogdanm 89:552587b429a1 411 /** @defgroup ADC_interrupts_definition
bogdanm 89:552587b429a1 412 * @{
bogdanm 89:552587b429a1 413 */
bogdanm 89:552587b429a1 414 #define ADC_IT_EOC ((uint32_t)ADC_CR1_EOCIE)
bogdanm 89:552587b429a1 415 #define ADC_IT_AWD ((uint32_t)ADC_CR1_AWDIE)
bogdanm 89:552587b429a1 416 #define ADC_IT_JEOC ((uint32_t)ADC_CR1_JEOCIE)
bogdanm 89:552587b429a1 417 #define ADC_IT_OVR ((uint32_t)ADC_CR1_OVRIE)
bogdanm 89:552587b429a1 418
bogdanm 89:552587b429a1 419 #define IS_ADC_IT(IT) (((IT) == ADC_IT_EOC) || ((IT) == ADC_IT_AWD) || \
bogdanm 89:552587b429a1 420 ((IT) == ADC_IT_JEOC)|| ((IT) == ADC_IT_OVR))
bogdanm 89:552587b429a1 421 /**
bogdanm 89:552587b429a1 422 * @}
bogdanm 89:552587b429a1 423 */
bogdanm 89:552587b429a1 424
bogdanm 89:552587b429a1 425 /** @defgroup ADC_flags_definition
bogdanm 89:552587b429a1 426 * @{
bogdanm 89:552587b429a1 427 */
bogdanm 89:552587b429a1 428 #define ADC_FLAG_AWD ((uint32_t)ADC_SR_AWD)
bogdanm 89:552587b429a1 429 #define ADC_FLAG_EOC ((uint32_t)ADC_SR_EOC)
bogdanm 89:552587b429a1 430 #define ADC_FLAG_JEOC ((uint32_t)ADC_SR_JEOC)
bogdanm 89:552587b429a1 431 #define ADC_FLAG_JSTRT ((uint32_t)ADC_SR_JSTRT)
bogdanm 89:552587b429a1 432 #define ADC_FLAG_STRT ((uint32_t)ADC_SR_STRT)
bogdanm 89:552587b429a1 433 #define ADC_FLAG_OVR ((uint32_t)ADC_SR_OVR)
bogdanm 89:552587b429a1 434 /**
bogdanm 89:552587b429a1 435 * @}
bogdanm 89:552587b429a1 436 */
bogdanm 89:552587b429a1 437
bogdanm 89:552587b429a1 438 /** @defgroup ADC_channels_type
bogdanm 89:552587b429a1 439 * @{
bogdanm 89:552587b429a1 440 */
bogdanm 89:552587b429a1 441 #define ALL_CHANNELS ((uint32_t)0x00000001)
bogdanm 89:552587b429a1 442 #define REGULAR_CHANNELS ((uint32_t)0x00000002) /*!< reserved for future use */
bogdanm 89:552587b429a1 443 #define INJECTED_CHANNELS ((uint32_t)0x00000003) /*!< reserved for future use */
bogdanm 89:552587b429a1 444
bogdanm 89:552587b429a1 445 #define IS_ADC_CHANNELS_TYPE(CHANNEL_TYPE) (((CHANNEL_TYPE) == ALL_CHANNELS) || \
bogdanm 89:552587b429a1 446 ((CHANNEL_TYPE) == REGULAR_CHANNELS) || \
bogdanm 89:552587b429a1 447 ((CHANNEL_TYPE) == INJECTED_CHANNELS))
bogdanm 89:552587b429a1 448 /**
bogdanm 89:552587b429a1 449 * @}
bogdanm 89:552587b429a1 450 */
bogdanm 89:552587b429a1 451
bogdanm 89:552587b429a1 452 /** @defgroup ADC_thresholds
bogdanm 89:552587b429a1 453 * @{
bogdanm 89:552587b429a1 454 */
bogdanm 89:552587b429a1 455 #define IS_ADC_THRESHOLD(THRESHOLD) ((THRESHOLD) <= ((uint32_t)0xFFF))
bogdanm 89:552587b429a1 456 /**
bogdanm 89:552587b429a1 457 * @}
bogdanm 89:552587b429a1 458 */
bogdanm 89:552587b429a1 459
bogdanm 89:552587b429a1 460 /** @defgroup ADC_regular_length
bogdanm 89:552587b429a1 461 * @{
bogdanm 89:552587b429a1 462 */
bogdanm 89:552587b429a1 463 #define IS_ADC_REGULAR_LENGTH(LENGTH) (((LENGTH) >= ((uint32_t)1)) && ((LENGTH) <= ((uint32_t)16)))
bogdanm 89:552587b429a1 464 /**
bogdanm 89:552587b429a1 465 * @}
bogdanm 89:552587b429a1 466 */
bogdanm 89:552587b429a1 467
bogdanm 89:552587b429a1 468 /** @defgroup ADC_regular_rank
bogdanm 89:552587b429a1 469 * @{
bogdanm 89:552587b429a1 470 */
bogdanm 89:552587b429a1 471 #define IS_ADC_REGULAR_RANK(RANK) (((RANK) >= ((uint32_t)1)) && ((RANK) <= ((uint32_t)16)))
bogdanm 89:552587b429a1 472 /**
bogdanm 89:552587b429a1 473 * @}
bogdanm 89:552587b429a1 474 */
bogdanm 89:552587b429a1 475
bogdanm 89:552587b429a1 476 /** @defgroup ADC_regular_discontinuous_mode_number
bogdanm 89:552587b429a1 477 * @{
bogdanm 89:552587b429a1 478 */
bogdanm 89:552587b429a1 479 #define IS_ADC_REGULAR_DISC_NUMBER(NUMBER) (((NUMBER) >= ((uint32_t)1)) && ((NUMBER) <= ((uint32_t)8)))
bogdanm 89:552587b429a1 480 /**
bogdanm 89:552587b429a1 481 * @}
bogdanm 89:552587b429a1 482 */
bogdanm 89:552587b429a1 483
bogdanm 89:552587b429a1 484 /** @defgroup ADC_range_verification
bogdanm 89:552587b429a1 485 * @{
bogdanm 89:552587b429a1 486 */
bogdanm 89:552587b429a1 487 #define IS_ADC_RANGE(RESOLUTION, ADC_VALUE) \
bogdanm 89:552587b429a1 488 ((((RESOLUTION) == ADC_RESOLUTION12b) && ((ADC_VALUE) <= ((uint32_t)0x0FFF))) || \
bogdanm 89:552587b429a1 489 (((RESOLUTION) == ADC_RESOLUTION10b) && ((ADC_VALUE) <= ((uint32_t)0x03FF))) || \
bogdanm 89:552587b429a1 490 (((RESOLUTION) == ADC_RESOLUTION8b) && ((ADC_VALUE) <= ((uint32_t)0x00FF))) || \
bogdanm 89:552587b429a1 491 (((RESOLUTION) == ADC_RESOLUTION6b) && ((ADC_VALUE) <= ((uint32_t)0x003F))))
bogdanm 89:552587b429a1 492 /**
bogdanm 89:552587b429a1 493 * @}
bogdanm 89:552587b429a1 494 */
bogdanm 89:552587b429a1 495
bogdanm 89:552587b429a1 496 /**
bogdanm 89:552587b429a1 497 * @}
bogdanm 89:552587b429a1 498 */
bogdanm 89:552587b429a1 499
bogdanm 89:552587b429a1 500 /* Exported macro ------------------------------------------------------------*/
bogdanm 89:552587b429a1 501
bogdanm 89:552587b429a1 502 /** @brief Reset ADC handle state
bogdanm 89:552587b429a1 503 * @param __HANDLE__: ADC handle
bogdanm 89:552587b429a1 504 * @retval None
bogdanm 89:552587b429a1 505 */
bogdanm 89:552587b429a1 506 #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
bogdanm 89:552587b429a1 507
bogdanm 89:552587b429a1 508 /**
bogdanm 89:552587b429a1 509 * @brief Enable the ADC peripheral.
bogdanm 89:552587b429a1 510 * @param __HANDLE__: ADC handle
bogdanm 89:552587b429a1 511 * @retval None
bogdanm 89:552587b429a1 512 */
bogdanm 89:552587b429a1 513 #define __HAL_ADC_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR2 |= ADC_CR2_ADON)
bogdanm 89:552587b429a1 514
bogdanm 89:552587b429a1 515 /**
bogdanm 89:552587b429a1 516 * @brief Disable the ADC peripheral.
bogdanm 89:552587b429a1 517 * @param __HANDLE__: ADC handle
bogdanm 89:552587b429a1 518 * @retval None
bogdanm 89:552587b429a1 519 */
bogdanm 89:552587b429a1 520 #define __HAL_ADC_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR2 &= ~ADC_CR2_ADON)
bogdanm 89:552587b429a1 521
bogdanm 89:552587b429a1 522 /**
bogdanm 89:552587b429a1 523 * @brief Set ADC Regular channel sequence length.
bogdanm 89:552587b429a1 524 * @param _NbrOfConversion_: Regular channel sequence length.
bogdanm 89:552587b429a1 525 * @retval None
bogdanm 89:552587b429a1 526 */
bogdanm 89:552587b429a1 527 #define __HAL_ADC_SQR1(_NbrOfConversion_) (((_NbrOfConversion_) - (uint8_t)1) << 20)
bogdanm 89:552587b429a1 528
bogdanm 89:552587b429a1 529 /**
bogdanm 89:552587b429a1 530 * @brief Set the ADC's sample time for channel numbers between 10 and 18.
bogdanm 89:552587b429a1 531 * @param _SAMPLETIME_: Sample time parameter.
bogdanm 89:552587b429a1 532 * @param _CHANNELNB_: Channel number.
bogdanm 89:552587b429a1 533 * @retval None
bogdanm 89:552587b429a1 534 */
bogdanm 89:552587b429a1 535 #define __HAL_ADC_SMPR1(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3 * ((_CHANNELNB_) - 10)))
bogdanm 89:552587b429a1 536
bogdanm 89:552587b429a1 537 /**
bogdanm 89:552587b429a1 538 * @brief Set the ADC's sample time for channel numbers between 0 and 9.
bogdanm 89:552587b429a1 539 * @param _SAMPLETIME_: Sample time parameter.
bogdanm 89:552587b429a1 540 * @param _CHANNELNB_: Channel number.
bogdanm 89:552587b429a1 541 * @retval None
bogdanm 89:552587b429a1 542 */
bogdanm 89:552587b429a1 543 #define __HAL_ADC_SMPR2(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3 * (_CHANNELNB_)))
bogdanm 89:552587b429a1 544
bogdanm 89:552587b429a1 545 /**
bogdanm 89:552587b429a1 546 * @brief Set the selected regular channel rank for rank between 1 and 6.
bogdanm 89:552587b429a1 547 * @param _CHANNELNB_: Channel number.
bogdanm 89:552587b429a1 548 * @param _RANKNB_: Rank number.
bogdanm 89:552587b429a1 549 * @retval None
bogdanm 89:552587b429a1 550 */
bogdanm 89:552587b429a1 551 #define __HAL_ADC_SQR3_RK(_CHANNELNB_, _RANKNB_) ((_CHANNELNB_) << (5 * ((_RANKNB_) - 1)))
bogdanm 89:552587b429a1 552
bogdanm 89:552587b429a1 553 /**
bogdanm 89:552587b429a1 554 * @brief Set the selected regular channel rank for rank between 7 and 12.
bogdanm 89:552587b429a1 555 * @param _CHANNELNB_: Channel number.
bogdanm 89:552587b429a1 556 * @param _RANKNB_: Rank number.
bogdanm 89:552587b429a1 557 * @retval None
bogdanm 89:552587b429a1 558 */
bogdanm 89:552587b429a1 559 #define __HAL_ADC_SQR2_RK(_CHANNELNB_, _RANKNB_) ((_CHANNELNB_) << (5 * ((_RANKNB_) - 7)))
bogdanm 89:552587b429a1 560
bogdanm 89:552587b429a1 561 /**
bogdanm 89:552587b429a1 562 * @brief Set the selected regular channel rank for rank between 13 and 16.
bogdanm 89:552587b429a1 563 * @param _CHANNELNB_: Channel number.
bogdanm 89:552587b429a1 564 * @param _RANKNB_: Rank number.
bogdanm 89:552587b429a1 565 * @retval None
bogdanm 89:552587b429a1 566 */
bogdanm 89:552587b429a1 567 #define __HAL_ADC_SQR1_RK(_CHANNELNB_, _RANKNB_) ((_CHANNELNB_) << (5 * ((_RANKNB_) - 13)))
bogdanm 89:552587b429a1 568
bogdanm 89:552587b429a1 569 /**
bogdanm 89:552587b429a1 570 * @brief Enable ADC continuous conversion mode.
bogdanm 89:552587b429a1 571 * @param _CONTINUOUS_MODE_: Continuous mode.
bogdanm 89:552587b429a1 572 * @retval None
bogdanm 89:552587b429a1 573 */
bogdanm 89:552587b429a1 574 #define __HAL_ADC_CR2_CONTINUOUS(_CONTINUOUS_MODE_) ((_CONTINUOUS_MODE_) << 1)
bogdanm 89:552587b429a1 575
bogdanm 89:552587b429a1 576 /**
bogdanm 89:552587b429a1 577 * @brief Configures the number of discontinuous conversions for the regular group channels.
bogdanm 89:552587b429a1 578 * @param _NBR_DISCONTINUOUSCONV_: Number of discontinuous conversions.
bogdanm 89:552587b429a1 579 * @retval None
bogdanm 89:552587b429a1 580 */
bogdanm 89:552587b429a1 581 #define __HAL_ADC_CR1_DISCONTINUOUS(_NBR_DISCONTINUOUSCONV_) (((_NBR_DISCONTINUOUSCONV_) - 1) << 13)
bogdanm 89:552587b429a1 582
bogdanm 89:552587b429a1 583 /**
bogdanm 89:552587b429a1 584 * @brief Enable ADC scan mode.
bogdanm 89:552587b429a1 585 * @param _SCANCONV_MODE_: Scan conversion mode.
bogdanm 89:552587b429a1 586 * @retval None
bogdanm 89:552587b429a1 587 */
bogdanm 89:552587b429a1 588 #define __HAL_ADC_CR1_SCANCONV(_SCANCONV_MODE_) ((_SCANCONV_MODE_) << 8)
bogdanm 89:552587b429a1 589
bogdanm 89:552587b429a1 590 /**
bogdanm 89:552587b429a1 591 * @brief Enable the ADC end of conversion selection.
bogdanm 89:552587b429a1 592 * @param _EOCSelection_MODE_: End of conversion selection mode.
bogdanm 89:552587b429a1 593 * @retval None
bogdanm 89:552587b429a1 594 */
bogdanm 89:552587b429a1 595 #define __HAL_ADC_CR2_EOCSelection(_EOCSelection_MODE_) ((_EOCSelection_MODE_) << 10)
bogdanm 89:552587b429a1 596
bogdanm 89:552587b429a1 597 /**
bogdanm 89:552587b429a1 598 * @brief Enable the ADC DMA continuous request.
bogdanm 89:552587b429a1 599 * @param _DMAContReq_MODE_: DMA continuous request mode.
bogdanm 89:552587b429a1 600 * @retval None
bogdanm 89:552587b429a1 601 */
bogdanm 89:552587b429a1 602 #define __HAL_ADC_CR2_DMAContReq(_DMAContReq_MODE_) ((_DMAContReq_MODE_) << 9)
bogdanm 89:552587b429a1 603
bogdanm 89:552587b429a1 604 /**
bogdanm 89:552587b429a1 605 * @brief Enable the ADC end of conversion interrupt.
bogdanm 89:552587b429a1 606 * @param __HANDLE__: specifies the ADC Handle.
bogdanm 89:552587b429a1 607 * @param __INTERRUPT__: ADC Interrupt.
bogdanm 89:552587b429a1 608 * @retval None
bogdanm 89:552587b429a1 609 */
bogdanm 89:552587b429a1 610 #define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1) |= (__INTERRUPT__))
bogdanm 89:552587b429a1 611
bogdanm 89:552587b429a1 612 /**
bogdanm 89:552587b429a1 613 * @brief Disable the ADC end of conversion interrupt.
bogdanm 89:552587b429a1 614 * @param __HANDLE__: specifies the ADC Handle.
bogdanm 89:552587b429a1 615 * @param __INTERRUPT__: ADC interrupt.
bogdanm 89:552587b429a1 616 * @retval None
bogdanm 89:552587b429a1 617 */
bogdanm 89:552587b429a1 618 #define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1) &= ~(__INTERRUPT__))
bogdanm 89:552587b429a1 619
bogdanm 89:552587b429a1 620 /** @brief Check if the specified ADC interrupt source is enabled or disabled.
bogdanm 89:552587b429a1 621 * @param __HANDLE__: specifies the ADC Handle.
bogdanm 89:552587b429a1 622 * @param __INTERRUPT__: specifies the ADC interrupt source to check.
bogdanm 89:552587b429a1 623 * @retval The new state of __IT__ (TRUE or FALSE).
bogdanm 89:552587b429a1 624 */
bogdanm 89:552587b429a1 625 #define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR1 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
bogdanm 89:552587b429a1 626
bogdanm 89:552587b429a1 627 /**
bogdanm 89:552587b429a1 628 * @brief Clear the ADC's pending flags.
bogdanm 89:552587b429a1 629 * @param __HANDLE__: specifies the ADC Handle.
bogdanm 89:552587b429a1 630 * @param __FLAG__: ADC flag.
bogdanm 89:552587b429a1 631 * @retval None
bogdanm 89:552587b429a1 632 */
bogdanm 89:552587b429a1 633 #define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) &= ~(__FLAG__))
bogdanm 89:552587b429a1 634
bogdanm 89:552587b429a1 635 /**
bogdanm 89:552587b429a1 636 * @brief Get the selected ADC's flag status.
bogdanm 89:552587b429a1 637 * @param __HANDLE__: specifies the ADC Handle.
bogdanm 89:552587b429a1 638 * @param __FLAG__: ADC flag.
bogdanm 89:552587b429a1 639 * @retval None
bogdanm 89:552587b429a1 640 */
bogdanm 89:552587b429a1 641 #define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
bogdanm 89:552587b429a1 642
bogdanm 89:552587b429a1 643 /**
bogdanm 89:552587b429a1 644 * @brief Return resolution bits in CR1 register.
bogdanm 89:552587b429a1 645 * @param __HANDLE__: ADC handle
bogdanm 89:552587b429a1 646 * @retval None
bogdanm 89:552587b429a1 647 */
bogdanm 89:552587b429a1 648 #define __HAL_ADC_GET_RESOLUTION(__HANDLE__) (((__HANDLE__)->Instance->CR1) & ADC_CR1_RES)
bogdanm 89:552587b429a1 649
bogdanm 89:552587b429a1 650 /* Include ADC HAL Extension module */
bogdanm 89:552587b429a1 651 #include "stm32f4xx_hal_adc_ex.h"
bogdanm 89:552587b429a1 652
bogdanm 89:552587b429a1 653 /* Exported functions --------------------------------------------------------*/
bogdanm 89:552587b429a1 654 /* Initialization/de-initialization functions ***********************************/
bogdanm 89:552587b429a1 655 HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc);
bogdanm 89:552587b429a1 656 HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc);
bogdanm 89:552587b429a1 657 void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc);
bogdanm 89:552587b429a1 658 void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc);
bogdanm 89:552587b429a1 659
bogdanm 89:552587b429a1 660 /* I/O operation functions ******************************************************/
bogdanm 89:552587b429a1 661 HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc);
bogdanm 89:552587b429a1 662 HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc);
bogdanm 89:552587b429a1 663 HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
bogdanm 89:552587b429a1 664
bogdanm 89:552587b429a1 665 HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout);
bogdanm 89:552587b429a1 666
bogdanm 89:552587b429a1 667 HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc);
bogdanm 89:552587b429a1 668 HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc);
bogdanm 89:552587b429a1 669
bogdanm 89:552587b429a1 670 void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc);
bogdanm 89:552587b429a1 671
bogdanm 89:552587b429a1 672 HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length);
bogdanm 89:552587b429a1 673 HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc);
bogdanm 89:552587b429a1 674
bogdanm 89:552587b429a1 675 uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc);
bogdanm 89:552587b429a1 676
bogdanm 89:552587b429a1 677 void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc);
bogdanm 89:552587b429a1 678 void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc);
bogdanm 89:552587b429a1 679 void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc);
bogdanm 89:552587b429a1 680 void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc);
bogdanm 89:552587b429a1 681
bogdanm 89:552587b429a1 682 /* Peripheral Control functions *************************************************/
bogdanm 89:552587b429a1 683 HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig);
bogdanm 89:552587b429a1 684 HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig);
bogdanm 89:552587b429a1 685
bogdanm 89:552587b429a1 686 /* Peripheral State functions ***************************************************/
bogdanm 89:552587b429a1 687 HAL_ADC_StateTypeDef HAL_ADC_GetState(ADC_HandleTypeDef* hadc);
bogdanm 89:552587b429a1 688 uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc);
bogdanm 89:552587b429a1 689
bogdanm 89:552587b429a1 690 /**
bogdanm 89:552587b429a1 691 * @}
bogdanm 89:552587b429a1 692 */
bogdanm 89:552587b429a1 693
bogdanm 89:552587b429a1 694 /**
bogdanm 89:552587b429a1 695 * @}
bogdanm 89:552587b429a1 696 */
bogdanm 89:552587b429a1 697
bogdanm 89:552587b429a1 698 #ifdef __cplusplus
bogdanm 89:552587b429a1 699 }
bogdanm 89:552587b429a1 700 #endif
bogdanm 89:552587b429a1 701
bogdanm 89:552587b429a1 702 #endif /*__STM32F4xx_ADC_H */
bogdanm 89:552587b429a1 703
bogdanm 89:552587b429a1 704
bogdanm 89:552587b429a1 705 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/