STM8S/A Standard Peripherals Drivers
|
stm8s_tim2.h
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm8s_tim2.h 00004 * @author MCD Application Team 00005 * @version V2.3.0 00006 * @date 16-June-2017 00007 * @brief This file contains all functions prototype and macros for the TIM2 peripheral. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© 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 /* Define to prevent recursive inclusion -------------------------------------*/ 00029 #ifndef __STM8S_TIM2_H 00030 #define __STM8S_TIM2_H 00031 00032 /* Includes ------------------------------------------------------------------*/ 00033 #include "stm8s.h" 00034 00035 /** @addtogroup STM8S_StdPeriph_Driver 00036 * @{ 00037 */ 00038 00039 /* Exported types ------------------------------------------------------------*/ 00040 00041 00042 /** TIM2 Forced Action */ 00043 typedef enum 00044 { 00045 TIM2_FORCEDACTION_ACTIVE = ((uint8_t)0x50), 00046 TIM2_FORCEDACTION_INACTIVE = ((uint8_t)0x40) 00047 }TIM2_ForcedAction_TypeDef; 00048 00049 #define IS_TIM2_FORCED_ACTION_OK(ACTION) (((ACTION) == TIM2_FORCEDACTION_ACTIVE) || \ 00050 ((ACTION) == TIM2_FORCEDACTION_INACTIVE)) 00051 00052 /** TIM2 Prescaler */ 00053 typedef enum 00054 { 00055 TIM2_PRESCALER_1 = ((uint8_t)0x00), 00056 TIM2_PRESCALER_2 = ((uint8_t)0x01), 00057 TIM2_PRESCALER_4 = ((uint8_t)0x02), 00058 TIM2_PRESCALER_8 = ((uint8_t)0x03), 00059 TIM2_PRESCALER_16 = ((uint8_t)0x04), 00060 TIM2_PRESCALER_32 = ((uint8_t)0x05), 00061 TIM2_PRESCALER_64 = ((uint8_t)0x06), 00062 TIM2_PRESCALER_128 = ((uint8_t)0x07), 00063 TIM2_PRESCALER_256 = ((uint8_t)0x08), 00064 TIM2_PRESCALER_512 = ((uint8_t)0x09), 00065 TIM2_PRESCALER_1024 = ((uint8_t)0x0A), 00066 TIM2_PRESCALER_2048 = ((uint8_t)0x0B), 00067 TIM2_PRESCALER_4096 = ((uint8_t)0x0C), 00068 TIM2_PRESCALER_8192 = ((uint8_t)0x0D), 00069 TIM2_PRESCALER_16384 = ((uint8_t)0x0E), 00070 TIM2_PRESCALER_32768 = ((uint8_t)0x0F) 00071 }TIM2_Prescaler_TypeDef; 00072 00073 #define IS_TIM2_PRESCALER_OK(PRESCALER) (((PRESCALER) == TIM2_PRESCALER_1 ) || \ 00074 ((PRESCALER) == TIM2_PRESCALER_2 ) || \ 00075 ((PRESCALER) == TIM2_PRESCALER_4 ) || \ 00076 ((PRESCALER) == TIM2_PRESCALER_8 ) || \ 00077 ((PRESCALER) == TIM2_PRESCALER_16 ) || \ 00078 ((PRESCALER) == TIM2_PRESCALER_32 ) || \ 00079 ((PRESCALER) == TIM2_PRESCALER_64 ) || \ 00080 ((PRESCALER) == TIM2_PRESCALER_128 ) || \ 00081 ((PRESCALER) == TIM2_PRESCALER_256 ) || \ 00082 ((PRESCALER) == TIM2_PRESCALER_512 ) || \ 00083 ((PRESCALER) == TIM2_PRESCALER_1024 ) || \ 00084 ((PRESCALER) == TIM2_PRESCALER_2048 ) || \ 00085 ((PRESCALER) == TIM2_PRESCALER_4096 ) || \ 00086 ((PRESCALER) == TIM2_PRESCALER_8192 ) || \ 00087 ((PRESCALER) == TIM2_PRESCALER_16384 ) || \ 00088 ((PRESCALER) == TIM2_PRESCALER_32768 )) 00089 00090 /** TIM2 Output Compare and PWM modes */ 00091 typedef enum 00092 { 00093 TIM2_OCMODE_TIMING = ((uint8_t)0x00), 00094 TIM2_OCMODE_ACTIVE = ((uint8_t)0x10), 00095 TIM2_OCMODE_INACTIVE = ((uint8_t)0x20), 00096 TIM2_OCMODE_TOGGLE = ((uint8_t)0x30), 00097 TIM2_OCMODE_PWM1 = ((uint8_t)0x60), 00098 TIM2_OCMODE_PWM2 = ((uint8_t)0x70) 00099 }TIM2_OCMode_TypeDef; 00100 00101 #define IS_TIM2_OC_MODE_OK(MODE) (((MODE) == TIM2_OCMODE_TIMING) || \ 00102 ((MODE) == TIM2_OCMODE_ACTIVE) || \ 00103 ((MODE) == TIM2_OCMODE_INACTIVE) || \ 00104 ((MODE) == TIM2_OCMODE_TOGGLE)|| \ 00105 ((MODE) == TIM2_OCMODE_PWM1) || \ 00106 ((MODE) == TIM2_OCMODE_PWM2)) 00107 00108 #define IS_TIM2_OCM_OK(MODE)(((MODE) == TIM2_OCMODE_TIMING) || \ 00109 ((MODE) == TIM2_OCMODE_ACTIVE) || \ 00110 ((MODE) == TIM2_OCMODE_INACTIVE) || \ 00111 ((MODE) == TIM2_OCMODE_TOGGLE)|| \ 00112 ((MODE) == TIM2_OCMODE_PWM1) || \ 00113 ((MODE) == TIM2_OCMODE_PWM2) || \ 00114 ((MODE) == (uint8_t)TIM2_FORCEDACTION_ACTIVE) || \ 00115 ((MODE) == (uint8_t)TIM2_FORCEDACTION_INACTIVE)) 00116 00117 /** TIM2 One Pulse Mode */ 00118 typedef enum 00119 { 00120 TIM2_OPMODE_SINGLE = ((uint8_t)0x01), 00121 TIM2_OPMODE_REPETITIVE = ((uint8_t)0x00) 00122 }TIM2_OPMode_TypeDef; 00123 00124 #define IS_TIM2_OPM_MODE_OK(MODE) (((MODE) == TIM2_OPMODE_SINGLE) || \ 00125 ((MODE) == TIM2_OPMODE_REPETITIVE)) 00126 00127 /** TIM2 Channel */ 00128 typedef enum 00129 { 00130 TIM2_CHANNEL_1 = ((uint8_t)0x00), 00131 TIM2_CHANNEL_2 = ((uint8_t)0x01), 00132 TIM2_CHANNEL_3 = ((uint8_t)0x02) 00133 }TIM2_Channel_TypeDef; 00134 00135 #define IS_TIM2_CHANNEL_OK(CHANNEL) (((CHANNEL) == TIM2_CHANNEL_1) || \ 00136 ((CHANNEL) == TIM2_CHANNEL_2) || \ 00137 ((CHANNEL) == TIM2_CHANNEL_3)) 00138 00139 #define IS_TIM2_PWMI_CHANNEL_OK(CHANNEL) (((CHANNEL) == TIM2_CHANNEL_1) || \ 00140 ((CHANNEL) == TIM2_CHANNEL_2)) 00141 00142 /** TIM2 Output Compare Polarity */ 00143 typedef enum 00144 { 00145 TIM2_OCPOLARITY_HIGH = ((uint8_t)0x00), 00146 TIM2_OCPOLARITY_LOW = ((uint8_t)0x22) 00147 }TIM2_OCPolarity_TypeDef; 00148 00149 #define IS_TIM2_OC_POLARITY_OK(POLARITY) (((POLARITY) == TIM2_OCPOLARITY_HIGH) || \ 00150 ((POLARITY) == TIM2_OCPOLARITY_LOW)) 00151 00152 /** TIM2 Output Compare states */ 00153 typedef enum 00154 { 00155 TIM2_OUTPUTSTATE_DISABLE = ((uint8_t)0x00), 00156 TIM2_OUTPUTSTATE_ENABLE = ((uint8_t)0x11) 00157 }TIM2_OutputState_TypeDef; 00158 00159 #define IS_TIM2_OUTPUT_STATE_OK(STATE) (((STATE) == TIM2_OUTPUTSTATE_DISABLE) || \ 00160 ((STATE) == TIM2_OUTPUTSTATE_ENABLE)) 00161 00162 /** TIM2 Input Capture Polarity */ 00163 typedef enum 00164 { 00165 TIM2_ICPOLARITY_RISING = ((uint8_t)0x00), 00166 TIM2_ICPOLARITY_FALLING = ((uint8_t)0x44) 00167 }TIM2_ICPolarity_TypeDef; 00168 00169 #define IS_TIM2_IC_POLARITY_OK(POLARITY) (((POLARITY) == TIM2_ICPOLARITY_RISING) || \ 00170 ((POLARITY) == TIM2_ICPOLARITY_FALLING)) 00171 00172 /** TIM2 Input Capture Selection */ 00173 typedef enum 00174 { 00175 TIM2_ICSELECTION_DIRECTTI = ((uint8_t)0x01), 00176 TIM2_ICSELECTION_INDIRECTTI = ((uint8_t)0x02), 00177 TIM2_ICSELECTION_TRGI = ((uint8_t)0x03) 00178 }TIM2_ICSelection_TypeDef; 00179 00180 #define IS_TIM2_IC_SELECTION_OK(SELECTION) (((SELECTION) == TIM2_ICSELECTION_DIRECTTI) || \ 00181 ((SELECTION) == TIM2_ICSELECTION_INDIRECTTI) || \ 00182 ((SELECTION) == TIM2_ICSELECTION_TRGI)) 00183 00184 #define IS_TIM2_IC_SELECTION1_OK(SELECTION) (((SELECTION) == TIM2_ICSELECTION_DIRECTTI) || \ 00185 ((SELECTION) == TIM2_ICSELECTION_TRGI)) 00186 00187 /** TIM2 Input Capture Prescaler */ 00188 typedef enum 00189 { 00190 TIM2_ICPSC_DIV1 = ((uint8_t)0x00), 00191 TIM2_ICPSC_DIV2 = ((uint8_t)0x04), 00192 TIM2_ICPSC_DIV4 = ((uint8_t)0x08), 00193 TIM2_ICPSC_DIV8 = ((uint8_t)0x0C) 00194 }TIM2_ICPSC_TypeDef; 00195 00196 #define IS_TIM2_IC_PRESCALER_OK(PRESCALER) (((PRESCALER) == TIM2_ICPSC_DIV1) || \ 00197 ((PRESCALER) == TIM2_ICPSC_DIV2) || \ 00198 ((PRESCALER) == TIM2_ICPSC_DIV4) || \ 00199 ((PRESCALER) == TIM2_ICPSC_DIV8)) 00200 00201 /** TIM2 Input Capture Filer Value */ 00202 #define IS_TIM2_IC_FILTER_OK(ICFILTER) ((ICFILTER) <= 0x0F) 00203 00204 /** TIM2 interrupt sources */ 00205 typedef enum 00206 { 00207 TIM2_IT_UPDATE = ((uint8_t)0x01), 00208 TIM2_IT_CC1 = ((uint8_t)0x02), 00209 TIM2_IT_CC2 = ((uint8_t)0x04), 00210 TIM2_IT_CC3 = ((uint8_t)0x08) 00211 }TIM2_IT_TypeDef; 00212 00213 #define IS_TIM2_IT_OK(IT) (((IT) != 0x00) && ((IT) <= 0x0F)) 00214 00215 #define IS_TIM2_GET_IT_OK(IT) (((IT) == TIM2_IT_UPDATE) || \ 00216 ((IT) == TIM2_IT_CC1) || \ 00217 ((IT) == TIM2_IT_CC2) || \ 00218 ((IT) == TIM2_IT_CC3)) 00219 00220 /** TIM2 Prescaler Reload Mode */ 00221 typedef enum 00222 { 00223 TIM2_PSCRELOADMODE_UPDATE = ((uint8_t)0x00), 00224 TIM2_PSCRELOADMODE_IMMEDIATE = ((uint8_t)0x01) 00225 }TIM2_PSCReloadMode_TypeDef; 00226 00227 #define IS_TIM2_PRESCALER_RELOAD_OK(RELOAD) (((RELOAD) == TIM2_PSCRELOADMODE_UPDATE) || \ 00228 ((RELOAD) == TIM2_PSCRELOADMODE_IMMEDIATE)) 00229 00230 /** TIM2 Event Source */ 00231 typedef enum 00232 { 00233 TIM2_EVENTSOURCE_UPDATE = ((uint8_t)0x01), 00234 TIM2_EVENTSOURCE_CC1 = ((uint8_t)0x02), 00235 TIM2_EVENTSOURCE_CC2 = ((uint8_t)0x04), 00236 TIM2_EVENTSOURCE_CC3 = ((uint8_t)0x08) 00237 }TIM2_EventSource_TypeDef; 00238 00239 #define IS_TIM2_EVENT_SOURCE_OK(SOURCE) (((SOURCE) != 0x00)) 00240 00241 /** TIM2 Update Source */ 00242 typedef enum 00243 { 00244 TIM2_UPDATESOURCE_GLOBAL = ((uint8_t)0x00), 00245 TIM2_UPDATESOURCE_REGULAR = ((uint8_t)0x01) 00246 }TIM2_UpdateSource_TypeDef; 00247 00248 #define IS_TIM2_UPDATE_SOURCE_OK(SOURCE) (((SOURCE) == TIM2_UPDATESOURCE_GLOBAL) || \ 00249 ((SOURCE) == TIM2_UPDATESOURCE_REGULAR)) 00250 00251 /** TIM2 Flags */ 00252 typedef enum 00253 { 00254 TIM2_FLAG_UPDATE = ((uint16_t)0x0001), 00255 TIM2_FLAG_CC1 = ((uint16_t)0x0002), 00256 TIM2_FLAG_CC2 = ((uint16_t)0x0004), 00257 TIM2_FLAG_CC3 = ((uint16_t)0x0008), 00258 TIM2_FLAG_CC1OF = ((uint16_t)0x0200), 00259 TIM2_FLAG_CC2OF = ((uint16_t)0x0400), 00260 TIM2_FLAG_CC3OF = ((uint16_t)0x0800) 00261 }TIM2_FLAG_TypeDef; 00262 00263 #define IS_TIM2_GET_FLAG_OK(FLAG) (((FLAG) == TIM2_FLAG_UPDATE) || \ 00264 ((FLAG) == TIM2_FLAG_CC1) || \ 00265 ((FLAG) == TIM2_FLAG_CC2) || \ 00266 ((FLAG) == TIM2_FLAG_CC3) || \ 00267 ((FLAG) == TIM2_FLAG_CC1OF) || \ 00268 ((FLAG) == TIM2_FLAG_CC2OF) || \ 00269 ((FLAG) == TIM2_FLAG_CC3OF)) 00270 00271 #define IS_TIM2_CLEAR_FLAG_OK(FLAG) ((((uint16_t)(FLAG) & 0xF1F0) == 0x0000) && ((uint16_t)(FLAG) != 0x0000)) 00272 00273 /** 00274 * @} 00275 */ 00276 00277 /* Exported macro ------------------------------------------------------------*/ 00278 00279 /* Exported functions --------------------------------------------------------*/ 00280 00281 /** @addtogroup TIM2_Exported_Functions 00282 * @{ 00283 */ 00284 00285 void TIM2_DeInit(void); 00286 void TIM2_TimeBaseInit(TIM2_Prescaler_TypeDef TIM2_Prescaler, uint16_t TIM2_Period); 00287 void TIM2_OC1Init(TIM2_OCMode_TypeDef TIM2_OCMode, TIM2_OutputState_TypeDef TIM2_OutputState, uint16_t TIM2_Pulse, TIM2_OCPolarity_TypeDef TIM2_OCPolarity); 00288 void TIM2_OC2Init(TIM2_OCMode_TypeDef TIM2_OCMode, TIM2_OutputState_TypeDef TIM2_OutputState, uint16_t TIM2_Pulse, TIM2_OCPolarity_TypeDef TIM2_OCPolarity); 00289 void TIM2_OC3Init(TIM2_OCMode_TypeDef TIM2_OCMode, TIM2_OutputState_TypeDef TIM2_OutputState, uint16_t TIM2_Pulse, TIM2_OCPolarity_TypeDef TIM2_OCPolarity); 00290 void TIM2_ICInit(TIM2_Channel_TypeDef TIM2_Channel, TIM2_ICPolarity_TypeDef TIM2_ICPolarity, TIM2_ICSelection_TypeDef TIM2_ICSelection, TIM2_ICPSC_TypeDef TIM2_ICPrescaler, uint8_t TIM2_ICFilter); 00291 void TIM2_PWMIConfig(TIM2_Channel_TypeDef TIM2_Channel, TIM2_ICPolarity_TypeDef TIM2_ICPolarity, TIM2_ICSelection_TypeDef TIM2_ICSelection, TIM2_ICPSC_TypeDef TIM2_ICPrescaler, uint8_t TIM2_ICFilter); 00292 void TIM2_Cmd(FunctionalState NewState); 00293 void TIM2_ITConfig(TIM2_IT_TypeDef TIM2_IT, FunctionalState NewState); 00294 void TIM2_InternalClockConfig(void); 00295 void TIM2_UpdateDisableConfig(FunctionalState NewState); 00296 void TIM2_UpdateRequestConfig(TIM2_UpdateSource_TypeDef TIM2_UpdateSource); 00297 void TIM2_SelectOnePulseMode(TIM2_OPMode_TypeDef TIM2_OPMode); 00298 void TIM2_PrescalerConfig(TIM2_Prescaler_TypeDef Prescaler, TIM2_PSCReloadMode_TypeDef TIM2_PSCReloadMode); 00299 void TIM2_ForcedOC1Config(TIM2_ForcedAction_TypeDef TIM2_ForcedAction); 00300 void TIM2_ForcedOC2Config(TIM2_ForcedAction_TypeDef TIM2_ForcedAction); 00301 void TIM2_ForcedOC3Config(TIM2_ForcedAction_TypeDef TIM2_ForcedAction); 00302 void TIM2_ARRPreloadConfig(FunctionalState NewState); 00303 void TIM2_CCPreloadControl(FunctionalState NewState); 00304 void TIM2_OC1PreloadConfig(FunctionalState NewState); 00305 void TIM2_OC2PreloadConfig(FunctionalState NewState); 00306 void TIM2_OC3PreloadConfig(FunctionalState NewState); 00307 void TIM2_GenerateEvent(TIM2_EventSource_TypeDef TIM2_EventSource); 00308 void TIM2_OC1PolarityConfig(TIM2_OCPolarity_TypeDef TIM2_OCPolarity); 00309 void TIM2_OC2PolarityConfig(TIM2_OCPolarity_TypeDef TIM2_OCPolarity); 00310 void TIM2_OC3PolarityConfig(TIM2_OCPolarity_TypeDef TIM2_OCPolarity); 00311 void TIM2_CCxCmd(TIM2_Channel_TypeDef TIM2_Channel, FunctionalState NewState); 00312 void TIM2_SelectOCxM(TIM2_Channel_TypeDef TIM2_Channel, TIM2_OCMode_TypeDef TIM2_OCMode); 00313 void TIM2_SetCounter(uint16_t Counter); 00314 void TIM2_SetAutoreload(uint16_t Autoreload); 00315 void TIM2_SetCompare1(uint16_t Compare1); 00316 void TIM2_SetCompare2(uint16_t Compare2); 00317 void TIM2_SetCompare3(uint16_t Compare3); 00318 void TIM2_SetIC1Prescaler(TIM2_ICPSC_TypeDef TIM2_IC1Prescaler); 00319 void TIM2_SetIC2Prescaler(TIM2_ICPSC_TypeDef TIM2_IC2Prescaler); 00320 void TIM2_SetIC3Prescaler(TIM2_ICPSC_TypeDef TIM2_IC3Prescaler); 00321 uint16_t TIM2_GetCapture1(void); 00322 uint16_t TIM2_GetCapture2(void); 00323 uint16_t TIM2_GetCapture3(void); 00324 uint16_t TIM2_GetCounter(void); 00325 TIM2_Prescaler_TypeDef TIM2_GetPrescaler(void); 00326 FlagStatus TIM2_GetFlagStatus(TIM2_FLAG_TypeDef TIM2_FLAG); 00327 void TIM2_ClearFlag(TIM2_FLAG_TypeDef TIM2_FLAG); 00328 ITStatus TIM2_GetITStatus(TIM2_IT_TypeDef TIM2_IT); 00329 void TIM2_ClearITPendingBit(TIM2_IT_TypeDef TIM2_IT); 00330 00331 /** 00332 * @} 00333 */ 00334 00335 #endif /* __STM8S_TIM2_H */ 00336 00337 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/