stm32l1xx_ll_tim.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_ll_tim.c
  4. * @author MCD Application Team
  5. * @brief TIM LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. #if defined(USE_FULL_LL_DRIVER)
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "stm32l1xx_ll_tim.h"
  38. #include "stm32l1xx_ll_bus.h"
  39. #ifdef USE_FULL_ASSERT
  40. #include "stm32_assert.h"
  41. #else
  42. #define assert_param(expr) ((void)0U)
  43. #endif
  44. /** @addtogroup STM32L1xx_LL_Driver
  45. * @{
  46. */
  47. #if defined (TIM2) || defined (TIM3) || defined (TIM4) || defined (TIM5) || defined (TIM9) || defined (TIM10) || defined (TIM11) || defined (TIM6) || defined (TIM7)
  48. /** @addtogroup TIM_LL
  49. * @{
  50. */
  51. /* Private types -------------------------------------------------------------*/
  52. /* Private variables ---------------------------------------------------------*/
  53. /* Private constants ---------------------------------------------------------*/
  54. /* Private macros ------------------------------------------------------------*/
  55. /** @addtogroup TIM_LL_Private_Macros
  56. * @{
  57. */
  58. #define IS_LL_TIM_COUNTERMODE(__VALUE__) (((__VALUE__) == LL_TIM_COUNTERMODE_UP) \
  59. || ((__VALUE__) == LL_TIM_COUNTERMODE_DOWN) \
  60. || ((__VALUE__) == LL_TIM_COUNTERMODE_CENTER_UP) \
  61. || ((__VALUE__) == LL_TIM_COUNTERMODE_CENTER_DOWN) \
  62. || ((__VALUE__) == LL_TIM_COUNTERMODE_CENTER_UP_DOWN))
  63. #define IS_LL_TIM_CLOCKDIVISION(__VALUE__) (((__VALUE__) == LL_TIM_CLOCKDIVISION_DIV1) \
  64. || ((__VALUE__) == LL_TIM_CLOCKDIVISION_DIV2) \
  65. || ((__VALUE__) == LL_TIM_CLOCKDIVISION_DIV4))
  66. #define IS_LL_TIM_OCMODE(__VALUE__) (((__VALUE__) == LL_TIM_OCMODE_FROZEN) \
  67. || ((__VALUE__) == LL_TIM_OCMODE_ACTIVE) \
  68. || ((__VALUE__) == LL_TIM_OCMODE_INACTIVE) \
  69. || ((__VALUE__) == LL_TIM_OCMODE_TOGGLE) \
  70. || ((__VALUE__) == LL_TIM_OCMODE_FORCED_INACTIVE) \
  71. || ((__VALUE__) == LL_TIM_OCMODE_FORCED_ACTIVE) \
  72. || ((__VALUE__) == LL_TIM_OCMODE_PWM1) \
  73. || ((__VALUE__) == LL_TIM_OCMODE_PWM2))
  74. #define IS_LL_TIM_OCSTATE(__VALUE__) (((__VALUE__) == LL_TIM_OCSTATE_DISABLE) \
  75. || ((__VALUE__) == LL_TIM_OCSTATE_ENABLE))
  76. #define IS_LL_TIM_OCPOLARITY(__VALUE__) (((__VALUE__) == LL_TIM_OCPOLARITY_HIGH) \
  77. || ((__VALUE__) == LL_TIM_OCPOLARITY_LOW))
  78. #define IS_LL_TIM_ACTIVEINPUT(__VALUE__) (((__VALUE__) == LL_TIM_ACTIVEINPUT_DIRECTTI) \
  79. || ((__VALUE__) == LL_TIM_ACTIVEINPUT_INDIRECTTI) \
  80. || ((__VALUE__) == LL_TIM_ACTIVEINPUT_TRC))
  81. #define IS_LL_TIM_ICPSC(__VALUE__) (((__VALUE__) == LL_TIM_ICPSC_DIV1) \
  82. || ((__VALUE__) == LL_TIM_ICPSC_DIV2) \
  83. || ((__VALUE__) == LL_TIM_ICPSC_DIV4) \
  84. || ((__VALUE__) == LL_TIM_ICPSC_DIV8))
  85. #define IS_LL_TIM_IC_FILTER(__VALUE__) (((__VALUE__) == LL_TIM_IC_FILTER_FDIV1) \
  86. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV1_N2) \
  87. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV1_N4) \
  88. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV1_N8) \
  89. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV2_N6) \
  90. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV2_N8) \
  91. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV4_N6) \
  92. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV4_N8) \
  93. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV8_N6) \
  94. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV8_N8) \
  95. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV16_N5) \
  96. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV16_N6) \
  97. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV16_N8) \
  98. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV32_N5) \
  99. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV32_N6) \
  100. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV32_N8))
  101. #define IS_LL_TIM_IC_POLARITY(__VALUE__) (((__VALUE__) == LL_TIM_IC_POLARITY_RISING) \
  102. || ((__VALUE__) == LL_TIM_IC_POLARITY_FALLING) \
  103. || ((__VALUE__) == LL_TIM_IC_POLARITY_BOTHEDGE))
  104. #define IS_LL_TIM_ENCODERMODE(__VALUE__) (((__VALUE__) == LL_TIM_ENCODERMODE_X2_TI1) \
  105. || ((__VALUE__) == LL_TIM_ENCODERMODE_X2_TI2) \
  106. || ((__VALUE__) == LL_TIM_ENCODERMODE_X4_TI12))
  107. #define IS_LL_TIM_IC_POLARITY_ENCODER(__VALUE__) (((__VALUE__) == LL_TIM_IC_POLARITY_RISING) \
  108. || ((__VALUE__) == LL_TIM_IC_POLARITY_FALLING))
  109. /**
  110. * @}
  111. */
  112. /* Private function prototypes -----------------------------------------------*/
  113. /** @defgroup TIM_LL_Private_Functions TIM Private Functions
  114. * @{
  115. */
  116. static ErrorStatus OC1Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  117. static ErrorStatus OC2Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  118. static ErrorStatus OC3Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  119. static ErrorStatus OC4Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  120. static ErrorStatus IC1Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
  121. static ErrorStatus IC2Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
  122. static ErrorStatus IC3Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
  123. static ErrorStatus IC4Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
  124. /**
  125. * @}
  126. */
  127. /* Exported functions --------------------------------------------------------*/
  128. /** @addtogroup TIM_LL_Exported_Functions
  129. * @{
  130. */
  131. /** @addtogroup TIM_LL_EF_Init
  132. * @{
  133. */
  134. /**
  135. * @brief Set TIMx registers to their reset values.
  136. * @param TIMx Timer instance
  137. * @retval An ErrorStatus enumeration value:
  138. * - SUCCESS: TIMx registers are de-initialized
  139. * - ERROR: invalid TIMx instance
  140. */
  141. ErrorStatus LL_TIM_DeInit(TIM_TypeDef *TIMx)
  142. {
  143. ErrorStatus result = SUCCESS;
  144. /* Check the parameters */
  145. assert_param(IS_TIM_INSTANCE(TIMx));
  146. if (TIMx == TIM2)
  147. {
  148. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM2);
  149. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM2);
  150. }
  151. #if defined(TIM3)
  152. else if (TIMx == TIM3)
  153. {
  154. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM3);
  155. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM3);
  156. }
  157. #endif /* TIM3 */
  158. #if defined(TIM4)
  159. else if (TIMx == TIM4)
  160. {
  161. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM4);
  162. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM4);
  163. }
  164. #endif /* TIM4 */
  165. #if defined(TIM5)
  166. else if (TIMx == TIM5)
  167. {
  168. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM5);
  169. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM5);
  170. }
  171. #endif /* TIM5 */
  172. #if defined(TIM6)
  173. else if (TIMx == TIM6)
  174. {
  175. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM6);
  176. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM6);
  177. }
  178. #endif /* TIM6 */
  179. #if defined(TIM7)
  180. else if (TIMx == TIM7)
  181. {
  182. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM7);
  183. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM7);
  184. }
  185. #endif /* TIM7 */
  186. #if defined(TIM9)
  187. else if (TIMx == TIM9)
  188. {
  189. LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM9);
  190. LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM9);
  191. }
  192. #endif /* TIM9 */
  193. #if defined(TIM10)
  194. else if (TIMx == TIM10)
  195. {
  196. LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM10);
  197. LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM10);
  198. }
  199. #endif /* TIM10 */
  200. #if defined(TIM11)
  201. else if (TIMx == TIM11)
  202. {
  203. LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM11);
  204. LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM11);
  205. }
  206. #endif /* TIM11 */
  207. else
  208. {
  209. result = ERROR;
  210. }
  211. return result;
  212. }
  213. /**
  214. * @brief Set the fields of the time base unit configuration data structure
  215. * to their default values.
  216. * @param TIM_InitStruct pointer to a @ref LL_TIM_InitTypeDef structure (time base unit configuration data structure)
  217. * @retval None
  218. */
  219. void LL_TIM_StructInit(LL_TIM_InitTypeDef *TIM_InitStruct)
  220. {
  221. /* Set the default configuration */
  222. TIM_InitStruct->Prescaler = (uint16_t)0x0000U;
  223. TIM_InitStruct->CounterMode = LL_TIM_COUNTERMODE_UP;
  224. TIM_InitStruct->Autoreload = 0xFFFFFFFFU;
  225. TIM_InitStruct->ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  226. }
  227. /**
  228. * @brief Configure the TIMx time base unit.
  229. * @param TIMx Timer Instance
  230. * @param TIM_InitStruct pointer to a @ref LL_TIM_InitTypeDef structure (TIMx time base unit configuration data structure)
  231. * @retval An ErrorStatus enumeration value:
  232. * - SUCCESS: TIMx registers are de-initialized
  233. * - ERROR: not applicable
  234. */
  235. ErrorStatus LL_TIM_Init(TIM_TypeDef *TIMx, LL_TIM_InitTypeDef *TIM_InitStruct)
  236. {
  237. uint32_t tmpcr1 = 0U;
  238. /* Check the parameters */
  239. assert_param(IS_TIM_INSTANCE(TIMx));
  240. assert_param(IS_LL_TIM_COUNTERMODE(TIM_InitStruct->CounterMode));
  241. assert_param(IS_LL_TIM_CLOCKDIVISION(TIM_InitStruct->ClockDivision));
  242. tmpcr1 = LL_TIM_ReadReg(TIMx, CR1);
  243. if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx))
  244. {
  245. /* Select the Counter Mode */
  246. MODIFY_REG(tmpcr1, (TIM_CR1_DIR | TIM_CR1_CMS), TIM_InitStruct->CounterMode);
  247. }
  248. if (IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx))
  249. {
  250. /* Set the clock division */
  251. MODIFY_REG(tmpcr1, TIM_CR1_CKD, TIM_InitStruct->ClockDivision);
  252. }
  253. /* Write to TIMx CR1 */
  254. LL_TIM_WriteReg(TIMx, CR1, tmpcr1);
  255. /* Set the Autoreload value */
  256. LL_TIM_SetAutoReload(TIMx, TIM_InitStruct->Autoreload);
  257. /* Set the Prescaler value */
  258. LL_TIM_SetPrescaler(TIMx, TIM_InitStruct->Prescaler);
  259. /* Generate an update event to reload the Prescaler
  260. and the repetition counter value (if applicable) immediately */
  261. LL_TIM_GenerateEvent_UPDATE(TIMx);
  262. return SUCCESS;
  263. }
  264. /**
  265. * @brief Set the fields of the TIMx output channel configuration data
  266. * structure to their default values.
  267. * @param TIM_OC_InitStruct pointer to a @ref LL_TIM_OC_InitTypeDef structure (the output channel configuration data structure)
  268. * @retval None
  269. */
  270. void LL_TIM_OC_StructInit(LL_TIM_OC_InitTypeDef *TIM_OC_InitStruct)
  271. {
  272. /* Set the default configuration */
  273. TIM_OC_InitStruct->OCMode = LL_TIM_OCMODE_FROZEN;
  274. TIM_OC_InitStruct->OCState = LL_TIM_OCSTATE_DISABLE;
  275. TIM_OC_InitStruct->CompareValue = 0x00000000U;
  276. TIM_OC_InitStruct->OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  277. }
  278. /**
  279. * @brief Configure the TIMx output channel.
  280. * @param TIMx Timer Instance
  281. * @param Channel This parameter can be one of the following values:
  282. * @arg @ref LL_TIM_CHANNEL_CH1
  283. * @arg @ref LL_TIM_CHANNEL_CH2
  284. * @arg @ref LL_TIM_CHANNEL_CH3
  285. * @arg @ref LL_TIM_CHANNEL_CH4
  286. * @param TIM_OC_InitStruct pointer to a @ref LL_TIM_OC_InitTypeDef structure (TIMx output channel configuration data structure)
  287. * @retval An ErrorStatus enumeration value:
  288. * - SUCCESS: TIMx output channel is initialized
  289. * - ERROR: TIMx output channel is not initialized
  290. */
  291. ErrorStatus LL_TIM_OC_Init(TIM_TypeDef *TIMx, uint32_t Channel, LL_TIM_OC_InitTypeDef *TIM_OC_InitStruct)
  292. {
  293. ErrorStatus result = ERROR;
  294. switch (Channel)
  295. {
  296. case LL_TIM_CHANNEL_CH1:
  297. result = OC1Config(TIMx, TIM_OC_InitStruct);
  298. break;
  299. case LL_TIM_CHANNEL_CH2:
  300. result = OC2Config(TIMx, TIM_OC_InitStruct);
  301. break;
  302. case LL_TIM_CHANNEL_CH3:
  303. result = OC3Config(TIMx, TIM_OC_InitStruct);
  304. break;
  305. case LL_TIM_CHANNEL_CH4:
  306. result = OC4Config(TIMx, TIM_OC_InitStruct);
  307. break;
  308. default:
  309. break;
  310. }
  311. return result;
  312. }
  313. /**
  314. * @brief Set the fields of the TIMx input channel configuration data
  315. * structure to their default values.
  316. * @param TIM_ICInitStruct pointer to a @ref LL_TIM_IC_InitTypeDef structure (the input channel configuration data structure)
  317. * @retval None
  318. */
  319. void LL_TIM_IC_StructInit(LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
  320. {
  321. /* Set the default configuration */
  322. TIM_ICInitStruct->ICPolarity = LL_TIM_IC_POLARITY_RISING;
  323. TIM_ICInitStruct->ICActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
  324. TIM_ICInitStruct->ICPrescaler = LL_TIM_ICPSC_DIV1;
  325. TIM_ICInitStruct->ICFilter = LL_TIM_IC_FILTER_FDIV1;
  326. }
  327. /**
  328. * @brief Configure the TIMx input channel.
  329. * @param TIMx Timer Instance
  330. * @param Channel This parameter can be one of the following values:
  331. * @arg @ref LL_TIM_CHANNEL_CH1
  332. * @arg @ref LL_TIM_CHANNEL_CH2
  333. * @arg @ref LL_TIM_CHANNEL_CH3
  334. * @arg @ref LL_TIM_CHANNEL_CH4
  335. * @param TIM_IC_InitStruct pointer to a @ref LL_TIM_IC_InitTypeDef structure (TIMx input channel configuration data structure)
  336. * @retval An ErrorStatus enumeration value:
  337. * - SUCCESS: TIMx output channel is initialized
  338. * - ERROR: TIMx output channel is not initialized
  339. */
  340. ErrorStatus LL_TIM_IC_Init(TIM_TypeDef *TIMx, uint32_t Channel, LL_TIM_IC_InitTypeDef *TIM_IC_InitStruct)
  341. {
  342. ErrorStatus result = ERROR;
  343. switch (Channel)
  344. {
  345. case LL_TIM_CHANNEL_CH1:
  346. result = IC1Config(TIMx, TIM_IC_InitStruct);
  347. break;
  348. case LL_TIM_CHANNEL_CH2:
  349. result = IC2Config(TIMx, TIM_IC_InitStruct);
  350. break;
  351. case LL_TIM_CHANNEL_CH3:
  352. result = IC3Config(TIMx, TIM_IC_InitStruct);
  353. break;
  354. case LL_TIM_CHANNEL_CH4:
  355. result = IC4Config(TIMx, TIM_IC_InitStruct);
  356. break;
  357. default:
  358. break;
  359. }
  360. return result;
  361. }
  362. /**
  363. * @brief Fills each TIM_EncoderInitStruct field with its default value
  364. * @param TIM_EncoderInitStruct pointer to a @ref LL_TIM_ENCODER_InitTypeDef structure (encoder interface configuration data structure)
  365. * @retval None
  366. */
  367. void LL_TIM_ENCODER_StructInit(LL_TIM_ENCODER_InitTypeDef *TIM_EncoderInitStruct)
  368. {
  369. /* Set the default configuration */
  370. TIM_EncoderInitStruct->EncoderMode = LL_TIM_ENCODERMODE_X2_TI1;
  371. TIM_EncoderInitStruct->IC1Polarity = LL_TIM_IC_POLARITY_RISING;
  372. TIM_EncoderInitStruct->IC1ActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
  373. TIM_EncoderInitStruct->IC1Prescaler = LL_TIM_ICPSC_DIV1;
  374. TIM_EncoderInitStruct->IC1Filter = LL_TIM_IC_FILTER_FDIV1;
  375. TIM_EncoderInitStruct->IC2Polarity = LL_TIM_IC_POLARITY_RISING;
  376. TIM_EncoderInitStruct->IC2ActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
  377. TIM_EncoderInitStruct->IC2Prescaler = LL_TIM_ICPSC_DIV1;
  378. TIM_EncoderInitStruct->IC2Filter = LL_TIM_IC_FILTER_FDIV1;
  379. }
  380. /**
  381. * @brief Configure the encoder interface of the timer instance.
  382. * @param TIMx Timer Instance
  383. * @param TIM_EncoderInitStruct pointer to a @ref LL_TIM_ENCODER_InitTypeDef structure (TIMx encoder interface configuration data structure)
  384. * @retval An ErrorStatus enumeration value:
  385. * - SUCCESS: TIMx registers are de-initialized
  386. * - ERROR: not applicable
  387. */
  388. ErrorStatus LL_TIM_ENCODER_Init(TIM_TypeDef *TIMx, LL_TIM_ENCODER_InitTypeDef *TIM_EncoderInitStruct)
  389. {
  390. uint32_t tmpccmr1 = 0U;
  391. uint32_t tmpccer = 0U;
  392. /* Check the parameters */
  393. assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(TIMx));
  394. assert_param(IS_LL_TIM_ENCODERMODE(TIM_EncoderInitStruct->EncoderMode));
  395. assert_param(IS_LL_TIM_IC_POLARITY_ENCODER(TIM_EncoderInitStruct->IC1Polarity));
  396. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_EncoderInitStruct->IC1ActiveInput));
  397. assert_param(IS_LL_TIM_ICPSC(TIM_EncoderInitStruct->IC1Prescaler));
  398. assert_param(IS_LL_TIM_IC_FILTER(TIM_EncoderInitStruct->IC1Filter));
  399. assert_param(IS_LL_TIM_IC_POLARITY_ENCODER(TIM_EncoderInitStruct->IC2Polarity));
  400. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_EncoderInitStruct->IC2ActiveInput));
  401. assert_param(IS_LL_TIM_ICPSC(TIM_EncoderInitStruct->IC2Prescaler));
  402. assert_param(IS_LL_TIM_IC_FILTER(TIM_EncoderInitStruct->IC2Filter));
  403. /* Disable the CC1 and CC2: Reset the CC1E and CC2E Bits */
  404. TIMx->CCER &= (uint32_t)~(TIM_CCER_CC1E | TIM_CCER_CC2E);
  405. /* Get the TIMx CCMR1 register value */
  406. tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
  407. /* Get the TIMx CCER register value */
  408. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  409. /* Configure TI1 */
  410. tmpccmr1 &= (uint32_t)~(TIM_CCMR1_CC1S | TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC);
  411. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC1ActiveInput >> 16U);
  412. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC1Filter >> 16U);
  413. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC1Prescaler >> 16U);
  414. /* Configure TI2 */
  415. tmpccmr1 &= (uint32_t)~(TIM_CCMR1_CC2S | TIM_CCMR1_IC2F | TIM_CCMR1_IC2PSC);
  416. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC2ActiveInput >> 8U);
  417. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC2Filter >> 8U);
  418. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC2Prescaler >> 8U);
  419. /* Set TI1 and TI2 polarity and enable TI1 and TI2 */
  420. tmpccer &= (uint32_t)~(TIM_CCER_CC1P | TIM_CCER_CC1NP | TIM_CCER_CC2P | TIM_CCER_CC2NP);
  421. tmpccer |= (uint32_t)(TIM_EncoderInitStruct->IC1Polarity);
  422. tmpccer |= (uint32_t)(TIM_EncoderInitStruct->IC2Polarity << 4U);
  423. tmpccer |= (uint32_t)(TIM_CCER_CC1E | TIM_CCER_CC2E);
  424. /* Set encoder mode */
  425. LL_TIM_SetEncoderMode(TIMx, TIM_EncoderInitStruct->EncoderMode);
  426. /* Write to TIMx CCMR1 */
  427. LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
  428. /* Write to TIMx CCER */
  429. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  430. return SUCCESS;
  431. }
  432. /**
  433. * @}
  434. */
  435. /**
  436. * @}
  437. */
  438. /** @addtogroup TIM_LL_Private_Functions TIM Private Functions
  439. * @brief Private functions
  440. * @{
  441. */
  442. /**
  443. * @brief Configure the TIMx output channel 1.
  444. * @param TIMx Timer Instance
  445. * @param TIM_OCInitStruct pointer to the the TIMx output channel 1 configuration data structure
  446. * @retval An ErrorStatus enumeration value:
  447. * - SUCCESS: TIMx registers are de-initialized
  448. * - ERROR: not applicable
  449. */
  450. static ErrorStatus OC1Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  451. {
  452. uint32_t tmpccmr1 = 0U;
  453. uint32_t tmpccer = 0U;
  454. uint32_t tmpcr2 = 0U;
  455. /* Check the parameters */
  456. assert_param(IS_TIM_CC1_INSTANCE(TIMx));
  457. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  458. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  459. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  460. /* Disable the Channel 1: Reset the CC1E Bit */
  461. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC1E);
  462. /* Get the TIMx CCER register value */
  463. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  464. /* Get the TIMx CR2 register value */
  465. tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
  466. /* Get the TIMx CCMR1 register value */
  467. tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
  468. /* Reset Capture/Compare selection Bits */
  469. CLEAR_BIT(tmpccmr1, TIM_CCMR1_CC1S);
  470. /* Set the Output Compare Mode */
  471. MODIFY_REG(tmpccmr1, TIM_CCMR1_OC1M, TIM_OCInitStruct->OCMode);
  472. /* Set the Output Compare Polarity */
  473. MODIFY_REG(tmpccer, TIM_CCER_CC1P, TIM_OCInitStruct->OCPolarity);
  474. /* Set the Output State */
  475. MODIFY_REG(tmpccer, TIM_CCER_CC1E, TIM_OCInitStruct->OCState);
  476. /* Write to TIMx CR2 */
  477. LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
  478. /* Write to TIMx CCMR1 */
  479. LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
  480. /* Set the Capture Compare Register value */
  481. LL_TIM_OC_SetCompareCH1(TIMx, TIM_OCInitStruct->CompareValue);
  482. /* Write to TIMx CCER */
  483. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  484. return SUCCESS;
  485. }
  486. /**
  487. * @brief Configure the TIMx output channel 2.
  488. * @param TIMx Timer Instance
  489. * @param TIM_OCInitStruct pointer to the the TIMx output channel 2 configuration data structure
  490. * @retval An ErrorStatus enumeration value:
  491. * - SUCCESS: TIMx registers are de-initialized
  492. * - ERROR: not applicable
  493. */
  494. static ErrorStatus OC2Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  495. {
  496. uint32_t tmpccmr1 = 0U;
  497. uint32_t tmpccer = 0U;
  498. uint32_t tmpcr2 = 0U;
  499. /* Check the parameters */
  500. assert_param(IS_TIM_CC2_INSTANCE(TIMx));
  501. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  502. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  503. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  504. /* Disable the Channel 2: Reset the CC2E Bit */
  505. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC2E);
  506. /* Get the TIMx CCER register value */
  507. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  508. /* Get the TIMx CR2 register value */
  509. tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
  510. /* Get the TIMx CCMR1 register value */
  511. tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
  512. /* Reset Capture/Compare selection Bits */
  513. CLEAR_BIT(tmpccmr1, TIM_CCMR1_CC2S);
  514. /* Select the Output Compare Mode */
  515. MODIFY_REG(tmpccmr1, TIM_CCMR1_OC2M, TIM_OCInitStruct->OCMode << 8U);
  516. /* Set the Output Compare Polarity */
  517. MODIFY_REG(tmpccer, TIM_CCER_CC2P, TIM_OCInitStruct->OCPolarity << 4U);
  518. /* Set the Output State */
  519. MODIFY_REG(tmpccer, TIM_CCER_CC2E, TIM_OCInitStruct->OCState << 4U);
  520. /* Write to TIMx CR2 */
  521. LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
  522. /* Write to TIMx CCMR1 */
  523. LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
  524. /* Set the Capture Compare Register value */
  525. LL_TIM_OC_SetCompareCH2(TIMx, TIM_OCInitStruct->CompareValue);
  526. /* Write to TIMx CCER */
  527. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  528. return SUCCESS;
  529. }
  530. /**
  531. * @brief Configure the TIMx output channel 3.
  532. * @param TIMx Timer Instance
  533. * @param TIM_OCInitStruct pointer to the the TIMx output channel 3 configuration data structure
  534. * @retval An ErrorStatus enumeration value:
  535. * - SUCCESS: TIMx registers are de-initialized
  536. * - ERROR: not applicable
  537. */
  538. static ErrorStatus OC3Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  539. {
  540. uint32_t tmpccmr2 = 0U;
  541. uint32_t tmpccer = 0U;
  542. uint32_t tmpcr2 = 0U;
  543. /* Check the parameters */
  544. assert_param(IS_TIM_CC3_INSTANCE(TIMx));
  545. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  546. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  547. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  548. /* Disable the Channel 3: Reset the CC3E Bit */
  549. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC3E);
  550. /* Get the TIMx CCER register value */
  551. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  552. /* Get the TIMx CR2 register value */
  553. tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
  554. /* Get the TIMx CCMR2 register value */
  555. tmpccmr2 = LL_TIM_ReadReg(TIMx, CCMR2);
  556. /* Reset Capture/Compare selection Bits */
  557. CLEAR_BIT(tmpccmr2, TIM_CCMR2_CC3S);
  558. /* Select the Output Compare Mode */
  559. MODIFY_REG(tmpccmr2, TIM_CCMR2_OC3M, TIM_OCInitStruct->OCMode);
  560. /* Set the Output Compare Polarity */
  561. MODIFY_REG(tmpccer, TIM_CCER_CC3P, TIM_OCInitStruct->OCPolarity << 8U);
  562. /* Set the Output State */
  563. MODIFY_REG(tmpccer, TIM_CCER_CC3E, TIM_OCInitStruct->OCState << 8U);
  564. /* Write to TIMx CR2 */
  565. LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
  566. /* Write to TIMx CCMR2 */
  567. LL_TIM_WriteReg(TIMx, CCMR2, tmpccmr2);
  568. /* Set the Capture Compare Register value */
  569. LL_TIM_OC_SetCompareCH3(TIMx, TIM_OCInitStruct->CompareValue);
  570. /* Write to TIMx CCER */
  571. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  572. return SUCCESS;
  573. }
  574. /**
  575. * @brief Configure the TIMx output channel 4.
  576. * @param TIMx Timer Instance
  577. * @param TIM_OCInitStruct pointer to the the TIMx output channel 4 configuration data structure
  578. * @retval An ErrorStatus enumeration value:
  579. * - SUCCESS: TIMx registers are de-initialized
  580. * - ERROR: not applicable
  581. */
  582. static ErrorStatus OC4Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  583. {
  584. uint32_t tmpccmr2 = 0U;
  585. uint32_t tmpccer = 0U;
  586. uint32_t tmpcr2 = 0U;
  587. /* Check the parameters */
  588. assert_param(IS_TIM_CC4_INSTANCE(TIMx));
  589. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  590. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  591. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  592. /* Disable the Channel 4: Reset the CC4E Bit */
  593. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC4E);
  594. /* Get the TIMx CCER register value */
  595. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  596. /* Get the TIMx CR2 register value */
  597. tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
  598. /* Get the TIMx CCMR2 register value */
  599. tmpccmr2 = LL_TIM_ReadReg(TIMx, CCMR2);
  600. /* Reset Capture/Compare selection Bits */
  601. CLEAR_BIT(tmpccmr2, TIM_CCMR2_CC4S);
  602. /* Select the Output Compare Mode */
  603. MODIFY_REG(tmpccmr2, TIM_CCMR2_OC4M, TIM_OCInitStruct->OCMode << 8U);
  604. /* Set the Output Compare Polarity */
  605. MODIFY_REG(tmpccer, TIM_CCER_CC4P, TIM_OCInitStruct->OCPolarity << 12U);
  606. /* Set the Output State */
  607. MODIFY_REG(tmpccer, TIM_CCER_CC4E, TIM_OCInitStruct->OCState << 12U);
  608. /* Write to TIMx CR2 */
  609. LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
  610. /* Write to TIMx CCMR2 */
  611. LL_TIM_WriteReg(TIMx, CCMR2, tmpccmr2);
  612. /* Set the Capture Compare Register value */
  613. LL_TIM_OC_SetCompareCH4(TIMx, TIM_OCInitStruct->CompareValue);
  614. /* Write to TIMx CCER */
  615. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  616. return SUCCESS;
  617. }
  618. /**
  619. * @brief Configure the TIMx input channel 1.
  620. * @param TIMx Timer Instance
  621. * @param TIM_ICInitStruct pointer to the the TIMx input channel 1 configuration data structure
  622. * @retval An ErrorStatus enumeration value:
  623. * - SUCCESS: TIMx registers are de-initialized
  624. * - ERROR: not applicable
  625. */
  626. static ErrorStatus IC1Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
  627. {
  628. /* Check the parameters */
  629. assert_param(IS_TIM_CC1_INSTANCE(TIMx));
  630. assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
  631. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
  632. assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
  633. assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
  634. /* Disable the Channel 1: Reset the CC1E Bit */
  635. TIMx->CCER &= (uint32_t)~TIM_CCER_CC1E;
  636. /* Select the Input and set the filter and the prescaler value */
  637. MODIFY_REG(TIMx->CCMR1,
  638. (TIM_CCMR1_CC1S | TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC),
  639. (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 16U);
  640. /* Select the Polarity and set the CC1E Bit */
  641. MODIFY_REG(TIMx->CCER,
  642. (TIM_CCER_CC1P | TIM_CCER_CC1NP),
  643. (TIM_ICInitStruct->ICPolarity | TIM_CCER_CC1E));
  644. return SUCCESS;
  645. }
  646. /**
  647. * @brief Configure the TIMx input channel 2.
  648. * @param TIMx Timer Instance
  649. * @param TIM_ICInitStruct pointer to the the TIMx input channel 2 configuration data structure
  650. * @retval An ErrorStatus enumeration value:
  651. * - SUCCESS: TIMx registers are de-initialized
  652. * - ERROR: not applicable
  653. */
  654. static ErrorStatus IC2Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
  655. {
  656. /* Check the parameters */
  657. assert_param(IS_TIM_CC2_INSTANCE(TIMx));
  658. assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
  659. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
  660. assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
  661. assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
  662. /* Disable the Channel 2: Reset the CC2E Bit */
  663. TIMx->CCER &= (uint32_t)~TIM_CCER_CC2E;
  664. /* Select the Input and set the filter and the prescaler value */
  665. MODIFY_REG(TIMx->CCMR1,
  666. (TIM_CCMR1_CC2S | TIM_CCMR1_IC2F | TIM_CCMR1_IC2PSC),
  667. (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 8U);
  668. /* Select the Polarity and set the CC2E Bit */
  669. MODIFY_REG(TIMx->CCER,
  670. (TIM_CCER_CC2P | TIM_CCER_CC2NP),
  671. ((TIM_ICInitStruct->ICPolarity << 4U) | TIM_CCER_CC2E));
  672. return SUCCESS;
  673. }
  674. /**
  675. * @brief Configure the TIMx input channel 3.
  676. * @param TIMx Timer Instance
  677. * @param TIM_ICInitStruct pointer to the the TIMx input channel 3 configuration data structure
  678. * @retval An ErrorStatus enumeration value:
  679. * - SUCCESS: TIMx registers are de-initialized
  680. * - ERROR: not applicable
  681. */
  682. static ErrorStatus IC3Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
  683. {
  684. /* Check the parameters */
  685. assert_param(IS_TIM_CC3_INSTANCE(TIMx));
  686. assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
  687. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
  688. assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
  689. assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
  690. /* Disable the Channel 3: Reset the CC3E Bit */
  691. TIMx->CCER &= (uint32_t)~TIM_CCER_CC3E;
  692. /* Select the Input and set the filter and the prescaler value */
  693. MODIFY_REG(TIMx->CCMR2,
  694. (TIM_CCMR2_CC3S | TIM_CCMR2_IC3F | TIM_CCMR2_IC3PSC),
  695. (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 16U);
  696. /* Select the Polarity and set the CC3E Bit */
  697. MODIFY_REG(TIMx->CCER,
  698. (TIM_CCER_CC3P | TIM_CCER_CC3NP),
  699. ((TIM_ICInitStruct->ICPolarity << 8U) | TIM_CCER_CC3E));
  700. return SUCCESS;
  701. }
  702. /**
  703. * @brief Configure the TIMx input channel 4.
  704. * @param TIMx Timer Instance
  705. * @param TIM_ICInitStruct pointer to the the TIMx input channel 4 configuration data structure
  706. * @retval An ErrorStatus enumeration value:
  707. * - SUCCESS: TIMx registers are de-initialized
  708. * - ERROR: not applicable
  709. */
  710. static ErrorStatus IC4Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
  711. {
  712. /* Check the parameters */
  713. assert_param(IS_TIM_CC4_INSTANCE(TIMx));
  714. assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
  715. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
  716. assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
  717. assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
  718. /* Disable the Channel 4: Reset the CC4E Bit */
  719. TIMx->CCER &= (uint32_t)~TIM_CCER_CC4E;
  720. /* Select the Input and set the filter and the prescaler value */
  721. MODIFY_REG(TIMx->CCMR2,
  722. (TIM_CCMR2_CC4S | TIM_CCMR2_IC4F | TIM_CCMR2_IC4PSC),
  723. (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 8U);
  724. /* Select the Polarity and set the CC2E Bit */
  725. MODIFY_REG(TIMx->CCER,
  726. (TIM_CCER_CC4P | TIM_CCER_CC4NP),
  727. ((TIM_ICInitStruct->ICPolarity << 12U) | TIM_CCER_CC4E));
  728. return SUCCESS;
  729. }
  730. /**
  731. * @}
  732. */
  733. /**
  734. * @}
  735. */
  736. #endif /* TIM2 || TIM3 || TIM4 || TIM5 || TIM9 || TIM10 || TIM11 TIM6 || TIM7 */
  737. /**
  738. * @}
  739. */
  740. #endif /* USE_FULL_LL_DRIVER */
  741. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/