STM8S/A Standard Peripherals Drivers: stm8s_adc2.h Source File

STM8S/A

stm8s_adc2.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm8s_adc2.h
00004   * @author  MCD Application Team
00005   * @version V2.3.0
00006   * @date    16-June-2017
00007   * @brief   This file contains all the prototypes/macros for the ADC2 peripheral.
00008    ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/software_license_agreement_liberty_v2
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022   * See the License for the specific language governing permissions and
00023   * limitations under the License.
00024   *
00025   ******************************************************************************
00026   */
00027 
00028 
00029 /* Define to prevent recursive inclusion -------------------------------------*/
00030 #ifndef __STM8S_ADC2_H
00031 #define __STM8S_ADC2_H
00032 
00033 /* Includes ------------------------------------------------------------------*/
00034 #include "stm8s.h"
00035 
00036 /* Exported types ------------------------------------------------------------*/
00037 
00038 /** @addtogroup ADC2_Exported_Types
00039   * @{
00040   */
00041 
00042 /**
00043   * @brief  ADC2 clock prescaler selection
00044   */
00045 
00046 typedef enum {
00047   ADC2_PRESSEL_FCPU_D2  = (uint8_t)0x00, /**< Prescaler selection fADC2 = fcpu/2 */
00048   ADC2_PRESSEL_FCPU_D3  = (uint8_t)0x10, /**< Prescaler selection fADC2 = fcpu/3 */
00049   ADC2_PRESSEL_FCPU_D4  = (uint8_t)0x20, /**< Prescaler selection fADC2 = fcpu/4 */
00050   ADC2_PRESSEL_FCPU_D6  = (uint8_t)0x30, /**< Prescaler selection fADC2 = fcpu/6 */
00051   ADC2_PRESSEL_FCPU_D8  = (uint8_t)0x40, /**< Prescaler selection fADC2 = fcpu/8 */
00052   ADC2_PRESSEL_FCPU_D10 = (uint8_t)0x50, /**< Prescaler selection fADC2 = fcpu/10 */
00053   ADC2_PRESSEL_FCPU_D12 = (uint8_t)0x60, /**< Prescaler selection fADC2 = fcpu/12 */
00054   ADC2_PRESSEL_FCPU_D18 = (uint8_t)0x70  /**< Prescaler selection fADC2 = fcpu/18 */
00055 } ADC2_PresSel_TypeDef;
00056 
00057 /**
00058   * @brief   ADC2 External conversion trigger event selection
00059   */
00060 typedef enum {
00061   ADC2_EXTTRIG_TIM   = (uint8_t)0x00, /**< Conversion from Internal TIM TRGO event */
00062   ADC2_EXTTRIG_GPIO  = (uint8_t)0x01  /**< Conversion from External interrupt on ADC_ETR pin*/
00063 } ADC2_ExtTrig_TypeDef;
00064 
00065 /**
00066   * @brief  ADC2 data alignment
00067   */
00068 typedef enum {
00069   ADC2_ALIGN_LEFT  = (uint8_t)0x00, /**< Data alignment left */
00070   ADC2_ALIGN_RIGHT = (uint8_t)0x08  /**< Data alignment right */
00071 } ADC2_Align_TypeDef;
00072 
00073 /**
00074   * @brief  ADC2 schmitt Trigger
00075   */
00076 typedef enum {
00077   ADC2_SCHMITTTRIG_CHANNEL0  = (uint8_t)0x00, /**< Schmitt trigger disable on AIN0 */
00078   ADC2_SCHMITTTRIG_CHANNEL1  = (uint8_t)0x01, /**< Schmitt trigger disable on AIN1 */
00079   ADC2_SCHMITTTRIG_CHANNEL2  = (uint8_t)0x02, /**< Schmitt trigger disable on AIN2 */
00080   ADC2_SCHMITTTRIG_CHANNEL3  = (uint8_t)0x03, /**< Schmitt trigger disable on AIN3 */
00081   ADC2_SCHMITTTRIG_CHANNEL4  = (uint8_t)0x04, /**< Schmitt trigger disable on AIN4 */
00082   ADC2_SCHMITTTRIG_CHANNEL5  = (uint8_t)0x05, /**< Schmitt trigger disable on AIN5 */
00083   ADC2_SCHMITTTRIG_CHANNEL6  = (uint8_t)0x06, /**< Schmitt trigger disable on AIN6 */
00084   ADC2_SCHMITTTRIG_CHANNEL7  = (uint8_t)0x07, /**< Schmitt trigger disable on AIN7 */
00085   ADC2_SCHMITTTRIG_CHANNEL8  = (uint8_t)0x08, /**< Schmitt trigger disable on AIN8 */
00086   ADC2_SCHMITTTRIG_CHANNEL9  = (uint8_t)0x09, /**< Schmitt trigger disable on AIN9 */
00087   ADC2_SCHMITTTRIG_CHANNEL10 = (uint8_t)0x0A, /**< Schmitt trigger disable on AIN10 */
00088   ADC2_SCHMITTTRIG_CHANNEL11 = (uint8_t)0x0B, /**< Schmitt trigger disable on AIN11 */
00089   ADC2_SCHMITTTRIG_CHANNEL12 = (uint8_t)0x0C, /**< Schmitt trigger disable on AIN12 */
00090   ADC2_SCHMITTTRIG_CHANNEL13 = (uint8_t)0x0D, /**< Schmitt trigger disable on AIN13 */
00091   ADC2_SCHMITTTRIG_CHANNEL14 = (uint8_t)0x0E, /**< Schmitt trigger disable on AIN14 */
00092   ADC2_SCHMITTTRIG_CHANNEL15 = (uint8_t)0x0F, /**< Schmitt trigger disable on AIN15 */
00093   ADC2_SCHMITTTRIG_ALL       = (uint8_t)0x1F /**< Schmitt trigger disable on all channels */
00094 
00095 } ADC2_SchmittTrigg_TypeDef;
00096 
00097 /**
00098   * @brief  ADC2 conversion mode selection
00099   */
00100 
00101 typedef enum {
00102   ADC2_CONVERSIONMODE_SINGLE     = (uint8_t)0x00, /**< Single conversion mode */
00103   ADC2_CONVERSIONMODE_CONTINUOUS = (uint8_t)0x01  /**< Continuous conversion mode */
00104 } ADC2_ConvMode_TypeDef;
00105 
00106 /**
00107   * @brief  ADC2 analog channel selection
00108   */
00109 
00110 typedef enum {
00111   ADC2_CHANNEL_0  = (uint8_t)0x00, /**< Analog channel 0 */
00112   ADC2_CHANNEL_1  = (uint8_t)0x01, /**< Analog channel 1 */
00113   ADC2_CHANNEL_2  = (uint8_t)0x02, /**< Analog channel 2 */
00114   ADC2_CHANNEL_3  = (uint8_t)0x03, /**< Analog channel 3 */
00115   ADC2_CHANNEL_4  = (uint8_t)0x04, /**< Analog channel 4 */
00116   ADC2_CHANNEL_5  = (uint8_t)0x05, /**< Analog channel 5 */
00117   ADC2_CHANNEL_6  = (uint8_t)0x06, /**< Analog channel 6 */
00118   ADC2_CHANNEL_7  = (uint8_t)0x07, /**< Analog channel 7 */
00119   ADC2_CHANNEL_8  = (uint8_t)0x08, /**< Analog channel 8 */
00120   ADC2_CHANNEL_9  = (uint8_t)0x09, /**< Analog channel 9 */
00121   ADC2_CHANNEL_10 = (uint8_t)0x0A, /**< Analog channel 10 */
00122   ADC2_CHANNEL_11 = (uint8_t)0x0B, /**< Analog channel 11 */
00123   ADC2_CHANNEL_12 = (uint8_t)0x0C, /**< Analog channel 12 */
00124   ADC2_CHANNEL_13 = (uint8_t)0x0D, /**< Analog channel 13 */
00125   ADC2_CHANNEL_14 = (uint8_t)0x0E, /**< Analog channel 14 */
00126   ADC2_CHANNEL_15 = (uint8_t)0x0F  /**< Analog channel 15 */
00127 } ADC2_Channel_TypeDef;
00128 
00129 /**
00130   * @}
00131   */
00132 
00133 /* Exported constants --------------------------------------------------------*/
00134 
00135 /* Exported macros ------------------------------------------------------------*/
00136 
00137 /* Private macros ------------------------------------------------------------*/
00138 
00139 /** @addtogroup ADC2_Private_Macros
00140   * @brief  Macros used by the assert function to check the different functions parameters.
00141   * @{
00142   */
00143 
00144 /**
00145   * @brief  Macro used by the assert function to check the different prescaler's values.
00146   */
00147 #define IS_ADC2_PRESSEL_OK(PRESCALER) (((PRESCALER) == ADC2_PRESSEL_FCPU_D2) || \
00148                                       ((PRESCALER) == ADC2_PRESSEL_FCPU_D3) || \
00149                                       ((PRESCALER) == ADC2_PRESSEL_FCPU_D4) || \
00150                                       ((PRESCALER) == ADC2_PRESSEL_FCPU_D6) || \
00151                                       ((PRESCALER) == ADC2_PRESSEL_FCPU_D8) || \
00152                                       ((PRESCALER) == ADC2_PRESSEL_FCPU_D10) || \
00153                                       ((PRESCALER) == ADC2_PRESSEL_FCPU_D12) || \
00154                                       ((PRESCALER) == ADC2_PRESSEL_FCPU_D18))
00155 
00156 /**
00157   * @brief  Macro used by the assert function to check the different external trigger values.
00158   */
00159 #define IS_ADC2_EXTTRIG_OK(EXTRIG) (((EXTRIG) == ADC2_EXTTRIG_TIM) || \
00160                                                                    ((EXTRIG) == ADC2_EXTTRIG_GPIO))
00161 
00162 /**
00163   * @brief  Macro used by the assert function to check the different alignment modes.
00164   */
00165 #define IS_ADC2_ALIGN_OK(ALIGN) (((ALIGN) == ADC2_ALIGN_LEFT) || \
00166                                 ((ALIGN) == ADC2_ALIGN_RIGHT))
00167 
00168 
00169 /**
00170   * @brief  Macro used by the assert function to check the different schmitt trigger values.
00171   */
00172 #define IS_ADC2_SCHMITTTRIG_OK(SCHMITTTRIG) (((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL0) || \
00173     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL1) || \
00174     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL2) || \
00175     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL3) || \
00176     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL4) || \
00177     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL5) || \
00178     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL6) || \
00179     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL7) || \
00180     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL8) || \
00181     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL9) || \
00182     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL10) || \
00183     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL11) || \
00184     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL12) || \
00185     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL13) || \
00186     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL14) || \
00187     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL15) || \
00188     ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_ALL))
00189 
00190 /**
00191   * @brief  Macro used by the assert function to check the different conversion modes.
00192   */
00193 #define IS_ADC2_CONVERSIONMODE_OK(MODE) (((MODE) == ADC2_CONVERSIONMODE_SINGLE) || \
00194                                         ((MODE) == ADC2_CONVERSIONMODE_CONTINUOUS))
00195 
00196 /**
00197   * @brief  Macro used by the assert function to check the different channels values.
00198   */
00199 #define IS_ADC2_CHANNEL_OK(CHANNEL) (((CHANNEL) == ADC2_CHANNEL_0) || \
00200                                     ((CHANNEL) == ADC2_CHANNEL_1) || \
00201                                     ((CHANNEL) == ADC2_CHANNEL_2) || \
00202                                     ((CHANNEL) == ADC2_CHANNEL_3) || \
00203                                     ((CHANNEL) == ADC2_CHANNEL_4) || \
00204                                     ((CHANNEL) == ADC2_CHANNEL_5) || \
00205                                     ((CHANNEL) == ADC2_CHANNEL_6) || \
00206                                     ((CHANNEL) == ADC2_CHANNEL_7) || \
00207                                     ((CHANNEL) == ADC2_CHANNEL_8) || \
00208                                     ((CHANNEL) == ADC2_CHANNEL_9) || \
00209                                     ((CHANNEL) == ADC2_CHANNEL_10) || \
00210                                     ((CHANNEL) == ADC2_CHANNEL_11) || \
00211                                     ((CHANNEL) == ADC2_CHANNEL_12) || \
00212                                     ((CHANNEL) == ADC2_CHANNEL_13) || \
00213                                     ((CHANNEL) == ADC2_CHANNEL_14) || \
00214                                     ((CHANNEL) == ADC2_CHANNEL_15))
00215 
00216 /**
00217   * @}
00218   */
00219 
00220 /* Exported functions ------------------------------------------------------- */
00221 
00222 /** @addtogroup ADC2_Exported_Functions
00223   * @{
00224   */
00225 void ADC2_DeInit(void);
00226 void ADC2_Init(ADC2_ConvMode_TypeDef ADC2_ConversionMode, 
00227                ADC2_Channel_TypeDef ADC2_Channel, 
00228                ADC2_PresSel_TypeDef ADC2_PrescalerSelection, 
00229                ADC2_ExtTrig_TypeDef ADC2_ExtTrigger, 
00230                FunctionalState ADC2_ExtTriggerState, 
00231                ADC2_Align_TypeDef ADC2_Align, 
00232                ADC2_SchmittTrigg_TypeDef ADC2_SchmittTriggerChannel, 
00233                FunctionalState ADC2_SchmittTriggerState);
00234 void ADC2_Cmd(FunctionalState NewState);
00235 void ADC2_ITConfig(FunctionalState NewState);
00236 void ADC2_PrescalerConfig(ADC2_PresSel_TypeDef ADC2_Prescaler);
00237 void ADC2_SchmittTriggerConfig(ADC2_SchmittTrigg_TypeDef ADC2_SchmittTriggerChannel, 
00238                               FunctionalState NewState);
00239 void ADC2_ConversionConfig(ADC2_ConvMode_TypeDef ADC2_ConversionMode, 
00240                            ADC2_Channel_TypeDef ADC2_Channel, 
00241                            ADC2_Align_TypeDef ADC2_Align);
00242 void ADC2_ExternalTriggerConfig(ADC2_ExtTrig_TypeDef ADC2_ExtTrigger, FunctionalState NewState);
00243 void ADC2_StartConversion(void);
00244 uint16_t ADC2_GetConversionValue(void);
00245 FlagStatus ADC2_GetFlagStatus(void);
00246 void ADC2_ClearFlag(void);
00247 ITStatus ADC2_GetITStatus(void);
00248 void ADC2_ClearITPendingBit(void);
00249 /**
00250   * @}
00251   */
00252 
00253 #endif /* __STM8S_ADC2_H */
00254 
00255 
00256 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM8 8-bit Microcontrollers platform visit www.st.com